mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
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>
This commit is contained in:
parent
0bd8297a22
commit
504334c7be
3 changed files with 27 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue