Skip to content

Commit 30f7a77

Browse files
authored
bpo-44395: Fix MIMEPart.as_string to pass unixfrom properly (pythonGH-26685)
1 parent 45a78f9 commit 30f7a77

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Lib/email/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def __init__(self, policy=None):
948948
if policy is None:
949949
from email.policy import default
950950
policy = default
951-
Message.__init__(self, policy)
951+
super().__init__(policy)
952952

953953

954954
def as_string(self, unixfrom=False, maxheaderlen=None, policy=None):
@@ -965,7 +965,7 @@ def as_string(self, unixfrom=False, maxheaderlen=None, policy=None):
965965
policy = self.policy if policy is None else policy
966966
if maxheaderlen is None:
967967
maxheaderlen = policy.max_line_length
968-
return super().as_string(maxheaderlen=maxheaderlen, policy=policy)
968+
return super().as_string(unixfrom, maxheaderlen, policy)
969969

970970
def __str__(self):
971971
return self.as_string(policy=self.policy.clone(utf8=True))

Lib/test/test_email/test_message.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,13 @@ def test_as_string_allows_maxheaderlen(self):
775775
self.assertEqual(len(m.as_string(maxheaderlen=34).strip().splitlines()),
776776
6)
777777

778+
def test_as_string_unixform(self):
779+
m = self._str_msg('test')
780+
m.set_unixfrom('From foo@bar Thu Jan 1 00:00:00 1970')
781+
self.assertEqual(m.as_string(unixfrom=True),
782+
'From foo@bar Thu Jan 1 00:00:00 1970\n\ntest')
783+
self.assertEqual(m.as_string(unixfrom=False), '\ntest')
784+
778785
def test_str_defaults_to_policy_max_line_length(self):
779786
m = self._str_msg('Subject: long line' + ' ab'*50 + '\n\n')
780787
self.assertEqual(len(str(m).strip().splitlines()), 3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :meth:`~email.message.MIMEPart.as_string` to pass unixfrom properly.
2+
Patch by Dong-hee Na.

0 commit comments

Comments
 (0)