mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-106186: Don't report MultipartInvariantViolationDefect for valid multipart emails when parsing header only (#107016)
This commit is contained in:
parent
54632528ee
commit
c65592c4d6
4 changed files with 28 additions and 1 deletions
14
Lib/test/test_email/data/msg_47.txt
Normal file
14
Lib/test/test_email/data/msg_47.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
Date: 01 Jan 2001 00:01+0000
|
||||
From: arthur@example.example
|
||||
MIME-Version: 1.0
|
||||
Content-Type: multipart/mixed; boundary=foo
|
||||
|
||||
--foo
|
||||
Content-Type: text/plain
|
||||
bar
|
||||
|
||||
--foo
|
||||
Content-Type: text/html
|
||||
<html><body><p>baz</p></body></html>
|
||||
|
||||
--foo--
|
|
@ -3712,6 +3712,16 @@ class TestParsers(TestEmailBase):
|
|||
self.assertIsInstance(msg.get_payload(), str)
|
||||
self.assertIsInstance(msg.get_payload(decode=True), bytes)
|
||||
|
||||
def test_header_parser_multipart_is_valid(self):
|
||||
# Don't flag valid multipart emails as having defects
|
||||
with openfile('msg_47.txt', encoding="utf-8") as fp:
|
||||
msgdata = fp.read()
|
||||
|
||||
parser = email.parser.Parser(policy=email.policy.default)
|
||||
parsed_msg = parser.parsestr(msgdata, headersonly=True)
|
||||
|
||||
self.assertEqual(parsed_msg.defects, [])
|
||||
|
||||
def test_bytes_parser_does_not_close_file(self):
|
||||
with openfile('msg_02.txt', 'rb') as fp:
|
||||
email.parser.BytesParser().parse(fp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue