From 7e29e57affc5cf8af0fe7356b3e2103900376ca6 Mon Sep 17 00:00:00 2001 From: simicar29 <53998265+simicar29@users.noreply.github.com> Date: Tue, 7 Jan 2020 16:13:48 +0100 Subject: [PATCH] Avoid adding unsubscribed contacts in mailing list Add an sql criterion to exclude unsubscribed email adresses from count of contacts (function getNbOfRecipients) and avoid their inclusion in mailing lists (function add_to_target) --- htdocs/core/modules/mailings/contacts1.modules.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/core/modules/mailings/contacts1.modules.php b/htdocs/core/modules/mailings/contacts1.modules.php index b3687e4f603..8e7b6bff77e 100644 --- a/htdocs/core/modules/mailings/contacts1.modules.php +++ b/htdocs/core/modules/mailings/contacts1.modules.php @@ -105,6 +105,8 @@ class mailing_contacts1 extends MailingTargets $sql.= " WHERE c.entity IN (".getEntity('socpeople').")"; $sql.= " AND c.email != ''"; // Note that null != '' is false $sql.= " AND c.no_email = 0"; + $sql .= " AND (SELECT count(*) FROM ". MAIN_DB_PREFIX . "mailing_unsubscribe WHERE email = c.email) = 0"; + // exclude unsubscribed users $sql.= " AND c.statut = 1"; // The request must return a field called "nb" to be understandable by parent::getNbOfRecipients @@ -384,6 +386,8 @@ class mailing_contacts1 extends MailingTargets $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; $sql.= " AND sp.email <> ''"; $sql.= " AND sp.no_email = 0"; + $sql .= " AND (SELECT count(*) FROM ". MAIN_DB_PREFIX . "mailing_unsubscribe WHERE email = sp.email) = 0"; + // Exclude unsubscribed email adresses $sql.= " AND sp.statut = 1"; $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; // Filter on category