Ticket #11212: 0001-Ticket-11212-default-to-7bit-email.patch

File 0001-Ticket-11212-default-to-7bit-email.patch, 6.6 KB (added by gisle, 15 years ago)

Patch with adjusted tests

  • django/core/mail/message.py

    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  
    1515
    1616# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from
    1717# some spam filters.
    18 Charset.add_charset('utf-8', Charset.SHORTEST, Charset.QP, 'utf-8')
     18Charset.add_charset('utf-8', Charset.SHORTEST, None, 'utf-8')
    1919
    2020# Default MIME type to use on attachments (if it is not explicitly given
    2121# and cannot be guessed).
  • tests/regressiontests/mail/tests.py

    diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
    index 79aff35..c84f8bb 100644
    a b r"""  
    2828>>> message['To']
    2929'to@example.com'
    3030
     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
    3141# Test multiple-recipient case
    3242
    3343>>> 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  
    6070>>> 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'])
    6171>>> message = email.message()
    6272>>> 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'
    6474
    6575# Specifying dates or message-ids in the extra headers overrides the defaul
    6676# values (#9233).
    BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection T  
    6878>>> headers = {"date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"}
    6979>>> email = EmailMessage('subject', 'content', 'from@example.com', ['to@example.com'], headers=headers)
    7080>>> 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'
    7282
    7383# Test that mail_admins/mail_managers doesn't connect to the mail server if there are no recipients (#9383)
    7484
    Content-Type: multipart/alternative;...  
    136146...
    137147Content-Type: text/plain; charset="utf-8"
    138148MIME-Version: 1.0
    139 Content-Transfer-Encoding: quoted-printable
     149Content-Transfer-Encoding: 7bit
    140150...
    141151This is an important message.
    142152...
    143153Content-Type: text/html; charset="utf-8"
    144154MIME-Version: 1.0
    145 Content-Transfer-Encoding: quoted-printable
     155Content-Transfer-Encoding: 7bit
    146156...
    147157<p>This is an <strong>important</strong> message.</p>
    148158...
    JVBERi0xLjQuJS4uLg==  
    161171>>> connection.send_messages([email])
    162172Content-Type: text/plain; charset="utf-8"
    163173MIME-Version: 1.0
    164 Content-Transfer-Encoding: quoted-printable
     174Content-Transfer-Encoding: 7bit
    165175Subject: Subject
    166176From: from@example.com
    167177To: to@example.com
    Content  
    180190>>> print s.getvalue()
    181191Content-Type: text/plain; charset="utf-8"
    182192MIME-Version: 1.0
    183 Content-Transfer-Encoding: quoted-printable
     193Content-Transfer-Encoding: 7bit
    184194Subject: Subject
    185195From: from@example.com
    186196To: to@example.com
    Content  
    233243>>> print open(os.path.join(tmp_dir, os.listdir(tmp_dir)[0])).read()
    234244Content-Type: text/plain; charset="utf-8"
    235245MIME-Version: 1.0
    236 Content-Transfer-Encoding: quoted-printable
     246Content-Transfer-Encoding: 7bit
    237247Subject: Subject
    238248From: from@example.com
    239249To: to@example.com
    True  
    300310>>> send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
    301311Content-Type: text/plain; charset="utf-8"
    302312MIME-Version: 1.0
    303 Content-Transfer-Encoding: quoted-printable
     313Content-Transfer-Encoding: 7bit
    304314Subject: Subject
    305315From: from@example.com
    306316To: to@example.com
    Content  
    317327...     ], connection=connection)
    318328Content-Type: text/plain; charset="utf-8"
    319329MIME-Version: 1.0
    320 Content-Transfer-Encoding: quoted-printable
     330Content-Transfer-Encoding: 7bit
    321331Subject: Subject1
    322332From: from1@example.com
    323333To: to1@example.com
    Content1  
    328338-------------------------------------------------------------------------------
    329339Content-Type: text/plain; charset="utf-8"
    330340MIME-Version: 1.0
    331 Content-Transfer-Encoding: quoted-printable
     341Content-Transfer-Encoding: 7bit
    332342Subject: Subject2
    333343From: from2@example.com
    334344To: to2@example.com
    Content2  
    342352>>> mail_admins('Subject', 'Content', connection=connection)
    343353Content-Type: text/plain; charset="utf-8"
    344354MIME-Version: 1.0
    345 Content-Transfer-Encoding: quoted-printable
     355Content-Transfer-Encoding: 7bit
    346356Subject: [Django] Subject
    347357From: root@localhost
    348358To: nobody@example.com
    Content  
    355365>>> mail_managers('Subject', 'Content', connection=connection)
    356366Content-Type: text/plain; charset="utf-8"
    357367MIME-Version: 1.0
    358 Content-Transfer-Encoding: quoted-printable
     368Content-Transfer-Encoding: 7bit
    359369Subject: [Django] Subject
    360370From: root@localhost
    361371To: nobody@example.com
Back to Top