]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] bpo-39100: _header_value_parser: do not treat a Group as invalid-mailbox ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 30 Apr 2026 18:15:43 +0000 (20:15 +0200)
committerGitHub <noreply@github.com>
Thu, 30 Apr 2026 18:15:43 +0000 (14:15 -0400)
commitb3e0c72fa4a852fccf8d72e9e833798bf087afbb
treec9fff7f78aedc5163c514c1ff2d5f49dd781ffec
parentc38c463c1434da155a936c1278ebfce0d27b42d9
[3.13] bpo-39100: _header_value_parser: do not treat a Group as invalid-mailbox (GH-24872) (#149192)

When an address in an address-list has garbage at the end, the code will
currently:

1. change the mailbox in the last parsed address into invalid-mailbox by
   overriding its token_type;
2. wrap the trailing garbage into another invalid-mailbox and append it
   to the last parsed address.

However, that does not take into account that an address may
also contain a Group instead of a single mailbox. In that case,
overwriting token_type leads to undesirable results, e.g. parsing an
email with the following 'To' header:

unlisted-recipients:; (no To-header on input)

raises an AttributeError from trying to treat the Group as a Mailbox.

Moreover it is questionable whether the previously parsed mailbox should
be treated as invalid in addition to the trailing garbage.

Address both of the above by wrapping the trailing garbage in a new
Address with a single invalid-mailbox, and append it to the AddressList
directly.

Changes the results of the
test_get_address_list_mailboxes_invalid_addresses test, where the
address list is now parsed into 4 mailboxes instead of 3 (all but the
first one are invalid).
(cherry picked from commit b413bc7a1f0946f734d9660239b4e2e8ddc48522)

Co-authored-by: elenril <anton@khirnov.net>
Lib/email/_header_value_parser.py
Lib/test/test_email/test__header_value_parser.py
Misc/NEWS.d/next/Library/2023-09-08-13-10-32.gh-issue-83281.2Plpcj.rst [new file with mode: 0644]