如何确定电子邮件是否经过 Base64 编码?
我很难确定文本电子邮件的正文是否采用 Base64 编码。 如果是,则使用这行代码; 使用 jython 2.2.1
dirty=base64.decodebytes(dirty)
,否则继续正常。
这是我atm 上的代码。 哪一行代码可以让我从电子邮件中提取此内容:
“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
好的,此代码现在可以使用了! 谢谢大家
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.decodebytes(dirty)
else continue as normal.
This is the code I have atm. What line of code will allow me to extract this from the email:
"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
OKAY this code works now! thanks all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
它是一个标题,因此您无法通过正文来获取它。 您应该能够到达找到主题的同一位置。
Try:
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.
它是一个标头,但您必须首先从消息中获取有效负载。
它将是:
我正在使用 Python 3
It is a header but you have to get the payload first from the message.
It'll be:
I'm using Python 3