mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-117313: Fix re-folding email messages containing non-standard line separators (GH-117369)
Only treat '\n', '\r' and '\r\n' as line separators in re-folding the email messages. Preserve control characters '\v', '\f', '\x1c', '\x1d' and '\x1e' and Unicode line separators '\x85', '\u2028' and '\u2029' as is.
This commit is contained in:
parent
4e502a4997
commit
aec1dac4ef
3 changed files with 56 additions and 2 deletions
|
@ -21,7 +21,7 @@ __all__ = [
|
|||
'HTTP',
|
||||
]
|
||||
|
||||
linesep_splitter = re.compile(r'\n|\r')
|
||||
linesep_splitter = re.compile(r'\n|\r\n?')
|
||||
|
||||
@_extend_docstrings
|
||||
class EmailPolicy(Policy):
|
||||
|
@ -205,7 +205,8 @@ class EmailPolicy(Policy):
|
|||
if hasattr(value, 'name'):
|
||||
return value.fold(policy=self)
|
||||
maxlen = self.max_line_length if self.max_line_length else sys.maxsize
|
||||
lines = value.splitlines()
|
||||
# We can't use splitlines here because it splits on more than \r and \n.
|
||||
lines = linesep_splitter.split(value)
|
||||
refold = (self.refold_source == 'all' or
|
||||
self.refold_source == 'long' and
|
||||
(lines and len(lines[0])+len(name)+2 > maxlen or
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue