Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imaplib/gmail how to download full message (all parts) while not marking read [duplicate]

I inadvertently marked all the messages in my inbox as read with this python statement:

status, data = conn.uid('fetch', fetch_uids, '(RFC822)')

But I was able to walk through all the parts of the message with the following set of statments:

email_message = email.message_from_string(data[0][1])
for part in email_message.walk():
  print '\n'
  print 'Content-Type:',part.get_content_type()
  print 'Main Content:',part.get_content_maintype()
  print 'Sub Content:',part.get_content_subtype()

The output:

Content-Type: multipart/mixed
Main Content: multipart
Sub Content: mixed


Content-Type: multipart/alternative
Main Content: multipart
Sub Content: alternative


Content-Type: text/plain
Main Content: text
Sub Content: plain


Content-Type: text/html
Main Content: text
Sub Content: html

I found that if I used this statement instead:

status, data = conn.uid('fetch', fetch_uids, '(RFC822.HEADER BODY.PEEK[1])')

that I wouldn't mark all of my messages read. However, I also wouldn't get all the parts of the message:

Content-Type: multipart/mixed
Main Content: multipart
Sub Content: mixed

I tried to read the manual for imaplib here, but the word "peek" is not mentioned. My question is, how do I get all the parts of the message while not marking my messages as read? Thanks.

like image 247
nomadicME Avatar asked Jun 12 '12 06:06

nomadicME


2 Answers

You can also open the mailbox in readonly mode. select(folder, readonly=True)

like image 157
Seraj Ahmad Avatar answered Sep 29 '22 05:09

Seraj Ahmad


I guess if you just keep trying enough combinations, you'll find your answer:

status, data = conn.uid('fetch', fetch_ids, '(RFC822 BODY.PEEK[])')

Along the way I found a lot of information in the RFC 1730 manual.

like image 31
nomadicME Avatar answered Sep 29 '22 04:09

nomadicME