From 8599f64e54adfb32ee6550ed7a6ec9944034d978 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 22 Sep 2012 15:17:13 +0200 Subject: [PATCH] Fixed #18861 -- Triggered message validation with locmem email backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Bruno ReniƩ for the report and the initial patch. --- django/core/mail/backends/locmem.py | 2 ++ tests/regressiontests/mail/tests.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/django/core/mail/backends/locmem.py b/django/core/mail/backends/locmem.py index 642bfc49fb..6826d09ee5 100644 --- a/django/core/mail/backends/locmem.py +++ b/django/core/mail/backends/locmem.py @@ -20,5 +20,7 @@ class EmailBackend(BaseEmailBackend): def send_messages(self, messages): """Redirect messages to the dummy outbox""" + for message in messages: # .message() triggers header validation + message.message() mail.outbox.extend(messages) return len(messages) diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py index 3e9ae84650..33898cc1d5 100644 --- a/tests/regressiontests/mail/tests.py +++ b/tests/regressiontests/mail/tests.py @@ -498,6 +498,11 @@ class LocmemBackendTests(BaseEmailBackendTests, TestCase): connection2.send_messages([email]) self.assertEqual(len(mail.outbox), 2) + def test_validate_multiline_headers(self): + # Ticket #18861 - Validate emails when using the locmem backend + with self.assertRaises(BadHeaderError): + send_mail('Subject\nMultiline', 'Content', 'from@example.com', ['to@example.com']) + class FileBackendTests(BaseEmailBackendTests, TestCase): email_backend = 'django.core.mail.backends.filebased.EmailBackend'