Skip to content

Commit

Permalink
Fixed #34904 -- Prevented mutating sent emails from outbox in locmem …
Browse files Browse the repository at this point in the history
…email backend.
  • Loading branch information
sindre authored and felixxm committed Oct 25, 2023
1 parent fdd1323 commit 64060d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/core/mail/backends/locmem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Backend for test environment.
"""
import copy

from django.core import mail
from django.core.mail.backends.base import BaseEmailBackend
Expand All @@ -26,6 +27,6 @@ def send_messages(self, messages):
msg_count = 0
for message in messages: # .message() triggers header validation
message.message()
mail.outbox.append(message)
mail.outbox.append(copy.deepcopy(message))
msg_count += 1
return msg_count
13 changes: 13 additions & 0 deletions tests/mail/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,19 @@ def test_validate_multiline_headers(self):
"Subject\nMultiline", "Content", "[email protected]", ["[email protected]"]
)

def test_outbox_not_mutated_after_send(self):
email = EmailMessage(
subject="correct subject",
body="test body",
from_email="[email protected]",
to=["[email protected]"],
)
email.send()
email.subject = "other subject"
email.to.append("[email protected]")
self.assertEqual(mail.outbox[0].subject, "correct subject")
self.assertEqual(mail.outbox[0].to, ["[email protected]"])


class FileBackendTests(BaseEmailBackendTests, SimpleTestCase):
email_backend = "django.core.mail.backends.filebased.EmailBackend"
Expand Down

0 comments on commit 64060d1

Please sign in to comment.