我无意中将收件箱中的所有邮件标记为已使用以下 python 语句读取:
status, data = conn.uid('fetch', fetch_uids, '(RFC822)')
但我能够通过以下一组语句浏览该消息的所有部分:
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()
输出:
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
我发现如果我用这个语句来代替:
status, data = conn.uid('fetch', fetch_uids, '(RFC822.HEADER BODY.PEEK[1])')
我不会将所有消息标记为已读。但是,我也不会收到消息的所有部分:
Content-Type: multipart/mixed
Main Content: multipart
Sub Content: mixed
我尝试阅读 imaplib 的手册here http://docs.python.org/release/2.6.5/library/imaplib.html,但没有提到“偷看”这个词。我的问题是,如何获取消息的所有部分而不将消息标记为已读?谢谢。