On 2019-04-30 17:45:52 +0200, Thomas Jollans wrote: > 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) > > >>> msg > 'Subject: =?utf-8?q?=C3=89lys=C3=A9e?=\nContent-Type: text/plain; > charset="utf-8"\nContent-Transfer-Encoding: 7bit\nMIME-Version: > 1.0\n\nTEST MESSAGE\n' > >>> p = email.parser.Parser(email.message.EmailMessage) > >>> p.parsestr(msg)['Subject'] > '=?utf-8?q?=C3=89lys=C3=A9e?=' > >>> p = email.parser.Parser(email.message.EmailMessage, > policy=email.policy.default) > >>> p.parsestr(msg)['Subject'] > 'Élysée' > >>>
O thanks. Since email.message.EmailMessage was only introduced in 3.6 (and therefore can't be compatible to 3.2) and the default policy for it is "default") I didn't expect email.parser.Parser to override that (although https://docs.python.org/3/library/email.parser.html#email.parser.BytesFeedParser clearly says "policy=policy.compat32" - silly me) hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | h...@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list