0

I'm using imap to retrieve mails from a server which works fine. I'm fetching the mails in RFC 822 like so:

r, data = mailserver.fetch(mailnr, '(RFC822)')

This gives me decipherable mails for the most part but now I have a multipart mail that looks like this:

From : xxx xxx

To : xxx xxx

Subject : =?utf-8?Q?online_verf=C3=BCgbar_-_TESTQUELLE_f=C3=BCr_Regel?= =?utf-8?Q?-_u_Benachrichtigungdienst_()?=

Content-Type : multipart/alternative; boundary="----=_NextPart_457512452482695058637"

Content-Transfer-Encoding : None

MIME-Version : 1.0

Payload:

=20 =20 sourcename:TESTQUELLE f=C3=BCr Regel- u Benachrichtigungdienst;csi:123456= ;publishdate:05=2E11=2E2013

The mail appears to be utf-8 but somehow the text is also url-encoded or something like that.

It seem like url encoded only instead of "%" "=" is used.

Any ideas on how i get this to look like normal text ?

2 Answers 2

1

The data appears to be unicode text that has been encoded as UTF-8, and then encoded as quotable-printable. There is a module "quopri" to encode / decode this - http://docs.python.org/3.3/library/quopri.html.

If you use quopri.decodestring to decode to UTF-8, and then decode that to unicode, yuo should be able to read it.

Sign up to request clarification or add additional context in comments.

Comments

1

Finally found this:

mail.get_payload(decode=1).decode('utf-8')

I've only used get_payload() which gave me that string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.