MCPcopy
hub / github.com/django/django / test_non_utf8_headers_multipart

Method test_non_utf8_headers_multipart

tests/mail/tests.py:686–717  ·  view source on GitHub ↗

Make sure headers can be set with a different encoding than utf-8 in EmailMultiAlternatives as well.

(self)

Source from the content-addressed store, hash-verified

684 self.assertEqual(parsed["Comments"], "My Sürname is non-ASCII")
685
686 def test_non_utf8_headers_multipart(self):
687 """
688 Make sure headers can be set with a different encoding than utf-8 in
689 EmailMultiAlternatives as well.
690 """
691 headers = {"Date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"}
692 from_email = "from@example.com"
693 to = '"Sürname, Firstname" <to@example.com>'
694 text_content = "This is an important message."
695 html_content = "<p>This is an <strong>important</strong> message.</p>"
696 email = EmailMultiAlternatives(
697 "Message from Firstname Sürname",
698 text_content,
699 from_email,
700 [to],
701 headers=headers,
702 )
703 email.attach_alternative(html_content, "text/html")
704 email.encoding = "iso-8859-1"
705 message = email.message()
706
707 # Verify sent headers use RFC 2047 encoded-words, not raw utf-8.
708 msg_bytes = message.as_bytes()
709 self.assertTrue(msg_bytes.isascii())
710
711 # Verify sent headers parse to original values.
712 parsed = message_from_bytes(msg_bytes)
713 self.assertEqual(parsed["Subject"], "Message from Firstname Sürname")
714 self.assertEqual(
715 parsed["To"].addresses,
716 (Address(display_name="Sürname, Firstname", addr_spec="to@example.com"),),
717 )
718
719 def test_multipart_with_attachments(self):
720 """

Callers

nothing calls this directly

Calls 6

attach_alternativeMethod · 0.95
message_from_bytesFunction · 0.85
messageMethod · 0.80
as_bytesMethod · 0.80
AddressClass · 0.50

Tested by

no test coverage detected