handle 'quoted-printable' shorthand version as Transfer-Encoding

This commit is contained in:
j3d1 2024-04-24 19:38:52 +02:00
parent 49d3b02b9c
commit bb07a6b641
2 changed files with 62 additions and 0 deletions

View file

@ -43,6 +43,11 @@ def unescape_and_decode_base64(s):
return decoded
def unescape_simplified_quoted_printable(s):
import quopri
return quopri.decodestring(s).decode('utf-8')
def collect_references(issue_thread):
mails = issue_thread.emails.order_by('timestamp')
references = []
@ -127,6 +132,8 @@ def parse_email_body(raw, log=None):
continue
segment = unescape_and_decode_quoted_printable(segment)
segment = unescape_and_decode_base64(segment)
if part.get('Content-Transfer-Encoding') == 'quoted-printable':
segment = unescape_simplified_quoted_printable(segment)
log.debug(segment)
body = body + segment
elif 'attachment' in cdispo or 'inline' in cdispo:
@ -158,6 +165,8 @@ def parse_email_body(raw, log=None):
body = "Unknown content type"
body = unescape_and_decode_quoted_printable(body)
body = unescape_and_decode_base64(body)
if parsed.get('Content-Transfer-Encoding') == 'quoted-printable':
body = unescape_simplified_quoted_printable(body)
log.debug(body)
return parsed, body, attachments