]> granicus.if.org Git - python/commitdiff
[email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (GH-595...
authorMariatta <Mariatta@users.noreply.github.com>
Fri, 16 Jun 2017 14:18:58 +0000 (07:18 -0700)
committerGitHub <noreply@github.com>
Fri, 16 Jun 2017 14:18:58 +0000 (07:18 -0700)
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
Lib/test/test_email/test_generator.py
Misc/ACKS
Misc/NEWS

index df4649676aed72418864b87494a215fde74cd4ed..c9cbadd2a80c48e7ce1c9247a22fd3024f365249 100644 (file)
@@ -361,8 +361,12 @@ class Compat32(Policy):
             # 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)
 
index 7c8877fdcb090ee36844a173f2c8d971cbe7ffae..c4f182903afefea848983045a42ef6dec3baecc4 100644 (file)
@@ -162,6 +162,13 @@ class TestGeneratorBase:
                 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):
 
index f1686b3118ff93e8a6213cc51c4ecfa34e6bbd05..64484f3f8f26aa9221ac0dc7d6d11bbc672e4ecc 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -309,6 +309,7 @@ Garrett Cooper
 Greg Copeland
 Ian Cordasco
 Aldo Cortesi
+Mircea Cosbuc
 David Costanzo
 Scott Cotton
 Greg Couch
index fd7ebf92dc56271cd16d993e9c74af92dc4e4d38..2cc71bded5f044af27c60d43135152a03dc56cc9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,6 +51,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
 -------