diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py
index 87e5e069fd8..abd5d5e736a 100644
--- a/openerp/tools/mail.py
+++ b/openerp/tools/mail.py
@@ -19,6 +19,8 @@
#
##############################################################################
+from lxml.html.soupparser import fromstring
+from lxml.etree import tostring
import lxml.html
import openerp.pooler as pooler
import operator
@@ -94,6 +96,62 @@ def append_to(elements, dest_node):
dest_node.append(element)
+#----------------------------------------------------------
+# HTML Cleaner
+#----------------------------------------------------------
+
+def html_email_clean(html):
+ """ html_email_clean: clean the html to display in the web client.
+ - strip email quotes (remove blockquote nodes)
+ - strip signatures (remove --\n{\n)Blahblah), by replacing
by
+ \n to avoid ignoring signatures converted into 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()] + '\n'
+ idx = item.end()
+ modified_html += html[idx:]
+
+ # 2. form a tree, handle (currently ?) pure-text by enclosing them in a pre
+ root = fromstring(modified_html)
+ if not len(root) and root.text is None and root.tail is None:
+ modified_html = '