Class: EasyIMAP::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_imap/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn, uid) ⇒ Message

Returns a new instance of Message.



7
8
9
10
# File 'lib/easy_imap/message.rb', line 7

def initialize(conn, uid)
  @conn = conn
  @uid = uid
end

Instance Method Details

#attachmentsObject

An array of Attachment instances if this message is a multipart message with attachments, or an empty array otherwise.



83
84
85
86
87
88
89
# File 'lib/easy_imap/message.rb', line 83

def attachments
  @attachments ||= if body.multipart?
    body.parts.find_all{|p| p.disposition == "attachment"}.map{|a| Attachment.new(a)}
  else
    []
  end
end

#bccObject

An array of bcc e-mail addresses (as Strings).



48
49
50
# File 'lib/easy_imap/message.rb', line 48

def bcc
  (envelope[:bcc] || []).map {|a| address(a)}
end

#ccObject

An array of cc e-mail addresses (as Strings).



43
44
45
# File 'lib/easy_imap/message.rb', line 43

def cc
  (envelope[:cc] || []).map {|a| address(a)}
end

#dateObject

The date this message was sent (an instance of Time).



13
14
15
# File 'lib/easy_imap/message.rb', line 13

def date
  Time.parse(envelope[:date])
end

#fromObject

An array of from e-mail addresses (as Strings).



23
24
25
# File 'lib/easy_imap/message.rb', line 23

def from
  (envelope[:from] || []).map {|a| address(a)}
end

#htmlObject

Returns the text/html portion of this message (which could be the body, or one of the parts if the message is multipart), or the empty string if there is no text/html portion.



75
76
77
78
# File 'lib/easy_imap/message.rb', line 75

def html
  html = find_part("text/html")
  html ? html.body : ""
end

#in_reply_toObject

The in_reply_to attribute (as a String).



53
54
55
# File 'lib/easy_imap/message.rb', line 53

def in_reply_to
  envelope[:in_reply_to]
end

#multipart?Boolean

Returns true if this message is a multipart message.

Returns:

  • (Boolean)


58
59
60
# File 'lib/easy_imap/message.rb', line 58

def multipart?
  body.multipart?
end

#reply_toObject

An array of reply_to e-mail addresses (as Strings).



33
34
35
# File 'lib/easy_imap/message.rb', line 33

def reply_to
  (envelope[:reply_to] || []).map{|a| address(a)}
end

#senderObject

An array of sender e-mail addresses (as Strings).



28
29
30
# File 'lib/easy_imap/message.rb', line 28

def sender
  (envelope[:sender] || []).map{|a| address(a)}
end

#subjectObject

The subject of this message.



18
19
20
# File 'lib/easy_imap/message.rb', line 18

def subject
  envelope[:subject]
end

#textObject

Returns the text/plain portion of this message (which could be the body, or one of the parts if the message is multipart), or the empty string if there is no text/plain portion.



66
67
68
69
# File 'lib/easy_imap/message.rb', line 66

def text
  text = find_part("text/plain")
  text ? text.body : ""
end

#toObject

An array of to e-mail addresses (as Strings).



38
39
40
# File 'lib/easy_imap/message.rb', line 38

def to
  (envelope[:to] || []).map {|a| address(a)}
end