Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitafa24d5

Browse files
[3.11]gh-106186: Don't report MultipartInvariantViolationDefect for valid multipart emails when parsing header only (GH-107016) (#107112)
(cherry picked from commitc65592c)Co-authored-by: htsedebenham <31847376+htsedebenham@users.noreply.github.com>
1 parentd2cdf08 commitafa24d5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

‎Lib/email/feedparser.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def close(self):
189189
assertnotself._msgstack
190190
# Look for final set of defects
191191
ifroot.get_content_maintype()=='multipart' \
192-
andnotroot.is_multipart():
192+
andnotroot.is_multipart()andnotself._headersonly:
193193
defect=errors.MultipartInvariantViolationDefect()
194194
self.policy.handle_defect(root,defect)
195195
returnroot
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Date: 01 Jan 2001 00:01+0000
2+
From: arthur@example.example
3+
MIME-Version: 1.0
4+
Content-Type: multipart/mixed; boundary=foo
5+
6+
--foo
7+
Content-Type: text/plain
8+
bar
9+
10+
--foo
11+
Content-Type: text/html
12+
<html><body><p>baz</p></body></html>
13+
14+
--foo--

‎Lib/test/test_email/test_email.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,6 +3696,16 @@ def test_bytes_header_parser(self):
36963696
self.assertIsInstance(msg.get_payload(),str)
36973697
self.assertIsInstance(msg.get_payload(decode=True),bytes)
36983698

3699+
deftest_header_parser_multipart_is_valid(self):
3700+
# Don't flag valid multipart emails as having defects
3701+
withopenfile('msg_47.txt',encoding="utf-8")asfp:
3702+
msgdata=fp.read()
3703+
3704+
parser=email.parser.Parser(policy=email.policy.default)
3705+
parsed_msg=parser.parsestr(msgdata,headersonly=True)
3706+
3707+
self.assertEqual(parsed_msg.defects, [])
3708+
36993709
deftest_bytes_parser_does_not_close_file(self):
37003710
withopenfile('msg_02.txt','rb')asfp:
37013711
email.parser.BytesParser().parse(fp)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Do not report ``MultipartInvariantViolationDefect`` defect
2+
when the:class:`email.parser.Parser` class is used
3+
to parse emails with ``headersonly=True``.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp