@@ -177,6 +177,17 @@ def test_message_rfc822_only(self):
177177 gen .flatten (msg , False )
178178 self .assertEqual (out .getvalue (), msgdata )
179179
180+ def test_byte_message_rfc822_only (self ):
181+ # Make sure new bytes header parser also passes this.
182+ with openfile ('msg_46.txt' , 'rb' ) as fp :
183+ msgdata = fp .read ()
184+ parser = email .parser .BytesHeaderParser ()
185+ msg = parser .parsebytes (msgdata )
186+ out = BytesIO ()
187+ gen = email .generator .BytesGenerator (out )
188+ gen .flatten (msg )
189+ self .assertEqual (out .getvalue (), msgdata )
190+
180191 def test_get_decoded_payload (self ):
181192 eq = self .assertEqual
182193 msg = self ._msgobj ('msg_10.txt' )
@@ -2749,6 +2760,7 @@ def test_pushCR_LF(self):
27492760
27502761
27512762class TestParsers (TestEmailBase ):
2763+
27522764 def test_header_parser (self ):
27532765 eq = self .assertEqual
27542766 # Parse only the headers of a complex multipart MIME document
@@ -2760,6 +2772,18 @@ def test_header_parser(self):
27602772 self .assertFalse (msg .is_multipart ())
27612773 self .assertTrue (isinstance (msg .get_payload (), str ))
27622774
2775+ def test_bytes_header_parser (self ):
2776+ eq = self .assertEqual
2777+ # Parse only the headers of a complex multipart MIME document
2778+ with openfile ('msg_02.txt' , 'rb' ) as fp :
2779+ msg = email .parser .BytesHeaderParser ().parse (fp )
2780+ eq (
msg [
'from' ],
'[email protected] ' )
2781+ eq (
msg [
'to' ],
'[email protected] ' )
2782+ eq (msg .get_content_type (), 'multipart/mixed' )
2783+ self .assertFalse (msg .is_multipart ())
2784+ self .assertTrue (isinstance (msg .get_payload (), str ))
2785+ self .assertTrue (isinstance (msg .get_payload (decode = True ), bytes ))
2786+
27632787 def test_whitespace_continuation (self ):
27642788 eq = self .assertEqual
27652789 # This message contains a line after the Subject: header that has only
0 commit comments