我很难确定文本电子邮件的正文是否是base64编码的。 如果是,那么就用这一行代码; 利用jython 2.2.1
dirty=base64.decodestring(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.decodestring(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.decodestring(dirty)
else:
return "cannot obtain the body of the email"
else:
return "cannot obtain the body of the email"
return dirty
except:
raise
好的,这个代码现在生效了!谢谢大家
尝试:
这是一个头球,所以你不能让它看尸体。你应该能在同一个地方找到主题。
它是一个头,但是您必须首先从消息中获取有效负载。
会是:
header=msg.get_payload()[0]
标题['Content-Transfer-Encoding']
我在用Python 3
相关问题 更多 >
编程相关推荐