[PATCH] Upstream patch - 20062022

This commit is contained in:
Parthiv Patel committed 2022-06-20 08:34:39 +00:00
1 parent bd5ad364c5
commit 071cfcaeb7
3 files changed
+7 -38

No files matched your search

+7 -14
View File
@@ -1250,14 +1250,6 @@ class MailThread(models.AbstractModel):
body = etree.tostring(root, pretty_print=False, encoding='unicode')
return {'body': body, 'attachments': attachments}
def _part_get_content_decoded(self, part):
try:
return part.get_content(errors='strict')
except TypeError: # no "errors" argument on the underlyding content manager
return tools.ustr(part.get_content())
except UnicodeDecodeError:
return part.get_payload(decode=True).decode(errors='replace')
def _message_parse_extract_payload(self, message, save_original=False):
"""Extract body as HTML and attachments from the mail message"""
attachments = []
@@ -1273,7 +1265,7 @@ class MailThread(models.AbstractModel):
# type="text/html"
if message.get_content_maintype() == 'text':
encoding = message.get_content_charset()
body = self._part_get_content_decoded(message)
body = message.get_content()
body = tools.ustr(body, encoding, errors='replace')
if message.get_content_type() == 'text/plain':
# text/plain -> <pre/>
@@ -1296,21 +1288,22 @@ class MailThread(models.AbstractModel):
# 0) Inline Attachments -> attachments, with a third part in the tuple to match cid / attachment
if filename and part.get('content-id'):
inner_cid = part.get('content-id').strip('><')
attachments.append(self._Attachment(filename, self._part_get_content_decoded(part), {'cid': inner_cid}))
attachments.append(self._Attachment(filename, part.get_content(), {'cid': inner_cid}))
continue
# 1) Explicit Attachments -> attachments
if filename or part.get('content-disposition', '').strip().startswith('attachment'):
attachments.append(self._Attachment(filename or 'attachment', self._part_get_content_decoded(part), {}))
attachments.append(self._Attachment(filename or 'attachment', part.get_content(), {}))
continue
# 2) text/plain -> <pre/>
if part.get_content_type() == 'text/plain' and (not alternative or not body):
body = tools.append_content_to_html(body, self._part_get_content_decoded(part), preserve=True)
body = tools.append_content_to_html(body, tools.ustr(part.get_content(),
encoding, errors='replace'), preserve=True)
# 3) text/html -> raw
elif part.get_content_type() == 'text/html':
# mutlipart/alternative have one text and a html part, keep only the second
# mixed allows several html parts, append html content
append_content = not alternative or (html and mixed)
html = self._part_get_content_decoded(part)
html = tools.ustr(part.get_content(), encoding, errors='replace')
if not append_content:
body = html
else:
@@ -1319,7 +1312,7 @@ class MailThread(models.AbstractModel):
body = tools.html_sanitize(body, sanitize_tags=False, strip_classes=True)
# 4) Anything else -> attachment
else:
attachments.append(self._Attachment(filename or 'attachment', self._part_get_content_decoded(part), {}))
attachments.append(self._Attachment(filename or 'attachment', part.get_content(), {}))
return self._message_parse_extract_payload_postprocess(message, {'body': body, 'attachments': attachments})