diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py index 2e77e619e1d..20feb026fdf 100644 --- a/Lib/email/encoders.py +++ b/Lib/email/encoders.py @@ -62,7 +62,7 @@ def encode_7or8bit(msg): # iso-2022-* is non-ASCII but still 7-bit charset = msg.get_charset() output_cset = charset and charset.output_charset - if output_cset and output_cset.lower().startswith('iso-2202-'): + if output_cset and output_cset.lower().startswith('iso-2022-'): msg['Content-Transfer-Encoding'] = '7bit' else: msg['Content-Transfer-Encoding'] = '8bit' diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 1f257c7a687..2ebd39f2db9 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -526,6 +526,13 @@ class TestEncoders(unittest.TestCase): msg = MIMEText('hello \xf8 world', _charset='iso-8859-1') eq(msg['content-transfer-encoding'], 'quoted-printable') + def test_encode7or8bit(self): + # Make sure a charset whose input character set is 8bit but + # whose output character set is 7bit gets a transfer-encoding + # of 7bit. + eq = self.assertEqual + msg = MIMEText('\xca\xb8', _charset='euc-jp') + eq(msg['content-transfer-encoding'], '7bit') # Test long header wrapping diff --git a/Misc/NEWS b/Misc/NEWS index 7147f775a33..227ebff37a6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,10 @@ Core and Builtins Library ------- +- Issue #7472: Fixed typo in email.encoders module; messages using ISO-2022 + character sets will now consistently use a Content-Transfer-Encoding of + 7bit rather than sometimes being marked as 8bit. + - Issue #4265: shutil.copyfile() was leaking file descriptors when disk fills. Patch by Tres Seaver.