mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
#14380: Have MIMEText defaults to utf-8 when passed non-ASCII unicode
Previously it would just accept the unicode, which would wind up as unicode in the transfer-encoded message object, which is just wrong. Patch by Jeff Knupp.
This commit is contained in:
parent
192195a4fc
commit
8680bcc5db
5 changed files with 31 additions and 4 deletions
|
|
@ -27,4 +27,14 @@ class MIMEText(MIMENonMultipart):
|
|||
"""
|
||||
MIMENonMultipart.__init__(self, 'text', _subtype,
|
||||
**{'charset': _charset})
|
||||
|
||||
# If _charset was defualted, check to see see if there are non-ascii
|
||||
# characters present. Default to utf-8 if there are.
|
||||
# XXX: This can be removed once #7304 is fixed.
|
||||
if _charset =='us-ascii':
|
||||
try:
|
||||
_text.encode(_charset)
|
||||
except UnicodeEncodeError:
|
||||
_charset = 'utf-8'
|
||||
|
||||
self.set_payload(_text, _charset)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue