From cff89b09a48cb9a266b9beb36a515f8d502e12c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 23 Sep 2019 13:50:12 +0000 Subject: [PATCH] [FIX] mail: make recipients unique when parsing emails Purpose of this commit is to have recipients of an incoming email being present only once in recipients / to. Indeed there is no need to have duplicate entries, for example if Delivered-To is set with same content of To. Followup of 7b79045fab809679e17d774f9a510e07ac39aa0b . LINKS Task 2076366 (send now) Task 2067873 (template access) PR #37298 PR odoo/enterprise#5750 --- addons/mail/models/mail_thread.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 5daf717e26f..101766fe9e2 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1384,7 +1384,7 @@ class MailThread(models.AbstractModel): msg_dict['cc'] = ','.join(email_cc_list) if email_cc_list else email_cc # Delivered-To is a safe bet in most modern MTAs, but we have to fallback on To + Cc values # for all the odd MTAs out there, as there is no standard header for the envelope's `rcpt_to` value. - msg_dict['recipients'] = ','.join(formatted_email + msg_dict['recipients'] = ','.join(set(formatted_email for address in [ tools.decode_message_header(message, 'Delivered-To'), tools.decode_message_header(message, 'To'), @@ -1392,14 +1392,15 @@ class MailThread(models.AbstractModel): tools.decode_message_header(message, 'Resent-To'), tools.decode_message_header(message, 'Resent-Cc') ] if address - for formatted_email in tools.email_split_and_format(address) + for formatted_email in tools.email_split_and_format(address)) ) - msg_dict['to'] = ','.join(formatted_email + msg_dict['to'] = ','.join(set(formatted_email for address in [ tools.decode_message_header(message, 'Delivered-To'), tools.decode_message_header(message, 'To') ] if address for formatted_email in tools.email_split_and_format(address)) + ) partner_ids = [x.id for x in self._mail_find_partner_from_emails(tools.email_split(msg_dict['recipients']), records=self) if x] msg_dict['partner_ids'] = partner_ids # compute references to find if email_message is a reply to an existing thread