diff options
| author | David Beguin <dbe@odoo.com> | 2018-10-01 15:02:51 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2018-10-02 16:53:43 +0200 |
| commit | 331d413f7a2f63734c6c4918ee8a1a91158cf53e (patch) | |
| tree | ff22f9c9fc92e595b9c327323cbef7dc94741942 /addons/mail | |
| parent | c7ad31f0a039ebf24ae45517b3363889988216d8 (diff) | |
[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.
Diffstat (limited to 'addons/mail')
| -rw-r--r-- | addons/mail/wizard/mail_compose_message.py | 12 |
1 files 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 = { |
