File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ def close(self):
189
189
assert not self ._msgstack
190
190
# Look for final set of defects
191
191
if root .get_content_maintype () == 'multipart' \
192
- and not root .is_multipart ():
192
+ and not root .is_multipart () and not self . _headersonly :
193
193
defect = errors .MultipartInvariantViolationDefect ()
194
194
self .policy .handle_defect (root , defect )
195
195
return root
Original file line number Diff line number Diff line change
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--
Original file line number Diff line number Diff line change @@ -3696,6 +3696,16 @@ def test_bytes_header_parser(self):
3696
3696
self .assertIsInstance (msg .get_payload (), str )
3697
3697
self .assertIsInstance (msg .get_payload (decode = True ), bytes )
3698
3698
3699
+ def test_header_parser_multipart_is_valid (self ):
3700
+ # Don't flag valid multipart emails as having defects
3701
+ with openfile ('msg_47.txt' , encoding = "utf-8" ) as fp :
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
+
3699
3709
def test_bytes_parser_does_not_close_file (self ):
3700
3710
with openfile ('msg_02.txt' , 'rb' ) as fp :
3701
3711
email .parser .BytesParser ().parse (fp )
Original file line number Diff line number Diff line change
1
+ Do not report ``MultipartInvariantViolationDefect `` defect
2
+ when the :class: `email.parser.Parser ` class is used
3
+ to parse emails with ``headersonly=True ``.
You can’t perform that action at this time.
0 commit comments