Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7747: Altered EmailMessage such that messages with long subjec…

…t lines don't use tabs in their continutation sequence. Tabs in subjects cause problems with Outlook and Thunderbird. Thanks to Mark Allison <mark.allison@maplecroft.com> for the report and fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8483 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0f869f905e7d3a335ea9090fa079baf4b5883ec7 1 parent b35acb3
Russell Keith-Magee authored August 23, 2008
3  django/core/mail.py
@@ -86,6 +86,9 @@ def forbid_multi_line_headers(name, val):
86 86
             val = ', '.join(result)
87 87
         else:
88 88
             val = Header(val, settings.DEFAULT_CHARSET)
  89
+    else:
  90
+        if name.lower() == 'subject':
  91
+            val = Header(val)
89 92
     return name, val
90 93
 
91 94
 class SafeMIMEText(MIMEText):
11  tests/regressiontests/mail/tests.py
@@ -10,6 +10,8 @@
10 10
 >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'])
11 11
 >>> message = email.message()
12 12
 >>> message['Subject']
  13
+<email.header.Header instance...>
  14
+>>> message['Subject'].encode()
13 15
 'Subject'
14 16
 >>> message.get_payload()
15 17
 'Content'
@@ -23,6 +25,8 @@
23 25
 >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com'])
24 26
 >>> message = email.message()
25 27
 >>> message['Subject']
  28
+<email.header.Header instance...>
  29
+>>> message['Subject'].encode()
26 30
 'Subject'
27 31
 >>> message.get_payload()
28 32
 'Content'
@@ -45,4 +49,11 @@
45 49
     ...
46 50
 BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection Test' for header 'Subject')
47 51
 
  52
+# Test for space continuation character in long (ascii) subject headers (#7747)
  53
+
  54
+>>> 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'])
  55
+>>> message = email.message()
  56
+>>> message.as_string()
  57
+'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'
  58
+
48 59
 """

0 notes on commit 0f869f9

Please sign in to comment.
Something went wrong with that request. Please try again.