From 7ee587bb874fdce8a352eb04eda1bb38c40c8215 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Rieckers Date: Mon, 6 Mar 2017 09:58:35 +0100 Subject: [PATCH] [Broadcast] Use db_in_clause instead of a foreach loop --- broadcast-message.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/broadcast-message.php b/broadcast-message.php index dfbd8dab..cac39bf8 100644 --- a/broadcast-message.php +++ b/broadcast-message.php @@ -59,17 +59,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $recipients = []; - foreach( $wanted_domains as $domain) { - $q = "SELECT username from $table_mailbox WHERE domain = '$domain'"; - if(!isset($_POST['mailboxes_only']) || $_POST['mailboxes_only'] != "on") { - $q .= " UNION SELECT GOTO FROM $table_alias WHERE domain = '$domain' " . - " AND goto NOT IN ($q)"; - } - $result = db_query ($q); - if($result['rows'] > 0) { - while($row = db_array($result['result'])) { - $recipients[] = $row[0]; - } + $q = "SELECT username from $table_mailbox WHERE ".db_in_clause("domain", $wanted_domains); + if(!isset($_POST['bailboxes_only']) || $_POST['mailboxes_only'] != "on") { + $q .= " UNION SELECT goto FROM $table_alias WHERE ".db_in_clause("domain", $wanted_domains)."AND goto NOT IN ($q)"; + } + $result = db_query($q); + if($result['rows'] > 0) { + while($row = db_array($result['result'])) { + $recipients[] = $row[0]; } }