重新组装以“消息/部分”编码的电子邮件消息使用Python
有没有办法在用 Content-Type: message/partial
编码的 Python 电子邮件中重新组装(即 RFC 1521)?
特别是,给定一组 电子邮件,如何将它们合并回原创的?即
emails = [...] # a list of `email`.
reassembled_email = merge_emails(emails)
merge_emails
有什么作用?有Python项目做过这个吗?
人们可以期待这样一封电子邮件:
From: [email protected] To: [email protected] 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: [email protected] Subject: To: [email protected] 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 程序可以执行此操作?
感谢您的阅读以及您可能提供的任何信息。
亲切的问候,
布莱恩
Is there a way to reassemble in Python email messages that are encoded with Content-Type: message/partial
(i.e. section '7.3.2. The Message/Partial subtype' of RFC 1521)?
In particular, given a set of emails, how can one merge them back into an original? i.e.
emails = [...] # a list of `email`.
reassembled_email = merge_emails(emails)
What does merge_emails
have to do? Has any Python project done this?
One can expect an email like-so:
From: [email protected] To: [email protected] 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: [email protected] Subject: To: [email protected] 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 ...
Here's my initial thought:
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)
Will this work (is it that simple)? How can you one reassemble this email?
As an alternative to doing this in Python, is there a command-line Unix/Mac OS X program that will do it?
Thank you for reading and any information you may be able to provide.
Kind regards,
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下对我有用:(Ubuntu Linux + Thunderbird)
Following works for me: (Ubuntu Linux + Thunderbird)
虽然不是 Python 解决方案,但程序 uudeview 在重新组装
消息/部分
电子邮件。While not a Python solution, the program uudeview has been very helpful in reassembling
message/partial
email.