[FIX] mail: correctly find and compare blacklist email when sending mass mailing

Until now, a recipient with a formatted email like 'John Doe
<john_doe@example.com>' 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.
This commit is contained in:
David Beguin
2018-10-02 16:53:43 +02:00
committed by Thibault Delavallée
parent c7ad31f0a0
commit 331d413f7a
+7 -5
View File
@@ -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 = {