mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #36309 -- Made email alternatives and attachments pickleable.
Regression inaba0e541caand ind5bebc1c26. Thanks Florent Messa for the report, and Jake Howard and Claude Paroz for the review.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import mimetypes
|
||||
import os
|
||||
import pickle
|
||||
import shutil
|
||||
import socket
|
||||
import sys
|
||||
@@ -654,6 +655,23 @@ class MailTests(MailTestsMixin, SimpleTestCase):
|
||||
|
||||
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):
|
||||
msg = EmailMessage("subject", None, "from@example.com", ["to@example.com"])
|
||||
self.assertEqual(msg.body, "")
|
||||
|
||||
Reference in New Issue
Block a user