diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 518a2f5edad772a9c19553573a9882e0cc8b14a0..b8e47a9eabc1c31cda86da4f0f68bb9b833454e7 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1221,8 +1221,8 @@ class MailThread(models.AbstractModel): Indeed those aspects should be covered by the html_sanitize method located in tools. """ body, attachments = payload_dict['body'], payload_dict['attachments'] - if not body: - return payload_dict + if not body.strip(): + return {'body': body, 'attachments': attachments} try: root = lxml.html.fromstring(body) except ValueError: diff --git a/addons/test_mail/data/test_mail_data.py b/addons/test_mail/data/test_mail_data.py index 9b7856732bf140b8b2e72e65366f4bd8f91eff4d..c7fd5cb853ef7baf83938cddacca16bb248e1d1a 100644 --- a/addons/test_mail/data/test_mail_data.py +++ b/addons/test_mail/data/test_mail_data.py @@ -884,6 +884,42 @@ OyI+T2RvbzwvYT4uCjwvcD4KPC9kaXY+CiAgICAgICAg --92726A5F09.1555335666/mail2.test.ironsky-- """ +MAIL_NO_BODY = '''\ +Return-Path: <{email_from}> +Delivered-To: catchall@xxxx.xxxx +Received: from in66.mail.ovh.net (unknown [10.101.4.66]) + by vr38.mail.ovh.net (Postfix) with ESMTP id 4GLCGr70Kyz1myr75 + for <catchall@xxxx.xxxx>; Thu, 8 Jul 2021 10:30:12 +0000 (UTC) +X-Comment: SPF check N/A for local connections - client-ip=213.186.33.59; helo=mail663.ha.ovh.net; envelope-from={email_from}; receiver=catchall@xxxx.xxxx +Authentication-Results: in66.mail.ovh.net; dkim=none; dkim-atps=neutral +Delivered-To: xxxx.xxxx-{email_to} +X-ME-Helo: opme11oxm23aub.bagnolet.francetelecom.fr +X-ME-Auth: ZnJlZGVyaWMuYmxhY2hvbjA3QG9yYW5nZS5mcg== +X-ME-Date: Thu, 08 Jul 2021 12:30:11 +0200 +X-ME-IP: 86.221.151.111 +Date: Thu, 8 Jul 2021 12:30:11 +0200 (CEST) +From: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_BLACHON?= <{email_from}> +Reply-To: + =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_BLACHON?= <{email_from}> +To: {email_to} +Message-ID: <1024471522.82574.1625740211606.JavaMail.open-xchange@opme11oxm23aub.bagnolet.francetelecom.fr> +Subject: transport autorisation 19T +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_Part_82573_178179506.1625740211587" + +------=_Part_82573_178179506.1625740211587 +MIME-Version: 1.0 +Content-Type: text/html; charset=UTF-8 +Content-Transfer-Encoding: 7bit + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml"><head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + </head><body style="font-family: arial,helvetica,sans-serif; font-size: 13pt"></body></html> +''' + MAIL_NO_FINAL_RECIPIENT = """\ Return-Path: <bounce-md_9656353.6125275c.v1-f28f7746389e45f0bfbf9faefe9e0dc8@mandrillapp.com> Delivered-To: catchall@xxxx.xxxx diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index 055c1eb3253e01b1bfdc1dbb11ee4f159c809413..38154ce51373540bf40e088a928c57427da23e4e 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -60,6 +60,10 @@ class TestEmailParsing(TestMailCommon): # message without Final-Recipient self.env['mail.thread'].message_parse(self.from_string(test_mail_data.MAIL_NO_FINAL_RECIPIENT)) + # message with empty body (including only void characters) + res = self.env['mail.thread'].message_parse(self.from_string(test_mail_data.MAIL_NO_BODY)) + self.assertEqual(res['body'], '\n \n', 'Gateway should not crash with void content') + def test_message_parse_eml(self): # Test that the parsing of mail with embedded emails as eml(msg) which generates empty attachments, can be processed. mail = self.format(test_mail_data.MAIL_EML_ATTACHMENT, email_from='"Sylvie Lelitre" <test.sylvie.lelitre@agrolait.com>', to='generic@test.com')