MCPcopy
hub / github.com/django/django / test_unicode_address_header

Method test_unicode_address_header

tests/mail/tests.py:626–660  ·  view source on GitHub ↗

Regression for #11144 - When a to/from/cc header contains Unicode, make sure the email addresses are parsed correctly (especially with regards to commas)

(self)

Source from the content-addressed store, hash-verified

624 self.assertEqual(message.get_all("From"), ["from@example.com"])
625
626 def test_unicode_address_header(self):
627 """
628 Regression for #11144 - When a to/from/cc header contains Unicode,
629 make sure the email addresses are parsed correctly (especially with
630 regards to commas)
631 """
632 with self.subTest("Without comma in display-name"):
633 email = EmailMessage(
634 to=['"Firstname Sürname" <to@example.com>', "other@example.com"],
635 )
636 parsed = message_from_bytes(email.message().as_bytes())
637 self.assertEqual(
638 parsed["To"].addresses,
639 (
640 Address(
641 display_name="Firstname Sürname", addr_spec="to@example.com"
642 ),
643 Address(addr_spec="other@example.com"),
644 ),
645 )
646
647 with self.subTest("With comma in display-name"):
648 email = EmailMessage(
649 to=['"Sürname, Firstname" <to@example.com>', "other@example.com"],
650 )
651 parsed = message_from_bytes(email.message().as_bytes())
652 self.assertEqual(
653 parsed["To"].addresses,
654 (
655 Address(
656 display_name="Sürname, Firstname", addr_spec="to@example.com"
657 ),
658 Address(addr_spec="other@example.com"),
659 ),
660 )
661
662 def test_unicode_headers(self):
663 email = EmailMessage(

Callers

nothing calls this directly

Calls 5

messageMethod · 0.95
EmailMessageClass · 0.90
message_from_bytesFunction · 0.85
as_bytesMethod · 0.80
AddressClass · 0.50

Tested by

no test coverage detected