From 125f80888e70711c2f779a64465b22e697cfc8ad Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 19 Dec 2012 11:37:14 +0100 Subject: [PATCH] [FIX] tools mail: return the initial variable if is false or if is not an instance of basestring. remove xml and doctype tags. bzr revid: chm@openerp.com-20121219103714-u52hfmqr5u508xa2 --- openerp/tools/mail.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py index a54f99ba1ad..9df7499d0c8 100644 --- a/openerp/tools/mail.py +++ b/openerp/tools/mail.py @@ -130,11 +130,15 @@ def html_email_clean(html): dest += source[idx:] return dest - if not html: + if not html or not isinstance(html, basestring): return html html = ustr(html) + # 0. remove doctype and xml tags + doctype = re.compile(r"(<[?]xml.*?[?]>|<[!]DOCTYPE.*?>)[\n\r\s]*", re.IGNORECASE | re.DOTALL) + html = doctype.sub(r"", html) + # 1. -> \n, because otherwise the tree is obfuscated br_tags = re.compile(r'([<]\s*[bB][rR]\s*\/?[>])') html = _replace_matching_regex(br_tags, html, '__BR_TAG__')