在python中解析电子邮件内容时,就像在某些时候使用编码格式一样获取正文 代码
请找到代码段:
str_list = list(filter(None, messages[0].decode().split(' ')))
print('No. of messages: {}'.format(len(str_list)))
if retcode == 'OK':
for num in messages[0].decode().split(' '):
if num:
typ, data = conn.fetch(num,'(RFC822)')
for response_part in data:
if isinstance(response_part, tuple):
email_message = email.message_from_string(str(response_part[1]))
print(email_message)
请在下面找到输出:
MIME-Version: 1.0
From: xxxxx@yyyyyyy.com
To: xxxxx@yyyyyyy.com
Date: Thu, 1 Oct 2017 03:02:45 +0000
Subject: Check Mail
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
Return-Path: xxxxx@yyyyyyy.com
Message-ID: <djfsdfjfio1212jio1@khapp>
X-OriginalArrivalTime: 1 Oct 2017 03:02:43.0174 (UTC) FILETIME= [79D8D860:01D49810]
X-SG-EID: Ni9KCeztslc0dF3s9ZK0rLD1BsYqqLCIUtt6iPiL4/rTHVW4HL7/7rS9U/ajjnLrCeU2GpRoJKFiOj
qhYAgMrjliHtgoMwHAIe9awgq7fTf0pblztE2xpgfqQfwjbZuHbHl/ViWGYLmXrOoppzYzSAX4neAx
Tv4LdCXpVv5dS9GgzXk2jbBCXbhNhBs8VGEA7wgzj/NMA55SceW3xftiVw==
X-Feedback-ID: 5710108:5+HXwQH0vVQ/iziqTPdSABmkuAdLxfkHnhxScrL8ZIw=:5+HXwQH0vVQ/iziqTPdSABmkuAd LxfkHnhxScrL8ZIw=:SG
PCFET0NUWVBFIGh0bWwgcHVibGljICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
Ly9FTiI+Cgk8aHRtbD4KCQk8aGVhZD4NCiA8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUi
IGNvbnRlbnQ9InRleHQvaHRtbDtjaGFyc2V0PXdpbmRvd3MtMTI1MiI+DQogPHN0eWxlPg0KICAg
LyogRm9udCBEZWZpbml0aW9ucyAqLw0KICAgQGZvbnQtZmFjZQ0KIAkge2ZvbnQtZmFtaWx5OiJD
反正有没有办法用python解码此邮件正文内容?