diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py index db29d266114..d35fbf5dddf 100644 --- a/addons/mail/models/mail_render_mixin.py +++ b/addons/mail/models/mail_render_mixin.py @@ -207,45 +207,26 @@ class MailRenderMixin(models.AbstractModel): return html @api.model - def _generate_preview(self, html): - """ Generate a preview of html, to used for example in marketing emails. - - We add the character `` (zero-width non-joiner) to fill the end of - the preview in order to not have the beginning of the mail at the end of - the preview (don't work with simple space as the content is trimmed). - https://litmus.com/blog/the-ultimate-guide-to-preview-text-support - - :param html: html content for which we generate the preview - :return: html to use as preview - """ - preview = "" - for element in re.finditer(r"\>([^<>]+)\<", html): - element = element.group(1).strip() - if element: - preview += " %s" % element - if len(preview) > 500: - break - - html_preview = f""" -
- """ if preview else '' - - return html_preview - - @api.model - def _prepend_preview(self, html): + def _prepend_preview(self, html, preview): """ Prepare the email body before sending. Add the text preview at the beginning of the mail. The preview text is displayed bellow the mail subject of most mail client (gmail, outlook...). - See ``_generate_preview()`` for more details about the preview computation. - :param html: html content for which we want to prepend a preview + :param preview: the preview to add before the html content :return: html with preprended preview """ - return tools.prepend_html_content(html, self._generate_preview(html)) + if preview: + preview = preview.strip() + + if preview: + html_preview = f""" + + """ + return tools.prepend_html_content(html, html_preview) + return html # ------------------------------------------------------------ # RENDERING diff --git a/addons/mass_mailing/data/mass_mailing_demo.xml b/addons/mass_mailing/data/mass_mailing_demo.xml index 34e72a7418b..9587eb48d2a 100644 --- a/addons/mass_mailing/data/mass_mailing_demo.xml +++ b/addons/mass_mailing/data/mass_mailing_demo.xml @@ -83,7 +83,7 @@
+
+
+
| - View this email in your browser + View Online | |||||||||||||
|
-
+
Column titleWrite one paragraph describing your product, @@ -391,7 +391,7 @@
|
-
+
Column titleWrite one paragraph describing your product, @@ -418,7 +418,7 @@
|
-
+
Column TitleA short description @@ -431,7 +431,7 @@
|
-
+
Column TitleA short description @@ -444,7 +444,7 @@
|
-
+
Column TitleA short description @@ -468,7 +468,7 @@
- |
+
|
Omnichannel sales@@ -498,7 +498,7 @@
- |
+
- |
+
- |
+
|
diff --git a/addons/mass_mailing/views/themes_templates.xml b/addons/mass_mailing/views/themes_templates.xml
index 812de3c7964..6d819395429 100644
--- a/addons/mass_mailing/views/themes_templates.xml
+++ b/addons/mass_mailing/views/themes_templates.xml
@@ -21,7 +21,7 @@
'''
- jinja_html_preview = self.env['mail.render.mixin']._generate_preview(jinja_html)
- self.assertIn('Hello ${object.name}', jinja_html_preview)
- self.assertIn('Here are your personal links', jinja_html_preview)
- self.assertIn('External link', jinja_html_preview)
- self.assertIn('Internal link', jinja_html_preview)
- self.assertIn('Unsubscribe link', jinja_html_preview)
- self.assertIn('View link', jinja_html_preview)
mailing.write({
+ 'preview': 'Hi ${object.name} :)',
'body_html': jinja_html,
'mailing_model_id': self.env['ir.model']._get('mailing.test.optout').id,
})
@@ -70,7 +64,7 @@ class TestMassMailing(TestMailFullCommon):
email = self._find_sent_mail_wemail(recipient.email_normalized)
# preview correctly integrated rendered jinja
self.assertIn(
- 'Hello %s Here are your personal links External link Internal link Unsubscribe link View link' % recipient.name,
+ 'Hi %s :)' % recipient.name,
email['body'])
# rendered unsubscribe
self.assertIn(
|
- |
+
diff --git a/addons/mass_mailing/wizard/mailing_mailing_test.py b/addons/mass_mailing/wizard/mailing_mailing_test.py
index e37fccd3e90..2ffba12ebf5 100644
--- a/addons/mass_mailing/wizard/mailing_mailing_test.py
+++ b/addons/mass_mailing/wizard/mailing_mailing_test.py
@@ -24,7 +24,7 @@ class TestMassMailing(models.TransientModel):
mass_mail_layout = self.env.ref('mass_mailing.mass_mailing_mail_layout')
for test_mail in test_emails:
# Convert links in absolute URLs before the application of the shortener
- body = mailing._prepend_preview(mailing.body_html)
+ body = mailing._prepend_preview(mailing.body_html, mailing.preview)
body = self.env['mail.render.mixin']._replace_local_links(body)
body = tools.html_sanitize(body, sanitize_attributes=True, sanitize_style=True)
mail_values = {
diff --git a/addons/test_mail_full/tests/test_mass_mailing.py b/addons/test_mail_full/tests/test_mass_mailing.py
index 9fefdab2248..e1051145e99 100644
--- a/addons/test_mail_full/tests/test_mass_mailing.py
+++ b/addons/test_mail_full/tests/test_mass_mailing.py
@@ -33,15 +33,9 @@ class TestMassMailing(TestMailFullCommon):
| |