[New-bugs-announce] [issue43501] email._header_value_parse throws AttributeError on display name ending with dot

Anton Khirnov report at bugs.python.org
Mon Mar 15 09:11:05 EDT 2021


New submission from Anton Khirnov <anton at khirnov.net>:

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/_header_value_parser.py 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 at spam>

----------
components: email
messages: 388738
nosy: barry, elenril, r.david.murray
priority: normal
severity: normal
status: open
title: email._header_value_parse throws AttributeError on display name ending with dot
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43501>
_______________________________________


More information about the New-bugs-announce mailing list