From 331d413f7a2f63734c6c4918ee8a1a91158cf53e Mon Sep 17 00:00:00 2001 From: David Beguin Date: Mon, 1 Oct 2018 15:02:51 +0200 Subject: [PATCH] [FIX] mail: correctly find and compare blacklist email when sending mass mailing Until now, a recipient with a formatted email like 'John Doe ' could be reached by email even if its email address was blacklisted. Now when sending a mass mail using the composer, the email is sanitized before comparing it to blacklist entries. This commit is related to task ID 33224 (original blacklist implementation done for v12) and its PR #25966 as well as task ID 1889703 (tests and fixes) and its PR #27330. Done with collaboration of @dbeguin. --- addons/mail/wizard/mail_compose_message.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index bac7148ca9c..5422a115fdf 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -282,14 +282,16 @@ class MailComposer(models.TransientModel): blacklisted_rec_ids = [] if mass_mail_mode and hasattr(self.env[self.model], "_primary_email"): BL_sudo = self.env['mail.blacklist'].sudo() - blacklist = set(email.lower() for email in BL_sudo.search([]).mapped('email')) + blacklist = set(BL_sudo.search([]).mapped('email')) if blacklist: [email_field] = self.env[self.model]._primary_email targets = self.env[self.model].browse(res_ids).read([email_field]) - blacklisted_rec_ids = [r['id'] - for r in targets - if r[email_field] - if r[email_field].lower() in blacklist] + # First extract email from recipient before comparing with blacklist + for target in targets: + sanitized_email = self.env['mail.blacklist']._sanitize_email(target.get(email_field)) + if sanitized_email and sanitized_email in blacklist: + blacklisted_rec_ids.append(target['id']) + for res_id in res_ids: # static wizard (mail.message) values mail_values = {