mail attachment with non-ascii name

Neil Hodgson nyamatongwe+thunder at
Sun Dec 11 17:25:17 EST 2005

Bernard Delmée:

> I am using the "email" module to decode incoming messages.
> (with msg = email.message_from_file( msg_file ))
> Sometimes an attachment has its name (as returned by
> msg.walk().part.get_filename()) not in ASCII (e.g.
> '=?iso-8859-1?q?somefile=2ezip?=') How can I turn that into
> simply '' ? I have looked into email.Utils and
> codecs, but cannot find what should work.

 >>> import email.Header
 >>> x = '=?iso-8859-1?q?somefile=2ezip?='
 >>> email.Header.decode_header(x)
[('', 'iso-8859-1')]


More information about the Python-list mailing list