Ticket #11212: 11212.1.diff
File 11212.1.diff, 4.9 KB (added by , 14 years ago) |
---|
-
django/core/mail/message.py
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
a b 21 21 22 22 # Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from 23 23 # some spam filters. 24 Charset.add_charset('utf-8', Charset.SHORTEST, Charset.QP, 'utf-8')24 Charset.add_charset('utf-8', Charset.SHORTEST, None, 'utf-8') 25 25 26 26 # Default MIME type to use on attachments (if it is not explicitly given 27 27 # and cannot be guessed). -
tests/regressiontests/mail/tests.py
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
a b 114 114 """ 115 115 headers = {"date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"} 116 116 email = EmailMessage('subject', 'content', 'from@example.com', ['to@example.com'], headers=headers) 117 self.assertEqual(email.message().as_string(), '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')117 self.assertEqual(email.message().as_string(), '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') 118 118 119 119 def test_from_header(self): 120 120 """ … … 288 288 email = EmailMessage('Subject', 'From the future', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'}) 289 289 self.assertFalse('>From the future' in email.message().as_string()) 290 290 291 def test_dont_base64_encode(self): 292 # Ticket #3472 293 # Shouldn't use Base64 encoding at all 294 msg = EmailMessage('Subject', 'UTF-8 encoded body', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'}) 295 self.assertFalse('Content-Transfer-Encoding: base64' in msg.message().as_string()) 296 297 # Ticket #11212 298 # Shouldn't use quoted printable, should detect it can represent content with 7 bit data 299 msg = EmailMessage('Subject', 'Body with only ASCII characters.', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'}) 300 s = msg.message().as_string() 301 self.assertFalse('Content-Transfer-Encoding: quoted-printable' in s) 302 self.assertTrue('Content-Transfer-Encoding: 7bit' in s) 303 304 # Shouldn't use quoted printable, should detect it can represent content with 8 bit data 305 msg = EmailMessage('Subject', 'Body with latin characters: àáä.', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'}) 306 s = msg.message().as_string() 307 self.assertFalse('Content-Transfer-Encoding: quoted-printable' in s) 308 self.assertTrue('Content-Transfer-Encoding: 8bit' in s) 309 310 msg = EmailMessage('Subject', u'Body with non latin characters: А Б В Г Д Е Ж Ѕ З И І К Л М Н О П.', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'}) 311 s = msg.message().as_string() 312 self.assertFalse('Content-Transfer-Encoding: quoted-printable' in s) 313 self.assertTrue('Content-Transfer-Encoding: 8bit' in s) 314 291 315 292 316 class BaseEmailBackendTests(object): 293 317 email_backend = None … … 409 433 email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com']) 410 434 mail.get_connection().send_messages([email]) 411 435 message = self.get_the_message() 412 self.assertStartsWith(message.as_string(), '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\nCc: cc@example.com\nDate: ')436 self.assertStartsWith(message.as_string(), '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\nCc: cc@example.com\nDate: ') 413 437 414 438 def test_idn_send(self): 415 439 """ … … 547 571 s = StringIO() 548 572 connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s) 549 573 send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection) 550 self.assertTrue(s.getvalue().startswith('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: '))574 self.assertTrue(s.getvalue().startswith('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: ')) 551 575 552 576 553 577 class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):