如何确定电子邮件是否经过Base64编码? [英] How do I determine if an email is Base64 encoded?
本文介绍了如何确定电子邮件是否经过Base64编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难确定文本电子邮件的正文是否为base64编码. 如果是,则使用以下代码行; 利用jython 2.2.1
I am having difficulty determining if the body of a text email message is base64 encoded. if it is then use this line of code; making use of jython 2.2.1
dirty=base64.decodestring(dirty)
其他都照常进行.
这是我有atm的代码.哪行代码可以让我从电子邮件中提取出来:
This is the code I have atm. What line of code will allow me to extract this from the email:
"Content-Transfer-Encoding:base64"
"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
好的,此代码现在可以使用!谢谢大家
OKAY this code works now! thanks all
推荐答案
尝试:
enc = msg['Content-Transfer-Encoding']
这是一个标头,因此您将无法看到它.您应该能够到达找到主题的地方.
It's a header so you won't be able to get it looking at the body. You should be able to get at the same place you find out the Subject.
这篇关于如何确定电子邮件是否经过Base64编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文