Decode email subjects into unicode
Ryan Ginstrom
software at ginstrom.com
Tue Mar 18 06:24:50 EDT 2008
> On Behalf Of Laszlo Nagy
> > =?koi8-r?B?4tnT1NLP19nQz8zOyc3PIMkgzcHMz9rB1NLB1M7P?=
> > [Fwd: re:Flags Of The World, Us States, And Military]
> > =?ISO-8859-2?Q?=E9rdekes?= =?UTF-8?B?aGliw6Fr?=
Try this code:
from email.header import decode_header
def getheader(header_text, default="ascii"):
"""Decode the specified header"""
headers = decode_header(header_text)
header_sections = [unicode(text, charset or default)
for text, charset in headers]
return u"".join(header_sections)
I get the following output for your strings:
Быстровыполнимо и малозатратно
érdekeshibák
Regards,
Ryan Ginstrom
More information about the Python-list
mailing list