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

email.parser header-only parsing records MultipartInvariantViolationDefect for valid multipart emails #106186

Copy link
Copy link
Closed
@me-and

Description

@me-and
Issue body actions

Bug report

A valid multipart email message, when parsed with email.parser.HeaderParser(policy=email.policy.default) will record a email.errors.MultipartInvariantViolationDefect.

If the parser isn't going to attempt to parse the message body, it shouldn't report that as a defect.

Simple test script:

import email.parser
import email.policy

email_str = '''\
Date: 01 Jan 2001 00:01+0000
From: arthur@example.example
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=autocracy

--autocracy
Content-Type: text/plain

By hanging on to outdated imperialist dogma which perpetuates the economic and
social differences in our society.

--autocracy
Content-Type: text/html

<html><body><p>By hanging on to outdated imperialist dogma which perpetuates
the economic and social differences in our society.</p></body></html>

--autocracy--
'''

full_parser = email.parser.Parser(policy=email.policy.default)
parsed_email_full = full_parser.parsestr(email_str)
print(parsed_email_full.defects)  # Prints [] as expected

header_parser = email.parser.HeaderParser(policy=email.policy.default)
parsed_email_headers_only = header_parser.parsestr(email_str)
print(parsed_email_headers_only.defects)  # Prints [MultipartInvariantViolationDefect()]

Your environment

  • Debian 12
  • Raspberry Pi 4 (arm64)
  • Python 3.11.2 (Debian package 3.11.2-1+b1)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirPython modules in the Lib dirtype-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.