[FIX] tools: Comments in e-mail templates are removed before mako/jinja2 processing...
authorAnael Closson <acl@openerp.com>
Tue, 15 Apr 2014 14:37:36 +0000 (16:37 +0200)
committerAnael Closson <acl@openerp.com>
Tue, 15 Apr 2014 14:37:36 +0000 (16:37 +0200)
bzr revid: acl@openerp.com-20140415143736-bcgwgribsv2hsbvo

openerp/tools/mail.py

index 85dcfd3..5cbd030 100644 (file)
@@ -45,7 +45,7 @@ tags_to_kill = ["script", "head", "meta", "title", "link", "style", "frame", "if
 tags_to_remove = ['html', 'body', 'font']
 
 # allow new semantic HTML5 tags
-allowed_tags = clean.defs.tags | frozenset('article section header footer hgroup nav aside figure main'.split())
+allowed_tags = clean.defs.tags | frozenset('article section header footer hgroup nav aside figure main'.split() + [etree.Comment])
 safe_attrs = clean.defs.safe_attrs | frozenset(
     ['style',
      'data-oe-model', 'data-oe-id', 'data-oe-field', 'data-oe-type', 'data-oe-expression', 'data-oe-translate', 'data-oe-nodeid',
@@ -70,6 +70,8 @@ def html_sanitize(src, silent=True, strict=False):
         'forms': True,              # remove form tags
         'remove_unknown_tags': False,
         'allow_tags': allowed_tags,
+        'comments': False,
+        'processing_instructions' : False
     }
     if etree.LXML_VERSION >= (2, 3, 1):
         # kill_tags attribute has been added in version 2.3.1
@@ -339,10 +341,14 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_o
     overlength_section_count = 0
     cur_char_nbr = 0
     for node in root.iter():
+        # comments do not need processing
+        if node.tag == etree.Comment:
+            continue
         # do not take into account multiple spaces that are displayed as max 1 space in html
         node_text = ' '.join((node.text and node.text.strip(' \t\r\n') or '').split())
 
         # root: try to tag the client used to write the html
+        # note: bug in node.get(value, default) for HtmlComments, default never returned
         if 'WordSection1' in node.get('class', '') or 'MsoNormal' in node.get('class', ''):
             root.set('msoffice', '1')
         if 'SkyDrivePlaceholder' in node.get('class', '') or 'SkyDrivePlaceholder' in node.get('id', ''):
@@ -657,4 +663,4 @@ def email_split(text):
                 # sometimes returns emails without at least '@'. The '@'
                 # is strictly required in RFC2822's `addr-spec`.
                 if addr[1]
-                if '@' in addr[1]]
\ No newline at end of file
+                if '@' in addr[1]]