Newbie question - parsing MIME(?) strings

Anssi Saari as at
Thu Oct 28 22:36:53 CEST 2010

Dan M <dan at> writes:

> On Thu, 28 Oct 2010 15:05:56 -0500, Dan M wrote:
> Ok, I didn't research enough before I posted this. I see now that this 
> *is* indeed a MIME message, and the '?Q' bit says that the next piece is 
> quoted-printable, and that the encoding is defined in RFC2047.
> So the question the becomes, do we have a library for reading info like
> this?

The quopri module handles quoted-printable. I've used it to demangle
mail headers. I had a regexp from a perl script available to split
headers, so I just fed the quoted-printable part to
quopri.decodestring, even though quopri.decode should be able to
handle a header directly.

Headers can sometime be encoded in base64 as well, at least in emails.
I don't think it's common in Usenet though. But that can be decoded by
the base64 module.

More information about the Python-list mailing list