[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Net/IMAP and FLAGGED messages

clegault

5/28/2009 5:22:00 PM

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
3 Answers

Jens Wille

5/28/2009 9:17:00 PM

0

hi collin!

clegault@gmail.com [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: jens.wille@uni-koeln.de
http://www.prometheus-bild...

Eric Hodel

5/28/2009 9:25:00 PM

0

On May 28, 2009, at 10:25, clegault@gmail.com 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...

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.

clegault

5/28/2009 9:43:00 PM

0

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

Thanks,
coLLin