tags:

views:

52

answers:

2

I am using the imap library to access my unread messages on gmail and to print out the subjects, is there a way to make sure that the messages being read are still tagged as unread.

Thanks

+2  A: 

Use PEEK instead. For example, something like:

typ, data = imap_conn.fetch(uid, '(BODY.PEEK[TEXT])')
ars
Can you tell me where in the docs this function is located: BODY.PEEK[TEXT]) So I can see which other options are available.
Ali
@Ali: it's actually part of the IMAP spec: http://tools.ietf.org/html/rfc2060.html -- also see the IMAP PyMOTW blog post which might be useful: http://blog.doughellmann.com/2008/09/pymotw-imaplib.html (though it appears to be down at the moment).
ars
My code was: b,response2 = M.fetch(e_id,'RFC822') msg = HeaderParser().parsestr(response2[0][1]) print msg['From']so I should now change the first line to the code you gave?
Ali
@Ali: It looks like you want the headers too, so you can say `fetch(id, 'BODY.PEEK[]')` and it should work. (The `TEXT` section simply retrieves the email text.)
ars
+1  A: 

For info, Yours is an inverse question of this one

Use peek, so that you do not affect the message.

But you should also be able to tag the message as unseen.

pyfunc