diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index b96323afd8..7f624c8ec2 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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 ->
@@ -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 -> 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}) diff --git a/addons/test_mail/data/test_mail_data.py b/addons/test_mail/data/test_mail_data.py index 299d2c49ef..a979ceab7d 100644 --- a/addons/test_mail/data/test_mail_data.py +++ b/addons/test_mail/data/test_mail_data.py @@ -1013,22 +1013,3 @@ Remote-MTA: 10.245.192.40 --_av-UfLe6y6qxNo54-urtAxbJQ--""" - - -MAIL_WRONG_CONTENT_CHARSET = """\ -Return-Path:\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n', 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))