To decode the Subject =?iso-8859-2?Q?=... in email in python

Roman Neuhauser neuhauser+python-list#python.org at sigpipe.cz
Wed Apr 20 03:54:11 EDT 2005


# dan.polansky at gmail.com / 2005-04-20 00:30:35 -0700:
> When parsing messages using python's libraries email and mailbox, the
> subject is often encoded using some kind of = notation. Apparently, the
> encoding used in this notation is specified like =?iso-8859-2?Q?=... or
> =?iso-8859-2?B?=.

    That's RFC 2047 encoding, both examples introduce an ISO8859-2
    string, the first variant says it's ascii-ized using
    "Q"uoted-Printable, the other says the string is "B"ase64-encoded.

> Is there a python library function to decode such a
> subject, returning a unicode string? The use would be like
> 
>   human_readable = cool_library.decode_equals(message['Subject'])

    quoting from http://docs.python.org/lib/module-email.Header.html

    >>> from email.Header import decode_header
    >>> decode_header('=?iso-8859-1?q?p=F6stal?=')
    [('p\xf6stal', 'iso-8859-1')]

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991



More information about the Python-list mailing list