File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,21 +54,12 @@ def encode_7or8bit(msg):
5454 # There's no payload. For backwards compatibility we use 7bit
5555 msg ['Content-Transfer-Encoding' ] = '7bit'
5656 return
57- # We play a trick to make this go fast. If encoding/decode to ASCII
58- # succeeds, we know the data must be 7bit, otherwise treat it as 8bit.
57+ # We play a trick to make this go fast. If decoding from ASCII succeeds,
58+ # we know the data must be 7bit, otherwise treat it as 8bit.
5959 try :
60- if isinstance (orig , str ):
61- orig .encode ('ascii' )
62- else :
63- orig .decode ('ascii' )
60+ orig .decode ('ascii' )
6461 except UnicodeError :
65- charset = msg .get_charset ()
66- output_cset = charset and charset .output_charset
67- # iso-2022-* is non-ASCII but encodes to a 7-bit representation
68- if output_cset and output_cset .lower ().startswith ('iso-2022-' ):
69- msg ['Content-Transfer-Encoding' ] = '7bit'
70- else :
71- msg ['Content-Transfer-Encoding' ] = '8bit'
62+ msg ['Content-Transfer-Encoding' ] = '8bit'
7263 else :
7364 msg ['Content-Transfer-Encoding' ] = '7bit'
7465
Original file line number Diff line number Diff line change @@ -765,8 +765,15 @@ def test_encode7or8bit(self):
765765 # whose output character set is 7bit gets a transfer-encoding
766766 # of 7bit.
767767 eq = self .assertEqual
768- msg = MIMEText ('文' , _charset = 'euc-jp' )
768+ msg = MIMEText ('文\n ' , _charset = 'euc-jp' )
769769 eq (msg ['content-transfer-encoding' ], '7bit' )
770+ eq (msg .as_string (), textwrap .dedent ("""\
771+ MIME-Version: 1.0
772+ Content-Type: text/plain; charset="iso-2022-jp"
773+ Content-Transfer-Encoding: 7bit
774+
775+ \x1b $BJ8\x1b (B
776+ """ ))
770777
771778 def test_qp_encode_latin1 (self ):
772779 msg = MIMEText ('\xe1 \xf6 \n ' , 'text' , 'ISO-8859-1' )
You can’t perform that action at this time.
0 commit comments