[issue32058] Faulty behaviour in email.utils.parseaddr if square brackets in subject
R. David Murray
report at bugs.python.org
Fri Nov 17 09:07:11 EST 2017
R. David Murray <rdmurray at bitdance.com> added the comment:
parseaddr is for parsing the contents of an address header, not for parsing any additional text. So the correct way to call it is parseaddress('someone <some at email.address>').
In any case, please look in to the new email policies, which provide a much more convenient API:
>>> from email import message_from_bytes
>>> from email.policy import default
>>> m = message_from_bytes(b'Subject: I am a bug [Random]\r\nFrom: someone <some at email.address>\r\n\r\n', policy=default)
>>> m['from']
'someone <some at email.address>'
>>> m['from'].addresses
(Address(display_name='someone', username='some', domain='email.address'),)
>>> m['from'].addresses[0].display_name
'someone'
>>> m['from'].addresses[0].username
'some'
>>> m['from'].addresses[0].addr_spec
'some at email.address'
----------
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32058>
_______________________________________
More information about the Python-bugs-list
mailing list