Title: email.policy.SMTP throws AttributeError on invalid header
Type: behavior Stage: patch review
Components: email Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, elenril, r.david.murray
Priority: normal Keywords: patch

Created on 2019-12-19 19:32 by elenril, last changed 2021-03-15 11:22 by elenril.

File name Uploaded Description Edit
mail.eml elenril, 2019-12-19 19:32
Pull Requests
URL Status Linked Edit
PR 24872 open elenril, 2021-03-15 11:22
Messages (1)
msg358689 - (view) Author: Anton Khirnov (elenril) * Date: 2019-12-19 19:32
When parsing a (broken) mail from (message-id, headers attached) with email.policy.SMTP, I get an AttributeError on trying to read the 'to' header:

/usr/lib/python3.7/email/ 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.
Date User Action Args
2021-03-15 11:22:23elenrilsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23633
2019-12-19 19:32:14elenrilcreate