Net/IMAP and FLAGGED messages

Hi,

I have been trying to find some example of how to check for the X-
Priority flag using Net/IMAP in ruby. I have tried to do a search for
it:

imap.search([“FLAGGED”]).collect

And I have tried to do a fetch on a given message to try to find it:

fetch_result = imap.fetch(msgID, [“UID”, “FLAGGED”])

I can’t find any example of this anywhere, and the docs for Net/IMAP
just simply say “Flag indicating a message has been flagged for
special or urgent attention”.

Does anyone have some example of how I can retrieve this information?

Thanks,
coLLin

hi collin!

[email protected] [2009-05-28 19:25]:

I can’t find any example of this anywhere, and the docs for
Net/IMAP just simply say “Flag indicating a message has been
flagged for special or urgent attention”.

Does anyone have some example of how I can retrieve this
information?
you’re talking about the X-Priority header, right? then something
like this should work:

fetch message header (see Net::IMAP::FetchData)

msg_header = imap.fetch(msgID, ‘RFC822.HEADER’).
first.attr[‘RFC822.HEADER’]

turn it into a hash

headers = Hash[*msg_header.split(/\r\n|: /)]

and retrieve the desired header value

priority = headers[‘X-Priority’]

hth
jens

On May 28, 2009, at 10:25, [email protected] wrote:

I have been trying to find some example of how to check for the X-
Priority flag using Net/IMAP in ruby.

X-Priority is not an IMAP flag, it is a message header. Flags are
stored separately from message headers and have nothing to do with
each other. Note that IMAP has several flags including \Flagged,
\Deleted, \Draft, etc. and keywords which are arbitrary text. None of
these have anything to do with message headers.

I have tried to do a search for it:

imap.search([“FLAGGED”]).collect

This search will give you messages you have flagged in your email
client, usually with a little orange flag icon.

You want this search to get messages with the X-Priority header:

imap.search [‘HEADER’, ‘X-Priority’, ‘’]

See RFC 3501 section 6.4.4

And I have tried to do a fetch on a given message to try to find it:

fetch_result = imap.fetch(msgID, [“UID”, “FLAGGED”])

There’s no “FLAGGED” fetch term.

If you only want to get the X-Priority value, this is sufficient:

BODY[HEADER.FIELDS (X-Priority)]

See RFC 3501 section 6.4.5

Beware bug 1496, as a workaround you can wrap this in
Net::IMAP::RawData.new if you’re fetching more than one item.

http://redmine.ruby-lang.org/issues/show/1496

Also, given that you have the UID already, you can use #zip to match a
response to its UID.

I can’t find any example of this anywhere, and the docs for Net/IMAP
just simply say “Flag indicating a message has been flagged for
special or urgent attention”.

Does anyone have some example of how I can retrieve this information?

See the imap_processor gem and the imap_to_rss gem.

Thanks Jens and Eric, this is exactly the information I was looking
for. I really appreciate all your help!

Thanks,
coLLin