我正在编写一个脚本来处理电子邮件,并且我可以访问电子邮件的原始字符串内容。
我目前正在寻找字符串“Content-Transfer-Encoding:”并扫描紧随其后的字符,以确定编码。编码示例:base64 或 7bit 或引用打印 ..
有没有更好的方法来自动确定电子邮件编码(至少是一种更Pythonic的方法)?
谢谢。
您可以使用这个标准 Python 包:email https://docs.python.org/2/library/email.html.
例如:
import email
raw = """From: John Doe <[email protected] /cdn-cgi/l/email-protection>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Hi there!
"""
my_email = email.message_from_string(raw)
print my_email["Content-Transfer-Encoding"]
查看其他示例here https://docs.python.org/3/library/email-examples.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)