Ticket #12791: emailmessage-body-encoding.diff
File emailmessage-body-encoding.diff, 2.2 KB (added by , 15 years ago) |
---|
-
django/core/mail/message.py
131 131 132 132 def message(self): 133 133 encoding = self.encoding or settings.DEFAULT_CHARSET 134 msg = SafeMIMEText(smart_str(self.body, settings.DEFAULT_CHARSET),134 msg = SafeMIMEText(smart_str(self.body, encoding), 135 135 self.content_subtype, encoding) 136 136 msg = self._create_message(msg) 137 137 msg['Subject'] = self.subject -
tests/regressiontests/mail/tests.py
112 112 >>> email.message()['To'] 113 113 '=?utf-8?q?S=C3=BCrname=2C_Firstname?= <to@example.com>, other@example.com' 114 114 115 # Handle attachments within an multipart/alternative mail correctly (#9367) 116 # (test is not as precise/clear as it could be w.r.t. email tree structure, 117 # but it's good enough.) 115 # Regression for #12791 - Encode body correctly with other encodings than utf-8 116 >>> email = EmailMessage('Subject', 'Æ e trønder æ å hærregud kor tøff æ e', 'from@example.com', ['other@example.com']) 117 >>> message = email.message() 118 >>> message.as_string() 119 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: from@example.com\nTo: other@example.com\nDate: ...\nMessage-ID: <...>\n\n=C3=86 e tr=C3=B8nder =C3=A6 =C3=A5 h=C3=A6rregud kor t=C3=B8ff =C3=A6 e' 118 120 121 >>> email.encoding = 'iso-8859-1' 122 >>> message = email.message() 123 >>> message.as_string() 124 'Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: from@example.com\nTo: other@example.com\nDate: ...\nMessage-ID: <...>\n\n=C6 e tr=F8nder =E6 =E5 h=E6rregud kor t=F8ff =E6 e' 125 119 126 >>> headers = {"Date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"} 120 127 >>> subject, from_email, to = 'hello', 'from@example.com', 'to@example.com' 121 128 >>> text_content = 'This is an important message.'