From d6aa0050dae663ba3c3259304fd6aea61d9495b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 22 Nov 2022 09:57:40 +0000 Subject: [PATCH] [FIX] mail: stop spamming CCs of outgoing emails Fix usage of CCs when sending emails. Currently CCs are added to all outgoing emails, which leads to unnecessary spam. Recipients are currently computed like * create an outgoing email based on 'email_to'; * create one outgoing email / partner in 'recipient_ids'; * add CCs to all outgoing emails; They are now sent only once, either with the email_to if given, either as standalone. That way partners receive specific emails (due to tracking and partner specific links management), email_to / email_cc are sent on their own. Task-3093268 (Mail: Stop spamming CCs) Prepares Task-2684479 (Mail: Better report errors when sending emails) Part-of: odoo/odoo#99482 --- addons/mail/models/mail_mail.py | 17 ++++++++++++++--- addons/test_mail/tests/test_mail_mail.py | 5 +++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 1fed4e7045c..5356e525ea4 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -373,19 +373,30 @@ class MailMail(models.Model): if self.email_to: email_to = tools.email_split_and_format(self.email_to) email_list.append({ + 'email_cc': [], 'email_to': email_to, # keep raw initial value for incoming pre processing of outgoing emails 'email_to_raw': self.email_to or '', 'partner_id': False, }) - # TODO: add all cc once, either to the "To", either as a single entry (do not mix + # add all cc once, either to the first "To", either as a single entry (do not mix # with partner-specific sending) - email_cc = tools.email_split(self.email_cc) + if self.email_cc: + if email_list: + email_list[0]['email_cc'] = tools.email_split(self.email_cc) + else: + email_list.append({ + 'email_cc': tools.email_split(self.email_cc), + 'email_to': [], + 'email_to_raw': False, + 'partner_id': False, + }) # specific behavior to customize the send email for notified partners for partner in self.recipient_ids: # check partner email content email_to = [tools.formataddr((partner.name or '', partner.email or 'False'))] email_list.append({ + 'email_cc': [], 'email_to': email_to, # keep raw initial value for incoming pre processing of outgoing emails 'email_to_raw': partner.email or '', @@ -415,7 +426,7 @@ class MailMail(models.Model): 'attachments': email_attachments, 'body': body, 'body_alternative': body_alternative, - 'email_cc': email_cc, + 'email_cc': email_values['email_cc'], 'email_from': self.email_from, 'email_to': email_values['email_to'], 'email_to_raw': email_values['email_to_raw'], diff --git a/addons/test_mail/tests/test_mail_mail.py b/addons/test_mail/tests/test_mail_mail.py index 164161079ca..b002fab7d01 100644 --- a/addons/test_mail/tests/test_mail_mail.py +++ b/addons/test_mail/tests/test_mail_mail.py @@ -195,9 +195,10 @@ class TestMailMail(TestMailCommon): self.assertSentEmail(mail.env.user.partner_id, ['test.rec.1@example.com', '"Raoul" '], email_cc=['test.cc.1@example.com', 'test.cc.2@example.com']) - # Mail: currently cc are put as copy of all sent emails (aka spam) + # don't put CCs as copy of each outgoing email, only the first one (and never + # with partner based recipients as those may receive specific links) self.assertSentEmail(mail.env.user.partner_id, [self.user_employee.email_formatted], - email_cc=['test.cc.1@example.com', 'test.cc.2@example.com']) + email_cc=[]) self.assertEqual(len(self._mails), 2) @mute_logger('odoo.addons.mail.models.mail_mail')