Net/IMAP and FLAGGED messages

C

clegault

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
 
J

Jens Wille

hi collin!

(e-mail address removed) [2009-05-28 19:25]:
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?
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

--
Jens Wille, Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
Kunsthistorisches Institut der Universität zu Köln
Albertus-Magnus-Platz, D-50923 Köln
Tel.: +49 (0)221 470-6668, E-Mail: (e-mail address removed)
http://www.prometheus-bildarchiv.de/
 
E

Eric Hodel

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.
 
T

Tigrao

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

Thanks,
coLLin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top