【发布时间】:2010-09-24 09:50:06
【问题描述】:
我很难确定文本电子邮件的正文是否为 base64 编码。 如果是,则使用这行代码; 使用 jython 2.2.1
dirty=base64.decodebytes(dirty)
否则照常继续。
这是我的自动取款机代码。哪行代码可以让我从电子邮件中提取:
“内容传输编码: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
好的,这段代码现在可以工作了!谢谢大家
【问题讨论】:
-
如果您能告诉我们您正在使用什么 MIME 库对象,这将有助于人们回答您。您使用的是 Python 库还是 Java 对象?
-
好的,谢谢你的提醒,这个通常很好!
标签: python email encoding jython email-headers