,/', $line, $explode)) { // Scan queue for matching id $idcount = count($idqueue); for ($i = 0; $i < $idcount; ++$i) { if ($idqueue[$i][0] === $explode[1]) { // Delivery attempt found $idqueue[$i][3] = $explode[2]; if (DEBUG_MILTER === true) { syslog(LOG_MAIL | LOG_DEBUG, 'milter_relay: delivery attempt for smtpid ' . $explode[1] . ' detected and updated in queue'); } break; } } } } function process_sql() { global $idqueue; // Scan queue for delivery attempts in queue and matching maillog entries $idcount = count($idqueue); for ($i = 0; $i < $idcount; ++$i) { if (null !== $idqueue[$i][3]) { $message_id = safe_value($idqueue[$i][1]); $to = safe_value($idqueue[$i][3]); $smtp_id = safe_value($idqueue[$i][0]); $result = dbquery("SELECT id from `maillog` where messageid='" . $message_id . "' and to_address LIKE '%" . $to . "%' LIMIT 1;"); @$smtpd_id = $result->fetch_row()[0]; if (DEBUG_MILTER === true) { syslog(LOG_MAIL | LOG_DEBUG, 'milter_relay: idqueue ' . $i . ' of ' . ($idcount - 1) . ' / ' . $smtp_id . ' / ' . $message_id . ' / ' . $to . ' => ' . $smtpd_id); } // Find correllating ids and update table, drop from queue if (isset($smtpd_id) && $smtpd_id !== $smtp_id) { dbquery("REPLACE INTO `mtalog_ids` VALUES ('" . $smtpd_id . "','" . $smtp_id . "')"); array_splice($idqueue, $i, 1); --$i; $idcount = count($idqueue); if (DEBUG_MILTER === true) { syslog(LOG_MAIL | LOG_DEBUG, 'milter_relay: maillog hit for ' . $smtp_id . ' entry logged and removed from queue'); } } } } } function remove_entry($id) { global $idqueue; // Search queue for id $idcount = count($idqueue); for ($i = 0; $i < $idcount; ++$i) { if (time() > $idqueue[$i][2] + QUEUETIMEOUT) { // Drop expired entry from queue if (DEBUG_MILTER === true) { syslog(LOG_MAIL | LOG_DEBUG, 'milter_relay: Expiring smtpid ' . $idqueue[$i][0] . ' after ' . QUEUETIMEOUT . ' seconds'); } array_splice($idqueue, $i, 1); --$i; $idcount = count($idqueue); continue; } if ($idqueue[$i][0] === $id) { // Drop id from array array_splice($idqueue, $i, 1); break; } } } if (isset($_SERVER['argv'][1]) && '--refresh' === $_SERVER['argv'][1]) { doit('cat ' . MS_LOG); } else { // Refresh first doit('cat ' . MS_LOG); // Start watching the maillog follow(MS_LOG); }