Flowdock
fetch(set, attr) public

Sends a FETCH command to retrieve data associated with a message in the mailbox.

The set parameter is a number or a range between two numbers, or an array of those. The number is a message sequence number, where -1 repesents a ‘*’ for use in range notation like 100..-1 being interpreted as ‘100:*’. Beware that the exclude_end? property of a Range object is ignored, and the contents of a range are independent of the order of the range endpoints as per the protocol specification, so 1…5, 5..1 and 5…1 are all equivalent to 1..5.

attr is a list of attributes to fetch; see the documentation for Net::IMAP::FetchData for a list of valid attributes.

The return value is an array of Net::IMAP::FetchData or nil (instead of an empty array) if there is no matching message.

For example:

p imap.fetch(6..8, "UID")
#=> [#<Net::IMAP::FetchData seqno=6, attr={"UID"=>98}>, \\
     #<Net::IMAP::FetchData seqno=7, attr={"UID"=>99}>, \\
     #<Net::IMAP::FetchData seqno=8, attr={"UID"=>100}>]
p imap.fetch(6, "BODY[HEADER.FIELDS (SUBJECT)]")
#=> [#<Net::IMAP::FetchData seqno=6, attr={"BODY[HEADER.FIELDS (SUBJECT)]"=>"Subject: test\r\n\r\n"}>]
data = imap.uid_fetch(98, ["RFC822.SIZE", "INTERNALDATE"])[0]
p data.seqno
#=> 6
p data.attr["RFC822.SIZE"]
#=> 611
p data.attr["INTERNALDATE"]
#=> "12-Oct-2000 22:40:59 +0900"
p data.attr["UID"]
#=> 98
Show source
Register or log in to add new notes.