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.

Title: email._header_value_parse throws AttributeError on display name ending with dot
Type: behavior Stage: patch review
Components: email Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, elenril, r.david.murray
Priority: normal Keywords: patch

Created on 2021-03-15 13:11 by elenril, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 24874 open elenril, 2021-03-15 13:29
Messages (1)
msg388738 - (view) Author: Anton Khirnov (elenril) * Date: 2021-03-15 13:11
On parsing an email where the display name in an address ends on a dot immediately followed by angle-addr, accessing the resulting mailbox display_name throws
/usr/lib/python3.9/email/ in value(self)
    589             if self[0].token_type=='cfws' or self[0][0].token_type=='cfws':
    590                 pre = ' '
--> 591             if self[-1].token_type=='cfws' or self[-1][-1].token_type=='cfws':
    592                 post = ' '
    593             return pre+quote_string(self.display_name)+post

AttributeError: 'str' object has no attribute 'token_type'

The problem is that self[-1] is the terminal DOT.

An example of the problematic header is:
From: foobar.<baz@spam>
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87667
2021-03-15 13:29:39elenrilsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23636
2021-03-15 13:11:05elenrilcreate