diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-06-21 07:27:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-21 07:27:42 -0700 |
commit | 67b3a9995368f89b7ce4a995920b2a83a81c599b (patch) | |
tree | 48dbdf662a79694da43d5b27b38ed94fc95be5dc | |
parent | 83ad40efc3e299d1e94692d958111a63c2fd6775 (diff) | |
download | cpython-git-67b3a9995368f89b7ce4a995920b2a83a81c599b.tar.gz |
bpo-44395: Fix MIMEPart.as_string to pass unixfrom properly (GH-26685)
(cherry picked from commit 30f7a77f359a0fc6e37988b0f317a77a15d66b7b)
Co-authored-by: Dong-hee Na <donghee.na@python.org>
-rw-r--r-- | Lib/email/message.py | 4 | ||||
-rw-r--r-- | Lib/test/test_email/test_message.py | 7 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-06-12-10-08-14.bpo-44395.PcW6Sx.rst | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py index 3701b30553..db30d9a170 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -948,7 +948,7 @@ class MIMEPart(Message): if policy is None: from email.policy import default policy = default - Message.__init__(self, policy) + super().__init__(policy) def as_string(self, unixfrom=False, maxheaderlen=None, policy=None): @@ -965,7 +965,7 @@ class MIMEPart(Message): policy = self.policy if policy is None else policy if maxheaderlen is None: maxheaderlen = policy.max_line_length - return super().as_string(maxheaderlen=maxheaderlen, policy=policy) + return super().as_string(unixfrom, maxheaderlen, policy) def __str__(self): return self.as_string(policy=self.policy.clone(utf8=True)) diff --git a/Lib/test/test_email/test_message.py b/Lib/test/test_email/test_message.py index fab97d9188..7aaf780c04 100644 --- a/Lib/test/test_email/test_message.py +++ b/Lib/test/test_email/test_message.py @@ -775,6 +775,13 @@ class TestEmailMessage(TestEmailMessageBase, TestEmailBase): self.assertEqual(len(m.as_string(maxheaderlen=34).strip().splitlines()), 6) + def test_as_string_unixform(self): + m = self._str_msg('test') + m.set_unixfrom('From foo@bar Thu Jan 1 00:00:00 1970') + self.assertEqual(m.as_string(unixfrom=True), + 'From foo@bar Thu Jan 1 00:00:00 1970\n\ntest') + self.assertEqual(m.as_string(unixfrom=False), '\ntest') + def test_str_defaults_to_policy_max_line_length(self): m = self._str_msg('Subject: long line' + ' ab'*50 + '\n\n') self.assertEqual(len(str(m).strip().splitlines()), 3) diff --git a/Misc/NEWS.d/next/Library/2021-06-12-10-08-14.bpo-44395.PcW6Sx.rst b/Misc/NEWS.d/next/Library/2021-06-12-10-08-14.bpo-44395.PcW6Sx.rst new file mode 100644 index 0000000000..6172eec0a9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-06-12-10-08-14.bpo-44395.PcW6Sx.rst @@ -0,0 +1,2 @@ +Fix :meth:`~email.message.MIMEPart.as_string` to pass unixfrom properly. +Patch by Dong-hee Na. |