This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author timb07
Recipients barry, r.david.murray, timb07
Date 2017-07-22.04:50:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500699002.76.0.343337119039.issue30988@psf.upfronthosting.co.za>
In-reply-to
Content
Email addresses with a display name starting with a dot ("."), or ending with a dot without whitespace before the angle bracket trigger exceptions when accessing the header, after creating the message object with the "default" policy.

For example:

>>> import email
>>> from email.policy import default
>>> email.message_from_bytes(b'To: . Doe <jxd@example.com>')['to']
'. Doe <jxd@example.com>'
>>> email.message_from_bytes(b'To: . Doe <jxd@example.com>', policy=default)['to']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bhat/git/cpython/Lib/email/message.py", line 391, in __getitem__
    return self.get(name)
  File "/Users/bhat/git/cpython/Lib/email/message.py", line 471, in get
    return self.policy.header_fetch_parse(k, v)
  File "/Users/bhat/git/cpython/Lib/email/policy.py", line 162, in header_fetch_parse
    return self.header_factory(name, value)
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 586, in __call__
    return self[name](name, value)
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 197, in __new__
    cls.parse(value, kwds)
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 344, in parse
    for mb in addr.all_mailboxes]))
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 344, in <listcomp>
    for mb in addr.all_mailboxes]))
  File "/Users/bhat/git/cpython/Lib/email/_header_value_parser.py", line 834, in display_name
    return self[0].display_name
  File "/Users/bhat/git/cpython/Lib/email/_header_value_parser.py", line 768, in display_name
    return self[0].display_name
  File "/Users/bhat/git/cpython/Lib/email/_header_value_parser.py", line 931, in display_name
    if res[0][0].token_type == 'cfws':
AttributeError: 'str' object has no attribute 'token_type'
>>>
>>> email.message_from_bytes(b'To: John X.<jxd@example.com>')['to']
'John X.<jxd@example.com>'
>>> email.message_from_bytes(b'To: John X.<jxd@example.com>', policy=default)['to']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bhat/git/cpython/Lib/email/message.py", line 391, in __getitem__
    return self.get(name)
  File "/Users/bhat/git/cpython/Lib/email/message.py", line 471, in get
    return self.policy.header_fetch_parse(k, v)
  File "/Users/bhat/git/cpython/Lib/email/policy.py", line 162, in header_fetch_parse
    return self.header_factory(name, value)
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 586, in __call__
    return self[name](name, value)
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 197, in __new__
    cls.parse(value, kwds)
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 344, in parse
    for mb in addr.all_mailboxes]))
  File "/Users/bhat/git/cpython/Lib/email/headerregistry.py", line 344, in <listcomp>
    for mb in addr.all_mailboxes]))
  File "/Users/bhat/git/cpython/Lib/email/_header_value_parser.py", line 834, in display_name
    return self[0].display_name
  File "/Users/bhat/git/cpython/Lib/email/_header_value_parser.py", line 768, in display_name
    return self[0].display_name
  File "/Users/bhat/git/cpython/Lib/email/_header_value_parser.py", line 936, in display_name
    if res[-1][-1].token_type == 'cfws':
AttributeError: 'str' object has no attribute 'token_type'
History
Date User Action Args
2017-07-22 04:50:02timb07setrecipients: + timb07, barry, r.david.murray
2017-07-22 04:50:02timb07setmessageid: <1500699002.76.0.343337119039.issue30988@psf.upfronthosting.co.za>
2017-07-22 04:50:02timb07linkissue30988 messages
2017-07-22 04:50:01timb07create