You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
email.policy.SMTP throws AttributeError on invalid header #83281
/usr/lib/python3.7/email/headerregistry.py in <listcomp>(.0)
345 mb.local_part or '',
346 mb.domain or '')
--> 347 for mb in addr.all_mailboxes]))
348 defects = list(address_list.all_defects)
349 else:
AttributeError: 'Group' object has no attribute 'local_part'
The header in question is:
To: unlisted-recipients:; (no To-header on input)
The problem seems to be that mb is a Group and not an Address, gets token_type of 'invalid-mailbox', but does not have the attributes local_part/domain that are expected in mailboxes. Copying the line
local_part=domain=route=addr_spec=display_name
from InvalidMailbox to Group fixes this, but it is not clear to me this is the right solution, so not sending a patch.
Anton: thanks for the report! In the message you say you are not sure of the solution, and because of that not sending a patch, but then you created the PR; - please clarify.
The exception is thrown on accessing the 'to' header, so make that
print(msg['to'])
elenril commented on Jul 7, 2021
elenrilmannequin
MannequinAuthor
More actions
Quoting Andrei Kulakov (2021-07-03 16:03:34)
Anton: thanks for the report! In the message you say you are not sure
of the solution, and because of that not sending a patch, but then you
created the PR; - please clarify.
I didn't send a patch when originally submitting the bugreport in 2019.
I did write a patch about a year later, since there was no response to
the bugreport.
Hit this when serializing emails parsed from Outlook PSTs (recipients via distribution lists produce group syntax in To: headers).
Workaround: pre-process address-list headers with the legacy email.utils.getaddresses parser, which flattens groups correctly, and write the headers back in flat-mailbox form before calling as_bytes(policy=default).
Activity
elenril commentedon Dec 19, 2019
When parsing a (broken) mail from linux-media@vger.kernel.org (message-id 20190212181908.Horde.pEiGHvV2KHy9EkUy8TA8D1o@webmail.your-server.de, headers attached) with email.policy.SMTP, I get an AttributeError on trying to read the 'to' header:
/usr/lib/python3.7/email/headerregistry.py in <listcomp>(.0)
345 mb.local_part or '',
346 mb.domain or '')
--> 347 for mb in addr.all_mailboxes]))
348 defects = list(address_list.all_defects)
349 else:
AttributeError: 'Group' object has no attribute 'local_part'
The header in question is:
To: unlisted-recipients:; (no To-header on input)
The problem seems to be that mb is a Group and not an Address, gets token_type of 'invalid-mailbox', but does not have the attributes local_part/domain that are expected in mailboxes. Copying the line
from InvalidMailbox to Group fixes this, but it is not clear to me this is the right solution, so not sending a patch.
akulakov commentedon Jul 3, 2021
Anton: thanks for the report! In the message you say you are not sure of the solution, and because of that not sending a patch, but then you created the PR; - please clarify.
bitdancer commentedon Jul 6, 2021
How are you encountering this error? The following program runs without exception for me on master:
akulakov commentedon Jul 6, 2021
Running R.David's test script on python3.7, it also works, there's no exception.
akulakov commentedon Jul 6, 2021
I should have been more exact - I've used python3.7.7 .
elenril commentedon Jul 7, 2021
Quoting R. David Murray (2021-07-06 18:59:56)
The exception is thrown on accessing the 'to' header, so make that
print(msg['to'])
elenril commentedon Jul 7, 2021
Quoting Andrei Kulakov (2021-07-03 16:03:34)
I didn't send a patch when originally submitting the bugreport in 2019.
I did write a patch about a year later, since there was no response to
the bugreport.
elenril commentedon Jan 30, 2022
Ping yet again. Can anyone please look at this?
akulakov commentedon Jan 30, 2022
I confirmed I get the same error as Anton on 3.9 and 3.11 .
ekamioka commentedon Jun 28, 2022
Also confirmed. Getting the same error as Anton on python
3.9.13_1and3.8.10rushkii commentedon Nov 1, 2022
This error has not been handled yet? I've got the same error taken from the lore.kerne.org mailing list.
Prettified email
Raw email
docs: process: Send patches 'To' maintainers and 'Cc' lists
slverpla commentedon Jul 21, 2023
Hi, also getting this error. Is there anything I can do to help resolve this? Or did anyone find a workaround?
aseering commentedon Dec 27, 2023
I'm hitting this as well. It looks like the PR with the fix ( #24872 ) is slowly moving forward?
SuddenlyCoding commentedon Apr 28, 2026
Hit this when serializing emails parsed from Outlook PSTs (recipients via distribution lists produce group syntax in To: headers).
Workaround: pre-process address-list headers with the legacy email.utils.getaddresses parser, which flattens groups correctly, and write the headers back in flat-mailbox form before calling as_bytes(policy=default).
bitdancer commentedon Apr 30, 2026
Thanks for the ping, and thanks elenril for the PR. Apologies to all for the delay in getting it committed.