使用Python显示电子邮件的完整原始来源 [英] Show the full original source of an email with Python

查看:60
本文介绍了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆