diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-04-17 10:00:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 10:00:25 (GMT) |
commit | aec1dac4efe36a7db51f08385ddcce978814dbe3 (patch) | |
tree | 79b182f01e4d917bfa03810fb9e73845765e16f8 /Lib/email | |
parent | 4e502a4997af4c8042a6ac13115a3f8ba31520ea (diff) | |
download | cpython-aec1dac4efe36a7db51f08385ddcce978814dbe3.zip cpython-aec1dac4efe36a7db51f08385ddcce978814dbe3.tar.gz cpython-aec1dac4efe36a7db51f08385ddcce978814dbe3.tar.bz2 |
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.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/policy.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/email/policy.py b/Lib/email/policy.py index 8816c84..46b7de5 100644 --- a/Lib/email/policy.py +++ b/Lib/email/policy.py @@ -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 |