[REF] various: remove usage and dependency on html2text library

We have our own html2plaintext, already used in lot of use cases instead of
just a few for the html2txt library.

Notably for emails: most emails going through Odoo stack use our simple
html2plaintext to format the body alternative. When no body alternative
is given to ``build_email`` an alternative is built using the library to
remove. Using our own parser allows to have the same results compared to
using ``MailMail.send()``. Difference lies in spaces and new lines as well
as markdown. Our html2plaintext is a bit simple and does not try to generate
Markdown but generates a simple plaintext version.

This also helps solving some issues with depending on that library.

Task-2702034

closes odoo/odoo#82486

X-original-commit: b3b9627b655cd7cb928925affed6cc8d92661e8d
Related: odoo/enterprise#23364
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2022-01-12 16:43:16 +00:00
parent be878f5d6a
commit 37db926fe8
10 changed files with 5 additions and 14 deletions
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from odoo import api, fields, models, Command, _
from odoo import api, fields, models, Command, tools, _
from odoo.tools import float_compare, float_is_zero
from odoo.osv.expression import get_unaccent_wrapper
from odoo.exceptions import UserError, ValidationError
@@ -8,7 +8,6 @@ import re
from math import copysign
from collections import defaultdict
from dateutil.relativedelta import relativedelta
import html2text
class AccountReconcileModelPartnerMapping(models.Model):
@@ -767,7 +766,7 @@ class AccountReconcileModel(models.Model):
for partner_mapping in self.partner_mapping_line_ids:
match_payment_ref = re.match(partner_mapping.payment_ref_regex, st_line.payment_ref) if partner_mapping.payment_ref_regex else True
match_narration = re.match(partner_mapping.narration_regex, html2text.html2text(st_line.narration or '').rstrip()) if partner_mapping.narration_regex else True
match_narration = re.match(partner_mapping.narration_regex, tools.html2plaintext(st_line.narration or '').rstrip()) if partner_mapping.narration_regex else True
if match_payment_ref and match_narration:
return partner_mapping.partner_id
@@ -52,7 +52,6 @@ PKGS_TO_INSTALL="
python3-decorator \
python3-dev \
python3-docutils \
python3-html2text \
python3-jinja2 \
python3-ldap \
python3-libsass \
-1
View File
@@ -30,7 +30,6 @@ Depends:
python3-decorator,
python3-docutils,
python3-freezegun,
python3-html2text,
python3-pil,
python3-jinja2,
python3-libsass,
+1 -2
View File
@@ -7,7 +7,6 @@ import base64
import datetime
import email
import email.policy
import html2text
import idna
import logging
import re
@@ -398,7 +397,7 @@ class IrMailServer(models.Model):
email_body = ustr(body)
if subtype == 'html' and not body_alternative:
msg.add_alternative(html2text.html2text(email_body), subtype='plain', charset='utf-8')
msg.add_alternative(tools.html2plaintext(email_body), subtype='plain', charset='utf-8')
msg.add_alternative(email_body, subtype=subtype, charset='utf-8')
elif body_alternative:
msg.add_alternative(ustr(body_alternative), subtype=subtype_alternative, charset='utf-8')
@@ -65,8 +65,8 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase):
'content',
'content',
'content',
"test1\n\n**test2**\n\n_test3_\n\n_test4_\n\n~~test5~~\n\ntest6\n\n * test7\n * test8\n\n 1. test9\n 2. test10\n\n> test11\n\n> > test12\n>>\n\n>> \n>\n\n[google](http://google.com) [test link](javascript:alert\('malicious code'\))",
'On 01/05/2016 10:24 AM, Raoul Poilvache wrote: \n\n> **_Test reply. The suite._** \n>\n>\n> \n>\n>\n> \-- \n>\n>\n> Raoul Poilvache\n\nTop cool !!! \n \n\n \n \n -- \n Raoul Poilvache\n ',
"test1\n*test2*\ntest3\ntest4\ntest5\ntest6 test7\ntest8 test9\ntest10\ntest11\ntest12\ngoogle [1]\ntest link [2]\n\n\n[1] http://google.com\n[2] javascript:alert('malicious code')",
'On 01/05/2016 10:24 AM, Raoul\nPoilvache wrote:\n\n* Test reply. The suite. *\n\n--\nRaoul Poilvache\n\nTop cool !!!\n\n--\nRaoul Poilvache',
]
for body, expected in zip(bodies, expected_list):
message = self.env['ir.mail_server'].build_email(
-1
View File
@@ -9,7 +9,6 @@ gevent==1.5.0 ; python_version == '3.7'
gevent==20.9.0 ; python_version >= '3.8'
greenlet==0.4.15 ; python_version == '3.7'
greenlet==0.4.17 ; python_version > '3.7'
html2text==2020.1.16
idna==2.8
Jinja2==2.10.1; python_version < '3.8'
# bullseye version, focal patched 2.10
-1
View File
@@ -15,7 +15,6 @@ requires =
python3-freezegun
python3-gevent
python3-greenlet
python3-html2text
python3-idna
python3-jinja2
python3-lxml
-1
View File
@@ -27,7 +27,6 @@ setup(
'decorator',
'docutils',
'gevent',
'html2text',
'idna',
'Jinja2',
'lxml', # windows binary http://www.lfd.uci.edu/~gohlke/pythonlibs/
-1
View File
@@ -28,7 +28,6 @@ RUN apt-get update -qq && \
python3-decorator \
python3-docutils \
python3-gevent \
python3-html2text \
python3-pil \
python3-jinja2 \
python3-libsass \
-1
View File
@@ -21,7 +21,6 @@ RUN dnf update -d 0 -e 0 -y && \
python3-freezegun \
python3-gevent \
python3-greenlet \
python3-html2text \
python3-idna \
python3-jinja2 \
python3-lxml \