我使用 POP3 从 Gmail 帐户下载邮件并将它们保存在 SQLite 数据库中以供进一步处理:
mailbox = poplib.POP3_SSL('pop.gmail.com', '995')
mailbox.user(user)
mailbox.pass_(password)
msgnum = mailbox.stat()[0]
for i in range(msgnum):
msg = '\n'.join(mailbox.retr(i+1)[1])
save_message(msg, dbmgr)
mailbox.quit()
但是,在数据库中查看,除消息正文(有效负载)的最后一行之外的所有行都具有尾随等号。你知道为什么会这样吗?
最佳答案
Frederic 的链接让我找到了答案。编码称为“引用的可打印”( wiki ),可以使用 quopri
Python 模块( documentation )对其进行解码:
msg.decode('quopri').decode('utf-8')
关于python - 电子邮件中的尾随等号 (=),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27421282/