forked from gfcapalbo/social
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mail_digest: improve message body rendering
Message's body can contains styles and other stuff that can screw the look and feel of digests' mails. Now we sanitize it if `sanitize_msg_body` is set on the digest (default on).
- Loading branch information
Showing
3 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ | |
# Copyright 2017 Simone Orsi <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import fields, models, api, exceptions, _ | ||
|
||
from odoo import fields, models, api, exceptions, tools, _ | ||
import logging | ||
|
||
logger = logging.getLogger('[mail_digest]') | ||
|
@@ -54,6 +53,14 @@ class MailDigest(models.Model): | |
domain=[('type', '=', 'qweb')], | ||
oldname='template_id', | ||
) | ||
sanitize_msg_body = fields.Boolean( | ||
string='Sanitize message body', | ||
help='Collected messages can have different styles applied ' | ||
'on each element. If this flag is enabled (default) ' | ||
'each message content will be sanitized ' | ||
'before generating the email.', | ||
default=True, | ||
) | ||
|
||
def _default_digest_template_id(self): | ||
"""Retrieve default template to render digest.""" | ||
|
@@ -129,6 +136,19 @@ def _message_group_by(self): | |
grouped.setdefault(self._message_group_by_key(msg), []).append(msg) | ||
return grouped | ||
|
||
@api.model | ||
def message_body(self, msg, strip_style=True): | ||
"""Return body message prepared for email content. | ||
Message's body can contains styles and other stuff | ||
that can screw the look and feel of digests' mails. | ||
Here we sanitize it if `sanitize_msg_body` is set on the digest. | ||
""" | ||
if not self.sanitize_msg_body: | ||
return msg.body | ||
return tools.html_sanitize(msg.body or '', strip_style=strip_style) | ||
|
||
def _get_site_name(self): | ||
"""Retrieve site name for meaningful mail subject. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters