Merge pull request #729 from auto-mat/quoted-printable

Decode quoted-printable html bodies when getting email
This commit is contained in:
Garret Wassermann 2019-03-06 11:27:10 -05:00 committed by GitHub
commit 37be1346cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -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:

View File

@ -0,0 +1,22 @@
MIME-Version: 1.0
Date: Tue, 5 Mar 2019 18:03:06 +0100
Message-ID: <CACf_UpPA7=DRF4NLFf4WpOVwHsRMtfNEwy1DHLjfh09DjuKZFA@mail.gmail.com>
Subject: =?UTF-8?B?xIxlc2vDvSB0ZXN0?=
From: Tim hobbs <tim.thelion@gmail.com>
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
<div dir=3D"ltr">Tohle je test =C4=8Desk=C3=BDch p=C3=ADsmen odeslan=C3=BDc=
h z gmailu.</div>
--00000000000002a7c505835bd998--

View File

@ -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"), '<div dir="ltr">Tohle je test českých písmen odeslaných z gmailu.</div>\n')
class GetEmailParametricTemplate(object):
"""TestCase that checks basic email functionality across methods and socks configs."""