summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorJens Troeger <jenstroeger@users.noreply.github.com>2019-05-14 01:07:39 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2019-05-14 01:07:39 (GMT)
commit45b2f8893c1b7ab3b3981a966f82e42beea82106 (patch)
tree9f8ae3a45d2280fe4cc6f0b2b8f9fb0f1c21e0f9 /Lib/test/test_email
parent8da5ebe11e0cb6599af682b22f7c2b2b7b9debd8 (diff)
downloadcpython-45b2f8893c1b7ab3b3981a966f82e42beea82106.zip
cpython-45b2f8893c1b7ab3b3981a966f82e42beea82106.tar.gz
cpython-45b2f8893c1b7ab3b3981a966f82e42beea82106.tar.bz2
bpo-34424: Handle different policy.linesep lengths correctly. (#8803)
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r--Lib/test/test_email/test_generator.py22
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 c1aeaef..89e7ede 100644
--- a/Lib/test/test_email/test_generator.py
+++ b/Lib/test/test_email/test_generator.py
@@ -4,6 +4,7 @@ import unittest
from email import message_from_string, message_from_bytes
from email.message import EmailMessage
from email.generator import Generator, BytesGenerator
+from email.headerregistry import Address
from email import policy
from test.test_email import TestEmailBase, parameterize
@@ -291,6 +292,27 @@ class TestBytesGenerator(TestGeneratorBase, TestEmailBase):
g.flatten(msg)
self.assertEqual(s.getvalue(), expected)
+ def test_smtp_policy(self):
+ msg = EmailMessage()
+ msg["From"] = Address(addr_spec="foo@bar.com", display_name="Páolo")
+ msg["To"] = Address(addr_spec="bar@foo.com", display_name="Dinsdale")
+ msg["Subject"] = "Nudge nudge, wink, wink"
+ msg.set_content("oh boy, know what I mean, know what I mean?")
+ expected = textwrap.dedent("""\
+ From: =?utf-8?q?P=C3=A1olo?= <foo@bar.com>
+ To: Dinsdale <bar@foo.com>
+ Subject: Nudge nudge, wink, wink
+ Content-Type: text/plain; charset="utf-8"
+ Content-Transfer-Encoding: 7bit
+ MIME-Version: 1.0
+
+ oh boy, know what I mean, know what I mean?
+ """).encode().replace(b"\n", b"\r\n")
+ s = io.BytesIO()
+ g = BytesGenerator(s, policy=policy.SMTP)
+ g.flatten(msg)
+ self.assertEqual(s.getvalue(), expected)
+
if __name__ == '__main__':
unittest.main()