Encode alternatives correctly with other encodings than utf-8.
(self)
| 849 | self.assertEqual(parsed.get_content(), "Firstname Sürname is a great guy.\n") |
| 850 | |
| 851 | def test_encoding_alternatives(self): |
| 852 | """ |
| 853 | Encode alternatives correctly with other encodings than utf-8. |
| 854 | """ |
| 855 | text_content = "Firstname Sürname is a great guy.\n" |
| 856 | html_content = "<p>Firstname Sürname is a <strong>great</strong> guy.</p>\n" |
| 857 | email = EmailMultiAlternatives(body=text_content) |
| 858 | email.encoding = "iso-8859-1" |
| 859 | email.attach_alternative(html_content, "text/html") |
| 860 | message = email.message() |
| 861 | # Check both parts are sent using the specified encoding. |
| 862 | self.assertEqual( |
| 863 | message.get_payload(0)["Content-Type"], 'text/plain; charset="iso-8859-1"' |
| 864 | ) |
| 865 | self.assertEqual( |
| 866 | message.get_payload(1)["Content-Type"], 'text/html; charset="iso-8859-1"' |
| 867 | ) |
| 868 | |
| 869 | # Check both parts decode to the original content at the receiving end. |
| 870 | parsed = message_from_bytes(message.as_bytes()) |
| 871 | self.assertEqual(parsed.get_body(("plain",)).get_content(), text_content) |
| 872 | self.assertEqual(parsed.get_body(("html",)).get_content(), html_content) |
| 873 | |
| 874 | def test_attachments(self): |
| 875 | msg = EmailMessage() |
nothing calls this directly
no test coverage detected