diff --git a/mail_usability/README.rst b/mail_usability/README.rst index ba08395..d2a7719 100644 --- a/mail_usability/README.rst +++ b/mail_usability/README.rst @@ -8,3 +8,13 @@ Take back the control on your email - add the option 'All Messages Except Notifications' on partner and use it by default to avoid sending unwanted mail to partner - better email preview, allow to select between the whole database object and not only the last 10 - use a light template version for notification without link (link should be explicit) +- add some additional style in the white list when santizing html field (see tools.py) +- make the email template by default not 'auto_delete' + +## TIPS + +Never, never tick the 'auto_delete' on mail template because it fucking hard to debug +and understand what have been sent (we should create a module with a crontask, that drop them latter) + +If the template of mail do not look like the same when saving it in odoo, maybe the sanitize style have drop some balise +please run odoo with "LOG_STYLE_SANITIZE=True odoo" to understand what have been drop, magic warning logger will tell you everthing diff --git a/mail_usability/__init__.py b/mail_usability/__init__.py index f3658f6..330afb0 100644 --- a/mail_usability/__init__.py +++ b/mail_usability/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- from . import mail +from . import tools from . import mail_template diff --git a/mail_usability/tools.py b/mail_usability/tools.py new file mode 100644 index 0000000..7d435c4 --- /dev/null +++ b/mail_usability/tools.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion (http://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tools.mail import _Cleaner +import os +import logging +_logger = logging.getLogger(__name__) + +_Cleaner._style_whitelist += [ + 'word-wrap', + 'display' + 'border-top', + 'border-bottom', + 'border-left', + 'border-right', + 'text-transform', + ] + + +if os.getenv('LOG_STYLE_SANITIZE'): + # Monkey patch the parse style method to debug + # the missing style + def parse_style(self, el): + attributes = el.attrib + styling = attributes.get('style') + if styling: + valid_styles = {} + styles = self._style_re.findall(styling) + for style in styles: + if style[0].lower() in self._style_whitelist: + valid_styles[style[0].lower()] = style[1] + # START HACK + else: + _logger.warning('Remove style %s %s', *style) + # END HACK + if valid_styles: + el.attrib['style'] = '; '.join( + '%s:%s' % (key, val) + for (key, val) in valid_styles.iteritems()) + else: + del el.attrib['style'] + import pdb; pdb.set_trace() + _Cleaner.parse_style = parse_style