如何在Python中解码二进制编码的邮件消息?
我正在编写一个处理传入邮件的Google应用程序引擎应用程序,下面是我当前用于处理邮件消息的代码:如何在Python中解码二进制编码的邮件消息?,python,google-app-engine,email,encoding,binary,Python,Google App Engine,Email,Encoding,Binary,我正在编写一个处理传入邮件的Google应用程序引擎应用程序,下面是我当前用于处理邮件消息的代码: for content_type, body in email_bodies: #8bit bug in mail messages - see bug report here #http://code.google.com/p/googleappengine/issues/detail?id=2383 if body.encoding == '8bit': body.encoding =
for content_type, body in email_bodies:
#8bit bug in mail messages - see bug report here
#http://code.google.com/p/googleappengine/issues/detail?id=2383
if body.encoding == '8bit':
body.encoding = '7bit'
#test for html content
if content_type == "text/html":
#parse html result
if content_type == "text/plain":
decoded_msg_body = body.decode()
然而,我刚刚得到一条使用二进制编码方案的消息,当我的程序试图使用body.decode()处理该消息时,我收到一个未知的编码错误。这个程序应该如何解析二进制内容类型?另外,我如何在本地版本的GAE上模拟这种消息类型,以便调试和测试它
我感谢你的帮助,
Kevin与其重新发明轮子,不如试试Python内置的电子邮件解析器 它旨在处理将各种不同的电子邮件格式转换成一个好的Python对象所涉及的提升。使用它进行解析,您将获得可预测的对象
电子邮件模块不进行消息发送和接收,它只是帮助将它们放在一起并解析出来。如果您使用消息的“原始”属性,它将在GAE上工作,这很公平。谢谢,保罗,太棒了。我不确定这奇怪的案件处理有多好,但考虑到这些事情通常是如何运作的,我认为这可能是一个好机会。