From 836ac34a251629b287cf82ed9dc5c3a38b2bcbbf Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 1 Dec 2026 00:52:56 -0500 Subject: [PATCH] Leave email from someone who isn't a contact at a domain no client has (unknown senders off), or whose sender checks failed, in the inbox flagged as before 7b so a mailbox shared with other email keeps it, with Unprocessed Email keeping only email that was taken and failed; drop Ignore Sender from Unprocessed Email; Try an Email, the Tickets setting help and the 26.12.3 changelog say so --- CHANGELOG.md | 7 +- admin/email_ignored_senders.php | 2 +- admin/settings_ticket.php | 2 +- agent/email_unprocessed.php | 11 +- .../email_unprocessed_ignore.php | 103 ------------------ .../email_unprocessed_view.php | 3 - agent/post/email_unprocessed.php | 36 +----- cron/ticket_email_parser.php | 22 +++- functions/mail_ignore.php | 24 +--- functions/mail_unprocessed.php | 12 +- functions/ticket_mail_try.php | 6 +- 11 files changed, 38 insertions(+), 190 deletions(-) delete mode 100644 agent/modals/email_unprocessed/email_unprocessed_ignore.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c73f598..a4e106be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.12.3 -Update from Maintenance > Update as usual - this release has fourteen database changes: 4.2.2 adds a table for passkeys and a setting to turn them on or off, 4.2.3 lets a document keep the Markdown it was written in, 4.2.4 lets a ticket keep its pictures as files, 4.2.5 adds identity providers, 4.2.6 keeps each ticket's email conversation together, 4.2.7 lets a reply from a CC say who sent it, 4.2.8 renames the watchers table for CCs, 4.2.9 lets the mail queue go at a pace your mail host takes, 4.3.0 lets contacts unsubscribe from bulk email, 4.3.1 encrypts the mail passwords and tokens, 4.3.2 keeps the email the ticket mailbox couldn't take, for your team to sort, 4.3.3 adds Undo send and Reply-To for ticket emails, 4.3.4 lets the links in emails stop working once they're done with and keeps your own wording for the emails about a ticket, and 4.3.5 adds ignored senders and ties a bounce to the email that bounced. The client portal's Microsoft 365 single sign-on becomes the first identity provider, for client contacts, and keeps its redirect address, so nothing changes in Microsoft Entra. Nothing else is required: passkeys are on, and no one has one until they add it. Pictures already inside tickets move to files in the background afterwards - the new Ticket Pictures job in Maintenance > Cron does a batch a minute, so an install with years of emailed screenshots may take a while, and tickets work as usual meanwhile. A passkey is made for your ITFlow's address (the one in config.php) and only works there, over HTTPS - if you move ITFlow to a new address, everyone adds theirs again. Watchers are called CCs now. Emails about a ticket go to its contact with the CCs copied in, rather than one each - Admin > Settings > Tickets has the switch, under Emails about a ticket. On nginx, where ITFlow's .htaccess files aren't read, add `location ^~ /uploads/mail_unprocessed/ { deny all; }` beside the other private folders - it holds copies of the email kept for Unprocessed Email. Emailed and texted replies now wait 10 seconds on the ticket page, with Undo, before they go - Admin > Settings > Tickets sets how long, or turns it off. Ticket emails sent from another address than the mailbox ITFlow reads now ask for replies at that mailbox (Reply-To) - turn that off in the same place if the From address is an alias of that mailbox and you'd rather clients only saw it. The links in emails that open a ticket, an invoice or a quote without signing in now stop working 90 days after it is done - a ticket closed, an invoice paid, a quote answered or run out - so after the update, links to ones done longer ago than that no longer open them. The client portal still shows them, and Admin > Settings > Security sets how long, or keeps them working as before. +Update from Maintenance > Update as usual - this release has fourteen database changes: 4.2.2 adds a table for passkeys and a setting to turn them on or off, 4.2.3 lets a document keep the Markdown it was written in, 4.2.4 lets a ticket keep its pictures as files, 4.2.5 adds identity providers, 4.2.6 keeps each ticket's email conversation together, 4.2.7 lets a reply from a CC say who sent it, 4.2.8 renames the watchers table for CCs, 4.2.9 lets the mail queue go at a pace your mail host takes, 4.3.0 lets contacts unsubscribe from bulk email, 4.3.1 encrypts the mail passwords and tokens, 4.3.2 keeps the email the ticket mailbox took but couldn't make a ticket from, for your team to sort, 4.3.3 adds Undo send and Reply-To for ticket emails, 4.3.4 lets the links in emails stop working once they're done with and keeps your own wording for the emails about a ticket, and 4.3.5 adds ignored senders and ties a bounce to the email that bounced. The client portal's Microsoft 365 single sign-on becomes the first identity provider, for client contacts, and keeps its redirect address, so nothing changes in Microsoft Entra. Nothing else is required: passkeys are on, and no one has one until they add it. Pictures already inside tickets move to files in the background afterwards - the new Ticket Pictures job in Maintenance > Cron does a batch a minute, so an install with years of emailed screenshots may take a while, and tickets work as usual meanwhile. A passkey is made for your ITFlow's address (the one in config.php) and only works there, over HTTPS - if you move ITFlow to a new address, everyone adds theirs again. Watchers are called CCs now. Emails about a ticket go to its contact with the CCs copied in, rather than one each - Admin > Settings > Tickets has the switch, under Emails about a ticket. On nginx, where ITFlow's .htaccess files aren't read, add `location ^~ /uploads/mail_unprocessed/ { deny all; }` beside the other private folders - it holds copies of the email kept for Unprocessed Email. Emailed and texted replies now wait 10 seconds on the ticket page, with Undo, before they go - Admin > Settings > Tickets sets how long, or turns it off. Ticket emails sent from another address than the mailbox ITFlow reads now ask for replies at that mailbox (Reply-To) - turn that off in the same place if the From address is an alias of that mailbox and you'd rather clients only saw it. The links in emails that open a ticket, an invoice or a quote without signing in now stop working 90 days after it is done - a ticket closed, an invoice paid, a quote answered or run out - so after the update, links to ones done longer ago than that no longer open them. The client portal still shows them, and Admin > Settings > Security sets how long, or keeps them working as before. ### Security @@ -79,14 +79,13 @@ Update from Maintenance > Update as usual - this release has fourteen database c - Email-to-ticket and website forms: a contact form's email comes from the website (wordpress@, a no-reply address) with the visitor in Reply-To. The visitor is the one answered now, and the ticket's CC, so your replies reach them - the website was, and the visitor never heard back. It's the ticket of the client whose domain the website is on, else a ticket with no client, and the website isn't made a contact. An email whose Reply-To is someone else at the same domain is taken as theirs. Anyone else's email is from them, whatever its Reply-To says. - A client's reply on a ticket nobody is assigned goes to the new-ticket address in Admin > Settings > Tickets, or to the admins in the bell when there isn't one. It reopened the ticket, but nobody was told. - An agent who answers the client's email from their own mailbox - reply to all, with the support address copied in - has it on the ticket as their reply, not an internal note: the client has it, so it shows as emailed to them and counts as the ticket's first response, and the ticket is theirs when nobody had it, as a reply from the ticket does. Nothing more is sent. An email only to the support address is still their internal note. -- Unprocessed Email: email the ticket mailbox couldn't make a ticket from - someone who isn't a contact, at a domain no client has, while unknown senders aren't let in, or one that failed - is kept in Tickets > Unprocessed Email (in the menu beside New Ticket) and moved to the mailbox's ITFlow folder, where it used to stay in the inbox flagged and unread for someone to find. The tickets list says how many are waiting. Each shows who it is from, its subject, a line of what it says and why it wasn't taken. +- Unprocessed Email: email the ticket mailbox took but couldn't make a ticket from - the ticket couldn't be made, or the email couldn't be read - is kept in Tickets > Unprocessed Email (in the menu beside New Ticket) and moved to the mailbox's ITFlow folder, where it used to stay in the inbox flagged and unread with nobody in ITFlow told. Email from someone who isn't a contact, at a domain no client has, while unknown senders aren't let in, still stays in the inbox flagged, so a mailbox shared with other email keeps it. The tickets list says how many are waiting. Each shows who it is from, its subject, a line of what it says and why it wasn't taken. - From Unprocessed Email an email can be opened (as text - nothing in it loads), made a ticket at the client you pick - for one of their contacts, or with the sender made a contact there first - added to a ticket, with the sender made a CC on it if you like, tried again (after making them a contact, say), dismissed, or downloaded as a .eml file. Try Again and Dismiss also work on several at once. The ticket or reply is made within a minute, as any email is, attachments and all, and the email shows which ticket it went on. Sorted and dismissed email is kept 30 days, and email nobody sorts 90. - Undo send: an emailed or texted reply waits a few seconds under the reply box - "Emailing it in 10 seconds" - with Undo and Send now. Undo leaves it in the reply box, as it was, to change or send later: nothing about it has happened yet - no email, no status change, no time added. Escape undoes it too, and leaving the page while it waits asks first. Admin > Settings > Tickets, Emails about a ticket, sets how long - 5, 10 (to start), 20 or 30 seconds - or turns it off. A public or internal note goes at once, as before. - Replies to ticket emails come back: an email about a ticket sent from another address than the mailbox ITFlow reads - a no-reply address, or one that isn't delivered there - asks for replies at that mailbox (Reply-To), where a client's reply used to go to the From address and be lost if nobody read it. Admin > Settings > Tickets says which addresses it uses, and turns it off for a From address that is an alias of the mailbox. - Links in emails stop working once they're done with: the link that opens a ticket, an invoice or a quote without signing in - in its emails, forwarded on or kept for years - stops working 90 days after the ticket is closed, the invoice paid in full, or the quote accepted, declined, invoiced or run out. Open tickets, unpaid invoices and quotes waiting for an answer always work, a reopened ticket's link works again, and emailing an invoice or quote again counts from then. An expired link says so and points to the client portal, where they're shown as always. On an invoice or a quote, Copy Client Link says Expired once it has. Admin > Settings > Security, Links in emails, sets 30, 60, 90 (to start), 180 days or a year - or never, as before. - Your own wording for the emails about a ticket to clients: Admin > Settings > Mail > Previews has Edit Wording on each of the 13 - ticket opened, their email became a ticket, scheduled ticket, reply, resolved, closed, a client's reply passed on, added as a CC, new ticket at their company, approval needed, work booked, booked work cancelled and replied to a closed ticket. Change its subject, heading, opening and closing text, with words in square brackets filled in as it goes, as in canned responses - [Ticket], [Subject], [First Name], [Client], [Agent], [Company] and each email's own, such as [By] and [When]. The preview shows it at once, the list marks the ones you changed, and Use ITFlow's Wording puts one back. The subject always starts with the ticket's number, so replies still find it. - Ignored senders: Admin > Ignored Senders lists the addresses and domains whose email the ticket mailbox sets aside - no ticket, no reply on one, no answer and nothing in Unprocessed Email. Newsletters, spam that gets through and noisy systems go straight to the mailbox's ITFlow folder. A domain takes its subdomains too, each shows how many emails it set aside and when the last came, and saving one that would set aside a contact's or a client's email says so. A mail server's bounce is still read, and Try an Email shows the step. -- Ignore Sender in Unprocessed Email: ignore the address, or everyone at its domain, and dismiss the others waiting from them in one go. A contact's address, a client's domain or a domain anyone can have an address at (gmail.com) is left to an admin, in Admin > Ignored Senders. - Bounces come back to the email they were about: a reply on a ticket says "Email to ... bounced" with what the mail server said, where it said it was emailed, and an invoice's or quote's history says its email bounced. The Mail Queue has a Bounced tab, and the email's window shows the mail server's reason. Each email ITFlow sends now has its own Message-ID, so the bounce finds it - one sent before the update is found by its address and subject. ### Bug Fixes @@ -172,7 +171,7 @@ Update from Maintenance > Update as usual - this release has fourteen database c - Mail review stage 7b: database 4.3.2 adds email_unprocessed. functions/mail_unprocessed.php keeps an email the parser couldn't take - mailUnprocessedKeep($raw, $meta, $reason) writes its MIME to uploads/mail_unprocessed (denied to the web, as uploads/backups) and a row, one per Message-ID - and mailUnprocessedDecide() records an agent's ticket, reply, retry or dismiss (agent/email_unprocessed.php, agent/post/email_unprocessed.php). cron/ticket_email_parser.php appends mailUnprocessedAsked() to the run as MailUnprocessedMessage (functions/mail_unprocessed_message.php), a FileMessage whose move() is mailUnprocessedDone() with the ticket it went on and whose flags do nothing: a ticket or reply ask skips steps 1 to 6 for addTicket() at the chosen contact or client (or a new contact, as the domain match makes one) or addReply() on the chosen ticket (the sender added through ticketAddCcs() first, if asked); a retry goes the usual way. mailUnprocessedLeave() takes the unprocessed and exception branches - kept, then marked seen and moved to the ITFlow folder; flagged and unread as before when it can't be kept; an ask that fails waits again with the reason. mailUnprocessedCleanup() runs nightly. - Mail review stage 7c: database 4.3.3 adds settings.config_ticket_reply_undo_seconds (0, 5, 10, 20 or 30 - TICKET_REPLY_UNDO_CHOICES) and config_ticket_reply_to_read, read by ticketReplySendSettings() (functions/ticket_reply_send.php). Undo send is the ticket page alone: #ticketReplyForm's data-undo-seconds, and agent/js/ticket_reply_extras.js holds an emailed or texted reply's submit in a window listener - after the form's own checks and the canned response check on the document - with the reply card inert and the [data-reply-hold] bar, then requestSubmit()s it with holdOk, cannedSendAnyway and noTimeOk set; agent/post/ticket.php is unchanged. emailQueue() puts Reply-To (ticketMailReplyToRead(): email to ticket on, the setting on, the IMAP username an address and not From) in a thread email's headers; MAIL_QUEUE_HEADERS lets one bare address through and sendQueueEmail() gives it to addReplyTo(), so Graph's large-email draft carries it too. - Mail review stage 7d: database 4.3.4 adds settings.config_guest_link_days (GUEST_LINK_DAYS_CHOICES, 90) and email_templates. functions/guest_link.php: guestLinkDoneAt() - ticket_closed_at; a Paid invoice's last unarchived payment (else its Paid history, else invoice_updated_at); an Accepted, Declined or Invoiced quote's history for it, or the end of quote_expire for one unanswered - later of that and the last history line with 'emailed' in it; guestLinkExpired() adds the days. ticketByGuestKey() returns null for an expired link, setting its new &$expired, so the guest ticket page, its attachments, its posts and its calendar file all refuse it; guest_view_invoice.php, guest_view_quote.php, the guest PDF exports (410) and the quote upload check it too, and guestLinkExpiredHtml() is the page; agent/invoice.php and agent/quote.php mark Copy Client Link Expired. functions/email_template.php: EMAIL_TEMPLATES (the 13 Tickets - to clients preview keys, with ITFlow's wording in placeholders), emailTemplateApply() replaces title, intro (paragraphs) and after where saved, filling [Placeholders] from emailTemplateValues() (ticketPlaceholderValues() and the email's own; empty when there is nothing), and puts the subject in template_subject for emailTemplateSubject(), which prefixes [REF] when it isn't in it. Applied in ticketEmailContent() (not the stranger's subject, nor Resolve - no response's intro), ticketMailSend(), ticketMailCcsAdded(), ticketMailColleaguesNew(), ticketMailTaskApproval() (the client's only) and ticketMailClosedReply(). admin/modals/email_template/email_template_edit.php and admin/post/email_template.php (save_email_template, reset_email_template - a part sent back as the default is NULL); mail_preview.php answers template and edited. -- Mail review stage 8: database 4.3.5 adds email_ignored_senders and email_queue.email_message_id (indexed, filled in from email_headers), email_about, email_bounced_at and email_bounce. functions/mail_ignore.php: mailIgnoreClean() takes an address or a domain (@ or *@ in front allowed), mailIgnoreFind() matches the From address - an address rule before a domain one, a domain matching its subdomains - and cron/ticket_email_parser.php sets the email aside (seen, moved, mailIgnoreHit()) after the bounce check, unless it is a MailUnprocessedMessage asked to make a ticket or reply; ticketMailTry() has the step. Admin > Ignored Senders (admin/email_ignored_senders.php, modals/email_ignored_sender/, admin/post/email_ignored_sender.php); Unprocessed Email's ignore_unprocessed_sender refuses a contact's address, a client's domain and EMAIL_PUBLIC_DOMAINS, and mailIgnoreDismissWaiting() dismisses the rest. emailQueue() gives every email a Message-ID (emailMessageId()) where the conversation gave none and takes about (invoice:N, quote:N - billingEmailQueue()'s about, passed by every invoice and quote send); addToMailQueue() keeps both. addBounce() calls mailQueueBounced(): the sent row by email_message_id, else the last week's sent to a failed address with the bounce's subject, marked with {address: why}, and a billing email's history written. mailQueueStateOf() has bounced (status 3 with email_bounced_at), mailQueueTabs() a Bounced tab, ticketReplyEmailStates() marks each bounced recipient and the key bounced, and ticketReplyEmailHtml() says so. .gitignore leaves out uploads/mail_unprocessed and uploads/kb, as the other upload folders. +- Mail review stage 8: database 4.3.5 adds email_ignored_senders and email_queue.email_message_id (indexed, filled in from email_headers), email_about, email_bounced_at and email_bounce. functions/mail_ignore.php: mailIgnoreClean() takes an address or a domain (@ or *@ in front allowed), mailIgnoreFind() matches the From address - an address rule before a domain one, a domain matching its subdomains - and cron/ticket_email_parser.php sets the email aside (seen, moved, mailIgnoreHit()) after the bounce check, unless it is a MailUnprocessedMessage asked to make a ticket or reply; ticketMailTry() has the step. Admin > Ignored Senders (admin/email_ignored_senders.php, modals/email_ignored_sender/, admin/post/email_ignored_sender.php). The parser leaves email from someone who isn't a contact at a domain no client has (unknown senders off), or whose sender checks failed, in the inbox flagged as before 7b - mailUnprocessedLeave() keeps only an email that was taken and failed, or an agent's ask; ticketMailTry() says Left in the inbox. emailQueue() gives every email a Message-ID (emailMessageId()) where the conversation gave none and takes about (invoice:N, quote:N - billingEmailQueue()'s about, passed by every invoice and quote send); addToMailQueue() keeps both. addBounce() calls mailQueueBounced(): the sent row by email_message_id, else the last week's sent to a failed address with the bounce's subject, marked with {address: why}, and a billing email's history written. mailQueueStateOf() has bounced (status 3 with email_bounced_at), mailQueueTabs() a Bounced tab, ticketReplyEmailStates() marks each bounced recipient and the key bounced, and ticketReplyEmailHtml() says so. .gitignore leaves out uploads/mail_unprocessed and uploads/kb, as the other upload folders. ## [26.12.2] diff --git a/admin/email_ignored_senders.php b/admin/email_ignored_senders.php index 5413979d3..21df90951 100644 --- a/admin/email_ignored_senders.php +++ b/admin/email_ignored_senders.php @@ -4,7 +4,7 @@ * Admin > Ignored Senders - addresses and domains whose email the ticket mailbox sets aside (functions/mail_ignore.php): * no ticket, no reply on one, no answer, no Unprocessed Email entry. Each with why, who added it, and how many emails it * set aside and the last. New and edit in modals/email_ignored_sender/email_ignored_sender.php; the handlers are - * admin/post/email_ignored_sender.php. Unprocessed Email's Ignore Sender adds them too. + * admin/post/email_ignored_sender.php. */ // Default Column Sortby Filter diff --git a/admin/settings_ticket.php b/admin/settings_ticket.php index 28ab1dd05..6a242cec9 100644 --- a/admin/settings_ticket.php +++ b/admin/settings_ticket.php @@ -33,7 +33,7 @@ echo settingsPageStart('ticket');
- 'From someone who isn\'t a contact, at a domain no client has - otherwise those wait in Tickets > Unprocessed Email for your team to sort.']) ?> + 'From someone who isn\'t a contact, at a domain no client has - otherwise ITFlow leaves those in the mailbox\'s inbox, flagged, so a mailbox shared with other email keeps them.']) ?>
diff --git a/agent/email_unprocessed.php b/agent/email_unprocessed.php index 03c2cab8d..291a9d368 100644 --- a/agent/email_unprocessed.php +++ b/agent/email_unprocessed.php @@ -1,8 +1,8 @@ Unprocessed Email - email the ticket mailbox couldn't take (functions/mail_unprocessed.php): from someone - * who isn't a contact, at a domain no client has, while unknown senders aren't let in - or one that failed. Each can + * Tickets > Unprocessed Email - email the ticket mailbox took but couldn't make a ticket from (functions/mail_unprocessed.php), + * and any kept before strangers' email was left in the inbox again. Each can * be opened, made a ticket, added to a ticket, tried again or dismissed (agent/post/email_unprocessed.php); the first * three are done by the email parser within a minute. The pills pick To sort, Sorted and Dismissed. */ @@ -115,7 +115,7 @@ $csrf = $_SESSION['csrf_token']; -
Email the ticket mailbox couldn't make a ticket from by itself. A ticket made here, or a reply added, is made by the email parser within a minute. Sorted and dismissed email is kept days.
+
Email the ticket mailbox took but couldn't make a ticket from. A ticket made here, or a reply added, is made by the email parser within a minute. Sorted and dismissed email is kept days.
@@ -193,9 +193,6 @@ $csrf = $_SESSION['csrf_token']; Try Again Dismiss - - Ignore Sender - Download .eml
@@ -214,7 +211,7 @@ $csrf = $_SESSION['csrf_token']; 'views' => ['show'], 'icon' => 'fa-envelope-open-text', 'title' => ['waiting' => 'Nothing to sort', 'sorted' => 'Nothing sorted lately', 'dismissed' => 'Nothing dismissed lately'][$show], - 'text' => 'Email the ticket mailbox can\'t make a ticket from by itself waits here - from someone who isn\'t a contact, at a domain no client has, say.', + 'text' => 'Email the ticket mailbox took but couldn\'t make a ticket from waits here. Email from someone who isn\'t a contact, at a domain no client has, stays in the mailbox\'s inbox, flagged - unless tickets from unknown senders are on.', ]; ?> diff --git a/agent/modals/email_unprocessed/email_unprocessed_ignore.php b/agent/modals/email_unprocessed/email_unprocessed_ignore.php deleted file mode 100644 index 1037389f6..000000000 --- a/agent/modals/email_unprocessed/email_unprocessed_ignore.php +++ /dev/null @@ -1,103 +0,0 @@ - Unprocessed Email > Ignore Sender - its sender's address, or everyone at their domain, added to the ignored - * senders (functions/mail_ignore.php), so their email is set aside from now on; this email is dismissed, and the others - * waiting from them if asked. Not a domain anyone can have an address at (gmail.com), nor a client's - those are an - * admin's, in Admin > Ignored Senders. Saved by ignore_unprocessed_sender (agent/post/email_unprocessed.php). - */ - -require_once '../../../includes/modal_header.php'; - -enforceUserPermission('module_support', 2); - -$row = mailUnprocessedReady() && mailIgnoreReady() ? mailUnprocessedRow($_GET['id'] ?? 0) : null; -$from = strtolower(trim((string) ($row['email_unprocessed_from_email'] ?? ''))); -if (!$row || !filter_var($from, FILTER_VALIDATE_EMAIL)) { - echo json_encode(['error' => !$row ? "That email isn't there any more." : 'It has no sender address to ignore.']); - exit; -} - -if (mailIgnoreReach($from)['contacts']) { - echo json_encode(['error' => "$from is a contact's address - an admin can ignore it, in Admin > Ignored Senders."]); - exit; -} - -$id = intval($row['email_unprocessed_id']); -$domain = substr($from, strrpos($from, '@') + 1); -$domain_reach = mailIgnoreReach($domain); -// Why the domain can't be ignored from here, or '' -$domain_no = in_array($domain, EMAIL_PUBLIC_DOMAINS, true) ? "Anyone can have an address at $domain" - : ($domain_reach['clients'] ? 'It is the domain of ' . implode(', ', $domain_reach['clients']) . ' - an admin can, in Admin > Ignored Senders' - : ($domain_reach['contacts'] ? $domain_reach['contacts'] . ' contact' . ($domain_reach['contacts'] === 1 ? ' has an address' : 's have addresses') . ' there - an admin can, in Admin > Ignored Senders' : '')); -$waiting = function ($match) use ($mysqli) { - $count = 0; - $sql = mysqli_query($mysqli, "SELECT email_unprocessed_from_email FROM email_unprocessed WHERE email_unprocessed_done_at IS NULL AND email_unprocessed_action = ''"); - while ($sql && ($other = mysqli_fetch_row($sql))) { - $count += mailIgnoreMatches($match, $other[0]) ? 1 : 0; - } - return $count; -}; -$address_others = max(0, $waiting($from) - 1); -$domain_others = max(0, $waiting($domain) - 1); -$already = mailIgnoreFind($from); - -ob_start(); - -?> - - - - - - - - -">Add to a Ticket Try Again Dismiss - - - Download diff --git a/agent/post/email_unprocessed.php b/agent/post/email_unprocessed.php index 8f6e2d8b0..2fa0067ec 100644 --- a/agent/post/email_unprocessed.php +++ b/agent/post/email_unprocessed.php @@ -2,7 +2,7 @@ /* * ITFlow - POST handlers for Tickets > Unprocessed Email (agent/email_unprocessed.php, functions/mail_unprocessed.php): - * Make a Ticket, Add to a Ticket, Try Again and Dismiss - one at a time or Bulk Action - Ignore Sender, and Download .eml. A ticket, a + * Make a Ticket, Add to a Ticket, Try Again and Dismiss - one at a time or Bulk Action - and Download .eml. A ticket, a * reply or a try again is asked of the email parser, which takes the email from its copy within a minute. */ @@ -88,40 +88,6 @@ if (isset($_POST['unprocessed_email_reply'])) { } -// Ignore Sender - its address, or everyone at its domain, set aside from now on (functions/mail_ignore.php); this one -// dismissed, and the others waiting from them if asked. Never a contact's address, a client's domain, or one anyone can -// have an address at - those are an admin's, in Admin > Ignored Senders -if (isset($_POST['ignore_unprocessed_sender'])) { - - validateCSRFToken(); - enforceUserPermission('module_support', 2); - - $row = unprocessedEmailForRequest($_POST['email_unprocessed_id'] ?? 0); - $from = strtolower(trim((string) $row['email_unprocessed_from_email'])); - if (!mailIgnoreReady() || !filter_var($from, FILTER_VALIDATE_EMAIL)) { - flashAlert("That email has no sender address to ignore", 'error'); - redirect(); - } - $domain = substr($from, strrpos($from, '@') + 1); - $match = ($_POST['ignore'] ?? '') === 'domain' ? $domain : $from; - $reach = mailIgnoreReach($match); - if ($reach['contacts'] || $reach['clients'] || ($match === $domain && in_array($domain, EMAIL_PUBLIC_DOMAINS, true))) { - flashAlert("" . escapeHtml($match) . " can't be ignored from here - " . ($reach['contacts'] || $reach['clients'] ? "it would set aside contacts' email" : "anyone can have an address there") - . ". An admin can, in Admin > Ignored Senders", 'error'); - redirect(); - } - - mailIgnoreAdd(mailIgnoreClean($match), trim((string) ($_POST['ignored_sender_note'] ?? '')) !== '' ? $_POST['ignored_sender_note'] : 'From Unprocessed Email', $session_user_id); - mailUnprocessedDecide([$row['email_unprocessed_id']], 'dismiss', [], $session_user_id); - $others = !empty($_POST['dismiss_others']) ? mailIgnoreDismissWaiting($match, $session_user_id) : 0; - - logAudit("Email", "Unprocessed", "$session_name ignored email from " . escapeSql($match)); - flashAlert("Email from " . escapeHtml($match === $domain ? "@$domain" : $from) . " is set aside from now on" . ($others ? " - and $others more waiting from them dismissed" : '')); - - redirect(); - -} - // Try Again or Dismiss - one, from its menu if (isset($_GET['unprocessed_email'])) { diff --git a/cron/ticket_email_parser.php b/cron/ticket_email_parser.php index 9b39c8ba6..55887c762 100644 --- a/cron/ticket_email_parser.php +++ b/cron/ticket_email_parser.php @@ -608,10 +608,11 @@ function addReplyAgentToClient($ticket_id, $reply_id, $user_id, array $to_client } /* - * An email the parser couldn't take - kept for agents to sort (mailUnprocessedKeep(), functions/mail_unprocessed.php), $why - * it wasn't, and moved to the ITFlow folder ($folder) like the rest. One kept already - an agent's ask that couldn't be - * done - waits again, saying why. When it can't be kept - before the 4.3.2 update, or the copy can't be written - it is - * left flagged and unread in the mailbox, as it always was. + * An email the parser took but couldn't make a ticket or reply from - kept for agents to sort (mailUnprocessedKeep(), + * functions/mail_unprocessed.php), $why, and moved to the ITFlow folder ($folder) like the rest. One kept already - an + * agent's ask that couldn't be done - waits again, saying why. When it can't be kept - before the 4.3.2 update, or the + * copy can't be written - it is left flagged and unread in the mailbox, as it always was. Email that isn't ITFlow's - + * from a stranger while unknown senders aren't let in - never gets here: it stays in the inbox, flagged. */ function mailUnprocessedLeave($message, $why, $folder) { $raw = (string) $message; @@ -1333,8 +1334,11 @@ foreach ($messages as $message) { ); } } else { - // Not taken - kept for agents to sort (Tickets > Unprocessed Email), and out of the inbox like the rest + // Not taken. From someone who isn't a contact, at a domain no client has (or not who it says) - not ITFlow's: left + // in the inbox as it is, flagged so it isn't looked at again, for whoever reads the mailbox. One that failed - kept + // for agents to sort (Tickets > Unprocessed Email), and out of the inbox like the rest $unprocessed_count++; + $not_ours = false; if ($asked_failed !== '') { $why = $asked_failed; } elseif ($asked_only) { @@ -1343,10 +1347,16 @@ foreach ($messages as $message) { $why = 'It couldn\'t be made a ticket'; } elseif ($domain_row && $forged !== '') { $why = "Its sender checks failed - $forged - so it isn't taken as from the client whose domain it is from"; + $not_ours = true; } else { $why = 'From someone who isn\'t a contact, at a domain no client has'; + $not_ours = true; + } + if ($not_ours && !($message instanceof MailUnprocessedMessage)) { + $message->markFlagged(); + } else { + mailUnprocessedLeave($message, $why, $targetFolderPath); } - mailUnprocessedLeave($message, $why, $targetFolderPath); } } catch (\Throwable $e) { diff --git a/functions/mail_ignore.php b/functions/mail_ignore.php index 1b4ef4410..aca7367dd 100644 --- a/functions/mail_ignore.php +++ b/functions/mail_ignore.php @@ -8,9 +8,8 @@ * Email) goes where they said. * * A rule is an address - alerts@vendor.example - or a domain - vendor.example, which takes its subdomains too - * (mail.vendor.example). Kept in Admin > Ignored Senders (admin/email_ignored_senders.php), and from Unprocessed Email's - * Ignore Sender (agent/post/email_unprocessed.php). Checked by cron/ticket_email_parser.php (mailIgnoreFind()) and by - * Try an Email (functions/ticket_mail_try.php). + * (mail.vendor.example). Kept in Admin > Ignored Senders (admin/email_ignored_senders.php). Checked by + * cron/ticket_email_parser.php (mailIgnoreFind()) and by Try an Email (functions/ticket_mail_try.php). */ /** Whether the 4.3.5 update has run - email_ignored_senders is there. */ @@ -146,22 +145,3 @@ function mailIgnoreAdd(array $rule, $note, $user_id) { mailIgnoreRules(true); return intval(mysqli_insert_id($mysqli)); } - -/* - * The emails waiting in Unprocessed Email (functions/mail_unprocessed.php) that a rule takes - dismissed, by $user_id, - * as it would have set them aside. How many. - */ -function mailIgnoreDismissWaiting($match, $user_id) { - global $mysqli; - if (!function_exists('mailUnprocessedReady') || !mailUnprocessedReady()) { - return 0; - } - $ids = []; - $sql = mysqli_query($mysqli, "SELECT email_unprocessed_id, email_unprocessed_from_email FROM email_unprocessed WHERE email_unprocessed_done_at IS NULL AND email_unprocessed_action = ''"); - while ($sql && ($row = mysqli_fetch_assoc($sql))) { - if (mailIgnoreMatches($match, $row['email_unprocessed_from_email'])) { - $ids[] = intval($row['email_unprocessed_id']); - } - } - return $ids ? count(mailUnprocessedDecide($ids, 'dismiss', [], $user_id)) : 0; -} diff --git a/functions/mail_unprocessed.php b/functions/mail_unprocessed.php index e84190f0a..8f98b9ebd 100644 --- a/functions/mail_unprocessed.php +++ b/functions/mail_unprocessed.php @@ -1,11 +1,13 @@ Unprocessed Email (agent/email_unprocessed.php) for someone to sort: + * ITFlow - email the ticket mailbox took but couldn't make a ticket or reply from (database 4.3.2, email_unprocessed): + * the ticket couldn't be made, or the email couldn't be read. It was left flagged and unread in the mailbox, where nobody + * in ITFlow saw it. Now the email parser (cron/ticket_email_parser.php) keeps a copy (uploads/mail_unprocessed/) and + * moves it to the mailbox's ITFlow folder like the rest, and it waits on Tickets > Unprocessed Email + * (agent/email_unprocessed.php) for someone to sort. Email that isn't ITFlow's - from someone who isn't a contact, at a + * domain no client has, while unknown senders aren't let in - still stays in the inbox, flagged, as a mailbox shared + * with other mail needs: * * ticket make it a ticket - for a client, with the sender made a contact there or not, or for no client * reply add it to a ticket - the sender made a CC on it or not diff --git a/functions/ticket_mail_try.php b/functions/ticket_mail_try.php index 0058d78d8..0492eb2dc 100644 --- a/functions/ticket_mail_try.php +++ b/functions/ticket_mail_try.php @@ -25,7 +25,7 @@ * domain it is, else where they last raised a ticket (ticketMailSenderContact()); * 5. an address at a client's domain - a new contact, and a ticket; * 6. anyone else - a ticket with no client when unknown senders are let in, - * else kept in Tickets > Unprocessed Email (functions/mail_unprocessed.php). + * else left in the inbox, flagged. * * Kept in step with the parser by hand - change one, change the other. A Reply-To (ticketMailReplyTo()) * can't be typed in here. @@ -162,8 +162,8 @@ function ticketMailTry($from_email, $subject, $auto_reply = false) { // 6. Anyone else if (!$config_ticket_email_parse_unknown_senders) { $steps[] = ['Tickets from unknown senders?', 'Off']; - return ['steps' => $steps, 'outcome' => ['fa-envelope-open-text', 'warning', 'Kept for your team to sort', - 'It waits in Tickets > Unprocessed Email, where it can be made a ticket at a client, added to a ticket or dismissed. Turn on Tickets from unknown senders to make them tickets with no client.']]; + return ['steps' => $steps, 'outcome' => ['fa-inbox', 'warning', 'Left in the inbox', + 'ITFlow leaves it in the mailbox\'s inbox, flagged, and doesn\'t look at it again. Make the sender a contact, add their domain to a client, or turn on Tickets from unknown senders to have email like it taken.']]; } $steps[] = ['Tickets from unknown senders?', 'On']; return ['steps' => $steps, 'outcome' => ['fa-plus-circle', 'success', 'A new ticket with no client',