diff --git a/helpdesk/email.py b/helpdesk/email.py index 2e076585..483d96b1 100644 --- a/helpdesk/email.py +++ b/helpdesk/email.py @@ -471,9 +471,12 @@ def object_from_message(message, queue, logger): if part.get_content_maintype() == 'text' and name is None: if part.get_content_subtype() == 'plain': - body = EmailReplyParser.parse_reply( - decodeUnknown(part.get_content_charset(), part.get_payload(decode=True)) - ) + body = part.get_payload(decode=True) + # https://github.com/django-helpdesk/django-helpdesk/issues/732 + if part['Content-Transfer-Encoding'] == '8bit' and part.get_content_charset() == 'utf-8': + body = body.decode('unicode_escape') + body = decodeUnknown(part.get_content_charset(), body) + body = EmailReplyParser.parse_reply(body) # workaround to get unicode text out rather than escaped text try: body = body.encode('ascii').decode('unicode_escape') @@ -481,9 +484,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 = """ + +
+ + +%s +""" % 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: diff --git a/helpdesk/tests/test_get_email.py b/helpdesk/tests/test_get_email.py index 76184ec1..50a5f1e5 100644 --- a/helpdesk/tests/test_get_email.py +++ b/helpdesk/tests/test_get_email.py @@ -53,7 +53,7 @@ class GetEmailCommonTests(TestCase): with open(os.path.join(THIS_DIR, "test_files/blank-body-with-attachment.eml")) as fd: test_email = fd.read() ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger) - self.assertEqual(ticket.title, "FollowUpAttachment without body") + self.assertEqual(ticket.title, "Attachment without body") self.assertEqual(ticket.description, "") def test_email_with_quoted_printable_body(self): @@ -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"), '