1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #26344 -- Made EmailMessage include alternatives when the body is empty and it has attachments.

This commit is contained in:
Igor Tokarev 2017-08-28 09:28:18 +05:00 committed by Tim Graham
parent d81c86d32c
commit af35c69a3c
2 changed files with 12 additions and 1 deletions

View File

@ -354,7 +354,7 @@ class EmailMessage:
encoding = self.encoding or settings.DEFAULT_CHARSET
body_msg = msg
msg = SafeMIMEMultipart(_subtype=self.mixed_subtype, encoding=encoding)
if self.body:
if self.body or body_msg.is_multipart():
msg.attach(body_msg)
for attachment in self.attachments:
if isinstance(attachment, MIMEBase):

View File

@ -319,6 +319,17 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
self.assertEqual(msg.message()['To'], '=?iso-8859-1?q?S=FCrname=2C_Firstname?= <to@example.com>')
self.assertEqual(msg.message()['Subject'], '=?iso-8859-1?q?Message_from_Firstname_S=FCrname?=')
def test_safe_mime_multipart_with_attachments(self):
"""
EmailMultiAlternatives includes alternatives if the body is empty and
it has attachments.
"""
msg = EmailMultiAlternatives(body='')
html_content = '<p>This is <strong>html</strong></p>'
msg.attach_alternative(html_content, 'text/html')
msg.attach('example.txt', 'Text file content', 'text/plain')
self.assertIn(html_content, msg.message().as_string())
def test_encoding(self):
"""
Regression for #12791 - Encode body correctly with other encodings