使用Python显示电子邮件的完整原始来源 [英] Show the full original source of an email with Python
问题描述
如果 message
是Python email.message.EmailMessage
对象(或旧版 email.massage.Message
类(来自Python 3.5之前的版本),只需调用其 .as_string()
方法.
有效载荷方法特别地仅提取一个MIME部分.
The main answer of Reading the mail content of an mbox file using python mailbox shows how to display the content of an email from a .mbox file:
if message.is_multipart():
content = ''.join(part.get_payload(decode=True) for part in message.get_payload())
else:
content = message.get_payload(decode=True)
However this does not show the "full original source" of the email ; I mean what we can have in nearly all webmails when clicking "Show original message":
Delivered-To: ...
Return-Path: ...
...
How to get this with Python mailbox
?
If message
is a Python email.message.EmailMessage
object (or the legacy email.massage.Message
class from before Python 3.5), simply call its .as_string()
method.
The payload method quite specifically extracts only one MIME part.
这篇关于使用Python显示电子邮件的完整原始来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!