Mail review stage 8: Admin > Ignored Senders lists addresses and domains whose email the ticket mailbox sets aside with no ticket, reply, answer or Unprocessed Email entry, a domain taking its subdomains, each counting what it set aside and saving one that takes a contact's or client's email saying so; Ignore Sender in Unprocessed Email ignores the address or its domain and dismisses the others waiting, leaving contacts, client domains and public domains to an admin; Try an Email has the step; every queued email gets its own Message-ID and invoice and quote emails say what they are about, so a bounce marks the email it came back about as Bounced with the mail server's reason in a new Mail Queue tab, on the ticket reply for those it names and in the invoice or quote history, matched by address and subject when the report has no Message-ID; .gitignore leaves out uploads/mail_unprocessed and uploads/kb (database 4.3.5); 26.12.3 changelog

This commit is contained in:
johnnyq
2026-12-01 00:06:27 -05:00
parent 812c4ae9c2
commit d2d9732efb
31 changed files with 878 additions and 26 deletions

View File

@@ -0,0 +1,58 @@
<?php
/*
* ITFlow - Database update to version 4.3.5 (from 4.3.4)
* Included by admin/database_updates.php - do not access directly
*
* email_ignored_senders - addresses and domains whose email the ticket mailbox sets aside (functions/mail_ignore.php),
* with why, who added each, and how many emails it set aside and when the last was
* email_queue.email_message_id - each email's own Message-ID, so a bounce finds the email it was about
* email_queue.email_about - what a billing email was about - invoice:12, quote:7 - for its history when it bounces
* email_queue.email_bounced_at, email_bounce - when a sent email bounced, and for whom, with what the mail server said
* ({"address": "why"})
* The Message-IDs of the email already in the queue are filled in from its headers, where it kept them.
*
* Re-runnable: the table and each column are made only where they aren't there, and only empty Message-IDs filled in.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `email_ignored_senders` (
`ignored_sender_id` int(11) NOT NULL AUTO_INCREMENT,
`ignored_sender_match` varchar(255) NOT NULL,
`ignored_sender_note` varchar(255) NOT NULL DEFAULT '',
`ignored_sender_matches` int(11) NOT NULL DEFAULT 0,
`ignored_sender_matched_at` datetime DEFAULT NULL,
`ignored_sender_created_by` int(11) NOT NULL DEFAULT 0,
`ignored_sender_created_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`ignored_sender_id`),
UNIQUE KEY `ignored_sender_match` (`ignored_sender_match`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
$itflow_queue_columns = [
['email_message_id', "varchar(255) DEFAULT NULL AFTER `email_headers`"],
['email_about', "varchar(50) DEFAULT NULL AFTER `email_message_id`"],
['email_bounced_at', "datetime DEFAULT NULL AFTER `email_sent_at`"],
['email_bounce', "text DEFAULT NULL AFTER `email_bounced_at`"],
];
foreach ($itflow_queue_columns as [$itflow_column, $itflow_definition]) {
$itflow_column_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'email_queue' AND COLUMN_NAME = '$itflow_column' LIMIT 1");
if (!$itflow_column_exists || mysqli_num_rows($itflow_column_exists) === 0) {
mysqli_query($mysqli, "ALTER TABLE `email_queue` ADD `$itflow_column` $itflow_definition");
}
}
$itflow_index_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'email_queue' AND INDEX_NAME = 'email_message_id' LIMIT 1");
if (!$itflow_index_exists || mysqli_num_rows($itflow_index_exists) === 0) {
mysqli_query($mysqli, "ALTER TABLE `email_queue` ADD KEY `email_message_id` (`email_message_id`)");
}
// The Message-IDs the queue kept in the headers of a ticket's email
$itflow_queue_sql = mysqli_query($mysqli, "SELECT email_id, email_headers FROM email_queue WHERE email_message_id IS NULL AND email_headers LIKE '%Message-ID%'");
while ($itflow_queue_sql && ($itflow_queue_row = mysqli_fetch_assoc($itflow_queue_sql))) {
$itflow_message_id = trim((string) (json_decode((string) $itflow_queue_row['email_headers'], true)['Message-ID'] ?? ''), "<> \t");
if ($itflow_message_id !== '' && strlen($itflow_message_id) <= 255) {
mysqli_query($mysqli, "UPDATE email_queue SET email_message_id = '" . mysqli_real_escape_string($mysqli, $itflow_message_id) . "' WHERE email_id = " . intval($itflow_queue_row['email_id']));
}
}