Contact alternate email (DB 4.4.1): one more address per contact in the contact window under Email, shown on their page, quick look and the Reach column, searched by the contacts, clients, tickets and global searches, exported and imported as Alternate Email and in the API as contact_email_alt, and recognized on incoming email as theirs - a new ticket as them at their client even with unknown senders off, and their reply by ticket number, conversation or subject - with the ticket's from line showing the address it came from while everything ITFlow sends still goes to their Email and neither address is copied in; the duplicate warning, Try an Email, Unprocessed Email and the ignored sender and routing rule warnings count it too, and the same-as-Email warning shows while typing (contactEmailSql(), contactHasEmail(), contactEmailMatchSql()); 26.12.4 changelog

This commit is contained in:
johnnyq
2026-12-02 13:36:49 -05:00
parent 8dae372d57
commit 2ad57e2865
31 changed files with 276 additions and 80 deletions

View File

@@ -234,12 +234,14 @@ function ticketMailSubjectTicket($subject) {
function ticketMailCopiedCcs($ticket_id, array $addresses, $sender) {
global $mysqli;
$ticket_id = intval($ticket_id);
$contact_email = strtolower(trim((string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT contact_email FROM tickets
JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = $ticket_id"))[0] ?? '')));
$contact = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_email, " . contactEmailAltColumn() . " FROM tickets
JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = $ticket_id")) ?: [];
$contact_email = strtolower(trim((string) ($contact['contact_email'] ?? '')));
$contact_email_alt = strtolower(trim((string) ($contact['contact_email_alt'] ?? '')));
$sender = strtolower(trim((string) $sender));
$emails = [];
foreach (ticketCcEmails($addresses) as $email) {
if ($email === $sender || $email === $contact_email || emailOwnAddress($email) || emailOwnDomain($email)
if ($email === $sender || $email === $contact_email || ($contact_email_alt !== '' && $email === $contact_email_alt) || emailOwnAddress($email) || emailOwnDomain($email)
|| preg_match('/do[\W_]*not[\W_]*reply|no[\W_]*reply/i', $email)) {
continue;
}
@@ -252,11 +254,12 @@ function ticketMailCopiedCcs($ticket_id, array $addresses, $sender) {
}
/*
* The contact an email from $email is from, when it is one - ['contact' => row (contact_id, contact_name, contact_email,
* contact_client_id, client_name) or null, 'others' => the other clients it is a contact at, [client_id => name],
* 'why' => how the one was picked]. An address can be a contact at more than one client - someone who works for two,
* a shared mailbox - and its email went to whichever the database gave first. Now: the client whose domain it is
* ($domain, Domains), else the one they last raised a ticket at, else the first they were added to.
* The contact an email from $email is from, when it is one - their Email or their alternate one - ['contact' => row
* (contact_id, contact_name, contact_email, contact_email_alt, contact_client_id, client_name) or null, 'others' => the
* other clients it is a contact at, [client_id => name], 'why' => how the one was picked]. An address can be a contact at
* more than one client - someone who works for two, a shared mailbox - and its email went to whichever the database gave
* first. Now: the client whose domain it is ($domain, Domains), else a contact whose Email it is over one whose alternate
* it is, else the one they last raised a ticket at, else the first they were added to.
*/
function ticketMailSenderContact($email, $domain = '') {
global $mysqli;
@@ -268,12 +271,12 @@ function ticketMailSenderContact($email, $domain = '') {
$email_sql = escapeSql($email);
$domain_sql = escapeSql(strtolower(trim((string) $domain)));
$rows = [];
$sql = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_email, contact_client_id, client_name,
$sql = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_email, " . contactEmailAltColumn() . ", contact_client_id, client_name,
(SELECT 1 FROM domains WHERE domain_client_id = contact_client_id AND domain_name = '$domain_sql' AND domain_archived_at IS NULL LIMIT 1) AS at_domain,
(SELECT MAX(ticket_created_at) FROM tickets WHERE ticket_contact_id = contact_id) AS last_ticket
FROM contacts LEFT JOIN clients ON client_id = contact_client_id
WHERE contact_email = '$email_sql' AND contact_archived_at IS NULL
ORDER BY at_domain DESC, last_ticket DESC, contact_id");
WHERE " . contactEmailSql($email) . " AND contact_archived_at IS NULL
ORDER BY at_domain DESC, contact_email = '$email_sql' DESC, last_ticket DESC, contact_id");
while ($row = mysqli_fetch_assoc($sql)) {
$rows[] = $row;
}
@@ -320,7 +323,7 @@ function ticketMailSenderContactNote($ticket_id, $email, array $picked) {
function ticketMailClientAddresses($ticket_id, array $addresses) {
global $mysqli;
$ticket_id = intval($ticket_id);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_client_id, contact_email FROM tickets LEFT JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = $ticket_id"));
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_client_id, contact_email, " . contactEmailAltColumn() . " FROM tickets LEFT JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = $ticket_id"));
if (!$row) {
return [];
}
@@ -331,9 +334,9 @@ function ticketMailClientAddresses($ticket_id, array $addresses) {
continue;
}
$email_sql = escapeSql($email);
if (strtolower(trim((string) $row['contact_email'])) === $email
if (contactHasEmail($row, $email)
|| mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id AND ticket_cc_email = '$email_sql' LIMIT 1"))
|| ($client_id && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM contacts WHERE contact_email = '$email_sql' AND contact_client_id = $client_id AND contact_archived_at IS NULL LIMIT 1")))) {
|| ($client_id && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM contacts WHERE " . contactEmailSql($email) . " AND contact_client_id = $client_id AND contact_archived_at IS NULL LIMIT 1")))) {
$found[] = $email;
}
}