EmailMessage and RFC 2047
tjol at tjol.eu
Tue Apr 30 11:45:52 EDT 2019
On 30/04/2019 13.11, Peter J. Holzer wrote:
> https://docs.python.org/3.7/library/email.header.html states:
> | This module is part of the legacy (Compat32) email API. In the current
> | API encoding and decoding of headers is handled transparently by the
> | dictionary-like API of the EmailMessage class.
> I understood this to mean that an EmailMessage does decode RFC 2047
> encoded header fields automatically.
I have no idea why it's doing what it's doing. The lesson appears to be:
don't use the compat32 mode unless you have to support Python 3.2 (which
you don't, because that's ridiculous)
'Subject: =?utf-8?q?=C3=89lys=C3=A9e?=\nContent-Type: text/plain;
>>> p = email.parser.Parser(email.message.EmailMessage)
>>> p = email.parser.Parser(email.message.EmailMessage,
Simple. Silly. Simply silly.
I've been confused by the unicode handling of this module before... 
[I'm still confused]
> However this does not seem to be the case:
> portia:~/tmp 13:06 :-) 16% python3
> Python 3.7.2+ (default, Feb 27 2019, 15:41:59)
> [GCC 8.2.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import email.parser
>>>> import email.message
>>>> p = email.parser.Parser(email.message.EmailMessage)
>>>> f = open("test.msg", "r")
>>>> m = p.parse(f)
> <email.message.EmailMessage object at 0x7f3b5cac4278>
> '[luga] =?utf-8?Q?=C3=84ndern_des_Passwortes_mittels_We?=\n\t=?utf-8?Q?bformular?='
> 'Martin =?iso-8859-15?Q?W=FCrtele?= <martin at xxxxxxxx.xxx>'
> Am I using it wrong or did I misunderstand what is meant by "handled
> transparently by the dictionary-like API of the EmailMessage class"? If
> the latter, what does it mean?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 836 bytes
Desc: OpenPGP digital signature
More information about the Python-list