summaryrefslogtreecommitdiff
path: root/addons/mail/models/mail_thread.py
diff options
context:
space:
mode:
authorRémy Voet (ryv) <ryv@odoo.com>2019-12-18 12:01:37 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-12 13:54:32 +0000
commitc5e6511e8d35a206e966658325ac8dce6a097a48 (patch)
tree821939459ad332fbab22766517e6b98e949d1e9f /addons/mail/models/mail_thread.py
parent974f512f5f5d3b9f80a8c3fcde290e4f55cf1230 (diff)
[IMP] mail: ease bounce email content update based on alias security
PURPOSE When incoming emails bounce due to alias security bounce email is quite generic. Purpose of this task is to ease its customization and update. SPECIFICATIONS In order to improve the flexibility of alias, add a customizable html field on the alias model. This html content will be send as bounce email core content in case of bounced/unauthorized mail received for this alias, Obviously it has no effect on 'everyone' security setting as no email will bounce due to that issue. If it is not set a default generic mail will be send depending on security setting. It allows to keep void html fields when no specific bounce content is required In HR, an old template allowing some light customization for employee based security option is removed as it is completely replaced by the new feature. Also add references message-id of the mail received to the answer so that threads are correctly set. LINKS Task ID 2126509
Diffstat (limited to 'addons/mail/models/mail_thread.py')
-rw-r--r--addons/mail/models/mail_thread.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py
index 748cf08ec71..90aebbff672 100644
--- a/addons/mail/models/mail_thread.py
+++ b/addons/mail/models/mail_thread.py
@@ -30,7 +30,7 @@ from odoo import _, api, exceptions, fields, models, tools, registry, SUPERUSER_
from odoo.exceptions import MissingError
from odoo.osv import expression
-from odoo.tools import pycompat, ustr
+from odoo.tools import ustr
from odoo.tools.misc import clean_context, split_every
_logger = logging.getLogger(__name__)
@@ -820,7 +820,6 @@ class MailThread(models.AbstractModel):
fallback on a message_new by resetting thread_id
2 - check that message_update exists if thread_id is set; or at least
that message_new exist
- [ - find author_id if udpate_author is set]
3 - if there is an alias, check alias_contact:
'followers' and thread_id:
check on target document that the author is in the followers
@@ -848,12 +847,6 @@ class MailThread(models.AbstractModel):
model, thread_id, alias = route[0], route[1], route[4]
record_set = None
- _generic_bounce_body_html = """<div>
-<p>Hello,</p>
-<p>The following email sent to %s cannot be accepted because this is a private email address.
- Only allowed people can contact us at this address.</p>
-</div><blockquote>%s</blockquote>""" % (message_dict.get('to'), message_dict.get('body'))
-
# Wrong model
if not model:
self._routing_warn(_('target model unspecified'), message_id, route, raise_exception)
@@ -877,7 +870,7 @@ class MailThread(models.AbstractModel):
self._routing_warn(_('model %s does not accept document creation') % model, message_id, route, raise_exception)
return ()
- # Update message author if asked. We do it now because we need it for aliases (contact settings)
+ # Update message author. We do it now because we need it for aliases (contact settings)
if not author_id:
if record_set:
authors = self._mail_find_partner_from_emails([email_from], records=record_set)
@@ -898,12 +891,13 @@ class MailThread(models.AbstractModel):
else:
obj = self.env[model]
if hasattr(obj, '_alias_check_contact'):
- check_result = obj._alias_check_contact(message, message_dict, alias)
+ error_code = obj._alias_check_contact(message, message_dict, alias)
else:
- check_result = self.env['mail.alias.mixin']._alias_check_contact_on_record(obj, message, message_dict, alias)
- if check_result is not True:
- self._routing_warn(_('alias %s: %s') % (alias.alias_name, check_result.get('error_message', _('unknown error'))), message_id, route, False)
- self._routing_create_bounce_email(email_from, check_result.get('error_template', _generic_bounce_body_html), message)
+ error_code = self.env['mail.alias.mixin']._alias_check_contact_on_record(obj, message, message_dict, alias)
+ if error_code is not True:
+ self._routing_warn(_('alias %s: %s') % (alias.alias_name, error_code or _('unknown error')), message_id, route, False)
+ body = alias._get_alias_bounced_body(message_dict)
+ self._routing_create_bounce_email(email_from, body, message, references=message_id)
return False
return (model, thread_id, route[2], route[3], route[4])
@@ -1055,7 +1049,7 @@ class MailThread(models.AbstractModel):
body = self.env.ref('mail.mail_bounce_catchall').render({
'message': message,
}, engine='ir.qweb')
- self._routing_create_bounce_email(email_from, body, message, reply_to=self.env.company.email)
+ self._routing_create_bounce_email(email_from, body, message, references=message_id, reply_to=self.env.company.email)
return []
dest_aliases = self.env['mail.alias'].search([('alias_name', 'in', rcpt_tos_valid_localparts)])