diff --git a/addons/test_mass_mailing/tests/test_mailing_test.py b/addons/test_mass_mailing/tests/test_mailing_test.py index 33c0419af07..d2bd2a96449 100644 --- a/addons/test_mass_mailing/tests/test_mailing_test.py +++ b/addons/test_mass_mailing/tests/test_mailing_test.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import lxml.html from odoo.addons.test_mass_mailing.tests.common import TestMassMailCommon from odoo.tests.common import users @@ -28,6 +29,16 @@ class TestMailingTest(TestMassMailCommon): with self.mock_mail_gateway(): mailing_test.send_mail_test() + # not great but matches send_mail_test, maybe that should be a method + # on mailing_test? + record = self.env[mailing.mailing_model_real].search([], limit=1) + first_child = lxml.html.fromstring(self._mails.pop()['body']).xpath('//body/*[1]')[0] + self.assertEqual(first_child.tag, 'div') + self.assertIn('display:none', first_child.get('style'), + "the preview node should be hidden") + self.assertEqual(first_child.text.strip(), "Preview " + record.name, + "the preview node should contain the preview text") + # Test if bad jinja in the subject raises an error mailing.write({'subject': 'Subject ${object.name_id.id}'}) with self.mock_mail_gateway(), self.assertRaises(Exception): diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index bbc8a660451..bfbfddea275 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -433,14 +433,11 @@ def append_content_to_html(html, content, plaintext=True, preserve=False, contai def prepend_html_content(html_body, html_content): """Prepend some HTML content at the beginning of an other HTML content.""" - html_content = re.sub(r'(?i)(]*>)', '', html_content) + html_content = type(html_content)(re.sub(r'(?i)(]*>)', '', html_content)) html_content = html_content.strip() - insert_index = next(re.finditer(r']*>', html_body), None) - if insert_index is None: - insert_index = next(re.finditer(r']*>', html_body), None) - - insert_index = insert_index.end() if insert_index else 0 + body_match = re.search(r']*>', html_body) or re.search(r']*>', html_body) + insert_index = body_match.end() if body_match else 0 return html_body[:insert_index] + html_content + html_body[insert_index:]