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

@@ -21,6 +21,11 @@
* email_error says why it last failed, or who cancelled it - cleared when it
* is sent or retried. Sent, failed and cancelled email is deleted after 90
* days (nightly).
*
* An email about a ticket can go to one person with others copied in (email_cc), and carries the
* headers that keep its conversation together (email_headers - mailQueueHeaders()). The address
* it is to is the one whose domain is checked before each try; a mail server turns away the
* copied-in itself.
*/
const MAIL_QUEUE_TRIES = 4;
@@ -286,6 +291,39 @@ function mailQueueAttachments($json) {
return $out;
}
/*
* The people copied in on an email (email_cc, emailQueue()'s together) - [['email', 'name'], ...],
* each an address.
*/
function mailQueueCc($json) {
$out = [];
foreach ((array) json_decode((string) $json, true) as $person) {
$email = trim((string) ($person['email'] ?? ''));
if (is_array($person) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$out[] = ['email' => $email, 'name' => trim((string) ($person['name'] ?? ''))];
}
}
return $out;
}
/** The headers an email may carry (email_headers) - the ones that keep a conversation together, nothing else. */
const MAIL_QUEUE_HEADERS = ['Message-ID', 'In-Reply-To', 'References'];
/*
* An email's own headers (email_headers, emailQueue()'s thread) - [name => value] of those it may
* carry (MAIL_QUEUE_HEADERS), each a list of <id@domain> and nothing else, on one line.
*/
function mailQueueHeaders($json) {
$out = [];
foreach ((array) json_decode((string) $json, true) as $name => $value) {
$value = trim(preg_replace('/[\r\n\t ]+/', ' ', (string) $value));
if (in_array($name, MAIL_QUEUE_HEADERS, true) && $value !== '' && strlen($value) <= 4000 && preg_match('/^(<[^<>\s]+@[^<>\s]+>)( <[^<>\s]+@[^<>\s]+>)*$/', $value)) {
$out[$name] = $value;
}
}
return $out;
}
/*
* An email's message with its pictures back in it as data, to show in Admin > Mail Queue - the
* message points at them by cid:, as the mail program that gets it reads them. One gone stays a cid:.