From b36547e3efca8d799c7250cd2549325a4a18f7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Nov 2012 16:41:29 +0100 Subject: [PATCH] [CLEAN] tools: mail: removed commented code; moved some code. bzr revid: tde@openerp.com-20121107154129-nhz7qjv1ksq521ur --- openerp/tools/mail.py | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py index 1290ebbdec6..cebc6313b08 100644 --- a/openerp/tools/mail.py +++ b/openerp/tools/mail.py @@ -20,10 +20,7 @@ ############################################################################## from lxml import etree -# try: -# from lxml.html.soupparser import fromstring as parser_fromstring -# except ImportError: -# from lxml.html import fromstring as parser_fromstring +import cgi import logging import lxml.html import openerp.pooler as pooler @@ -39,6 +36,10 @@ from openerp.loglevels import ustr _logger = logging.getLogger(__name__) +#---------------------------------------------------------- +# HTML Sanitizer +#---------------------------------------------------------- + def html_sanitize(src): if not src: return src @@ -173,25 +174,9 @@ def html_email_clean(html): #---------------------------------------------------------- -# Emails +# HTML/Text management #---------------------------------------------------------- -email_re = re.compile(r""" - ([a-zA-Z][\w\.-]*[a-zA-Z0-9] # username part - @ # mandatory @ sign - [a-zA-Z0-9][\w\.-]* # domain must start with a letter ... Ged> why do we include a 0-9 then? - \. - [a-z]{2,3} # TLD - ) - """, re.VERBOSE) -res_re = re.compile(r"\[([0-9]+)\]", re.UNICODE) -command_re = re.compile("^Set-([a-z]+) *: *(.+)$", re.I + re.UNICODE) - -# Updated in 7.0 to match the model name as well -# Typical form of references is -# group(1) = the record ID ; group(2) = the model (if any) ; group(3) = the domain -reference_re = re.compile("<.*-open(?:object|erp)-(\\d+)(?:-([\w.]+))?.*@(.*)>", re.UNICODE) - 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 @@ -248,6 +233,27 @@ def html2plaintext(html, body_id=None, encoding='utf-8'): return html + +#---------------------------------------------------------- +# Emails +#---------------------------------------------------------- + +email_re = re.compile(r""" + ([a-zA-Z][\w\.-]*[a-zA-Z0-9] # username part + @ # mandatory @ sign + [a-zA-Z0-9][\w\.-]* # domain must start with a letter ... Ged> why do we include a 0-9 then? + \. + [a-z]{2,3} # TLD + ) + """, re.VERBOSE) +res_re = re.compile(r"\[([0-9]+)\]", re.UNICODE) +command_re = re.compile("^Set-([a-z]+) *: *(.+)$", re.I + re.UNICODE) + +# Updated in 7.0 to match the model name as well +# Typical form of references is +# group(1) = the record ID ; group(2) = the model (if any) ; group(3) = the domain +reference_re = re.compile("<.*-open(?:object|erp)-(\\d+)(?:-([\w.]+))?.*@(.*)>", re.UNICODE) + def generate_tracking_message_id(res_id): """Returns a string that can be used in the Message-ID RFC822 header field