From 280c1a65ccacd679bf298bf2b169ff01e7266b8e Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Sat, 28 Dec 2013 15:24:25 +0100 Subject: [PATCH] Worked around a bug in python 3.3.3. Refs #21093 --- django/core/mail/message.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 051a00fa81..cde37ea6d2 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -167,7 +167,14 @@ class SafeMIMEText(MIMEMixin, MIMEText): # 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) + # Work around a bug in python 3.3.3 [sic], see + # http://bugs.python.org/issue19063 for details. + if sys.version_info[:3] == (3, 3, 3): + payload = text.encode(utf8_charset.output_charset) + self._payload = payload.decode('ascii', 'surrogateescape') + self.set_charset(utf8_charset) + else: + self.set_payload(text, utf8_charset) self.replace_header('Content-Type', 'text/%s; charset="%s"' % (subtype, charset)) else: MIMEText.__init__(self, text, subtype, charset)