diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-04-17 07:44:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 07:44:41 (GMT) |
commit | f74e51229c83e3265f905dc15283bfe0ec1a659e (patch) | |
tree | dc57201a51b519138adad23f7e265f1fc2d41b31 /Lib/email | |
parent | 8cc9adbfddc8e37cf7d621b12754eecb0584f5da (diff) | |
download | cpython-f74e51229c83e3265f905dc15283bfe0ec1a659e.zip cpython-f74e51229c83e3265f905dc15283bfe0ec1a659e.tar.gz cpython-f74e51229c83e3265f905dc15283bfe0ec1a659e.tar.bz2 |
gh-86650: Fix IndexError when parse emails with invalid Message-ID (GH-117934)
In particularly, one-off addresses generated by Microsoft Outlook:
https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/one-off-addresses
Co-authored-by: fsc-eriker <72394365+fsc-eriker@users.noreply.github.com>
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/_header_value_parser.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 0cf23fc..7755e62 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1520,13 +1520,18 @@ def get_obs_local_part(value): raise token, value = get_cfws(value) obs_local_part.append(token) + if not obs_local_part: + raise errors.HeaderParseError( + "expected obs-local-part but found '{}'".format(value)) if (obs_local_part[0].token_type == 'dot' or obs_local_part[0].token_type=='cfws' and + len(obs_local_part) > 1 and obs_local_part[1].token_type=='dot'): obs_local_part.defects.append(errors.InvalidHeaderDefect( "Invalid leading '.' in local part")) if (obs_local_part[-1].token_type == 'dot' or obs_local_part[-1].token_type=='cfws' and + len(obs_local_part) > 1 and obs_local_part[-2].token_type=='dot'): obs_local_part.defects.append(errors.InvalidHeaderDefect( "Invalid trailing '.' in local part")) |