Merge branch 'master-upstream-patch-20062022' into 'master'

[PATCH] Upstream patch - 20062022

See merge request flectra-hq/flectra!722
This commit is contained in:
Parthiv Patel committed 2022-06-20 09:17:22 +00:00
commit 9e61e030ff
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})
-19
View File
@@ -1013,22 +1013,3 @@ Remote-MTA: 10.245.192.40
--_av-UfLe6y6qxNo54-urtAxbJQ--"""
MAIL_WRONG_CONTENT_CHARSET = """\
Return-Path: <whatever-2a840@postmaster.twitter.com>
To: gaston.lagaffe@example.com
Received: by mail1.openerp.com (Postfix, from userid 10002)
id 5DF9ABFB2A; Fri, 10 Aug 2012 16:16:39 +0200 (CEST)
From: spirou@example.com
Subject: Ze Subject
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_4200734_24778174.1344608186754"
------=_Part_4200734_24778174.1344608186754
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
Tonton, ton th=C3=A9 t'a-t-il ot=C3=A9 ta toux ?
------=_Part_4200734_24778174.1344608186754
"""
@@ -89,11 +89,6 @@ class TestEmailParsing(TestMailCommon):
res = self.env['mail.thread'].message_parse(self.from_string(mail))
self.assertIn('<pre>\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n</pre>', res['body'])
def test_message_parse_wrong_content_charset(self):
mail = test_mail_data.MAIL_WRONG_CONTENT_CHARSET
res = self.env['mail.thread'].message_parse(self.from_string(mail))
self.assertIn("Tonton, ton thé t'a-t-il oté ta toux ?", res['body'])
def test_message_parse_xhtml(self):
# Test that the parsing of XHTML mails does not fail
self.env['mail.thread'].message_parse(self.from_string(test_mail_data.MAIL_XHTML))