Mail review stage 5: a website form's email is answered at the visitor in its Reply-To, who becomes the ticket's CC under the client whose domain the site is on or none, and Reply-To at the sender's own domain is taken as the sender; someone who isn't a contact is answered without their subject or the ticket's link, and a forged ticket or one with no contact no longer emails the client's colleagues; a client's reply on a ticket nobody is assigned goes to the new-ticket address or the admins, and bounce and closed-ticket notices go to the assigned agent or the admins instead of every agent; an email with no From is from nobody rather than itflow-guest@example.com; a forged email no longer clears Email bounced; an address that is a contact at two clients goes to the one whose domain it is or where they last raised a ticket, with a note; an agent's emailed reply that went to the client is their public reply and the first response; 26.12.3 changelog

This commit is contained in:
johnnyq
2026-11-30 18:22:59 -05:00
parent 039c1b11da
commit e57faeeb3a
9 changed files with 422 additions and 126 deletions

View File

@@ -577,7 +577,8 @@ function ticketEmailExcerpt($html, $limit = 700) {
* What an email about a ticket says - emailHtml()'s fields (functions/email.php),
* all but who it is to and why they get it, which ticketMailSend() adds for
* each. $row is ticketRow(). $kind and its $opts:
* created it was opened - how: agent (the default), email (the reply to an emailed one) or scheduled
* created it was opened - how: agent (the default), email (the reply to an emailed one) or scheduled;
* stranger (email): to someone who isn't a contact - without its subject or the ticket's link
* reply an agent's reply - message (its HTML), by (who wrote it)
* client_reply a client's reply, passed on to the people following the ticket who didn't have
* it (ticketMailRelayClientReply()) - message (its HTML), by (who wrote it), skip (the
@@ -613,7 +614,11 @@ function ticketEmailContent(array $row, $kind, array $opts = []) {
if ($how === 'email') {
$email['title'] = 'We have your email';
$email['intro'] = ["Thank you - it is ticket $reference now, and we will reply to you here. To add anything, just reply to this email."];
// Never their own words back: the sender of an email can be forged, and an echo would carry whatever it said to them
// Never their own words back: the sender of an email can be forged, and an echo would carry whatever it said to them.
// To someone who isn't a contact (stranger) not even its subject, nor the link to the ticket, which shows the lot
if (!empty($opts['stranger'])) {
unset($summary['Subject'], $email['button']);
}
} else {
$email['title'] = $how === 'scheduled' ? 'A scheduled ticket was opened for you' : 'We have opened a ticket for you';
$email['intro'] = [($how === 'scheduled' ? "Ticket $reference was opened for you, as scheduled." : "We have opened ticket $reference for you.")
@@ -622,7 +627,9 @@ function ticketEmailContent(array $row, $kind, array $opts = []) {
}
$email['summary'] = $summary + ['Priority' => (string) $row['ticket_priority']] + $sla['summary'];
$email['callout'] = $sla['callout'];
$email['button']['label'] = 'View your ticket';
if (isset($email['button'])) {
$email['button']['label'] = 'View your ticket';
}
} elseif ($kind === 'reply') {
$email['kind'] = 'Ticket update';
$email['title'] = $subject;
@@ -875,18 +882,21 @@ function ticketMailColleaguesNew($ticket_id) {
/*
* The "a ticket was created for you" email - to its contact, and its CCs
* unless $to_ccs is false; or to $to (ticketMailSend()'s) in their
* place. $how agent, email or scheduled (ticketEmailContent()).
* place. $how agent, email or scheduled (ticketEmailContent()). $stranger:
* an emailed ticket from someone who isn't a contact, answered without
* their own words - "[TCK-123] We have your email", with no subject in it
* and no link to the ticket, which shows the lot.
*/
function ticketMailCreated($ticket_id, $attachments = [], $to_ccs = true, $how = 'agent', ?array $to = null, ?string $subject = null) {
function ticketMailCreated($ticket_id, $attachments = [], $to_ccs = true, $how = 'agent', ?array $to = null, bool $stranger = false) {
$row = ticketRow($ticket_id);
if (!$row) {
return 0;
}
// Emailed in, it is an automatic answer to that email - which says so, so the other side doesn't answer it (functions/ticket_mail_auto.php).
// $subject in place of the ticket's - an emailed ticket from someone who isn't a contact is answered without their own words
return ticketMailSend($row['ticket_id'], ticketEmailContent($row, 'created', ['how' => $how]),
// Emailed in, it is an automatic answer to that email - which says so, so the other side doesn't answer it (functions/ticket_mail_auto.php)
$stranger = $stranger && $how === 'email';
return ticketMailSend($row['ticket_id'], ticketEmailContent($row, 'created', ['how' => $how, 'stranger' => $stranger]),
['attachments' => $attachments, 'to_ccs' => $to_ccs, 'kind' => 'created'] + ($to !== null ? ['to' => $to] : []) + ($how === 'email' ? ['auto' => 'replied'] : [])
+ ($subject !== null ? ['subject' => $subject] : []));
+ ($stranger ? ['subject' => '[' . ticketReference($row) . '] We have your email'] : []));
}
/*
@@ -1056,6 +1066,23 @@ function ticketMailCcsAdded($ticket_id, array $emails, $by) {
/* ------------------------------------------------------------ Emails about a ticket, to agents */
/*
* A notice in the bell about ticket $row (ticketRow(), or null for none) for whoever looks after it - the agent it is
* assigned to, or the admins (signInAdmins()) when nobody has it or there is no ticket. $details SQL-escaped, as
* appNotify()'s. What the ticket mailbox found - a bounce, a reply to a closed ticket - went to every agent, one
* notice an email each. How many were told.
*/
function ticketNotifyOwner(?array $row, $details) {
global $mysqli;
$user_id = intval($row['ticket_assigned_to'] ?? 0);
if ($user_id && !mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM users WHERE user_id = $user_id AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL"))) {
$user_id = 0;
}
$client_id = intval($row['ticket_client_id'] ?? 0);
return appNotifyUsers($user_id ? [$user_id] : array_keys(signInAdmins()), 'Ticket', $details,
$row ? '/agent/' . ticketUrl($row['ticket_id'], $client_id) : '', $client_id, intval($row['ticket_id'] ?? 0));
}
/** Where an agent opens a ticket - in ITFlow. */
function ticketAgentUrl(array $row) {
global $config_base_url;
@@ -1198,13 +1225,17 @@ function ticketMailNewTicketAddress($ticket_id, $how) {
$subject, ticketAgentEmailContent($row, 'new', ['how' => $how]));
}
/** Tell the agent a ticket is assigned to that the client replied - and the agents helping on it - $how portal or email, $reply its HTML, $by who. */
/*
* Tell the agent a ticket is assigned to that the client replied - and the agents helping on it - $how portal, email or
* text, $reply its HTML, $by who. On a ticket nobody has, the new-ticket address (Admin > Ticket) is emailed, or the admins
* get a notice in the bell when there is none: the reply reopened the ticket, and nobody was told.
*/
function ticketMailAssigneeReplied($ticket_id, $how, $reply, $by) {
global $config_app_name;
$row = ticketRow($ticket_id);
$agent = $row ? ticketMailAgent($row['ticket_assigned_to']) : null;
if (!$agent) {
return 0;
return $row ? ticketMailUnassignedReplied($row, $how, $reply, $by) : 0;
}
return ticketMailAgents([$agent + ['footnote' => 'You get this as the agent ' . ticketReference($row) . ' is assigned to.']],
($config_app_name ?: 'ITFlow') . " - Ticket updated - [" . ticketReference($row) . "] " . $row['ticket_subject'],
@@ -1212,6 +1243,21 @@ function ticketMailAssigneeReplied($ticket_id, $how, $reply, $by) {
+ ticketHelpersMailReplied($row, $agent, $how, $reply, $by);
}
/* A client's reply on ticket $row, which nobody is assigned (ticketMailAssigneeReplied()) - to the new-ticket address, else the admins' bell. */
function ticketMailUnassignedReplied(array $row, $how, $reply, $by) {
global $mysqli, $config_app_name;
$reference = ticketReference($row);
$address = (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT config_ticket_new_ticket_notification_email FROM settings WHERE company_id = 1"))[0] ?? '');
if (filter_var($address, FILTER_VALIDATE_EMAIL) && !emailReadMailbox($address)) {
$email = ticketAgentEmailContent($row, 'replied', ['how' => $how, 'message' => (string) $reply, 'by' => (string) $by]);
$email['intro'][] = 'Nobody is assigned it.';
return ticketMailAgents([['email' => $address, 'greet' => '', 'footnote' => "You get this at the new-ticket address in Admin > Ticket, as nobody is assigned $reference."]],
($config_app_name ?: 'ITFlow') . " - Ticket updated - [$reference] " . $row['ticket_subject'], $email);
}
$by = trim((string) $by) !== '' ? trim((string) $by) : 'The client';
return ticketNotifyOwner($row, escapeSql("$by replied to $reference - " . $row['ticket_subject'] . " - which nobody is assigned"));
}
/**
* Is this email or notice to your team switched on (Admin > Settings >
* Notifications, Emails to your team - database 3.9.1)? $key assigned_app