From 967d228a44080381d185c252ff29c993b2b88429 Mon Sep 17 00:00:00 2001 From: Deep Patel Date: Mon, 4 Jun 2018 17:04:39 +0530 Subject: [PATCH] [IMP] mass_mailing, mail: added support for media queries in mass mail - Email generated from mass mailing will have its own layout with internal css. - strip_classes is removed from mail_message because mail client are now supporting internal stylesheet. we need it for make mail responsive. mail: manually removed classes from incoming mail body Because we removed strip_classes from mail message body field because we want to allow classes in outgoing mail to make it responsive but classes are not removed from incoming mails so here we manually removed classes from incoming mail. opw-1836556 --- addons/mail/models/mail_message.py | 2 +- addons/mail/models/mail_thread.py | 2 + addons/mass_mailing/__manifest__.py | 1 + .../static/src/scss/themes/theme_default.scss | 16 +-- addons/mass_mailing/tests/__init__.py | 1 + .../tests/test_mass_mailing_responsive.py | 33 +++++ .../mass_mailing/views/editor_field_html.xml | 1 + .../views/mass_mailing_layout.xml | 37 ++++++ addons/mass_mailing/views/snippets_themes.xml | 114 +++++++++--------- .../wizard/mail_compose_message.py | 3 + addons/mass_mailing/wizard/test_mailing.py | 4 +- .../static/src/js/editor/transcoder.js | 1 - 12 files changed, 143 insertions(+), 72 deletions(-) create mode 100644 addons/mass_mailing/tests/test_mass_mailing_responsive.py create mode 100644 addons/mass_mailing/views/mass_mailing_layout.xml diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 522400fd495..816f15a5b24 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -40,7 +40,7 @@ class Message(models.Model): # content subject = fields.Char('Subject') date = fields.Datetime('Date', default=fields.Datetime.now) - body = fields.Html('Contents', default='', sanitize_style=True, strip_classes=True) + body = fields.Html('Contents', default='', sanitize_style=True) attachment_ids = fields.Many2many( 'ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index fe08600259d..55e28e5c196 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1567,6 +1567,8 @@ class MailThread(models.AbstractModel): body = html else: body = tools.append_content_to_html(body, html, plaintext=False) + # we only strip_classes here everything else will be done in by html field of mail.message + body = tools.html_sanitize(body, sanitize_tags=False, strip_classes=True) # 4) Anything else -> attachment else: attachments.append(self._Attachment(filename or 'attachment', part.get_payload(decode=True), {})) diff --git a/addons/mass_mailing/__manifest__.py b/addons/mass_mailing/__manifest__.py index 5f820bbf30f..78941fc1f30 100644 --- a/addons/mass_mailing/__manifest__.py +++ b/addons/mass_mailing/__manifest__.py @@ -31,6 +31,7 @@ 'views/mass_mailing_views.xml', 'views/res_config_settings_views.xml', 'security/ir.model.access.csv', + 'views/mass_mailing_layout.xml', 'views/editor_field_html.xml', 'views/themes_templates.xml', 'views/snippets_themes.xml', diff --git a/addons/mass_mailing/static/src/scss/themes/theme_default.scss b/addons/mass_mailing/static/src/scss/themes/theme_default.scss index 704ea7656d7..96d6a61e805 100644 --- a/addons/mass_mailing/static/src/scss/themes/theme_default.scss +++ b/addons/mass_mailing/static/src/scss/themes/theme_default.scss @@ -162,7 +162,7 @@ td { } } -.o_mail_block_steps { +.o_mail_block_steps .o_mail_snippet_general{ background-color: $o-mm-def-color-alpha; } @@ -306,20 +306,6 @@ td { border-collapse:separate; } -// ===== Mobile ===== -@media screen and (max-width: $o-mm-def-body-bobile) { - .o_mail_col_mv { - display: block!important; - max-width: $o-mm-def-body-bobile!important; - width: 100%!important; - } - - .o_mail_table_styles { - max-width: $o-mm-def-body-bobile!important; - width: 100%!important; - } -} - // Compatibility: mb/mt classes on elements were interpreted as paddings // instead of margins before the introduction of pb/pt classes. As thoses mb/mt // classes may remain on clients' templates, are forced to 0 margin to diff --git a/addons/mass_mailing/tests/__init__.py b/addons/mass_mailing/tests/__init__.py index b02648f85eb..f228b7d5635 100644 --- a/addons/mass_mailing/tests/__init__.py +++ b/addons/mass_mailing/tests/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import test_mass_mailing_list_merge +from . import test_mass_mailing_responsive diff --git a/addons/mass_mailing/tests/test_mass_mailing_responsive.py b/addons/mass_mailing/tests/test_mass_mailing_responsive.py new file mode 100644 index 00000000000..4a186ae652c --- /dev/null +++ b/addons/mass_mailing/tests/test_mass_mailing_responsive.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests import common + + +class TestResponsiveMail(common.SavepointCase): + + def test_responsive_mail(self): + """ + Testing mail mailing responsive mail body + """ + test_record = self.env['res.partner'].create({'name': 'Mass Mail Partner'}) + mass_mail_record = self.env.ref('mass_mailing.mass_mail_2') + + composer = self.env['mail.compose.message'].sudo().with_context({ + 'default_composition_mode': 'mass_mail', + 'default_model': 'res.partner', + 'default_res_id': test_record.id, + }).create({ + 'subject': 'Mass Mail Responsive', + 'body': 'I am Responsive body', + 'mass_mailing_id': mass_mail_record.id + }) + + mail_values = composer.get_mail_values([test_record.id]) + body_html = str(mail_values[test_record.id]['body_html']) + + self.assertIn('', body_html) + self.assertIn('', body_html) + self.assertIn('viewport', body_html) + self.assertIn('@media', body_html) + self.assertIn('I am Responsive body', body_html) diff --git a/addons/mass_mailing/views/editor_field_html.xml b/addons/mass_mailing/views/editor_field_html.xml index a962647670e..8a1a8845aa8 100644 --- a/addons/mass_mailing/views/editor_field_html.xml +++ b/addons/mass_mailing/views/editor_field_html.xml @@ -3,6 +3,7 @@