email.retr récupère étrange = 20 caractères lorsque le corps de l'e-mail contient des caractères chinois

StackOverflow https://stackoverflow.com/questions/320166

Question

    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) renvoie = 20 dans le corps de l'e-mail lorsque celui-ci contient des caractères chinois.

Comment puis-je gérer cela?

texte brut du courrier électronique:

Objet: (B / L: 4363-0192-809.015) SI POUR 15680XXXX436

= 20

Cher

= 20

SI FERMÉ

PLS NOUS ENVOYEZ LE PROJET BL ET LA NOTE DE DEBIT

= 20

TKS

= 20

MYRI

----- Message d'origine ----- = 20

Était-ce utile?

La solution

Il s'agit probablement d'un caractère espace codé dans quoted-printable

Autres conseils

Utilisez le module quopri pour décoder la chaîne.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top