From ec2cd4721864416c08c14feaa3422a17507a81ee Mon Sep 17 00:00:00 2001
From: Gisle Aas <gisle@aas.no>
Date: Tue, 23 Feb 2010 11:30:47 -0500
Subject: [PATCH] Ticket #11212 default to 7bit email
---
django/core/mail/message.py | 2 +-
tests/regressiontests/mail/tests.py | 34 ++++++++++++++++++++++------------
2 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index 14d0017..ac12384 100644
a
|
b
|
from django.utils.encoding import smart_str, force_unicode
|
15 | 15 | |
16 | 16 | # Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from |
17 | 17 | # some spam filters. |
18 | | Charset.add_charset('utf-8', Charset.SHORTEST, Charset.QP, 'utf-8') |
| 18 | Charset.add_charset('utf-8', Charset.SHORTEST, None, 'utf-8') |
19 | 19 | |
20 | 20 | # Default MIME type to use on attachments (if it is not explicitly given |
21 | 21 | # and cannot be guessed). |
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index 79aff35..c84f8bb 100644
a
|
b
|
r"""
|
28 | 28 | >>> message['To'] |
29 | 29 | 'to@example.com' |
30 | 30 | |
| 31 | # Test unicode message |
| 32 | >>> email = EmailMessage(u'Subject \u2624', u'Content \u2624', 'from@example.com', ['to@example.com']) |
| 33 | >>> message = email.message() |
| 34 | >>> message['Subject'].encode() |
| 35 | '=?utf-8?b?U3ViamVjdCDimKQ=?=' |
| 36 | >>> message.get_payload() |
| 37 | 'Content \xe2\x98\xa4' |
| 38 | >>> message.as_string() |
| 39 | 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\nSubject: =?utf-8?b?U3ViamVjdCDimKQ=?=\nFrom: from@example.com\nTo: to@example.com\nDate: ...\nMessage-ID: <...>\n\nContent \xe2\x98\xa4' |
| 40 | |
31 | 41 | # Test multiple-recipient case |
32 | 42 | |
33 | 43 | >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com']) |
… |
… |
BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection T
|
60 | 70 | >>> email = EmailMessage('Long subject lines that get wrapped should use a space continuation character to get expected behaviour in Outlook and Thunderbird', 'Content', 'from@example.com', ['to@example.com']) |
61 | 71 | >>> message = email.message() |
62 | 72 | >>> message.as_string() |
63 | | 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Long subject lines that get wrapped should use a space continuation\n character to get expected behaviour in Outlook and Thunderbird\nFrom: from@example.com\nTo: to@example.com\nDate: ...\nMessage-ID: <...>\n\nContent' |
| 73 | 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Long subject lines that get wrapped should use a space continuation\n character to get expected behaviour in Outlook and Thunderbird\nFrom: from@example.com\nTo: to@example.com\nDate: ...\nMessage-ID: <...>\n\nContent' |
64 | 74 | |
65 | 75 | # Specifying dates or message-ids in the extra headers overrides the defaul |
66 | 76 | # values (#9233). |
… |
… |
BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection T
|
68 | 78 | >>> headers = {"date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"} |
69 | 79 | >>> email = EmailMessage('subject', 'content', 'from@example.com', ['to@example.com'], headers=headers) |
70 | 80 | >>> email.message().as_string() |
71 | | 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: subject\nFrom: from@example.com\nTo: to@example.com\ndate: Fri, 09 Nov 2001 01:08:47 -0000\nMessage-ID: foo\n\ncontent' |
| 81 | 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: subject\nFrom: from@example.com\nTo: to@example.com\ndate: Fri, 09 Nov 2001 01:08:47 -0000\nMessage-ID: foo\n\ncontent' |
72 | 82 | |
73 | 83 | # Test that mail_admins/mail_managers doesn't connect to the mail server if there are no recipients (#9383) |
74 | 84 | |
… |
… |
Content-Type: multipart/alternative;...
|
136 | 146 | ... |
137 | 147 | Content-Type: text/plain; charset="utf-8" |
138 | 148 | MIME-Version: 1.0 |
139 | | Content-Transfer-Encoding: quoted-printable |
| 149 | Content-Transfer-Encoding: 7bit |
140 | 150 | ... |
141 | 151 | This is an important message. |
142 | 152 | ... |
143 | 153 | Content-Type: text/html; charset="utf-8" |
144 | 154 | MIME-Version: 1.0 |
145 | | Content-Transfer-Encoding: quoted-printable |
| 155 | Content-Transfer-Encoding: 7bit |
146 | 156 | ... |
147 | 157 | <p>This is an <strong>important</strong> message.</p> |
148 | 158 | ... |
… |
… |
JVBERi0xLjQuJS4uLg==
|
161 | 171 | >>> connection.send_messages([email]) |
162 | 172 | Content-Type: text/plain; charset="utf-8" |
163 | 173 | MIME-Version: 1.0 |
164 | | Content-Transfer-Encoding: quoted-printable |
| 174 | Content-Transfer-Encoding: 7bit |
165 | 175 | Subject: Subject |
166 | 176 | From: from@example.com |
167 | 177 | To: to@example.com |
… |
… |
Content
|
180 | 190 | >>> print s.getvalue() |
181 | 191 | Content-Type: text/plain; charset="utf-8" |
182 | 192 | MIME-Version: 1.0 |
183 | | Content-Transfer-Encoding: quoted-printable |
| 193 | Content-Transfer-Encoding: 7bit |
184 | 194 | Subject: Subject |
185 | 195 | From: from@example.com |
186 | 196 | To: to@example.com |
… |
… |
Content
|
233 | 243 | >>> print open(os.path.join(tmp_dir, os.listdir(tmp_dir)[0])).read() |
234 | 244 | Content-Type: text/plain; charset="utf-8" |
235 | 245 | MIME-Version: 1.0 |
236 | | Content-Transfer-Encoding: quoted-printable |
| 246 | Content-Transfer-Encoding: 7bit |
237 | 247 | Subject: Subject |
238 | 248 | From: from@example.com |
239 | 249 | To: to@example.com |
… |
… |
True
|
300 | 310 | >>> send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection) |
301 | 311 | Content-Type: text/plain; charset="utf-8" |
302 | 312 | MIME-Version: 1.0 |
303 | | Content-Transfer-Encoding: quoted-printable |
| 313 | Content-Transfer-Encoding: 7bit |
304 | 314 | Subject: Subject |
305 | 315 | From: from@example.com |
306 | 316 | To: to@example.com |
… |
… |
Content
|
317 | 327 | ... ], connection=connection) |
318 | 328 | Content-Type: text/plain; charset="utf-8" |
319 | 329 | MIME-Version: 1.0 |
320 | | Content-Transfer-Encoding: quoted-printable |
| 330 | Content-Transfer-Encoding: 7bit |
321 | 331 | Subject: Subject1 |
322 | 332 | From: from1@example.com |
323 | 333 | To: to1@example.com |
… |
… |
Content1
|
328 | 338 | ------------------------------------------------------------------------------- |
329 | 339 | Content-Type: text/plain; charset="utf-8" |
330 | 340 | MIME-Version: 1.0 |
331 | | Content-Transfer-Encoding: quoted-printable |
| 341 | Content-Transfer-Encoding: 7bit |
332 | 342 | Subject: Subject2 |
333 | 343 | From: from2@example.com |
334 | 344 | To: to2@example.com |
… |
… |
Content2
|
342 | 352 | >>> mail_admins('Subject', 'Content', connection=connection) |
343 | 353 | Content-Type: text/plain; charset="utf-8" |
344 | 354 | MIME-Version: 1.0 |
345 | | Content-Transfer-Encoding: quoted-printable |
| 355 | Content-Transfer-Encoding: 7bit |
346 | 356 | Subject: [Django] Subject |
347 | 357 | From: root@localhost |
348 | 358 | To: nobody@example.com |
… |
… |
Content
|
355 | 365 | >>> mail_managers('Subject', 'Content', connection=connection) |
356 | 366 | Content-Type: text/plain; charset="utf-8" |
357 | 367 | MIME-Version: 1.0 |
358 | | Content-Transfer-Encoding: quoted-printable |
| 368 | Content-Transfer-Encoding: 7bit |
359 | 369 | Subject: [Django] Subject |
360 | 370 | From: root@localhost |
361 | 371 | To: nobody@example.com |