diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-03-11 12:42:48 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-03-24 10:25:04 +0000 |
| commit | aaefa35e29f7e87e8e914cf1d9eb68af7d26464a (patch) | |
| tree | 0835ddf9cea2ffebfa0ca441411b32e3fa1db502 /odoo | |
| parent | 3d86a29aeb21c7e5812c988866117a495f20ebed (diff) | |
[MOV] link_tracker, various: more link shortening tools to mail.render.mixin
PURPOSE
Move links shortening tools on mail.render.mixin to have rendering and
post procesing tools available on that mixin.
SPECIFICATIONS
Move html and text links shortening methods on mail.render.mixin class.
That way rendering and post processing is done in that mixin instead of
being specific to link.tracker model. Indeed those methods are tools and
not really business related methods.
Future commits will improve the way mail and sms composer use the render
mixin. This commit is therefore both a cleaning and preparing commit.
LINKS
Task ID 1963529
Community PR odoo/odoo#32397
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/tools/mail.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 21756fe0640..d1bc961e8ff 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -13,6 +13,7 @@ import time from email.utils import getaddresses from lxml import etree +from werkzeug import urls import odoo from odoo.loglevels import ustr @@ -250,9 +251,19 @@ def html_sanitize(src, silent=True, sanitize_tags=True, sanitize_attributes=Fals return cleaned -#---------------------------------------------------------- +# ---------------------------------------------------------- # HTML/Text management -#---------------------------------------------------------- +# ---------------------------------------------------------- + +URL_REGEX = r'(\bhref=[\'"](?!mailto:|tel:|sms:)([^\'"]+)[\'"])' +TEXT_URL_REGEX = r'https?://[a-zA-Z0-9@:%._\+~#=/-]+(?:\?\S+)?' + + +def validate_url(url): + if urls.url_parse(url).scheme not in ('http', 'https', 'ftp', 'ftps'): + return 'http://' + url + + return url def is_html_empty(html_content): @@ -281,6 +292,7 @@ def html_keep_url(text): final += text[idx:] return final + def html2plaintext(html, body_id=None, encoding='utf-8'): """ From an HTML text, convert the HTML to plain text. If @param body_id is provided then this is the tag where the |
