diff options
| author | Rito Takeuchi <licht-t@outlook.jp> | 2024-01-26 15:19:41 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-26 15:19:41 (GMT) |
| commit | 504334c7be5a56237df2598d338cd494a42fca4c (patch) | |
| tree | 48e41f69428ffedf8866c3e227ee8a9c0d190649 /Lib/email/policy.py | |
| parent | 0bd8297a2208125f76807cdf01f72abe5c94136b (diff) | |
| download | cpython-504334c7be5a56237df2598d338cd494a42fca4c.zip cpython-504334c7be5a56237df2598d338cd494a42fca4c.tar.gz cpython-504334c7be5a56237df2598d338cd494a42fca4c.tar.bz2 | |
gh-77749: Fix inconsistent behavior of non-ASCII handling in EmailPolicy.fold() (GH-6986)
It now always encodes non-ASCII characters in headers if utf8 is false.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/email/policy.py')
| -rw-r--r-- | Lib/email/policy.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/email/policy.py b/Lib/email/policy.py index 611deb5..8816c84 100644 --- a/Lib/email/policy.py +++ b/Lib/email/policy.py @@ -210,8 +210,15 @@ class EmailPolicy(Policy): self.refold_source == 'long' and (lines and len(lines[0])+len(name)+2 > maxlen or any(len(x) > maxlen for x in lines[1:]))) - if refold or refold_binary and _has_surrogates(value): + + if not refold: + if not self.utf8: + refold = not value.isascii() + elif refold_binary: + refold = _has_surrogates(value) + if refold: return self.header_factory(name, ''.join(lines)).fold(policy=self) + return name + ': ' + self.linesep.join(lines) + self.linesep |
