0

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

Ali
  • 4,311
  • 11
  • 44
  • 49

2 Answers2

3

Use PEEK instead. For example, something like:

typ, data = imap_conn.fetch(uid, '(BODY.PEEK[TEXT])')
ars
  • 120,335
  • 23
  • 147
  • 134
  • 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 Sep 30 '10 at 19:42
  • 1
    @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 Sep 30 '10 at 19:50
  • 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 Sep 30 '10 at 20:18
  • 1
    @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 Sep 30 '10 at 20:39
  • For what it's worth, the PyMOTW stuff is now available at https://pymotw.com/2/imaplib/ – tripleee Jun 22 '16 at 08:18
1

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.

Community
  • 1
  • 1
pyfunc
  • 65,343
  • 15
  • 148
  • 136