summaryrefslogtreecommitdiff
path: root/addons/mail/models/mail_thread.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-01-13 13:11:59 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-03 16:25:01 +0000
commit48d884678cc57ac3d3d350ceb13a208e921f9046 (patch)
tree1ebf1eaefe0ded9b53d5430795be5da2afbae8fa /addons/mail/models/mail_thread.py
parent68a457e17491ac90e3b806178eefc4b7150d176b (diff)
[FIX] mail: route only to other models when routing a forward
When mailgateway receives an incoming email being a reply to a thread but containing a recipient being an alias linked to another model, it is considered as a forward to that new alias. It therefore skips the reply step in routing and applies rules related to new thread, aka checking all recipients. Consider this use case: receives a email on a task from "project@domain" project being the alias of the project which creates new tasks when not routing replies. Reply / forward it to "project@domain, sales@domain" in order to transfer it to the sales team (sales alias creates new leads). As this is a forward, both aliases are evaluated, leading to a new task and a lead which is not what we expect. We solve this issue by removing alias linked to the ignored reply model when considering recipients. PR #46764 Task ID 2121551 closes odoo/odoo#46784 X-original-commit: 7cff7787cb42cc9d3d0cb4c5af41a9f09d59d1ff Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/mail/models/mail_thread.py')
-rw-r--r--addons/mail/models/mail_thread.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py
index bfa5bbe6f19..748cf08ec71 100644
--- a/addons/mail/models/mail_thread.py
+++ b/addons/mail/models/mail_thread.py
@@ -990,6 +990,7 @@ class MailThread(models.AbstractModel):
e.split('@')[0].lower()
for e in tools.email_split(message_dict['recipients'])
]
+ rcpt_tos_valid_localparts = [to for to in rcpt_tos_localparts]
# 0. Handle bounce: verify whether this is a bounced email and use it to collect bounce data and update notifications for customers
# Bounce regex: typical form of bounce is bounce_alias+128-crm.lead-34@domain
@@ -1014,13 +1015,15 @@ class MailThread(models.AbstractModel):
# if destination = alias with different model -> consider it is a forward and not a reply
# if destination = alias with same model -> check contact settings as they still apply
if reply_model and reply_thread_id:
- alias_count = self.env['mail.alias'].search_count([
+ other_model_aliases = self.env['mail.alias'].search([
'&', '&',
('alias_name', '!=', False),
('alias_name', 'in', email_to_localparts),
('alias_model_id.model', '!=', reply_model),
])
- is_a_reply = alias_count == 0
+ if other_model_aliases:
+ is_a_reply = False
+ rcpt_tos_valid_localparts = [to for to in rcpt_tos_valid_localparts if to in other_model_aliases.mapped('alias_name')]
if is_a_reply:
dest_aliases = self.env['mail.alias'].search([
@@ -1055,7 +1058,7 @@ class MailThread(models.AbstractModel):
self._routing_create_bounce_email(email_from, body, message, reply_to=self.env.company.email)
return []
- dest_aliases = self.env['mail.alias'].search([('alias_name', 'in', rcpt_tos_localparts)])
+ dest_aliases = self.env['mail.alias'].search([('alias_name', 'in', rcpt_tos_valid_localparts)])
if dest_aliases:
routes = []
for alias in dest_aliases: