diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2013-08-19 20:04:50 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2013-08-21 07:44:20 -0300 |
| commit | ececbe77ff573707d8f25084018e66ee07f820fd (patch) | |
| tree | 1903d31ae57bbdd551373b7381d12695d5ff9a97 /django | |
| parent | b065aeb17f9daf395e22d4d5f9f49c0e2c7f4522 (diff) | |
Fixed #12422 -- Don't override global email charset behavior for utf-8.
Thanks simonb for the report, Claude Paroz and Susan Tan for their work
on a fix.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/mail/message.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 9796e59260..a24817ac90 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -22,7 +22,8 @@ from django.utils import six # Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from # some spam filters. -Charset.add_charset('utf-8', Charset.SHORTEST, None, 'utf-8') +utf8_charset = Charset.Charset('utf-8') +utf8_charset.body_encoding = None # Python defaults to BASE64 # Default MIME type to use on attachments (if it is not explicitly given # and cannot be guessed). @@ -145,7 +146,16 @@ class SafeMIMEText(MIMEText): def __init__(self, text, subtype, charset): self.encoding = charset - MIMEText.__init__(self, text, subtype, charset) + if charset == 'utf-8': + # Unfortunately, Python doesn't support setting a Charset instance + # as MIMEText init parameter (http://bugs.python.org/issue16324). + # We do it manually and trigger re-encoding of the payload. + MIMEText.__init__(self, text, subtype, None) + del self['Content-Transfer-Encoding'] + self.set_payload(text, utf8_charset) + self.replace_header('Content-Type', 'text/%s; charset="%s"' % (subtype, charset)) + else: + MIMEText.__init__(self, text, subtype, charset) def __setitem__(self, name, val): name, val = forbid_multi_line_headers(name, val, self.encoding) |
