diff --git a/django/core/mail.py b/django/core/mail.py index d6c6eea190..1ac2a39908 100644 --- a/django/core/mail.py +++ b/django/core/mail.py @@ -86,6 +86,9 @@ def forbid_multi_line_headers(name, val): val = ', '.join(result) else: val = Header(val, settings.DEFAULT_CHARSET) + else: + if name.lower() == 'subject': + val = Header(val) return name, val class SafeMIMEText(MIMEText): diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py index be59234342..ba08929137 100644 --- a/tests/regressiontests/mail/tests.py +++ b/tests/regressiontests/mail/tests.py @@ -10,6 +10,8 @@ r""" >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com']) >>> message = email.message() >>> message['Subject'] + +>>> message['Subject'].encode() 'Subject' >>> message.get_payload() 'Content' @@ -23,6 +25,8 @@ r""" >>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com']) >>> message = email.message() >>> message['Subject'] + +>>> message['Subject'].encode() 'Subject' >>> message.get_payload() 'Content' @@ -45,4 +49,11 @@ Traceback (most recent call last): ... BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection Test' for header 'Subject') +# Test for space continuation character in long (ascii) subject headers (#7747) + +>>> 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']) +>>> message = email.message() +>>> message.as_string() +'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' + """