8000 [email] bpo-29478: Fix passing max_line_length=None from Compat32 pol… · python/cpython@e9f4d8d · GitHub
[go: up one dir, main page]

Skip to content

Commit e9f4d8d

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

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
@@ -361,8 +361,12 @@ def _fold(self, name, value, sanitize):
361361
# Assume it is a Header-like object.
362362
h = value
363363
if h is not None:
364-
parts.append(h.encode(linesep=self.linesep,
365-
maxlinelen=self.max_line_length))
364+
# The Header class interprets a value of None for maxlinelen as the
365+
# default value of 78, as recommended by RFC 2822.
366+
maxlinelen = 0
367+
if self.max_line_length is not None:
368+
maxlinelen = self.max_line_length
369+
parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
366370
parts.append(self.linesep)
367371
return ''.join(parts)
368372

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
@@ -309,6 +309,7 @@ Garrett Cooper
309309
Greg Copeland
310310
Ian Cordasco
311311
Aldo Cortesi
312+
Mircea Cosbuc
312313
David Costanzo
313314
Scott Cotton
314315
Greg Couch

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Core and Builtins
5151
- bpo-29714: Fix a regression that bytes format may fail when containing zero
5252
bytes inside.
5353

54+
- bpo-29478: If max_line_length=None is specified while using the Compat32 policy,
55+
it is no longer ignored. Patch by Mircea Cosbuc.
56+
5457
Library
5558
-------
5659

0 commit comments

Comments
 (0)
0