Set*_*ori 4 python email encoding jython email-headers
我很难确定文本电子邮件的正文是否为base64编码.如果它然后使用这行代码; 利用jython 2.2.1
dirty=base64.decodestring(dirty)
Run Code Online (Sandbox Code Playgroud)
否则继续正常.
这是我的代码.哪些代码行允许我从电子邮件中提取此内容:
"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.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
Run Code Online (Sandbox Code Playgroud)
好了,这个代码现在可以使用!谢谢大家
尝试:
enc = msg['Content-Transfer-Encoding']
Run Code Online (Sandbox Code Playgroud)
这是一个标题,所以你将无法看到它的身体.你应该能够找到你找到主题的同一个地方.
| 归档时间: |
|
| 查看次数: |
6747 次 |
| 最近记录: |