Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Defects when parsing email headers aren't raised or propagated to the email object #106144

Copy link
Copy link
Open
@me-and

Description

@me-and
Issue body actions

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

No one assigned

    Labels

    stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.