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__')