Open
Description
Bug report
When parsing an email using email.parser.Parser(policy=email.policy.strict)
, where the email has invalid headers, I expected exceptions to be raised when the email was parsed. Instead, the header objects within the generated EmailMessage record defects, but no exception is raised and the overall EmailMessage has no defects listed.
import email
import email.policy
email_str = '''\
Date: xxx
From: "Bad from header" <bad, value>
'''
parsed_email = email.message_from_string(email_str, policy=email.policy.strict)
# Should never get to this point as the above should already have raised an
# exception.
print(parsed_email['Date'].defects) # Prints "(InvalidDateDefect('Invalid date value or format'),)", expected
print(parsed_email['From'].defects) # Prints "(InvalidHeaderDefect('invalid address in address-list'), ..." , expected
print(parsed_email.defects) # Prints "[]", not expected
Your environment
- Debian 12
- Raspberry Pi 4 (arm64)
- Python 3.11.2 (Debian package 3.11.2-1+b1)
Metadata
Metadata
Assignees
Labels
Python modules in the Lib dirPython modules in the Lib dirAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error