mirror of
https://github.com/itflow-org/itflow
synced 2026-12-03 09:39:02 +00:00
Agent's name in the From name: an email an agent writes to a client - their email reply, resolving with a note, closing for no response and the your-ticket-is-with note - comes from them by name at the ticket mailbox's address as Agent | Mailbox name, read from the public reply it carries, while automatic ticket emails and emails to the team keep the mailbox's name, names are cleaned of line breaks, quotes and brackets, and Admin > Mail > From addresses shows how it reads (ticketEmailFromName(), ticketReplyAgentName()); 26.12.4 changelog
This commit is contained in:
@@ -15,6 +15,7 @@ Update from Maintenance > Update as usual. This release has two database changes
|
||||
- Saved cards are checked with Stripe each night when they expire soon or have lately, so a card the bank replaced shows its new expiry and nobody is asked about it. Admin > Payment Providers > Saved Cards says when each card was checked, and when the team was told it is running out.
|
||||
- Autopay that doesn't go through - a declined or expired card, or a card that's gone - sends your team an Autopay Failed notification with Stripe's reason. Before, it was only in the invoice's history.
|
||||
- Email routing rules, in Admin > Email Routing: pick an address or a domain - alerts@vendor.example, or vendor.example - and, if you like, words its subject has, and say where its new tickets go: a client and a contact, a category, a priority, an agent and a ticket template. A vendor's monitoring alerts about one client go to that client at High priority and land with the technician who looks after them, with the template's tasks already on the ticket. A rule decides the client over the sender's own contact or domain, and takes email even with tickets from unknown senders off. What it leaves as it is comes from its template. When more than one rule fits, the most exact wins - an address before a domain, a subdomain before its domain, and a rule with subject words before one without. Replies to a ticket still go on that ticket, Ignored Senders are still set aside first, and out-of-office replies are never routed. The sender is only answered and copied in when they are the ticket's contact, so a system's address isn't sent "we have your email" or every reply, and nobody at the client is emailed about an alert they didn't send. The agent a rule assigns is told, as when a ticket is assigned by hand. Each rule shows how many tickets it has routed and when the last was, and warns when it takes another client's contacts or domain, when Ignored Senders sets its email aside first, or when its client, contact, category, agent or template has been archived. Try an Email in Settings > Tickets shows which rule an email would meet and what it would do, and Email to ticket links to the page.
|
||||
- An agent's email to a client now comes from them by name: "Tess Tech | PittPC Support", at the ticket mailbox's address, so the client sees who wrote and their reply still goes on the ticket. That's their email replies, resolving a ticket with a note, closing one for no response, and the "your ticket is with" note. ITFlow's automatic emails - we have your email, closed, a booked visit - and emails to your team keep the mailbox's name. Admin > Mail > From addresses shows how it reads.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -33,6 +34,7 @@ Update from Maintenance > Update as usual. This release has two database changes
|
||||
- Texts: `smsInboxBulk($action, $ids, $user_id)` in `functions/sms.php` runs an action from `SMS_INBOX_BULK` (dismiss, spam, clear, not_spam, delete => the status it takes texts from and the permission it needs) on the ticked inbound texts, or with `$ids` null on the whole tab, inside `clientScopeSql()`. Spam and not spam block or unblock the numbers and move every text from them, as the single actions do. Clearing a code sets it to dismissed with its body, code and media wiped, so the text log's search can't find its words. `agent/post/texts.php` takes `bulk_texts` (with `sms_message_ids[]`) and `bulk_texts_all`, plus `sms_clear_code` for one code. `agent/texts.php` uses the standard `js/bulk_actions.js` select-all and Bulk Action button.
|
||||
- Forwarded client emails: new `functions/ticket_mail_forward.php`. In `cron/ticket_email_parser.php`, after the thread and ticket-number steps and before `ticketMailSenderContact()`, an email from an active agent (`ticketMailForwardAgent()`) that isn't forged, automatic or answered at its Reply-To goes to `ticketMailForwarded($html, $text, $subject, $attachments)`. It looks for the first header block - a From line with an address and a Sent, Date, To or Subject line beside it, with English and common European labels - below a forward line (Gmail's, Thunderbird's, Apple Mail's), or anywhere when the subject is a forward (`TICKET_MAIL_FORWARD_ONLY`); Outlook's `-----Original Message-----` and underscore line only count with a forward subject, as its replies have them too. The HTML is split at `gmail_quote`, `moz-forward-container`, `divRplyFwdMsg`/`appendonsend`, Outlook's bordered header div, `blockquote type="cite"` or the forward line, as long as the part from there holds the sender, else the text part is split; a single `message/rfc822` attachment is parsed with MailMimeParser, its cid pictures inlined. When the forwarded sender isn't one of your addresses, your domain or an agent (`ticketMailForwardFromClient()`), the parser takes its sender, subject (`ticketMailForwardSubject()`) and body and sets `$email['forward'] = ['agent', 'note']`. A forward is never a similar-subject reply (it is linked as related, `linkSimilarTicket(..., true)`), a contact it creates says who forwarded it, and step 6 runs for it whatever `config_ticket_email_parse_unknown_senders` says. `addTicket()` adds "forwarded by" to the from line and audit entry, calls `ticketMailForwardNote()` (an Internal reply by the agent, when there is a note, and a history line), and doesn't CC or answer a forwarded sender with no contact. Parser attachments now carry `mime`. `ticketMailTry()` adds a "From one of your agents?" step.
|
||||
- Email routing rules (DB 4.3.9, `email_routing_rules`): new `functions/mail_route.php`. A rule is `routing_rule_match` (an address or a domain, cleaned by `mailIgnoreClean()` and matched by `mailIgnoreMatches()`, so a domain takes its subdomains), optional `routing_rule_subject` (case-insensitive, whitespace-collapsed substring), and what it sets: `routing_rule_client_id`, `routing_rule_contact_id`, `routing_rule_category_id`, `routing_rule_priority`, `routing_rule_assigned_to`, `routing_rule_ticket_template_id` - 0 or '' for none - with a note, a hit count and `routing_rule_matched_at`. `mailRouteFind()` takes the most exact match (`mailRouteExactness()`: address, then more domain labels, then longer subject words, then the older rule); `mailRouteFor()` adds `mailRouteTargets()`, which re-checks each target (client and contact not archived and the contact the client's, category, active agent, template not archived) and lists what's `gone`. In `cron/ticket_email_parser.php` the rule is found after the thread, ticket-number and forward steps and never for an out-of-office; with a client it replaces `$picked`/`$domain_row`, its contact is the rule's, else the sender as that client's contact, and a client with no contact gets its own `addTicket()` call before the domain step. `$email['route']` carries the rule, with `quiet` when the sender isn't the ticket's contact (or a website form's visitor, or a new contact at a client's domain), and `$email['sender']` when the ticket's contact isn't the sender. `addTicket()` now sets priority, category, agent and billable from `mailRouteTicketFields()` (the rule's, else the template's), Open when assigned, logs the rule in the ticket history, runs `ticketTemplateFinish(..., true, true)` for the template, notifies and emails the assignee (`ticketMailAssigned()`), and when `quiet` skips the sender CC, the created email and `ticketMailColleaguesNew()`; the from line, audit, forged note and copied-CC exclusion use the sender. A quiet email is never a similar-subject reply (`linkSimilarTicket($new, $similar, 'route')`, whose third argument is now the reason - 'forward' or 'route'), step 6 runs for a routed email whatever `config_ticket_email_parse_unknown_senders` says, and the hit is counted only when a ticket was made. Admin page `admin/email_routing_rules.php` (standard list, search across sender, words, client, contact, category, agent, template and note), modal `admin/modals/email_routing_rule/email_routing_rule.php` (its contact list reloads from `agent/ajax.php?get_client_contacts`), handlers `admin/post/email_routing_rule.php` (`add_routing_rule`, `edit_routing_rule`, `delete_routing_rule`; `mailRouteReach()` for the other-clients warning). `ticketMailTry()` adds an "An email routing rule?" step and `ticketMailTryRoute()` for the outcome.
|
||||
- Agent's name in the From name: `ticketEmailFrom($agent_name = '')` in `functions/ticket.php` now takes the agent's name and gives `ticketEmailFromName($agent_name, $mailbox_name)` - "Agent | Mailbox", the agent alone when the mailbox has no name or the same one, the mailbox's name unchanged without an agent; line breaks, quotes and angle brackets are removed, HTML entities decoded, and it is cut to 255. `ticketMailSend()` reads the agent from its `ticket_reply_id` (`ticketReplyAgentName()`: a Public reply whose `ticket_reply_by` is a `user_type` 1 user) or a new `agent_name` option, which `ticketMailReply()` passes from `$by` when there is no reply id (the email previews). So the reply, `ticketMailResolved()` with a note, `ticketResolveNoResponse()` and the first-response "assigned" note in `ticketStatusMovedByAgent()` carry it; the created, closed, scheduled and client-reply-relay emails and `ticketMailAgents()` don't. No database change.
|
||||
|
||||
## [26.12.3]
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ if (!$config_module_enable_ticketing) {
|
||||
<?= $from_box('mail', 'System emails', 'Share links, password resets, alerts - anything without its own address below.', $config_mail_from_email, $config_mail_from_name, 'noreply@example.com', (string) ($session_company_name ?? 'Your company')) ?>
|
||||
<?= $from_box('invoice', 'Invoices', 'Invoices, receipts, statements and payment reminders.', $config_invoice_from_email, $config_invoice_from_name, 'billing@example.com', 'Billing') ?>
|
||||
<?= $from_box('quote', 'Quotes', 'Quotes sent to clients. Empty - they come from the invoices address.', $config_quote_from_email, $config_quote_from_name, 'sales@example.com', 'Sales') ?>
|
||||
<?= $from_box('ticket', 'Tickets', 'Ticket emails to clients. Make it the mailbox Receiving reads, so their replies go on the ticket.', $config_ticket_from_email, $config_ticket_from_name, 'support@example.com', 'Support') ?>
|
||||
<?= $from_box('ticket', 'Tickets', 'Ticket emails to clients. Make it the mailbox Receiving reads, so their replies go on the ticket. An agent\'s reply goes out with their name in front of this one - <em>' . escapeHtml(ticketEmailFromName(stripslashes((string) ($session_name ?? 'Tess Tech')), (string) $config_ticket_from_name !== '' ? (string) $config_ticket_from_name : 'Support')) . '</em> - from the same address.', $config_ticket_from_email, $config_ticket_from_name, 'support@example.com', 'Support') ?>
|
||||
|
||||
<?= settingsSaveBar('edit_mail_from_settings') ?>
|
||||
</form>
|
||||
|
||||
@@ -337,9 +337,47 @@ function ticketDeleteForGood($ticket_id) {
|
||||
|
||||
/* ------------------------------------------------------------ Emails about a ticket */
|
||||
|
||||
/** Who ticket emails come from - the ticket mailbox (Admin > Mail). */
|
||||
function ticketEmailFrom() {
|
||||
return emailFrom('ticket');
|
||||
/*
|
||||
* Who ticket emails come from - the ticket mailbox (Admin > Mail). $agent_name (raw): an email with an agent's own words
|
||||
* in it - their reply, resolving with a note, "your ticket is with" - comes from them by name, at the same address:
|
||||
* "Tess Tech | PittPC Support" (ticketEmailFromName()). The client sees who wrote, and their reply still reaches the
|
||||
* mailbox. ITFlow's automatic emails, and those to agents, keep the mailbox's own name.
|
||||
*/
|
||||
function ticketEmailFrom($agent_name = '') {
|
||||
$from = emailFrom('ticket');
|
||||
$from['name'] = ticketEmailFromName($agent_name, $from['name']);
|
||||
return $from;
|
||||
}
|
||||
|
||||
/*
|
||||
* The From name of an email an agent wrote - "Tess Tech | PittPC Support": their name and the mailbox's, or their name
|
||||
* alone when the mailbox has none or it is the same. Without an agent, the mailbox's name as it is. Line breaks, quotes
|
||||
* and angle brackets are taken out, an old install's & read as &, and it is cut to the 255 characters the mail
|
||||
* queue keeps.
|
||||
*/
|
||||
function ticketEmailFromName($agent_name, $mailbox_name) {
|
||||
$clean = function ($name) {
|
||||
$name = html_entity_decode((string) $name, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
return trim((string) preg_replace('/\s+/u', ' ', str_replace(["\r", "\n", "\t", '<', '>', '"'], ' ', $name)));
|
||||
};
|
||||
$agent = mb_substr($clean($agent_name), 0, 100);
|
||||
if ($agent === '') {
|
||||
return (string) $mailbox_name;
|
||||
}
|
||||
$mailbox = $clean($mailbox_name);
|
||||
return mb_substr($mailbox !== '' && mb_strtolower($mailbox) !== mb_strtolower($agent) ? "$agent | $mailbox" : $agent, 0, 255);
|
||||
}
|
||||
|
||||
/** The agent who wrote $reply_id - their name, raw - when it is a public reply by an agent, else ''. */
|
||||
function ticketReplyAgentName($reply_id) {
|
||||
global $mysqli;
|
||||
$reply_id = intval($reply_id);
|
||||
if (!$reply_id) {
|
||||
return '';
|
||||
}
|
||||
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT user_name FROM ticket_replies JOIN users ON user_id = ticket_reply_by AND user_type = 1
|
||||
WHERE ticket_reply_id = $reply_id AND ticket_reply_type = 'Public' LIMIT 1"));
|
||||
return $row ? (string) $row[0] : '';
|
||||
}
|
||||
|
||||
/** Where a contact or CC opens a ticket - its guest link, no sign-in needed, or the portal when it has none. */
|
||||
@@ -769,7 +807,9 @@ function ticketEmailPreview(array $email) {
|
||||
* company's tickets get the rest, as a CC does
|
||||
* (ticketColleagueRecipients())
|
||||
* ticket_reply_id the agent's reply it carries - each email is kept with it
|
||||
* (emailQueue()), for ticketReplyEmailed()
|
||||
* (emailQueue()), for ticketReplyEmailed() - and comes from them by name
|
||||
* (ticketEmailFrom(), ticketReplyAgentName())
|
||||
* agent_name who wrote it, raw, for its From name - in place of the reply's agent (a preview has no reply)
|
||||
* answering the Message-ID of the email it answers, when it answers one
|
||||
* auto replied or generated - one of ITFlow's own automatic emails (emailQueue()'s auto)
|
||||
* subject in place of the ticket's own (ticketEmailSubject()) - with its number, so a reply finds it
|
||||
@@ -824,7 +864,9 @@ function ticketMailSend($ticket_id, array $email, array $opts = []) {
|
||||
$to_contact = ($recipients[0]['group'] ?? '') === 'contact';
|
||||
// Your own subject for it, when you changed it (emailTemplateSubject(), functions/email_template.php) - a fixed one ($opts) first
|
||||
$templated = emailTemplateSubject($row, $email, ticketEmailSubject($row));
|
||||
return count(emailQueue($recipients, (string) ($opts['subject'] ?? $templated), $email, ['from' => ticketEmailFrom(), 'attachments' => $opts['attachments'] ?? [], 'cal_str' => $opts['cal_str'] ?? '',
|
||||
// An agent's own words come from them by name, at the mailbox's address
|
||||
$agent_name = (string) ($opts['agent_name'] ?? ticketReplyAgentName($opts['ticket_reply_id'] ?? 0));
|
||||
return count(emailQueue($recipients, (string) ($opts['subject'] ?? $templated), $email, ['from' => ticketEmailFrom($agent_name), 'attachments' => $opts['attachments'] ?? [], 'cal_str' => $opts['cal_str'] ?? '',
|
||||
'ticket_reply_id' => intval($opts['ticket_reply_id'] ?? 0), 'ticket_id' => $ticket_id,
|
||||
'together' => ticketMailSettings()['copy'],
|
||||
'together_footnote' => $to_contact
|
||||
@@ -948,8 +990,9 @@ function ticketMailReply($ticket_id, $reply_html, $by, $resolved = false, $attac
|
||||
ticketReplyEmailed($reply_id, false);
|
||||
return 0;
|
||||
}
|
||||
// From them by name - read from the reply, or for a preview, which has none, $by
|
||||
$sent = ticketMailSend($row['ticket_id'], ticketEmailContent($row, $resolved ? 'resolved' : 'reply', ['message' => (string) $reply_html, 'by' => (string) $by]),
|
||||
['attachments' => $attachments, 'ticket_reply_id' => intval($reply_id)] + ($to !== null ? ['recipients' => $to] : []));
|
||||
['attachments' => $attachments, 'ticket_reply_id' => intval($reply_id)] + ($to !== null ? ['recipients' => $to] : []) + (intval($reply_id) ? [] : ['agent_name' => (string) $by]));
|
||||
ticketReplyEmailed($reply_id, $sent > 0);
|
||||
return $sent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user