[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
```
<div class="WordSection1">
<p class="MsoNormal">Test<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Two break lines<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
```
So when parsing it transforms the ``<o:p></o:p>`` in ``<p></p>``
which adds more lines break when displayed.

Solution:
Remove empty ``<o:...>`` and ``</o:...>`` tags which are specific to outlook desktop before.

opw-3089550

closes odoo/odoo#144931

X-original-commit: a3e9db87277771c9801f24a5f52aa73b98a0d879
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Eteil Djoumatchoua(etdj) etdj@odoo.com
2023-12-05 10:54:59 +00:00
parent 1f42c0f468
commit 870acffba6
2 changed files with 43 additions and 0 deletions
+3
View File
@@ -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 '<o:.*></o:.*>' tags which are parsed
# in '<p></p>' which may alter the appearance (eg. spacing) of the mail body
src = re.sub(r'</?o:.*?>', '', src)
doc = html.fromstring(src)
except etree.ParserError as e:
# HTML comment only string, whitespace only..