diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 273e47a753..a288d6c5fc 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -55,8 +55,8 @@ def make_msgid(idstring=None): def forbid_multi_line_headers(name, val, encoding): - encoding = encoding or settings.DEFAULT_CHARSET """Forbids multi-line headers, to prevent header injection.""" + encoding = encoding or settings.DEFAULT_CHARSET val = force_unicode(val) if '\n' in val or '\r' in val: raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py index 96ad83ba38..e27804c11d 100644 --- a/tests/regressiontests/mail/tests.py +++ b/tests/regressiontests/mail/tests.py @@ -147,8 +147,10 @@ u'=?iso-8859-1?q?Message_from_Firstname_S=FCrname?=' >>> msg = EmailMultiAlternatives('Subject', text_content, 'from@example.com', ['to@example.com']) >>> msg.encoding = 'iso-8859-1' >>> msg.attach_alternative(html_content, "text/html") ->>> msg.message().as_string() -'Content-Type: multipart/alternative; boundary="===============...=="\nMIME-Version: 1.0\nSubject: Subject\nFrom: from@example.com\nTo: to@example.com\nDate: ...\nMessage-ID: <...>\n\n--===============...==\nContent-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\nFirstname S=FCrname is a great guy.\n--===============...==\nContent-Type: text/html; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\n
Firstname S=FCrname is a great guy.
\n--===============...==--' +>>> msg.message().get_payload(0).as_string() +'Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\nFirstname S=FCrname is a great guy.' +>>> msg.message().get_payload(1).as_string() +'Content-Type: text/html; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\nFirstname S=FCrname is a great guy.
' # Handle attachments within an multipart/alternative mail correctly (#9367) # (test is not as precise/clear as it could be w.r.t. email tree structure,