当电子邮件正文中有中文字符时,email.retr会检索到奇怪的= 20个字符 [英] email.retr retrieves strange =20 characters when the email body has chinese characters in it
本文介绍了当电子邮件正文中有中文字符时,email.retr会检索到奇怪的= 20个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
self.logger.info(msg)
popinstance = poplib.POP3(self.account [0])
self.logger.info(popinstance.getwelcome ())
popinstance.user(self.account [1])$ b $ b popinstance.pass_(self.account [2])
try:
(numMsgs,totalSize)= popinstance (1,numMsgs + 1)中的thisNum
:
self.logger.info(POP contains+ str(numMsgs)+emails)
try:
(server_msg,body,octets)= popinstance.retr(thisNum)
除外:
self.logger.error(无法下载电子邮件)
提升
text =\\\
.join(body)
mesg = StringIO.StringIO(text)
msg = rfc822.Message(mesg)
MessageID = email.Utils.parseaddr(msg [ Message-ID])[1]
self.logger.info(下载电子邮件+ MessageID)
emailpath = os.path.join(self._emailpath + self._inboxfolder +\ \+ self._sanitize_string(MessageID +.eml))
emailpath = self._replace_whitespace(emailpath)
try:
self._dual_dump(text,emailpath)
除外:
传递
self.logger.info(popinstance.dele(thisNum))
finally:
self.logger.info(popinstance.quit())
$ c当电子邮件包含中文字符时,$ c>
(server_msg,body,octets)= popinstance.retr(thisNum)在邮件正文中返回= 20 。
我如何处理这个问题?
电子邮件的原始文本:
主题:(B / L:4363-0192-809.015)SI FOR 15680XXXX436
= 20
亲爱的
= 20
SI ENCLOSED
PLS发送我们的BL草稿和借记笔记
= 20
= 20
MYRI
<----> -----原始消息----- = 20
解决方案
这可能是一个空格字符编码 quoted-printable
self.logger.info(msg)
popinstance=poplib.POP3(self.account[0])
self.logger.info(popinstance.getwelcome())
popinstance.user(self.account[1])
popinstance.pass_(self.account[2])
try:
(numMsgs, totalSize)=popinstance.stat()
self.logger.info("POP contains " + str(numMsgs) + " emails")
for thisNum in xrange(1, numMsgs + 1):
try:
(server_msg, body, octets)=popinstance.retr(thisNum)
except:
self.logger.error("Could not download email")
raise
text="\n".join(body)
mesg=StringIO.StringIO(text)
msg=rfc822.Message(mesg)
MessageID=email.Utils.parseaddr(msg["Message-ID"])[1]
self.logger.info("downloading email " + MessageID)
emailpath=os.path.join(self._emailpath + self._inboxfolder + "\\" + self._sanitize_string(MessageID + ".eml"))
emailpath=self._replace_whitespace(emailpath)
try:
self._dual_dump(text,emailpath)
except:
pass
self.logger.info(popinstance.dele(thisNum))
finally:
self.logger.info(popinstance.quit())
(server_msg, body, octets)=popinstance.retr(thisNum) returns =20 in the body of the email when the email contains chinese characters.
How do I handle this?
raw text of email:
Subject: (B/L:4363-0192-809.015) SI FOR 15680XXXX436
=20
Dear
=20
SI ENCLOSED
PLS SEND US THE BL DRAFT AND DEBIT NOTE
=20
TKS
=20
MYRI
----- Original Message -----=20
解决方案
It is probably a Space character encoded in quoted-printable
这篇关于当电子邮件正文中有中文字符时,email.retr会检索到奇怪的= 20个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文