有没有办法在用Content-Type: message/partial
编码的Python电子邮件中重新组合(即“{3}}”的“7.3.2。消息/部分子类型”部分?
特别是,给定一组RFC 1521,如何将它们合并回原始版本?即。
emails = [...] # a list of `email`.
reassembled_email = merge_emails(emails)
merge_emails
必须做什么?有没有Python项目完成这个?
人们可以期待像这样的电子邮件:
From: me@example.com To: me2@example.com Date: Wed, 30 Jun 2010 14:19:45 -0400 MIME-Version: 1.0 Content-Type: message/partial; id="TAN_U_R<0.0000749046c4>"; number=1; total=2 From: me@example.com Subject: To: me2@example.com Date: Wed, 30 Jun 2010 14:19:45 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DC_BOUND_PRE_<1277921980.0000744>" This is a multi-part message in MIME format. --DC_BOUND_PRE_<1277921980.0000c4> Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit This E-mail was sent from Your Printer Some random text. --DC_BOUND_PRE_<1277921980.0000744> Content-Type: application/pdf; name="abcdef.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="abcdef.pdf" JVBERi0xLjMKJZKgoooKNCAwIG9iago8PC9UeXBlL1hPYmplY3QKL1N1YnR5cGUvSW1hZ2UK ...
这是我最初的想法:
from email import parser
def merge_emails(emails):
# we can presume emails are ordered correctly and all the parts accounted for
content = ''
for eml im emails:
content += emails.get_payload()
return parser.Parser().parsestr(content)
这会有用吗(就这么简单)?你怎么能重新组合这封电子邮件?
作为在Python中执行此操作的替代方法,是否有命令行Unix / Mac OS X程序可以执行此操作?
感谢您阅读以及您可能提供的任何信息。
亲切的问候,
布赖恩
答案 0 :(得分:3)
以下为我工作:( Ubuntu Linux + Thunderbird)
答案 1 :(得分:2)
虽然不是Python解决方案,但程序uudeview在重新组装message/partial
电子邮件方面非常有帮助。