mirror of
https://github.com/python/cpython
synced 2024-10-14 09:43:55 +00:00
bpo-44395: Fix MIMEPart.as_string to pass unixfrom properly (GH-26685)
This commit is contained in:
parent
45a78f906d
commit
30f7a77f35
|
@ -948,7 +948,7 @@ def __init__(self, policy=None):
|
|||
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 @@ def as_string(self, unixfrom=False, maxheaderlen=None, policy=None):
|
|||
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))
|
||||
|
|
|
@ -775,6 +775,13 @@ def test_as_string_allows_maxheaderlen(self):
|
|||
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)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix :meth:`~email.message.MIMEPart.as_string` to pass unixfrom properly.
|
||||
Patch by Dong-hee Na.
|
Loading…
Reference in a new issue