我很难确定文本电子邮件消息的正文是否是base64编码的。 如果是,使用以下代码行; 利用jython 2.2.1
dirty=base64.decodebytes(dirty)
否则继续正常运行。
这是我目前的代码。哪一行代码可以让我从电子邮件中提取这个内容:
"Content-Transfer-Encoding: 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
好的,这段代码现在可以正常工作了!谢谢大家