Skip to content

Commit 820b714

Browse files
authored
[email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (GH-595) (GH-2234)
If max_line_length=None is specified while using the Compat32 policy, it is no longer ignored.. (cherry picked from commit b459f74)
1 parent 0b13f58 commit 820b714

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Lib/email/_policybase.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,12 @@ def _fold(self, name, value, sanitize):
357357
# Assume it is a Header-like object.
358358
h = value
359359
if h is not None:
360-
parts.append(h.encode(linesep=self.linesep,
361-
maxlinelen=self.max_line_length))
360+
# The Header class interprets a value of None for maxlinelen as the
361+
# default value of 78, as recommended by RFC 2822.
362+
maxlinelen = 0
363+
if self.max_line_length is not None:
364+
maxlinelen = self.max_line_length
365+
parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
362366
parts.append(self.linesep)
363367
return ''.join(parts)
364368

Lib/test/test_email/test_generator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ def test_set_mangle_from_via_policy(self):
162162
g.flatten(msg)
163163
self.assertEqual(s.getvalue(), self.typ(expected))
164164

165+
def test_compat32_max_line_length_does_not_fold_when_none(self):
166+
msg = self.msgmaker(self.typ(self.refold_long_expected[0]))
167+
s = self.ioclass()
168+
g = self.genclass(s, policy=policy.compat32.clone(max_line_length=None))
169+
g.flatten(msg)
170+
self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[0]))
171+
165172

166173
class TestGenerator(TestGeneratorBase, TestEmailBase):
167174

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ Garrett Cooper
304304
Greg Copeland
305305
Ian Cordasco
306306
Aldo Cortesi
307+
Mircea Cosbuc
307308
David Costanzo
308309
Scott Cotton
309310
Greg Couch

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Core and Builtins
4848
- Issue #29337: Fixed possible BytesWarning when compare the code objects.
4949
Warnings could be emitted at compile time.
5050

51+
- bpo-29478: If max_line_length=None is specified while using the Compat32 policy,
52+
it is no longer ignored. Patch by Mircea Cosbuc.
53+
5154
Extension Modules
5255
-----------------
5356

0 commit comments

Comments
 (0)