Skip to content

Conversation

@htsedebenham
Copy link
Contributor

@htsedebenham htsedebenham commented Jul 22, 2023

The following code used to report a MultipartInvariantViolationDefect. However, the message body is not parsed when headersonly=True, so the parsing required for is_multipart() to work is not carried out. Add this as a case to ignore when validating the message body in close()

import email.parser
import email.policy

email_str = '''\
Date: 01 Jan 2001 00:01+0000
From: [email protected]
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)  # Used to print [MultipartInvariantViolationDefect()].  Now prints []

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost
Copy link

ghost commented Jul 22, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ambv ambv added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jul 23, 2023
@ambv ambv merged commit c65592c into python:main Jul 23, 2023
@miss-islington
Copy link
Contributor

Thanks @htsedebenham for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-107111 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2023
…alid multipart emails when parsing header only (pythonGH-107016)

(cherry picked from commit c65592c)

Co-authored-by: htsedebenham <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jul 23, 2023
@bedevere-bot
Copy link

GH-107112 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2023
…alid multipart emails when parsing header only (pythonGH-107016)

(cherry picked from commit c65592c)

Co-authored-by: htsedebenham <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 23, 2023
ambv pushed a commit that referenced this pull request Jul 23, 2023
…valid multipart emails when parsing header only (GH-107016) (#107111)

(cherry picked from commit c65592c)

Co-authored-by: htsedebenham <[email protected]>
ambv pushed a commit that referenced this pull request Jul 23, 2023
…valid multipart emails when parsing header only (GH-107016) (#107112)

(cherry picked from commit c65592c)

Co-authored-by: htsedebenham <[email protected]>
jtcave pushed a commit to jtcave/cpython that referenced this pull request Jul 23, 2023
mementum pushed a commit to mementum/cpython that referenced this pull request Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants