diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py
index 020ab2313b4..5f8c65c1d9b 100644
--- a/openerp/tools/mail.py
+++ b/openerp/tools/mail.py
@@ -121,17 +121,20 @@ def html_email_clean(html):
be present in the html string. This method therefore takes as input
html code coming from a sanitized source, like fields.html.
"""
+ def _replace_matching_regex(regex, source, replace=''):
+ dest = ''
+ idx = 0
+ for item in re.finditer(regex, source):
+ dest += source[idx:item.start()] + replace
+ idx = item.end()
+ dest += source[idx:]
+ return dest
+
html = ustr(html)
- modified_html = ''
# 1.
-> \n, because otherwise the tree is obfuscated
br_tags = re.compile(r'([<]\s*br\s*\/?[>])')
- idx = 0
- for item in re.finditer(br_tags, html):
- modified_html += html[idx:item.start()] + '__BR_TAG__'
- idx = item.end()
- modified_html += html[idx:]
- html = modified_html
+ html = _replace_matching_regex(br_tags, html, '__BR_TAG__')
# TDE note: seems to have lots of