Show the full original source of an email with Python

拜拜、爱过 提交于 2020-01-16 08:06:33

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/59681576/show-the-full-original-source-of-an-email-with-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!