Specify encoding of html email bodies explicitly

This commit is contained in:
Timothy Hobbs 2019-03-26 13:59:01 +01:00
parent 6693496214
commit 6886a7920e
2 changed files with 9 additions and 3 deletions

View File

@ -481,9 +481,15 @@ def object_from_message(message, queue, logger):
body.encode('utf-8')
logger.debug("Discovered plain text MIME part")
else:
payload = encoding.smart_bytes(part.get_payload(decode=True))
payload = """
<html>
<head>
<meta charset="utf-8"/>
</head>
%s
</html>""" % encoding.smart_text(part.get_payload(decode=True))
files.append(
SimpleUploadedFile(_("email_html_body.html"), payload, 'text/html')
SimpleUploadedFile(_("email_html_body.html"), payload.encode("utf-8"), 'text/html')
)
logger.debug("Discovered HTML MIME part")
else:

View File

@ -71,7 +71,7 @@ class GetEmailCommonTests(TestCase):
attachments = FollowUpAttachment.objects.filter(followup=followup)
self.assertEqual(len(attachments), 1)
attachment = attachments[0]
self.assertEqual(attachment.file.read().decode("utf-8"), '<div dir="ltr">Tohle je test českých písmen odeslaných z gmailu.</div>\n')
self.assertIn('<div dir="ltr">Tohle je test českých písmen odeslaných z gmailu.</div>\n', attachment.file.read().decode("utf-8"))
def test_email_with_8bit_encoding_and_utf_8(self):
"""