diff --git a/helpdesk/email.py b/helpdesk/email.py index ff80f47a..2e076585 100644 --- a/helpdesk/email.py +++ b/helpdesk/email.py @@ -481,8 +481,9 @@ 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)) files.append( - SimpleUploadedFile(_("email_html_body.html"), encoding.smart_bytes(part.get_payload()), 'text/html') + SimpleUploadedFile(_("email_html_body.html"), payload, 'text/html') ) logger.debug("Discovered HTML MIME part") else: diff --git a/helpdesk/tests/test_files/quoted_printable.eml b/helpdesk/tests/test_files/quoted_printable.eml new file mode 100644 index 00000000..477079f5 --- /dev/null +++ b/helpdesk/tests/test_files/quoted_printable.eml @@ -0,0 +1,22 @@ +MIME-Version: 1.0 +Date: Tue, 5 Mar 2019 18:03:06 +0100 +Message-ID: +Subject: =?UTF-8?B?xIxlc2vDvSB0ZXN0?= +From: Tim hobbs +To: helpdesk@auto-mat.cz +Content-Type: multipart/alternative; boundary="00000000000002a7c505835bd998" + +--00000000000002a7c505835bd998 +Content-Type: text/plain; charset="UTF-8" +Content-Transfer-Encoding: quoted-printable + +Tohle je test =C4=8Desk=C3=BDch p=C3=ADsmen odeslan=C3=BDch z gmailu. + +--00000000000002a7c505835bd998 +Content-Type: text/html; charset="UTF-8" +Content-Transfer-Encoding: quoted-printable + +
Tohle je test =C4=8Desk=C3=BDch p=C3=ADsmen odeslan=C3=BDc= +h z gmailu.
+ +--00000000000002a7c505835bd998-- \ No newline at end of file diff --git a/helpdesk/tests/test_get_email.py b/helpdesk/tests/test_get_email.py index a861cb14..7a4fe448 100644 --- a/helpdesk/tests/test_get_email.py +++ b/helpdesk/tests/test_get_email.py @@ -56,6 +56,23 @@ class GetEmailCommonTests(TestCase): self.assertEqual(ticket.title, "Attachment without body") self.assertEqual(ticket.description, "") + def test_email_with_blank_body_and_attachment(self): + """ + Tests that emails with quoted-printable bodies work. + """ + with open(os.path.join(THIS_DIR, "test_files/quoted_printable.eml")) as fd: + test_email = fd.read() + ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger) + self.assertEqual(ticket.title, "Český test") + self.assertEqual(ticket.description, "Tohle je test českých písmen odeslaných z gmailu.") + followups = FollowUp.objects.filter(ticket=ticket) + self.assertEqual(len(followups), 1) + followup = followups[0] + attachments = Attachment.objects.filter(followup=followup) + self.assertEqual(len(attachments), 1) + attachment = attachments[0] + self.assertEqual(attachment.file.read().decode("utf-8"), '
Tohle je test českých písmen odeslaných z gmailu.
\n') + class GetEmailParametricTemplate(object): """TestCase that checks basic email functionality across methods and socks configs."""