@@ -3989,6 +3989,38 @@ def test_bytes_parser_on_exception_does_not_close_file(self):
39893989 bytesParser (policy = email .policy .strict ).parse ,
39903990 fp )
39913991 self .assertFalse (fp .closed )
3992+
3993+ def test_bytes_parser_uses_policy_utf8_setting (self ):
3994+ m = """
3995+ From: Nathaniel Nameson <[email protected] > 3996+ To: Ned Sampleson <[email protected] > 3997+ Subject: Sample message
3998+ MIME-Version: 1.0
3999+ Content-type: multipart/mixed; boundary="i-am-boundary"
4000+
4001+ This is the préamble. It is to be ignored, though it
4002+ is a handy place for mail composers to include an
4003+ explanatory note to non-MIME compliant readers.
4004+
4005+ --i-am-boundary
4006+ Content-type: text/plain; charset=us-ascii
4007+
4008+ This is explicitly typed plain ASCII text.
4009+ It DOES end with a linebreak.
4010+
4011+ --i-am-boundary
4012+ Content-type: text/plain; charset=utf-8
4013+ Content-Transfer-Encoding: 8bit
4014+
4015+ This should be correctly encapsulated: Un petit café ?
4016+
4017+ --i-am-boundary--
4018+ This is the epilogue. It is also to be ignored.
4019+
4020+ """ .lstrip ()
4021+ M_BYTES = BytesIO (m .encode ())
4022+ msg = email .message_from_binary_file (M_BYTES , policy = email .policy .default .clone (utf8 = True ))
4023+ self .assertEqual (msg .as_string (), m )
39924024
39934025 def test_parser_does_not_close_file (self ):
39944026 with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
0 commit comments