EmailMessage and RFC 2047

Peter J. Holzer hjp-python at hjp.at
Tue Apr 30 07:11:38 EDT 2019


Hi,

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.

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)
>>> m
<email.message.EmailMessage object at 0x7f3b5cac4278>
>>> m["Subject"]
'[luga] =?utf-8?Q?=C3=84ndern_des_Passwortes_mittels_We?=\n\t=?utf-8?Q?bformular?='
>>> m["From"]
'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?

        hp


-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20190430/1a992895/attachment.sig>


More information about the Python-list mailing list