简体   繁体   English

Python:解码7位或8位编码的电子邮件正文

[英]Python: decode 7bit or 8bit encoded email body

https://docs.python.org/2/library/email.encoders.html lists way to encode the email payload. https://docs.python.org/2/library/email.encoders.html列出了编码电子邮件有效负载的方法。 Is there a way to decode the payload that was received over email? 有没有办法解码通过电子邮件收到的有效负载?

I need to decode the html body from the email encoded in base64 or 7/8bit or quoted printable formats and mine some data. 我需要从以base64或7 / 8bit或引用的可打印格式编码的电子邮件中解码html正文,并挖掘一些数据。 Luckily there are modules that can deal with quoted printable(quopri) and base64 formats. 幸运的是,有些模块可以处理引用的printable(quopri)和base64格式。

I tried finding one for the 7/8bit encoded emails, but was unable to find anything satisfactory. 我尝试为7/8位编码的电子邮件找到一个,但是找不到满意的邮件。 What is the best way to decode such email payloads? 解码此类电子邮件有效载荷的最佳方法是什么?

Looks like the easiest way to decode 7bit data is to use the quopri module in python. 看起来,解码7位数据的最简单方法是在python中使用quopri模块。 Essentially quoted-printable is a format which is used to send 8bit data over a 7bit channel. 本质上引号可打印是一种用于通过7位通道发送8位数据的格式。 The code below is working well for me: 下面的代码对我来说运行良好:

import quopri
quopri.decodestring(email_multipart_payload) # payload has 7bit encoded data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM