Ticket #11212: 11212.1.diff

File 11212.1.diff, 4.9 KB (added by Ramiro Morales, 14 years ago)

Patch updated to trunk status as of now, also added test for #3472/r5143.

  • django/core/mail/message.py

    diff --git a/django/core/mail/message.py b/django/core/mail/message.py
    a b  
    2121
    2222# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from
    2323# some spam filters.
    24 Charset.add_charset('utf-8', Charset.SHORTEST, Charset.QP, 'utf-8')
     24Charset.add_charset('utf-8', Charset.SHORTEST, None, 'utf-8')
    2525
    2626# Default MIME type to use on attachments (if it is not explicitly given
    2727# 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  
    114114        """
    115115        headers = {"date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"}
    116116        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')
    118118
    119119    def test_from_header(self):
    120120        """
     
    288288        email = EmailMessage('Subject', 'From the future', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
    289289        self.assertFalse('>From the future' in email.message().as_string())
    290290
     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
    291315
    292316class BaseEmailBackendTests(object):
    293317    email_backend = None
     
    409433        email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
    410434        mail.get_connection().send_messages([email])
    411435        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: ')
    413437
    414438    def test_idn_send(self):
    415439        """
     
    547571        s = StringIO()
    548572        connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s)
    549573        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: '))
    551575
    552576
    553577class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
Back to Top