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

╄→尐↘猪︶ㄣ 提交于 2019-12-05 11:28:23

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

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.

I think I am talking to myself, just in a formal way. :)

I think I really found the answer this time:

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

This does everything that I was looking for. It does not mark the message as read (Seen), and it retrieves all parts of the message.

Looking at the RFC 1730 manual it seemed like this should have worked:

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

but that produced an error as well???

If you want just the headers, but still want the message to be left marked unread (UNSEEN), it requires two commands fetch and then store:

# get uids of unseen messages
result, uids = conn.uid('search', None, '(UNSEEN)')

# convert these uids to a comma separated list
fetch_ids = ','.join(uids[0].split())

# first fetch the headers, this will mark them read (SEEN)
status, headers = conn.uid('fetch', fetch_ids, '(RFC822.HEADER)')

# now mark each message unread (UNSEEN)
status1, flags = conn.uid('store', fetch_ids,'-FLAGS','\\Seen')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!