Ticket #29830: patch.diff
File patch.diff, 2.7 KB (added by , 6 years ago) |
---|
-
django/core/mail/message.py
diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 9a0f0eba45..2f89ffbfc4 100644
a b class SafeMIMEText(MIMEMixin, MIMEText): 170 170 MIMEText.__setitem__(self, name, val) 171 171 172 172 def set_payload(self, payload, charset=None): 173 if charset == 'utf-8' :173 if charset == 'utf-8' and not isinstance(charset, Charset.Charset): 174 174 has_long_lines = any( 175 175 len(l.encode()) > RFC5322_EMAIL_LINE_LENGTH_LIMIT 176 176 for l in payload.splitlines() -
tests/mail/tests.py
diff --git a/tests/mail/tests.py b/tests/mail/tests.py index b2de5e4c10..037963453c 100644
a b import socket 8 8 import sys 9 9 import tempfile 10 10 import threading 11 from email import message_from_binary_file, message_from_bytes 11 from email import message_from_binary_file, message_from_bytes, charset 12 12 from email.header import Header 13 13 from email.mime.text import MIMEText 14 14 from email.utils import parseaddr … … class MailTests(HeadersCheckMixin, SimpleTestCase): 686 686 # The child message header is not base64 encoded 687 687 self.assertIn('Child Subject', parent_s) 688 688 689 def test_respect_body_encoding(self): 690 """Test that a custom body encoding is respected.""" 691 body = 'Body with latin characters: àáä.' 692 msg = EmailMessage( 693 'Subject', body, 'bounce@example.com', ['to@example.com'], 694 headers={'From': 'from@example.com'}, 695 ) 696 encoding = charset.Charset("utf-8") 697 encoding.body_encoding = charset.QP 698 msg.encoding = encoding 699 message = msg.message() 700 self.assertMessageHasHeaders(message, { 701 ('MIME-Version', '1.0'), 702 ('Content-Type', 'text/plain; charset="utf-8"'), 703 ('Content-Transfer-Encoding', 'quoted-printable'), 704 }) 705 self.assertEqual(message.get_payload(), encoding.body_encode(body)) 706 707 body = 'Hello World' 708 msg = EmailMessage( 709 'Subject', body, 'bounce@example.com', ['to@example.com'], 710 headers={'From': 'from@example.com'}, 711 ) 712 encoding = charset.Charset("iso-8859-1") 713 encoding.body_encoding = charset.BASE64 714 msg.encoding = encoding 715 message = msg.message() 716 self.assertMessageHasHeaders(message, { 717 ('MIME-Version', '1.0'), 718 ('Content-Type', 'text/plain; charset="iso-8859-1"'), 719 ('Content-Transfer-Encoding', 'base64'), 720 }) 721 self.assertEqual(message.get_payload(), encoding.body_encode(body)) 722 689 723 def test_sanitize_address(self): 690 724 """ 691 725 Email addresses are properly sanitized.