diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-07-23 12:28:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-23 12:28:28 (GMT) |
commit | af95a1da465da82740541bf011a324fefaf53713 (patch) | |
tree | 099e9d2f6615298536245b0f8315849e613c9a8c /Lib/test | |
parent | 95a82dcbe74d1ed226a3df0763546f27bd5a6f61 (diff) | |
download | cpython-af95a1da465da82740541bf011a324fefaf53713.zip cpython-af95a1da465da82740541bf011a324fefaf53713.tar.gz cpython-af95a1da465da82740541bf011a324fefaf53713.tar.bz2 |
[3.12] gh-106186: Don't report MultipartInvariantViolationDefect for valid multipart emails when parsing header only (GH-107016) (#107111)
(cherry picked from commit c65592c4d6d7552fb6284442906a96a6874cb266)
Co-authored-by: htsedebenham <31847376+htsedebenham@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_email/data/msg_47.txt | 14 | ||||
-rw-r--r-- | Lib/test/test_email/test_email.py | 10 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_email/data/msg_47.txt b/Lib/test/test_email/data/msg_47.txt new file mode 100644 index 0000000..bb48b47 --- /dev/null +++ b/Lib/test/test_email/data/msg_47.txt @@ -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--
\ No newline at end of file diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index b4f3a24..cdb6ef1 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -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) |