Skip to content Skip to sidebar Skip to footer

Decode Utf8 Mail Header

In my MUA (Thunderbird 15.0.1) both mail subjects are displayed like this: Keine Mail zu 'Abschlagsänderung' gefunden Here is a snippet to reproduce it: import email for subject

Solution 1:

According to RFC 2047,

An 'encoded-word' MUST NOT appear within a 'quoted-string'.

A 'quoted-string' according to RFC 822 is

quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or quoted chars.

So I think the Python library is right, as

"=?utf-8?q?Abschlags=C3=A4nderung?="

is a quoted string. A better alternative with minimal quoting would be

=?utf-8?q?=22Abschlags=C3=A4nderung=22?=

having the " encoded as =22.

You could parse them by replacing the " with =?utf-8?q?=22?=:

>>> email.Header.decode_header('=?utf-8?q?=22?= =?utf-8?q?Abschlags=C3=A4nderung?= =?utf-8?q?=22?=')
[('"Abschlags\xc3\xa4nderung"', 'utf-8')]

Post a Comment for "Decode Utf8 Mail Header"