From e383aa6d4563ff24f246127416ec6221ef2167e1 Mon Sep 17 00:00:00 2001 From: mircea-cosbuc Date: Mon, 12 Jun 2017 08:43:41 +0200 Subject: [PATCH] [3.6] [email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (GH-595) If max_line_length=None is specified while using the Compat32 policy, it is no longer ignored.. (cherry picked from commit b459f7482612d340b88b62edc024628595ec6337) --- Lib/email/_policybase.py | 8 ++++++-- Lib/test/test_email/test_generator.py | 7 +++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Lib/email/_policybase.py b/Lib/email/_policybase.py index df4649676aed72..c9cbadd2a80c48 100644 --- a/Lib/email/_policybase.py +++ b/Lib/email/_policybase.py @@ -361,8 +361,12 @@ def _fold(self, name, value, sanitize): # Assume it is a Header-like object. h = value if h is not None: - parts.append(h.encode(linesep=self.linesep, - maxlinelen=self.max_line_length)) + # The Header class interprets a value of None for maxlinelen as the + # default value of 78, as recommended by RFC 2822. + maxlinelen = 0 + if self.max_line_length is not None: + maxlinelen = self.max_line_length + parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen)) parts.append(self.linesep) return ''.join(parts) diff --git a/Lib/test/test_email/test_generator.py b/Lib/test/test_email/test_generator.py index 7c8877fdcb090e..c4f182903afefe 100644 --- a/Lib/test/test_email/test_generator.py +++ b/Lib/test/test_email/test_generator.py @@ -162,6 +162,13 @@ def test_set_mangle_from_via_policy(self): g.flatten(msg) self.assertEqual(s.getvalue(), self.typ(expected)) + def test_compat32_max_line_length_does_not_fold_when_none(self): + msg = self.msgmaker(self.typ(self.refold_long_expected[0])) + s = self.ioclass() + g = self.genclass(s, policy=policy.compat32.clone(max_line_length=None)) + g.flatten(msg) + self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[0])) + class TestGenerator(TestGeneratorBase, TestEmailBase): diff --git a/Misc/ACKS b/Misc/ACKS index 1f3a0cceb274b2..fd898e18d939b4 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -308,6 +308,7 @@ Garrett Cooper Greg Copeland Ian Cordasco Aldo Cortesi +Mircea Cosbuc David Costanzo Scott Cotton Greg Couch diff --git a/Misc/NEWS b/Misc/NEWS index 476a50c9d9b22a..2247e81cb83003 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -48,6 +48,9 @@ Core and Builtins - bpo-29714: Fix a regression that bytes format may fail when containing zero bytes inside. +- bpo-29478: If max_line_length=None is specified while using the Compat32 policy, + it is no longer ignored. Patch by Mircea Cosbuc. + Library -------