summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2015-05-17 15:29:21 (GMT)
committerR David Murray <rdmurray@bitdance.com>2015-05-17 15:29:21 (GMT)
commit224ef3ec3b0758956789c4c98e6cc93704304419 (patch)
tree4e06303f8a764f65842b432057845c012916ab5c /Lib/test/test_email
parentc1ecef78a3d5f5db47df66cc24929a66466fdcd4 (diff)
downloadcpython-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')
-rw-r--r--Lib/test/test_email/test_generator.py22
-rw-r--r--Lib/test/test_email/test_policy.py4
2 files changed, 26 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()
diff --git a/Lib/test/test_email/test_policy.py b/Lib/test/test_email/test_policy.py
index e797f36..4b0a04e 100644
--- a/Lib/test/test_email/test_policy.py
+++ b/Lib/test/test_email/test_policy.py
@@ -27,6 +27,7 @@ class PolicyAPITests(unittest.TestCase):
# If any of these defaults change, the docs must be updated.
policy_defaults = compat32_defaults.copy()
policy_defaults.update({
+ 'utf8': False,
'raise_on_defect': False,
'header_factory': email.policy.EmailPolicy.header_factory,
'refold_source': 'long',
@@ -42,6 +43,9 @@ class PolicyAPITests(unittest.TestCase):
email.policy.default: make_defaults(policy_defaults, {}),
email.policy.SMTP: make_defaults(policy_defaults,
{'linesep': '\r\n'}),
+ email.policy.SMTPUTF8: make_defaults(policy_defaults,
+ {'linesep': '\r\n',
+ 'utf8': True}),
email.policy.HTTP: make_defaults(policy_defaults,
{'linesep': '\r\n',
'max_line_length': None}),