Skip to content

Commit d79197f

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#82330 X-original-commit: odoo/odoo@9b5f86e Related: odoo/enterprise#23292 Signed-off-by: Thibault Delavallee (tde) <[email protected]>
1 parent abd375a commit d79197f

File tree

9 files changed

+3
-11
lines changed

9 files changed

+3
-11
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ PKGS_TO_INSTALL="
5151
python3-decorator \
5252
python3-dev \
5353
python3-docutils \
54-
python3-html2text \
5554
python3-jinja2 \
5655
python3-ldap \
5756
python3-libsass \

debian/control

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Depends:
2727
python3-decorator,
2828
python3-docutils,
2929
python3-freezegun,
30-
python3-html2text,
3130
python3-pil,
3231
python3-jinja2,
3332
python3-libsass,

odoo/addons/base/models/ir_mail_server.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import sys
1515
import threading
1616

17-
import html2text
1817
import idna
1918

2019
from odoo import api, fields, models, tools, _
@@ -325,7 +324,7 @@ def build_email(self, email_from, email_to, subject, body, email_cc=None, email_
325324

326325
email_body = ustr(body)
327326
if subtype == 'html' and not body_alternative:
328-
msg.add_alternative(html2text.html2text(email_body), subtype='plain', charset='utf-8')
327+
msg.add_alternative(tools.html2plaintext(email_body), subtype='plain', charset='utf-8')
329328
msg.add_alternative(email_body, subtype=subtype, charset='utf-8')
330329
elif body_alternative:
331330
msg.add_alternative(ustr(body_alternative), subtype=subtype_alternative, charset='utf-8')

odoo/addons/base/tests/test_ir_mail_server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_mail_body(self):
2222
'content',
2323
'content',
2424
'content',
25-
"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'\))",
26-
'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 ',
25+
"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')",
26+
'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',
2727
]
2828
for body, expected in zip(bodies, expected_list):
2929
message = self.env['ir.mail_server'].build_email(

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ gevent==1.4.0 ; sys_platform == 'win32' and python_version < '3.7'
1212
greenlet==0.4.10 ; python_version < '3.7'
1313
greenlet==0.4.15 ; python_version == '3.7'
1414
greenlet==0.4.17 ; python_version > '3.7'
15-
html2text==2018.1.9
1615
idna==2.6
1716
Jinja2==2.10.1; python_version < '3.8'
1817
# bullseye version, focal patched 2.10

setup.cfg

-1
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

-1
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

-1
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

-1
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)