]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44395: Fix MIMEPart.as_string to pass unixfrom properly (GH-26685)
authorDong-hee Na <donghee.na@python.org>
Mon, 21 Jun 2021 13:59:02 +0000 (22:59 +0900)
committerGitHub <noreply@github.com>
Mon, 21 Jun 2021 13:59:02 +0000 (22:59 +0900)
Lib/email/message.py
Lib/test/test_email/test_message.py
Misc/NEWS.d/next/Library/2021-06-12-10-08-14.bpo-44395.PcW6Sx.rst [new file with mode: 0644]

index 3701b305532b4c15e65e861d042ad395e3d6cd59..db30d9a17089928010629c722769d681a2b6515a 100644 (file)
@@ -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))
index fab97d91882b8b42c962ceb3588f1df89df5f7d6..7aaf780c042b03c9afdbf5ff7f7e39d34630b669 100644 (file)
@@ -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 (file)
index 0000000..6172eec
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :meth:`~email.message.MIMEPart.as_string` to pass unixfrom properly.
+Patch by Dong-hee Na.