[IMP] mass_mailing : apply email_normalized on _get_opt_out_list
To avoid sending mail to an opted-out mass_mailing_contact with email address that is not strictly an email address (a <a@a.com> instead of a@a.com), the the get_opt_out method must be adapted to use the email_normalized field, as this method is only useful for that specific model. Task ID : 1896677
This commit is contained in:
@@ -768,10 +768,9 @@ class MassMailing(models.Model):
|
||||
# TODO DBE Fixme : Optimise the following to get real opt_out and opt_in
|
||||
target_list_contacts = self.env['mail.mass_mailing.list_contact_rel'].search(
|
||||
[('list_id', 'in', self.contact_list_ids.ids)])
|
||||
opt_out_contacts = target_list_contacts.filtered(lambda rel: rel.opt_out).mapped('contact_id.email')
|
||||
opt_in_contacts = target_list_contacts.filtered(lambda rel: not rel.opt_out).mapped('contact_id.email')
|
||||
normalized_email = [tools.email_split(c) for c in opt_out_contacts if c not in opt_in_contacts]
|
||||
opt_out = set(email[0].lower() for email in normalized_email if email)
|
||||
opt_out_contacts = target_list_contacts.filtered(lambda rel: rel.opt_out).mapped('contact_id.email_normalized')
|
||||
opt_in_contacts = target_list_contacts.filtered(lambda rel: not rel.opt_out).mapped('contact_id.email_normalized')
|
||||
opt_out = set(c for c in opt_out_contacts if c not in opt_in_contacts)
|
||||
|
||||
_logger.info(
|
||||
"Mass-mailing %s targets %s, blacklist: %s emails",
|
||||
|
||||
@@ -62,10 +62,9 @@ class MailComposeMessage(models.TransientModel):
|
||||
for res_id in res_ids:
|
||||
mail_values = res[res_id]
|
||||
if mail_values.get('email_to'):
|
||||
recips = tools.email_split(mail_values['email_to'])
|
||||
mail_to = tools.email_normalize(mail_values['email_to'])
|
||||
else:
|
||||
recips = tools.email_split(partners_email.get(res_id))
|
||||
mail_to = recips[0].lower() if recips else False
|
||||
mail_to = tools.email_normalize(partners_email.get(res_id))
|
||||
if (opt_out_list and mail_to in opt_out_list) or (seen_list and mail_to in seen_list) \
|
||||
or (not mail_to or not email_re.findall(mail_to)):
|
||||
# prevent sending to blocked addresses that were included by mistake
|
||||
|
||||
Reference in New Issue
Block a user