-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception parsing invalid email address headers starting or ending with dot #75171
Comments
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' |
Hi! I confirm this problem too, also with the SMTPUTF8 policy. I was able to reproduce this error on my end (Python v3.7.5). Note that when calling |
I can also confirm this bug, with Python 3.9.1 on Debian GNU/Linux ('testing' distro up-to-date as of 2020-12-21).
Here is a minimal problematic message you can reproduce this with (i.e., just make
Note that *any* number of dots for the recipient's name would also result in an error. The above example uses just ".", but it could be "..", "...", ".................", etc. |
Reproduced on 3.11. |
I had the same issue and converting it to a tuple solved the issue for me.
|
…g with a dot (GH-15600) Co-authored-by: Tim Bell <timothybell@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
… ending with a dot (pythonGH-15600) (cherry picked from commit 8cc9adb) Co-authored-by: tsufeki <tsufeki@ymail.com> Co-authored-by: Tim Bell <timothybell@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
… ending with a dot (pythonGH-15600) Co-authored-by: Tim Bell <timothybell@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
I noticed the fix being resolved for 3.12 but wonder on which version of Python exactly? Because I just ran a test on 3.12.3 and even though the error has changed, the issue is kind of style here:
Do you have any precision on when the fix was released ? |
(FYI it fails with |
It was released today, in 3.12.4. |
Ok great! Thank you for the info ! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: