From d92a5b79b1ec7fa7b7ebc0888a5a8dcf53e3b05c Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller <45882981+Hystepik@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:32:11 +0100 Subject: [PATCH] New add new const to pervent sending mail to with autocopy (#26894) * New add new const to pervent sending mail to with autocopy * to test * fix pr to always have the check on $to, $addr_cc and addr_bcc * remove unwanted code * fix errors --------- Co-authored-by: Hystepik Co-authored-by: hystepik --- htdocs/core/class/CMailFile.class.php | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index fb3a9df8c51..159ab973372 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -355,6 +355,46 @@ class CMailFile } } + // Verify if $to, $addr_cc and addr_bcc have unwanted addresses + if (getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO')) { + //Verify for $to + $tabto = explode(",", $to); + $listofemailstonotsendto = explode(',', getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO')); + foreach ($tabto as $key => $addrto) { + if (in_array($addrto, $listofemailstonotsendto)) { + unset($tabto[$key]); + } + } + if (empty($tabto) && !getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO_REPLACE')) { + $tabto[] = getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO_REPLACE'); + } + $to = implode(',', $tabto); + + //Verify for $addr_cc + $tabcc = explode(',', $addr_cc); + foreach ($tabcc as $key => $cc) { + if (in_array($cc, $tabcc)) { + unset($tabcc[$key]); + } + } + if (empty($addr_cc) && !getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO_REPLACE')) { + $addr_cc[] = getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO_REPLACE'); + } + $addr_cc = implode(',', $tabcc); + + //Verify for $addr_bcc + $tabbcc = explode(',', $addr_bcc); + foreach ($tabbcc as $key => $bcc) { + if (in_array($bcc, $tabbcc)) { + unset($tabbcc[$key]); + } + } + if (empty($tabbcc) && !getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO_REPLACE')) { + $tabbcc[] = getDolGlobalString('MAIN_MAIL_FORCE_NOT_SENDING_TO_REPLACE'); + } + $addr_bcc = implode(',', $tabbcc); + } + // We always use a replyto if (empty($replyto)) { $replyto = dol_sanitizeEmail($from);