diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/email/contentmanager.py | 4 | ||||
-rw-r--r-- | Lib/test/test_email/test_contentmanager.py | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/Lib/email/contentmanager.py b/Lib/email/contentmanager.py index b91fb0e..3cf62dc 100644 --- a/Lib/email/contentmanager.py +++ b/Lib/email/contentmanager.py @@ -238,9 +238,7 @@ def set_bytes_content(msg, data, maintype, subtype, cte='base64', data = binascii.b2a_qp(data, istext=False, header=False, quotetabs=True) data = data.decode('ascii') elif cte == '7bit': - # Make sure it really is only ASCII. The early warning here seems - # worth the overhead...if you care write your own content manager :). - data.encode('ascii') + data = data.decode('ascii') elif cte in ('8bit', 'binary'): data = data.decode('ascii', 'surrogateescape') msg.set_payload(data) diff --git a/Lib/test/test_email/test_contentmanager.py b/Lib/test/test_email/test_contentmanager.py index f4f6bb7..694cef4 100644 --- a/Lib/test/test_email/test_contentmanager.py +++ b/Lib/test/test_email/test_contentmanager.py @@ -776,6 +776,18 @@ class TestRawDataManager(TestEmailBase): foo """).encode('ascii')) + def test_set_content_bytes_cte_7bit(self): + m = self._make_message() + m.set_content(b'ASCII-only message.\n', + maintype='application', subtype='octet-stream', cte='7bit') + self.assertEqual(str(m), textwrap.dedent("""\ + Content-Type: application/octet-stream + Content-Transfer-Encoding: 7bit + MIME-Version: 1.0 + + ASCII-only message. + """)) + content_object_params = { 'text_plain': ('content', ()), 'text_html': ('content', ('html',)), |