Code

Ticket #18861: 18861-2.diff

File 18861-2.diff, 1.3 KB (added by claudep, 23 months ago)

Move test in LocmemBackendTests

Line 
1diff --git a/django/core/mail/backends/locmem.py b/django/core/mail/backends/locmem.py
2index 642bfc4..6826d09 100644
3--- a/django/core/mail/backends/locmem.py
4+++ b/django/core/mail/backends/locmem.py
5@@ -20,5 +20,7 @@ class EmailBackend(BaseEmailBackend):
6 
7     def send_messages(self, messages):
8         """Redirect messages to the dummy outbox"""
9+        for message in messages:  # .message() triggers header validation
10+            message.message()
11         mail.outbox.extend(messages)
12         return len(messages)
13diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
14index 3e9ae84..33898cc 100644
15--- a/tests/regressiontests/mail/tests.py
16+++ b/tests/regressiontests/mail/tests.py
17@@ -498,6 +498,11 @@ class LocmemBackendTests(BaseEmailBackendTests, TestCase):
18         connection2.send_messages([email])
19         self.assertEqual(len(mail.outbox), 2)
20 
21+    def test_validate_multiline_headers(self):
22+        # Ticket #18861 - Validate emails when using the locmem backend
23+        with self.assertRaises(BadHeaderError):
24+            send_mail('Subject\nMultiline', 'Content', 'from@example.com', ['to@example.com'])
25+
26 
27 class FileBackendTests(BaseEmailBackendTests, TestCase):
28     email_backend = 'django.core.mail.backends.filebased.EmailBackend'