From 870acffba64ba5e68d60c90e7b38698d85549c5a Mon Sep 17 00:00:00 2001 From: "Eteil Djoumatchoua(etdj) etdj@odoo.com" Date: Tue, 31 Oct 2023 08:47:33 +0000 Subject: [PATCH] [FIX] mail: well sanitize the mails coming from outlook desktop Steps: - Create a ticket with a customer ( it will the email) - Answer to the mail with Outlook Desktop( a multiple lines break) - Look at the response in the discuss frame. Issue: In the frame there is much more lines break than in the original mail Cause: The format of outlook desktop mail before sanitizing looks like this ```

Test

 

 

Two break lines

 

``` So when parsing it transforms the ```` in ``

`` which adds more lines break when displayed. Solution: Remove empty ```` and ```` tags which are specific to outlook desktop before. opw-3089550 closes odoo/odoo#144931 X-original-commit: a3e9db87277771c9801f24a5f52aa73b98a0d879 Signed-off-by: Thibault Delavallee (tde) --- odoo/addons/base/tests/test_mail.py | 40 +++++++++++++++++++++++++++++ odoo/tools/mail.py | 3 +++ 2 files changed, 43 insertions(+) diff --git a/odoo/addons/base/tests/test_mail.py b/odoo/addons/base/tests/test_mail.py index e86dbd34fcf..97d6a3fe39c 100644 --- a/odoo/addons/base/tests/test_mail.py +++ b/odoo/addons/base/tests/test_mail.py @@ -119,6 +119,46 @@ class TestSanitizer(BaseCase): for attr in ['javascript']: self.assertNotIn(attr, sanitized_html, 'html_sanitize did not remove enough unwanted attributes') + def test_outlook_mail_sanitize(self): + case = """
+

Here is a test mail

+

 

+

With a break line

+

 

+

 

+

Then two

+

 

+
+
+

From: Mitchell Admin <dummy@example.com> +
+Sent: Monday, November 20, 2023 8:34 AM
+To: test user <dummy@example.com>
+Subject: test (#23)

+
+
""" + + expected = """
+

Here is a test mail

+

 

+

With a break line

+

 

+

 

+

Then two

+

 

+
+
+

From: Mitchell Admin <dummy@example.com> +
+Sent: Monday, November 20, 2023 8:34 AM
+To: test user <dummy@example.com>
+Subject: test (#23)

+
+
""" + + result = html_sanitize(case) + self.assertEqual(result, expected) + def test_sanitize_unescape_emails(self): not_emails = [ '
cat
', diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 5b2914ab264..5ec2d133ca0 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -202,6 +202,9 @@ def html_normalize(src, filter_callback=None): try: src = src.replace('--!>', '-->') src = re.sub(r'(|)', '', src) + # On the specific case of Outlook desktop it adds unnecessary '' tags which are parsed + # in '

' which may alter the appearance (eg. spacing) of the mail body + src = re.sub(r'', '', src) doc = html.fromstring(src) except etree.ParserError as e: # HTML comment only string, whitespace only..