diff options
author | R David Murray <rdmurray@bitdance.com> | 2015-05-17 15:29:21 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2015-05-17 15:29:21 (GMT) |
commit | 224ef3ec3b0758956789c4c98e6cc93704304419 (patch) | |
tree | 4e06303f8a764f65842b432057845c012916ab5c /Lib/test/test_email/test_generator.py | |
parent | c1ecef78a3d5f5db47df66cc24929a66466fdcd4 (diff) | |
download | cpython-224ef3ec3b0758956789c4c98e6cc93704304419.zip cpython-224ef3ec3b0758956789c4c98e6cc93704304419.tar.gz cpython-224ef3ec3b0758956789c4c98e6cc93704304419.tar.bz2 |
#24211: Add RFC6532 support to the email library.
This could use more edge case tests, but the basic functionality is tested.
(Note that this changeset does not add tailored support for the RFC 6532
message/global MIME type, but the email package generic facilities will handle
it.)
Reviewed by Maciej Szulik.
Diffstat (limited to 'Lib/test/test_email/test_generator.py')
-rw-r--r-- | Lib/test/test_email/test_generator.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_generator.py b/Lib/test/test_email/test_generator.py index 8917408..920f870 100644 --- a/Lib/test/test_email/test_generator.py +++ b/Lib/test/test_email/test_generator.py @@ -2,6 +2,7 @@ import io import textwrap import unittest from email import message_from_string, message_from_bytes +from email.message import EmailMessage from email.generator import Generator, BytesGenerator from email import policy from test.test_email import TestEmailBase, parameterize @@ -194,6 +195,27 @@ class TestBytesGenerator(TestGeneratorBase, TestEmailBase): g.flatten(msg) self.assertEqual(s.getvalue(), expected) + def test_smtputf8_policy(self): + msg = EmailMessage() + msg['From'] = "Páolo <főo@bar.com>" + msg['To'] = 'Dinsdale' + msg['Subject'] = 'Nudge nudge, wink, wink \u1F609' + msg.set_content("oh là là, know what I mean, know what I mean?") + expected = textwrap.dedent("""\ + From: Páolo <főo@bar.com> + To: Dinsdale + Subject: Nudge nudge, wink, wink \u1F609 + Content-Type: text/plain; charset="utf-8" + Content-Transfer-Encoding: 8bit + MIME-Version: 1.0 + + oh là là, know what I mean, know what I mean? + """).encode('utf-8').replace(b'\n', b'\r\n') + s = io.BytesIO() + g = BytesGenerator(s, policy=policy.SMTPUTF8) + g.flatten(msg) + self.assertEqual(s.getvalue(), expected) + if __name__ == '__main__': unittest.main() |