Use BeautifulSoup to get text out of HTML-only emails, to address issue in #565

This commit is contained in:
Garret Wassermann 2017-10-31 03:24:04 -04:00
parent 8f375e1379
commit 65c1d05eef
2 changed files with 10 additions and 1 deletions

View File

@ -25,6 +25,8 @@ import base64
import binascii
from time import ctime
from bs4 import BeautifulSoup
from email_reply_parser import EmailReplyParser
from django.core.files.base import ContentFile
@ -366,7 +368,12 @@ def ticket_from_message(message, queue, logger):
counter += 1
if not body:
body = _('No plain-text email body available. Please see attachment "email_html_body.html".')
mail = BeautifulSoup(part.get_payload(), "lxml")
if ">" in mail.text:
message_body = mail.text.split(">")[1]
body = message_body.encode('ascii', errors='ignore')
else:
body = mail.text
if ticket:
try:

View File

@ -2,6 +2,8 @@ Django>=1.11,<2
django-bootstrap-form>=3.3,<4
email-reply-parser
django-markdown-deux
beautifulsoup4
lxml
simplejson
pytz
six