Code

Ticket #7747: long_email_subject_wrapping_fix_and_test.diff

File long_email_subject_wrapping_fix_and_test.diff, 2.1 KB (added by mark.allison@…, 6 years ago)

updated patch for compatibility with latest code and added test

Line 
1Index: django/django/core/mail.py
2===================================================================
3--- django/django/core/mail.py  (revision 8431)
4+++ django/django/core/mail.py  (working copy)
5@@ -86,6 +86,9 @@
6             val = ', '.join(result)
7         else:
8             val = Header(val, settings.DEFAULT_CHARSET)
9+    else:
10+        if name.lower() == 'subject':
11+            val = Header(val)
12     return name, val
13 
14 class SafeMIMEText(MIMEText):
15Index: django/tests/regressiontests/mail/tests.py
16===================================================================
17--- django/tests/regressiontests/mail/tests.py  (revision 8431)
18+++ django/tests/regressiontests/mail/tests.py  (working copy)
19@@ -10,6 +10,8 @@
20 >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'])
21 >>> message = email.message()
22 >>> message['Subject']
23+<email.header.Header instance at 0x...>
24+>>> message['Subject'].encode()
25 'Subject'
26 >>> message.get_payload()
27 'Content'
28@@ -23,6 +25,8 @@
29 >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com'])
30 >>> message = email.message()
31 >>> message['Subject']
32+<email.header.Header instance at 0x...>
33+>>> message['Subject'].encode()
34 'Subject'
35 >>> message.get_payload()
36 'Content'
37@@ -45,4 +49,11 @@
38     ...
39 BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection Test' for header 'Subject')
40 
41+# Test for space continuation character in long (ascii) subject headers
42+
43+>>> 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'])
44+>>> message = email.message()
45+>>> message.as_string()
46+'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'
47+
48 """