mirror of
https://github.com/django/django.git
synced 2025-06-16 17:09:12 +00:00
[5.2.x] Fixed #36309 -- Made email alternatives and attachments pickleable.
Regression in aba0e541caaa086f183197eaaca0ac20a730bbe4 and in d5bebc1c26d4c0ec9eaa057aefc5b38649c0ba3b. Thanks Florent Messa for the report, and Jake Howard and Claude Paroz for the review. Backport of 0596263c3136bc26cffa670e5322bd0aa56c4d34 from main.
This commit is contained in:
parent
7d80f70988
commit
90fa9f4cc0
@ -191,8 +191,8 @@ class SafeMIMEMultipart(MIMEMixin, MIMEMultipart):
|
|||||||
MIMEMultipart.__setitem__(self, name, val)
|
MIMEMultipart.__setitem__(self, name, val)
|
||||||
|
|
||||||
|
|
||||||
EmailAlternative = namedtuple("Alternative", ["content", "mimetype"])
|
EmailAlternative = namedtuple("EmailAlternative", ["content", "mimetype"])
|
||||||
EmailAttachment = namedtuple("Attachment", ["filename", "content", "mimetype"])
|
EmailAttachment = namedtuple("EmailAttachment", ["filename", "content", "mimetype"])
|
||||||
|
|
||||||
|
|
||||||
class EmailMessage:
|
class EmailMessage:
|
||||||
|
@ -48,3 +48,6 @@ Bugfixes
|
|||||||
* Fixed a regression in Django 5.2, introduced when fixing :cve:`2025-26699`,
|
* Fixed a regression in Django 5.2, introduced when fixing :cve:`2025-26699`,
|
||||||
where the :tfilter:`wordwrap` template filter did not preserve empty lines
|
where the :tfilter:`wordwrap` template filter did not preserve empty lines
|
||||||
between paragraphs after wrapping text (:ticket:`36341`).
|
between paragraphs after wrapping text (:ticket:`36341`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 5.2 that caused a crash when serializing email
|
||||||
|
alternatives or attachments due to named tuple mismatches (:ticket:`36309`).
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
|
import pickle
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
@ -652,6 +653,23 @@ class MailTests(MailTestsMixin, SimpleTestCase):
|
|||||||
|
|
||||||
self.assertIn(html_content, msg.message().as_string())
|
self.assertIn(html_content, msg.message().as_string())
|
||||||
|
|
||||||
|
def test_alternatives_and_attachment_serializable(self):
|
||||||
|
html_content = "<p>This is <strong>html</strong></p>"
|
||||||
|
mime_type = "text/html"
|
||||||
|
|
||||||
|
msg = EmailMultiAlternatives(alternatives=[(html_content, mime_type)])
|
||||||
|
msg.attach("test.txt", "This is plain text.", "plain/text")
|
||||||
|
|
||||||
|
# Alternatives and attachments can be serialized.
|
||||||
|
restored = pickle.loads(pickle.dumps(msg))
|
||||||
|
|
||||||
|
self.assertEqual(restored.subject, msg.subject)
|
||||||
|
self.assertEqual(restored.body, msg.body)
|
||||||
|
self.assertEqual(restored.from_email, msg.from_email)
|
||||||
|
self.assertEqual(restored.to, msg.to)
|
||||||
|
self.assertEqual(restored.alternatives, msg.alternatives)
|
||||||
|
self.assertEqual(restored.attachments, msg.attachments)
|
||||||
|
|
||||||
def test_none_body(self):
|
def test_none_body(self):
|
||||||
msg = EmailMessage("subject", None, "from@example.com", ["to@example.com"])
|
msg = EmailMessage("subject", None, "from@example.com", ["to@example.com"])
|
||||||
self.assertEqual(msg.body, "")
|
self.assertEqual(msg.body, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user