如何在python中检测编码电子邮件主题并对其进行解码?我在PHP中看到代码mb_decode_mimeheader();但不是python中的地图代码。
这是我的代码:
print "=============Subject==============="
print mystr = email_message['Subject']
这是输出:
=============Subject===============
'=?UTF-8?Q?Fry=27s=2DDay=20Deal=20Alert=21=20 More=20Smokin?=^M
=?UTF-8?Q?=27=20HOT=20Summer=20Deals=20Have=20 Arrived=21=20=24299=205?=^M
=?UTF-8?Q?5=2DInch=20RCA=20Full=20HD=20 LED=20TV=20=7C=20FREE=20Kasper?=^M
=?UTF-8?Q?sky=20Internet=20 Security=202016=2A=20=26=20Much=20More?='
这是我想要的电子邮件显示主题(> 75): 炒股交易警报!更多Smokin'热门夏季优惠已经到来! $ 299 55英寸RCA全高清LED电视|免费卡巴斯基互联网安全2016 *&多得多 谢谢你的帮助!
答案 0 :(得分:0)
也许您可以使用decode_header之类的:
>>> from email.header import decode_header
>>> decode_header(email_message['Subject'])
[(b"Fry's-Day Deal Alert! More Smokin", 'utf-8'),
(b'^M', None),
(b"' HOT Summer Deals Have Arrived! $299 5", 'utf-8'),
(b'^M', None),
(b'5-Inch RCA Full HD LED TV | FREE Kasper', 'utf-8'),
(b'^M', None),
(b'sky Internet Security 2016* & Much More', 'utf-8')]