Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"""

import re
import sys
import urllib # For urllib.parse.unquote
from string import hexdigits
from collections import OrderedDict
Expand Down Expand Up @@ -2591,7 +2592,7 @@ def _refold_parse_tree(parse_tree, *, policy):

"""
# max_line_length 0/None means no limit, ie: infinitely long.
maxlen = policy.max_line_length or float("+inf")
maxlen = policy.max_line_length or sys.maxsize
encoding = 'utf-8' if policy.utf8 else 'us-ascii'
lines = ['']
last_ew = None
Expand Down
3 changes: 2 additions & 1 deletion Lib/email/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import re
import sys
from email._policybase import Policy, Compat32, compat32, _extend_docstrings
from email.utils import _has_surrogates
from email.headerregistry import HeaderRegistry as HeaderRegistry
Expand Down Expand Up @@ -203,7 +204,7 @@ def fold_binary(self, name, value):
def _fold(self, name, value, refold_binary=False):
if hasattr(value, 'name'):
return value.fold(policy=self)
maxlen = self.max_line_length if self.max_line_length else float('inf')
maxlen = self.max_line_length if self.max_line_length else sys.maxsize
lines = value.splitlines()
refold = (self.refold_source == 'all' or
self.refold_source == 'long' and
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_email/test_policy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io
import sys
import types
import textwrap
import unittest
Expand Down Expand Up @@ -134,6 +135,18 @@ def test_policy_addition(self):
for attr, value in expected.items():
self.assertEqual(getattr(added, attr), value)

def test_fold_zero_max_line_length(self):
expected = 'Subject: =?utf-8?q?=C3=A1?=\n'

msg = email.message.EmailMessage()
msg['Subject'] = 'á'

p1 = email.policy.default.clone(max_line_length=0)
p2 = email.policy.default.clone(max_line_length=None)

self.assertEqual(p1.fold('Subject', msg['Subject']), expected)
self.assertEqual(p2.fold('Subject', msg['Subject']), expected)

def test_register_defect(self):
class Dummy:
def __init__(self):
Expand Down