[英]How do I determine if an email is Base64 encoded?
我很难确定文本电子邮件的正文是否是 base64 编码的。 如果是,则使用这行代码; 使用 jython 2.2.1
dirty=base64.decodebytes(dirty)
否则继续正常。
这是我有 atm 的代码。 哪行代码将允许我从电子邮件中提取此内容:
“内容传输编码:base64”
import email, email.Message
import base64
def _get_email_body(self):
try:
parts=self._email.get_payload()
check=parts[0].get_content_type()
if check=="text/plain":
part=parts[0].get_payload()
enc = part[0]['Content-Transfer-Encoding']
if enc == "base64":
dirty=base64.decodebytes(dirty)
elif check=="multipart/alternative":
part=parts[0].get_payload()
enc = part[0]['Content-Transfer-Encoding']
if part[0].get_content_type()=="text/plain":
dirty=part[0].get_payload()
if enc == "base64":
dirty=base64.decodebytes(dirty)
else:
return "cannot obtain the body of the email"
else:
return "cannot obtain the body of the email"
return dirty
except:
raise
OKAY 这段代码现在可以工作了! 谢谢大家
尝试:
enc = msg['Content-Transfer-Encoding']
这是一个标题,所以你将无法看到它的身体。 你应该能够在你找到主题的同一个地方找到。
它是一个标头,但您必须首先从消息中获取有效负载。
这将是:
header = msg.get_payload()[0]
header['Content-Transfer-Encoding']
我正在使用 Python 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.