Fixed #18861 -- Triggered message validation with locmem email backend

Thanks Bruno Renié for the report and the initial patch.
This commit is contained in:
Claude Paroz 2012-09-22 15:17:13 +02:00
parent 0ab8c58ca8
commit 8599f64e54
2 changed files with 7 additions and 0 deletions

View File

@ -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)

View File

@ -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'