Skip to content

Commit 3bc8212

Browse files
authored
email: Correctly decode using policy UTF-8 attribute in BytesParser
1 parent 91e6a58 commit 3bc8212

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Lib/email/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def parse(self, fp, headersonly=False):
100100
parsing after reading the headers or not. The default is False,
101101
meaning it parses the entire contents of the file.
102102
"""
103-
fp = TextIOWrapper(fp, encoding='ascii', errors='surrogateescape')
103+
encoding = "utf-8" if getattr(self.parser.policy, "utf8", False) else "ascii"
104+
fp = TextIOWrapper(fp, encoding=encoding, errors='surrogateescape')
104105
try:
105106
return self.parser.parse(fp, headersonly)
106107
finally:

0 commit comments

Comments
 (0)