Keep a ticket's emails in one conversation: every client email about a ticket has the subject [TCK-123] and its subject and carries Message-ID, In-Reply-To and References, kept per ticket in ticket_mail_threads, and the email parser finds a reply's ticket by those headers first, then by the number in brackets with the prefix that ticket was given; one email goes to the contact with the watchers and colleagues copied in, switchable in Admin, Settings, Tickets; a client's reply by email, text or portal is passed on to the people following the ticket who weren't on it, by email only when it answers one of the ticket's emails; others in To and Cc on a client's or watcher's email become watchers, never your own domain or agents; the same email twice makes one ticket and a merged ticket's replies go to the ticket it went into; database 4.2.6; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-30 13:08:24 -05:00
parent b208ed0069
commit 42ea7e58a5
27 changed files with 831 additions and 162 deletions

View File

@@ -0,0 +1,53 @@
<?php
/*
* ITFlow - Database update to version 4.2.6 (from 4.2.5)
* Included by admin/database_updates.php - do not access directly
*
* One email conversation per ticket (functions/ticket_mail_thread.php):
* ticket_mail_threads - the Message-ID of each email about a ticket, ITFlow's own (mail_thread_ours 1)
* and the client's that raised it or replied on it, so the Ticket Email Parser finds the ticket an
* email answers by its In-Reply-To and References, and each email ITFlow sends names the ones before it
* email_queue.email_cc - the people copied in on an email, as JSON [{email, name}], when one email goes
* to a ticket's contact with its watchers copied in
* email_queue.email_headers - the conversation's headers an email goes with, as JSON {name: value}
* settings.config_ticket_email_copy - one email about a ticket, its watchers copied in (1), or one each (0)
* settings.config_ticket_email_relay - a client's reply goes on to the watchers who didn't have it (1)
* tickets.ticket_number indexed - every email with a ticket number in its subject finds the ticket by it
*
* Re-runnable: the table is made and each column and the index added only where it isn't there.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `ticket_mail_threads` (
`mail_thread_id` int(11) NOT NULL AUTO_INCREMENT,
`mail_thread_ticket_id` int(11) NOT NULL,
`mail_thread_message_id` varchar(255) NOT NULL,
`mail_thread_ours` tinyint(1) NOT NULL DEFAULT 0,
`mail_thread_created_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`mail_thread_id`),
UNIQUE KEY `mail_thread_message_id` (`mail_thread_message_id`, `mail_thread_ticket_id`),
KEY `mail_thread_ticket_id` (`mail_thread_ticket_id`),
CONSTRAINT `ticket_mail_threads_ibfk_1` FOREIGN KEY (`mail_thread_ticket_id`) REFERENCES `tickets` (`ticket_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
$itflow_thread_columns = [
['email_queue', 'email_cc', "text DEFAULT NULL AFTER `email_recipient_name`"],
['email_queue', 'email_headers', "text DEFAULT NULL AFTER `email_attachments`"],
['settings', 'config_ticket_email_copy', "tinyint(1) NOT NULL DEFAULT 1 AFTER `config_ticket_client_general_notifications`"],
['settings', 'config_ticket_email_relay', "tinyint(1) NOT NULL DEFAULT 1 AFTER `config_ticket_email_copy`"],
];
foreach ($itflow_thread_columns as [$itflow_table, $itflow_column, $itflow_definition]) {
$itflow_column_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$itflow_table' AND COLUMN_NAME = '$itflow_column' LIMIT 1");
if (!$itflow_column_exists || mysqli_num_rows($itflow_column_exists) === 0) {
mysqli_query($mysqli, "ALTER TABLE `$itflow_table` ADD `$itflow_column` $itflow_definition");
}
}
$itflow_index_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tickets' AND INDEX_NAME = 'ticket_number' LIMIT 1");
if (!$itflow_index_exists || mysqli_num_rows($itflow_index_exists) === 0) {
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD KEY `ticket_number` (`ticket_number`)");
}

View File

@@ -3,7 +3,7 @@
/*
* ITFlow - GET /admin/mail_preview.php?email=KEY
* One email from Admin > Mail > Previews, as JSON - its subject, who it is
* from and to, and its HTML - made on sample records that are thrown away
* from, to and copied to, and its HTML - made on sample records that are thrown away
* again (emailPreview(), functions/email_preview.php).
*/
@@ -41,6 +41,8 @@ echo json_encode([
'subject' => $email['subject'] ?? '',
'from' => $email ? ($email['from'] !== '' ? $person($email['from_name'], $email['from']) : 'No address yet - set it under From Addresses') : '',
'to' => $email ? $person($email['to_name'], $email['to']) : '',
// Copied in on it - a ticket's watchers, on one email with its contact (emailQueue()'s together)
'cc' => $email ? array_map(function ($copied) use ($person) { return $person($copied['name'], $copied['email']); }, $email['cc'] ?? []) : [],
'also' => array_values(array_unique($others)),
'calendar' => !empty($email['cal_str']),
'html' => $email['html'] ?? '',

View File

@@ -35,10 +35,10 @@ if (!isset($sortable_columns[$sort])) {
}
$search = "(email_id LIKE '%$q%' OR email_from LIKE '%$q%' OR email_from_name LIKE '%$q%' OR email_recipient LIKE '%$q%' OR email_recipient_name LIKE '%$q%' OR email_subject LIKE '%$q%'"
. (mailQueueHasError() ? " OR email_error LIKE '%$q%'" : '') . ")
. (mailQueueHasError() ? " OR email_error LIKE '%$q%'" : '') . (ticketMailThreadReady() ? " OR email_cc LIKE '%$q%'" : '') . ")
AND DATE(email_queued_at) BETWEEN '$dtf' AND '$dtt'";
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS email_id, email_status, email_attempts, email_from, email_from_name, email_recipient, email_recipient_name,
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS email_id, email_status, email_attempts, email_from, email_from_name, email_recipient, email_recipient_name, " . (ticketMailThreadReady() ? 'email_cc' : "'' AS email_cc") . ",
email_subject, email_queued_at, email_failed_at, email_sent_at, " . mailQueueErrorColumn() . ", email_attachments, COALESCE(email_cal_str, '') <> '' AS has_invite, email_content = '' AS email_cleared
FROM email_queue
WHERE $search AND {$tabs[$show][2]}
@@ -203,6 +203,9 @@ $filtered_dates = isset($_GET['dtf']) && $_GET['dtf'] !== '' && $_GET['dtf'] !==
</td>
<td class="min-w-0">
<div><?= $person($row['email_recipient_name'], $row['email_recipient']) ?></div>
<?php if ($cc = mailQueueCc($row['email_cc'])) { ?>
<div class="small text-body-secondary" title="<?= escapeHtml(implode(', ', array_column($cc, 'email'))) ?>" data-email-cc>+ <?= count($cc) ?> copied in</div>
<?php } ?>
<!-- On smaller screens the subject comes along under who it is to, and on a phone where it stands -->
<div class="d-md-none small"><a class="ajax-modal" href="#" <?= $view ?>><?= $subject ?></a></div>
<div class="d-sm-none small mt-1"><span class="badge rounded-pill <?= $state['badge'] ?>"><?= $state['label'] ?></span> <span class="text-body-secondary"><?= escapeHtml($state['detail']) ?></span></div>

View File

@@ -2,7 +2,7 @@
/*
* Maintenance > Mail Queue - one email: where it stands, and why it last
* failed or who cancelled it; who it is to and from; when it was queued,
* failed or who cancelled it; who it is to, copied to and from; when it was queued,
* tried, sent or given up on; its attachments and calendar file; and what it
* says - unless it carried a link or code that opens something, cleared once it
* has gone (functions/mail_queue.php). The
@@ -14,7 +14,7 @@
require_once '../../includes/modal_header.php';
$email_id = intval($_GET['id'] ?? 0);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT email_id, email_status, email_attempts, email_from, email_from_name, email_recipient, email_recipient_name,
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT email_id, email_status, email_attempts, email_from, email_from_name, email_recipient, email_recipient_name, " . (ticketMailThreadReady() ? 'email_cc' : "'' AS email_cc") . ",
email_subject, email_content, email_content = '' AS email_cleared, email_cal_str, email_attachments, email_queued_at, email_failed_at, email_sent_at, " . mailQueueErrorColumn() . "
FROM email_queue WHERE email_id = $email_id LIMIT 1"));
@@ -88,6 +88,10 @@ if (!$row) { ?>
<dl class="row small mb-3 itflow-mail-queue-facts">
<dt class="col-sm-2 text-body-secondary fw-normal">To</dt>
<dd class="col-sm-10 text-break"><?= $person($row['email_recipient_name'], $row['email_recipient']) ?></dd>
<?php if ($cc = mailQueueCc($row['email_cc'])) { ?>
<dt class="col-sm-2 text-body-secondary fw-normal">Cc</dt>
<dd class="col-sm-10 text-break" data-email-cc><?= implode(', ', array_map(function ($copied) use ($person) { return $person($copied['name'], $copied['email']); }, $cc)) ?></dd>
<?php } ?>
<dt class="col-sm-2 text-body-secondary fw-normal">From</dt>
<dd class="col-sm-10 text-break"><?= $person($row['email_from_name'], $row['email_from']) ?></dd>
<dt class="col-sm-2 text-body-secondary fw-normal">Queued</dt>

View File

@@ -2,7 +2,7 @@
/*
* Admin > Settings > Tickets (admin/settings_ticket.php):
* edit_ticket_settings saves the numbering, email and text to ticket, who hears of a
* edit_ticket_settings saves the numbering, email to ticket, the emails about a ticket, text to ticket, who hears of a
* new ticket and whether AI triages it, whether the first agent to reply to an
* unassigned ticket is assigned it, what a quick ticket starts with, the timer
* and billing, the messages to clients, closing and the tickets page. A next
@@ -23,6 +23,7 @@ if (isset($_POST['edit_ticket_settings'])) {
'config_ticket_new_ticket_notification_email', 'config_ticket_timer_autostart', 'config_ticket_default_billable', 'config_ticket_autoclose_hours',
'config_ticket_default_view', 'config_ticket_ordering', 'config_ticket_moving_columns'], aiTriageReady() ? ['config_ticket_ai_triage'] : [],
version_compare((string) CURRENT_DATABASE_VERSION, '4.0.9', '>=') ? ['config_ticket_reply_assigns'] : [],
ticketMailThreadReady() ? ['config_ticket_email_copy', 'config_ticket_email_relay'] : [],
settingsColumnExists($mysqli, 'config_ticket_sms_parse') ? ['config_ticket_sms_parse', 'config_ticket_sms_unknown_senders', 'config_ticket_sms_acknowledge'] : [],
ticketStatusReplyReady() ? ['config_ticket_assigned_message'] : [], ticketNoResponseReady() ? ['config_ticket_no_response_message'] : [],
quickTicketReady() ? ['config_quick_ticket_on', 'config_quick_ticket_assign', 'config_quick_ticket_status', 'config_quick_ticket_priority', 'config_quick_ticket_category',
@@ -47,6 +48,12 @@ if (isset($_POST['edit_ticket_settings'])) {
if (array_key_exists('config_ticket_reply_assigns', $before)) {
$after['config_ticket_reply_assigns'] = empty($_POST['config_ticket_reply_assigns']) ? 0 : 1;
}
// Emails about a ticket - once the database has them
if (array_key_exists('config_ticket_email_copy', $before)) {
foreach (['config_ticket_email_copy', 'config_ticket_email_relay'] as $switch) {
$after[$switch] = empty($_POST[$switch]) ? 0 : 1;
}
}
// Text to ticket - once the database has it
if (array_key_exists('config_ticket_sms_parse', $before)) {
foreach (['config_ticket_sms_parse', 'config_ticket_sms_unknown_senders', 'config_ticket_sms_acknowledge'] as $switch) {

View File

@@ -463,6 +463,7 @@ if (!$config_module_enable_ticketing) {
<div class="fw-semibold text-break" data-preview-subject></div>
<div class="small text-body-secondary text-break"><span class="fw-semibold">From</span> <span data-preview-from></span></div>
<div class="small text-body-secondary text-break"><span class="fw-semibold">To</span> <span data-preview-to></span> <span data-preview-also></span></div>
<div class="small text-body-secondary text-break d-none" data-preview-cc-line><span class="fw-semibold">Cc</span> <span data-preview-cc></span></div>
<div class="small text-body-secondary"><i class="fas fa-fw fa-bolt me-1"></i><span data-preview-when></span><span class="ms-2 badge text-bg-secondary d-none" data-preview-calendar><i class="fas fa-calendar-alt me-1"></i>Calendar file attached</span></div>
</div>
<div class="d-flex gap-2 align-items-center">
@@ -540,6 +541,8 @@ if (!$config_module_enable_ticketing) {
card.querySelector('[data-preview-from]').textContent = data.from || '-';
card.querySelector('[data-preview-to]').textContent = data.to || data.to_who || '-';
card.querySelector('[data-preview-also]').textContent = data.also && data.also.length ? '(and ' + data.also.join(', ') + ')' : '';
card.querySelector('[data-preview-cc]').textContent = data.cc && data.cc.length ? data.cc.join(', ') : '';
card.querySelector('[data-preview-cc-line]').classList.toggle('d-none', !(data.cc && data.cc.length));
card.querySelector('[data-preview-when]').textContent = 'Sent when: ' + (data.when || '');
card.querySelector('[data-preview-calendar]').classList.toggle('d-none', !data.calendar);
var error = card.querySelector('[data-preview-error]');

View File

@@ -2,7 +2,8 @@
/*
* Admin > Settings > Tickets - how tickets are numbered, made from email
* (cron/ticket_email_parser.php, reading the mailbox in Mail > Receiving) and
* (cron/ticket_email_parser.php, reading the mailbox in Mail > Receiving), who
* the emails about one go to (functions/ticket_mail_thread.php), made
* from texts (functions/sms.php, once texting is set up in Text Messaging),
* timed and billed, who hears about new ones, when resolved ones close, and
* how the tickets page opens, and whether AI triages new tickets
@@ -41,6 +42,14 @@ echo settingsPageStart('ticket');
</div>
<?= settingsSectionEnd() ?>
<?php if (ticketMailThreadReady()) {
$ticket_mail = ticketMailSettings(); ?>
<?= settingsSectionStart('emails', 'Emails about a ticket', 'Each has the subject <code>[' . escapeHtml($config_ticket_prefix) . '123] Subject</code>, the same from the first to the last, and carries the headers a mail program keeps a conversation together by - so they stay together in the client\'s inbox, and a reply finds its ticket even when its subject was changed.') ?>
<?= settingsSwitch('config_ticket_email_copy', $ticket_mail['copy'] ? 1 : 0, ['help' => 'An email about a ticket goes to its contact with the watchers, and the colleagues who asked for every update, copied in (Cc) - everyone sees who else has it, and a reply to all reaches them. Off, each gets an email of their own.']) ?>
<?= settingsSwitch('config_ticket_email_relay', $ticket_mail['relay'] ? 1 : 0, ['help' => 'When the client replies - by email, text or in the portal - the people an agent\'s reply would go to get it too, with its files, unless it was already to them. By email, only a reply to one of the ticket\'s emails: anyone can put a ticket number in a subject.']) ?>
<?= settingsSectionEnd() ?>
<?php } ?>
<?php if (settingsColumnExists($mysqli, 'config_ticket_sms_parse')) {
$sms_settings = smsTicketSettings(); ?>
<?= settingsSectionStart('text', 'Text to ticket', 'A text to your number from one of your contacts becomes a ticket, and a text on a ticket goes on it - texts from anyone else, verification codes and spam wait in Texts instead. Texting is set up in <a href="text_messaging.php">Text Messaging</a>.') ?>