diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 73c3e6f8c8b..a26fc7fbd6f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2236,7 +2236,7 @@ class MailThread(models.AbstractModel): node.set('src', f'/web/image/{att_id}?access_token={token}') postprocessed = True if postprocessed: - return_values['body'] = lxml.html.tostring(root, pretty_print=False, encoding='UTF-8') + return_values['body'] = lxml.html.tostring(root, pretty_print=False, encoding='unicode') return_values['attachment_ids'] = m2m_attachment_ids return return_values diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index e3206f9e78d..f4989fe8da8 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -11,6 +11,7 @@ from unittest.mock import DEFAULT from unittest.mock import patch from odoo import exceptions +from odoo.addons.mail.models.mail_thread import MailThread from odoo.addons.mail.tests.common import mail_new_test_user, MailCommon from odoo.addons.test_mail.data import test_mail_data from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE @@ -216,7 +217,15 @@ class TestMailgateway(MailCommon): @mute_logger('odoo.addons.mail.models.mail_thread') def test_message_process_cid(self): - record = self.format_and_process(test_mail_data.MAIL_MULTIPART_IMAGE, self.email_from, f'groups@{self.alias_domain}') + origin_message_parse_extract_payload = MailThread._message_parse_extract_payload + + def _message_parse_extract_payload(this, *args, **kwargs): + res = origin_message_parse_extract_payload(this, *args, **kwargs) + self.assertTrue(isinstance(res['body'], str), 'Body from extracted payload should still be a string.') + return res + + with patch.object(MailThread, '_message_parse_extract_payload', _message_parse_extract_payload): + record = self.format_and_process(test_mail_data.MAIL_MULTIPART_IMAGE, self.email_from, f'groups@{self.alias_domain}') message = record.message_ids[0] for attachment in message.attachment_ids: self.assertIn('/web/image/%s' % attachment.id, message.body)