[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
This commit is contained in:
Christophe Matthieu 2012-12-19 11:37:14 +01:00
parent b63518345e
commit 125f80888e
1 changed files with 5 additions and 1 deletions

View File

@ -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. <br[ /]> -> \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__')