Skip to content

Commit 37db926

Browse files
[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#82486 X-original-commit: b3b9627 Related: odoo/enterprise#23364 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
1 parent be878f5 commit 37db926

File tree

10 files changed

+5
-14
lines changed

10 files changed

+5
-14
lines changed

addons/account/models/account_reconcile_model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# -*- coding: utf-8 -*-
22

3-
from odoo import api, fields, models, Command, _
3+
from odoo import api, fields, models, Command, tools, _
44
from odoo.tools import float_compare, float_is_zero
55
from odoo.osv.expression import get_unaccent_wrapper
66
from odoo.exceptions import UserError, ValidationError
77
import re
88
from math import copysign
99
from collections import defaultdict
1010
from dateutil.relativedelta import relativedelta
11-
import html2text
1211

1312

1413
class AccountReconcileModelPartnerMapping(models.Model):
@@ -767,7 +766,7 @@ def _get_partner_from_mapping(self, st_line):
767766

768767
for partner_mapping in self.partner_mapping_line_ids:
769768
match_payment_ref = re.match(partner_mapping.payment_ref_regex, st_line.payment_ref) if partner_mapping.payment_ref_regex else True
770-
match_narration = re.match(partner_mapping.narration_regex, html2text.html2text(st_line.narration or '').rstrip()) if partner_mapping.narration_regex else True
769+
match_narration = re.match(partner_mapping.narration_regex, tools.html2plaintext(st_line.narration or '').rstrip()) if partner_mapping.narration_regex else True
771770

772771
if match_payment_ref and match_narration:
773772
return partner_mapping.partner_id

addons/point_of_sale/tools/posbox/overwrite_before_init/etc/init_posbox_image.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ PKGS_TO_INSTALL="
5252
python3-decorator \
5353
python3-dev \
5454
python3-docutils \
55-
python3-html2text \
5655
python3-jinja2 \
5756
python3-ldap \
5857
python3-libsass \

debian/control

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Depends:
3030
python3-decorator,
3131
python3-docutils,
3232
python3-freezegun,
33-
python3-html2text,
3433
python3-pil,
3534
python3-jinja2,
3635
python3-libsass,

odoo/addons/base/models/ir_mail_server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import datetime
88
import email
99
import email.policy
10-
import html2text
1110
import idna
1211
import logging
1312
import re
@@ -398,7 +397,7 @@ def build_email(self, email_from, email_to, subject, body, email_cc=None, email_
398397

399398
email_body = ustr(body)
400399
if subtype == 'html' and not body_alternative:
401-
msg.add_alternative(html2text.html2text(email_body), subtype='plain', charset='utf-8')
400+
msg.add_alternative(tools.html2plaintext(email_body), subtype='plain', charset='utf-8')
402401
msg.add_alternative(email_body, subtype=subtype, charset='utf-8')
403402
elif body_alternative:
404403
msg.add_alternative(ustr(body_alternative), subtype=subtype_alternative, charset='utf-8')

odoo/addons/base/tests/test_ir_mail_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def test_mail_body(self):
6565
'content',
6666
'content',
6767
'content',
68-
"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'\))",
69-
'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 ',
68+
"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')",
69+
'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',
7070
]
7171
for body, expected in zip(bodies, expected_list):
7272
message = self.env['ir.mail_server'].build_email(

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ gevent==1.5.0 ; python_version == '3.7'
99
gevent==20.9.0 ; python_version >= '3.8'
1010
greenlet==0.4.15 ; python_version == '3.7'
1111
greenlet==0.4.17 ; python_version > '3.7'
12-
html2text==2020.1.16
1312
idna==2.8
1413
Jinja2==2.10.1; python_version < '3.8'
1514
# bullseye version, focal patched 2.10

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ requires =
1515
python3-freezegun
1616
python3-gevent
1717
python3-greenlet
18-
python3-html2text
1918
python3-idna
2019
python3-jinja2
2120
python3-lxml

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
'decorator',
2828
'docutils',
2929
'gevent',
30-
'html2text',
3130
'idna',
3231
'Jinja2',
3332
'lxml', # windows binary http://www.lfd.uci.edu/~gohlke/pythonlibs/

setup/package.dfdebian

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ RUN apt-get update -qq && \
2828
python3-decorator \
2929
python3-docutils \
3030
python3-gevent \
31-
python3-html2text \
3231
python3-pil \
3332
python3-jinja2 \
3433
python3-libsass \

setup/package.dffedora

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ RUN dnf update -d 0 -e 0 -y && \
2121
python3-freezegun \
2222
python3-gevent \
2323
python3-greenlet \
24-
python3-html2text \
2524
python3-idna \
2625
python3-jinja2 \
2726
python3-lxml \

0 commit comments

Comments
 (0)