-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Some invalid email address groups cause an IndexError instead of a HeaderParseError #76359
Comments
With some malformed email address list, the parser for email groups raises an This results in a complete failure to parse the email while it is still preferable to just ignore the malformed header. An example of such a malformed list is this: |
In case an address email header contains and empty string, the tokenizer return a BareQuotedString For example an email with this header will trigger the IndexError: |
Disregard my last message, I posted it in the wrong bug report by mistake. |
I don't think this is an issue anymore, I guess this was fixed as a part of some other PR. I tested this out on a recent branch: >>> import email
>>> msg = email.message_from_string('From: Abhilash <maxking@email.com> <Another@some.com>')
>>> msg['From']
'Abhilash <maxking@email.com> <Another@some.com>' |
Based on @maxking's comment, I'm going to close this issue. Thank you! |
The fact that the original report mentions HeaderParserError implies that the new API is being used, though the report didn't make that clear. The problem still exists: >>> m = message_from_string("To: :Foo <foo@example.com> <bar@example.com>\n\n", policy=default)
>>> m['To']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rdmurray/python/p38/Lib/email/message.py", line 391, in __getitem__
return self.get(name)
File "/home/rdmurray/python/p38/Lib/email/message.py", line 471, in get
return self.policy.header_fetch_parse(k, v)
File "/home/rdmurray/python/p38/Lib/email/policy.py", line 163, in header_fetch_parse
return self.header_factory(name, value)
File "/home/rdmurray/python/p38/Lib/email/headerregistry.py", line 602, in __call__
return self[name](name, value)
File "/home/rdmurray/python/p38/Lib/email/headerregistry.py", line 197, in __new__
cls.parse(value, kwds)
File "/home/rdmurray/python/p38/Lib/email/headerregistry.py", line 343, in parse
groups.append(Group(addr.display_name,
File "/home/rdmurray/python/p38/Lib/email/_header_value_parser.py", line 315, in display_name
return self[0].display_name
File "/home/rdmurray/python/p38/Lib/email/_header_value_parser.py", line 382, in display_name
return self[0].display_name
File "/home/rdmurray/python/p38/Lib/email/_header_value_parser.py", line 564, in display_name
if res[0].token_type == 'cfws':
IndexError: list index out of range |
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:
The text was updated successfully, but these errors were encountered: