Mail review stage 4: a failed email is retried only while its last try is within a day, so emails given up on under the old four tries stay Failed instead of being sent again and Failed shows their own count of tries; only a recipient address that doesn't exist is turned away for good and marks its contact Email bounced - relay refusals, full mailboxes and other policy refusals are tried again and two in a row stop the run with a notice to admins; a dismissed notice counts toward the hour; password links and invites go first; 26.12.3 changelog

This commit is contained in:
johnnyq
2026-11-30 17:32:30 -05:00
parent 17d2611b60
commit 039c1b11da
3 changed files with 79 additions and 33 deletions

View File

@@ -62,7 +62,7 @@ Update from Maintenance > Update as usual - this release has eight database chan
- Email sent by a system, a mailing list or a newsletter still makes tickets - alerts emailed in keep working - but is never answered: no "we have your email", no "that ticket is closed". ITFlow's own automatic emails say they are automatic, so the other side's out-of-office doesn't answer them, and no one address gets more than five of them an hour - so two systems can't keep answering each other.
- Two people at a client raising the same problem in the same week - "Printer not working" - get a ticket each, linked as related, rather than the second email landing on the first person's ticket. It's still a reply on the ticket from its contact or a CC.
- A reply to a closed ticket is kept on it as an internal note instead of left in the mailbox, and the notice says so. The ticket isn't reopened. The client or CC is told it is closed, as before - but not someone with no part in the ticket, who learned nothing from a number they guessed.
- Mail queue: email goes out at a pace your mail host takes - 30 a minute to start, set under Pace in Admin > Settings > Mail, Sending - over one connection, ticket emails first and email from the contacts or clients list last. A host's limit doesn't lose email any more: the rest wait their turn. A failed email is tried again over about eight hours, sooner at first. An address the mail server turns away for good isn't tried again, and its contact shows Email bounced. A mail server ITFlow can't reach or sign in to costs no email a try - it waits, and goes once it can. Admins hear about the queue once an hour at most, where every agent got a notice for each failed email.
- Mail queue: email goes out at a pace your mail host takes - 30 a minute to start, set under Pace in Admin > Settings > Mail, Sending - over one connection - password links and invites first, email from the contacts or clients list last. A host's limit doesn't lose email any more: the rest wait their turn. A failed email is tried again over about eight hours, sooner at first. An address the mail server says doesn't exist isn't tried again, and its contact shows Email bounced; turned away for any other reason - the server's own rules, a full mailbox - an email is tried again. A mail server ITFlow can't reach or sign in to costs no email a try - it waits, and goes once it can. Admins hear about the queue once an hour at most, where every agent got a notice for each failed email.
- Every email has a plain text part beside its HTML, and names the machine sending it by ITFlow's own address rather than the server's own name ("vm", say) - both counted against an email with spam filters.
- Email-to-ticket checks who an email is really from, by what your mail server found as it arrived (SPF, DKIM and DMARC). An email that failed - DMARC for a domain that asks for forged email to be rejected or quarantined, or SPF with nothing else passing - is treated as from a stranger, whoever it says it's from: a reply is an internal note saying which check failed and reopens nothing, adds nobody and goes to nobody; a new email still makes a ticket, with a note, but copies nobody in and gets no answer; and it never makes a contact. An email that says it's from one of your agents isn't taken as their note. A domain that asks nothing of forged email (DMARC p=none) is taken as before.
- Email-to-ticket: someone who isn't a contact is answered "[TCK-123] We have your email", without their own subject. Anyone can send an email that says it's from someone else, and the answer carried their words to that person from your mailbox.
@@ -140,6 +140,7 @@ Update from Maintenance > Update as usual - this release has eight database chan
- Mail review stage 1: emailQueue() cuts the subject and the recipient's and sender's names to the queue's 255 characters (emailFit(), functions/email.php) and queues each email on its own; addToMailQueue() (functions/app.php) catches an insert the database turns away, logs it to App Logs (Mail) and returns how many went in, so emailQueue() answers with only those queued and a ticket reply's Emailed state is right - the email preview's send too. cron/ticket_email_parser.php takes TICKET_ATTACHMENT_EXTENSIONS (functions/files.php) in place of its own list; the list gains heic, heif, tif, tiff, eml, xlsm, ppt, rtf and log, and ticketAttachmentAccept() gives every file field's accept from it (the reply box, New Ticket, the portal's two, canned responses). Files not added - a kind it doesn't take (ticketMailFileTypeWhy()) or over $max_attachment_bytes - go in an internal note (ticketMailFilesLeftOut(), functions/ticket_mail_thread.php) through addTicket()'s new $dropped and addReply()'s email dropped. addReply() makes the copied-in CCs (ticketMailCopiedCcs()) only when the email is threaded. addTicket() takes its SQL-escaped name and address back to raw and escapes each once for HTML and SQL; the domain-match contact is inserted as escaped once, its name cut to 200 characters.
- Mail review stage 2: cron/mail_queue.php sends what is due - waiting, and failed ones whose wait is over - in one query, at most mailQueuePerMinute() a run (settings.config_mail_send_per_minute, database 4.2.9), ORDER BY email_bulk (4.2.9, emailQueue()'s bulk, set by emailBulkSend()), over one PHPMailer kept open (SMTPKeepAlive, mailQueueMailer()). MailQueueSmtp keeps each refused recipient's code: everyone refused for good (5xx) - email_attempts 99 and contactBounceMark(); some refused - sent, and they're named in email_error; refused for now (4xx) - tried again. A connection or sign-in failure (MailQueueUnreachable) puts the email back as it was and ends the run with cronJobStop(..., 1); two failures in a row end it for the minute. MAIL_QUEUE_RETRY_MINUTES gives way to MAIL_QUEUE_RETRY_AFTER - 5, 10, 20, 40, 60, 120 and 240 minutes (mailQueueRetryMinutes(), mailQueueRetryDueSql()) - and MAIL_QUEUE_TRIES is 8. Each failed email's appNotify() to every agent gives way to one mailQueueNotifyAdmins() for the run, an hour apart at most. PHPMailer's Hostname is mailQueueHostname(), its AltBody mailQueueTextPart(). sendQueueEmail() takes the run's mailer and answers with who the mail server took and turned away.
- Mail review stage 3: ticketMailSenderCheck() (functions/ticket_mail_auto.php) reads the topmost Authentication-Results - the receiving server's - and answers why it failed, or '': dmarc=fail with p= or policy= reject or quarantine, or Microsoft 365's action reject, oreject or quarantine; or spf=fail with no dkim=pass and no dmarc result; never with arc=pass or compauth=pass. Only a failure is acted on, so a pass a sender writes in gains nothing. cron/ticket_email_parser.php keeps it as the email's forged: addReply() makes a forged email a stranger's, with its own note, history and audit line; addTicket() takes $email (copied, message_id, automatic, dropped, forged) in place of its last four arguments, writes ticketMailForgedNote() (functions/ticket_mail_thread.php) and leaves out the copied-in CCs, the client-less ticket's CC and the answer for a forged one; the domain match makes no contact from one. ticketMailCreated() takes a subject, as ticketMailSend()'s subject; a client-less emailed ticket is answered "[REF] We have your email".
- Mail review stage 4: a failed email is still being tried while it is under MAIL_QUEUE_TRIES and its last try is within MAIL_QUEUE_GIVE_UP_HOURS (24) - mailQueueRetryingSql(), mailQueueFailedSql() and mailQueueRetrying(), for the job, the tabs, an email's state, Cancel and the summary - so one given up on before the tries went from 4 to 8 stays Failed rather than being sent again, and Failed gives its own count of tries. mailQueueRefusedForGood() decides which refused recipients are for good: the enhanced codes 5.1.1, 5.1.2, 5.1.3, 5.1.6 and 5.1.10, or 550, 551 or 553 naming an unknown recipient from a server that gives none (MailQueueSmtp keeps code_ex). Any other refusal is tried again and counts toward the two-in-a-row stop. mailQueueNotifyAdmins() counts dismissed notices toward its hour. The job orders by email_bulk, then email_sensitive DESC.
## [26.12.2]

View File

@@ -211,7 +211,8 @@ class MailQueueSmtp extends SMTP {
$accepted = parent::recipient($address, $dsn);
if (!$accepted) {
$error = $this->getError();
$this->refused[strtolower(trim((string) $address))] = ['code' => (string) ($error['smtp_code'] ?? ''), 'detail' => trim(trim((string) ($error['smtp_code_ex'] ?? '')) . ' ' . trim((string) ($error['detail'] ?? '')))];
$this->refused[strtolower(trim((string) $address))] = ['code' => (string) ($error['smtp_code'] ?? ''), 'code_ex' => trim((string) ($error['smtp_code_ex'] ?? '')),
'detail' => trim(trim((string) ($error['smtp_code_ex'] ?? '')) . ' ' . trim((string) ($error['detail'] ?? '')))];
}
return $accepted;
}
@@ -464,17 +465,18 @@ if ($orphaned_emails > 0) {
/** =======================================================================
* SEND: what is due - waiting (status 0) and failed ones whose wait is over (status 2) - at most the
* pace a minute (mailQueuePerMinute()), bulk email after everything else, oldest first
* pace a minute (mailQueuePerMinute()): a password link, an invite or a shared login first, as someone
* is waiting for it, bulk email after everything else, oldest first
* ======================================================================= */
// The copied in and the headers - once the 4.2.6 update has made their columns
$thread_columns = ticketMailThreadReady() ? 'email_cc, email_headers' : "'' AS email_cc, '' AS email_headers";
$per_minute = mailQueuePerMinute();
$bulk_order = mailQueuePaceReady() ? 'email_bulk, ' : '';
$bulk_order = (mailQueuePaceReady() ? 'email_bulk, ' : '') . (mailQueueHasSensitive() ? 'email_sensitive DESC, ' : '');
$sql_queue = mysqli_query($mysqli, "SELECT email_attachments, email_attempts, email_cal_str, email_content, email_from, email_from_name, email_id,
email_recipient, email_recipient_name, email_status, email_subject, $thread_columns FROM email_queue
WHERE (email_status = 0 AND email_queued_at <= NOW())
OR (email_status = 2 AND email_attempts < " . MAIL_QUEUE_TRIES . " AND " . mailQueueRetryDueSql() . ")
OR (" . mailQueueRetryingSql() . " AND " . mailQueueRetryDueSql() . ")
ORDER BY {$bulk_order}email_queued_at, email_id LIMIT $per_minute");
$mailer = null;
@@ -553,12 +555,11 @@ while ($sql_queue && ($rowq = mysqli_fetch_assoc($sql_queue))) {
}
continue;
}
$temporary_in_a_row = 0;
// Who the mail server turned away for good (5xx) - their contacts show Email bounced (functions/contact_bounce.php), and no email
// to them is tried again
// Who the mail server said doesn't exist (mailQueueRefusedForGood()) - their contacts show Email bounced (functions/contact_bounce.php),
// and no email to them is tried again. Turned away for any other reason, it is tried again
$for_good = array_filter($result['refused'], function ($why) {
return substr($why['code'], 0, 1) === '5';
return mailQueueRefusedForGood($why['code'], $why['code_ex'] ?? '', $why['detail']);
});
foreach ($for_good as $address => $why) {
foreach (contactBounceMark($address, trim($why['code'] . ' ' . $why['detail'])) as $bounced_contact_id => [$bounced_name, $bounced_client_id]) {
@@ -568,6 +569,7 @@ while ($sql_queue && ($rowq = mysqli_fetch_assoc($sql_queue))) {
}
if ($result['accepted']) {
$temporary_in_a_row = 0;
// Sent - one with a link or code that opens something is cleared now (mailQueueSentSql()). Any of the copied in turned away
// are said with it: it isn't sent again, as everyone else has it
$note = $result['refused'] ? 'Sent - but the mail server turned away ' . mailQueueRefusedText($result['refused']) : null;
@@ -577,16 +579,23 @@ while ($sql_queue && ($rowq = mysqli_fetch_assoc($sql_queue))) {
$run['partial']++;
}
} elseif (count($for_good) === count($result['refused'])) {
// Everyone turned away for good - not tried again
// Everyone turned away for good - not tried again. About the addresses, not the server
$temporary_in_a_row = 0;
mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_failed_at = NOW(), email_attempts = 99" . mailQueueErrorSql('Turned away for good - ' . mailQueueRefusedText($result['refused'])) . " WHERE email_id = $email_id");
logApp("Cron-Mail-Queue", "Error", "The mail server turned away email #$email_id for good - " . escapeSql(mailQueueRefusedText($result['refused'])));
$run['turned_away']++;
} else {
// Turned away for now - tried again after a wait
// Turned away for now - tried again after a wait. Two in a row is the server - a relay that won't send for ITFlow, a quota -
// and the rest wait for the next minute, the admins told (below)
$why = 'Turned away for now - ' . mailQueueRefusedText($result['refused']);
mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_failed_at = NOW(), email_attempts = $attempts" . mailQueueErrorSql($why) . " WHERE email_id = $email_id");
$run['last_error'] = $why;
$attempts >= MAIL_QUEUE_TRIES ? $run['gave_up']++ : $run['again']++;
if (++$temporary_in_a_row >= 2) {
$run['stopped'] = 'The mail server turned away two emails in a row - the rest wait for the next minute. It said: ' . mailQueueErrorText($why);
$run['stopped_soft'] = true;
break;
}
}
}

View File

@@ -9,10 +9,11 @@
* 0 waiting - or scheduled, while its email_queued_at is still ahead
* 1 being sent this minute
* 2 failed - tried again after a wait that grows (MAIL_QUEUE_RETRY_AFTER, about eight
* hours in all) until it has had MAIL_QUEUE_TRIES; 99 tries means it isn't tried
* again - an address the mail server turned away for good. A domain with no mail
* server is a failed try like any other (mailQueueDomainProblem()), as a lookup
* can fail for a moment
* hours in all) until it has had MAIL_QUEUE_TRIES, and not once its last try is
* MAIL_QUEUE_GIVE_UP_HOURS behind it (mailQueueRetryingSql()); 99 tries means it isn't
* tried again - an address the mail server said doesn't exist (mailQueueRefusedForGood()).
* A domain with no mail server is a failed try like any other (mailQueueDomainProblem()),
* as a lookup can fail for a moment
* 3 sent - it keeps what it said, its calendar file and attachments, except
* one that carried a link or code that opens something (email_sensitive:
* a shared login, an invite, a password link, a signing or approval link),
@@ -29,7 +30,8 @@
* copied-in itself.
*
* The job sends at most config_mail_send_per_minute a run (database 4.2.9 - 30 until then) over one
* connection, bulk email (email_bulk) after everything else, and stops for the minute when the mail
* connection - one with a link or code that opens something (email_sensitive: a password link, an invite) first,
* as someone is waiting for it, and bulk email (email_bulk) after everything else - and stops for the minute when the mail
* server turns two away in a row for now - a host's limit - so the rest wait their turn rather than
* use up their tries. A mail server it can't reach or sign in to costs no email a try.
*/
@@ -37,6 +39,9 @@
// Minutes before each try again - after the first failed try, the second... about eight hours in all
const MAIL_QUEUE_RETRY_AFTER = [5, 10, 20, 40, 60, 120, 240];
const MAIL_QUEUE_TRIES = 8;
// A failed email isn't picked up again by itself once its last try is this far behind it - the longest wait is 4 hours.
// An email given up on before the tries went from 4 to 8 has fewer than 8, and was sent again, however old
const MAIL_QUEUE_GIVE_UP_HOURS = 24;
const MAIL_QUEUE_KEEP_DAYS = 90;
const MAIL_QUEUE_CANCELLED = 4;
// Pictures that were in an email as data, kept once each for the queue to attach inline (emailInlineImages()) - the web can't reach uploads/tmp
@@ -64,6 +69,40 @@ function mailQueueRetryDueSql() {
return "email_failed_at <= NOW() - INTERVAL (CASE email_attempts$cases ELSE $last END) MINUTE";
}
/* SQL - a failed email still being tried: under MAIL_QUEUE_TRIES, and its last try within MAIL_QUEUE_GIVE_UP_HOURS. */
function mailQueueRetryingSql() {
return "(email_status = 2 AND email_attempts < " . MAIL_QUEUE_TRIES . " AND email_failed_at >= NOW() - INTERVAL " . MAIL_QUEUE_GIVE_UP_HOURS . " HOUR)";
}
/* SQL - a failed email given up on: out of tries, not tried again (99), or its last try too long ago (mailQueueRetryingSql()). */
function mailQueueFailedSql() {
return "(email_status = 2 AND (email_attempts >= " . MAIL_QUEUE_TRIES . " OR email_failed_at IS NULL OR email_failed_at < NOW() - INTERVAL " . MAIL_QUEUE_GIVE_UP_HOURS . " HOUR))";
}
/* Whether a failed email ($row - email_status, email_attempts, email_failed_at) is still being tried (mailQueueRetryingSql()). */
function mailQueueRetrying(array $row) {
$failed = (string) ($row['email_failed_at'] ?? '');
return intval($row['email_status']) === 2 && intval($row['email_attempts']) < MAIL_QUEUE_TRIES
&& $failed !== '' && strtotime($failed) >= time() - MAIL_QUEUE_GIVE_UP_HOURS * 3600;
}
/*
* Whether a mail server's refusal of a recipient says the address doesn't exist - for good, so the email isn't tried
* again and the contact shows Email bounced. Only the enhanced codes for a recipient's address (RFC 3463): 5.1.1 no
* such mailbox, 5.1.2 no such domain, 5.1.3 not an address, 5.1.6 moved with nowhere to forward to, 5.1.10 a domain
* that takes no mail (RFC 7505) - or, from a server that gives no enhanced code, 550, 551 or 553 saying there is no
* such recipient. Any other refusal is tried again: the server's own policy (5.7.x - a relay that won't send for
* you), a full mailbox (5.2.2), a sending quota. Every 5xx used to count, and marked real contacts bounced.
*/
function mailQueueRefusedForGood($code, $code_ex, $detail) {
$code_ex = trim((string) $code_ex);
if ($code_ex !== '') {
return in_array($code_ex, ['5.1.1', '5.1.2', '5.1.3', '5.1.6', '5.1.10'], true);
}
return in_array(trim((string) $code), ['550', '551', '553'], true)
&& preg_match("/user unknown|unknown user|no such (user|mailbox|recipient|address)|does ?n[o']?t exist|recipient (not found|unknown)|unknown recipient|mailbox not found|invalid (recipient|mailbox)/i", (string) $detail) === 1;
}
/* Whether the 4.2.9 update has run - the sending pace (config_mail_send_per_minute) and bulk email (email_bulk). */
function mailQueuePaceReady() {
global $mysqli;
@@ -124,8 +163,8 @@ function mailQueueTextPart($html) {
/*
* Tell the admins about the mail queue - $text, and where to look ($action). Once an hour at most: an
* admin with a notice from the queue that is still there from the last hour isn't told again, as a run
* a minute with a mail server down would fill their bell. It used to tell every agent, once an email.
* admin told in the last hour isn't told again - read or not, as one dismissed came back the next minute
* while a mail server was down. It used to tell every agent, once an email.
*/
function mailQueueNotifyAdmins($text, $action = '/admin/mail_queue.php') {
global $mysqli;
@@ -133,7 +172,7 @@ function mailQueueNotifyAdmins($text, $action = '/admin/mail_queue.php') {
$action_sql = logSqlText($action, 250);
$sql = mysqli_query($mysqli, "SELECT user_id FROM users JOIN user_roles ON role_id = user_role_id
WHERE role_is_admin = 1 AND user_type = 1" . serviceAccountsOutSql() . " AND user_status = 1 AND user_archived_at IS NULL
AND user_id NOT IN (SELECT notification_user_id FROM notifications WHERE notification_type = 'Mail Queue' AND notification_dismissed_at IS NULL
AND user_id NOT IN (SELECT notification_user_id FROM notifications WHERE notification_type = 'Mail Queue'
AND notification_timestamp >= NOW() - INTERVAL 1 HOUR)");
$told = 0;
while ($row = mysqli_fetch_row($sql)) {
@@ -156,13 +195,12 @@ function mailQueueDomainProblem($recipient) {
/* The tabs of the list - key => [label, icon, SQL for what is in it]. */
function mailQueueTabs() {
$tries = MAIL_QUEUE_TRIES;
return [
'' => ['All', 'fa-inbox', '1 = 1'],
'waiting' => ['Waiting', 'fa-hourglass-half', 'email_status = 0'],
'sending' => ['Sending', 'fa-paper-plane', 'email_status = 1'],
'retrying' => ['Retrying', 'fa-redo-alt', "email_status = 2 AND email_attempts < $tries"],
'failed' => ['Failed', 'fa-exclamation-circle', "email_status = 2 AND email_attempts >= $tries"],
'retrying' => ['Retrying', 'fa-redo-alt', mailQueueRetryingSql()],
'failed' => ['Failed', 'fa-exclamation-circle', mailQueueFailedSql()],
'sent' => ['Sent', 'fa-check', 'email_status = 3'],
'cancelled' => ['Cancelled', 'fa-ban', 'email_status = ' . MAIL_QUEUE_CANCELLED],
];
@@ -202,15 +240,15 @@ function mailQueueStateOf(array $row) {
return ['key' => 'sending', 'label' => 'Sending', 'badge' => 'text-bg-warning', 'icon' => 'fa-paper-plane',
'detail' => 'Going now', 'title' => ''];
}
if ($status === 2 && $tries < MAIL_QUEUE_TRIES) {
$next = $failed !== '' ? strtotime($failed) + mailQueueRetryMinutes($tries) * 60 : time();
if (mailQueueRetrying($row)) {
$next = strtotime($failed) + mailQueueRetryMinutes($tries) * 60;
return ['key' => 'retrying', 'label' => 'Retrying', 'badge' => 'text-bg-warning', 'icon' => 'fa-redo-alt',
'detail' => 'Tried ' . max(1, $tries) . ' of ' . MAIL_QUEUE_TRIES . ' · next ' . ($next > time() ? 'about ' . date('g:i A', $next) : 'any minute'),
'title' => $failed !== '' ? 'Last failed ' . $when($failed) : ''];
}
if ($status === 2) {
return ['key' => 'failed', 'label' => 'Failed', 'badge' => 'text-bg-danger', 'icon' => 'fa-exclamation-circle',
'detail' => ($tries > MAIL_QUEUE_TRIES ? 'Not tried again' : 'Gave up after ' . MAIL_QUEUE_TRIES . ' tries') . ($failed !== '' ? ' · ' . timeAgo($failed) : ''),
'detail' => ($tries > MAIL_QUEUE_TRIES ? 'Not tried again' : 'Gave up after ' . max(1, $tries) . ' ' . ($tries === 1 ? 'try' : 'tries')) . ($failed !== '' ? ' · ' . timeAgo($failed) : ''),
'title' => $failed !== '' ? 'Failed ' . $when($failed) : ''];
}
if ($status === 3) {
@@ -235,7 +273,7 @@ function mailQueueCan(array $row, $action) {
// Not one whose link was cleared - there is nothing left to send
return ($status === 2 || $status === MAIL_QUEUE_CANCELLED) && empty($row['email_cleared']);
case 'cancel':
return $status === 0 || ($status === 2 && $tries < MAIL_QUEUE_TRIES);
return $status === 0 || mailQueueRetrying($row);
case 'delete':
return $status !== 1;
}
@@ -254,11 +292,10 @@ function mailQueueAct($action, array $email_ids) {
return [];
}
$list = implode(',', $ids);
$tries = MAIL_QUEUE_TRIES;
$cancelled = MAIL_QUEUE_CANCELLED;
$where = [
'retry' => "email_status IN (2, $cancelled) AND email_content <> ''",
'cancel' => "(email_status = 0 OR (email_status = 2 AND email_attempts < $tries))",
'cancel' => "(email_status = 0 OR " . mailQueueRetryingSql() . ")",
'delete' => 'email_status <> 1',
][$action] ?? null;
if ($where === null) {
@@ -332,7 +369,7 @@ function mailQueueHealth() {
return ['level' => 'warning', 'key' => 'slow', 'title' => 'Email is waiting longer than it should', 'text' => trim($held) . ' The Mail Queue job last ran ' . $ago($job['cron_job_last_run_at'] ?? null) . '.' . $error,
'url' => 'cron.php', 'action' => 'Maintenance > Cron', 'waiting' => $waiting];
}
return ['level' => '', 'key' => 'ok', 'title' => '', 'text' => 'Sent by the Mail Queue job each minute, up to ' . mailQueuePerMinute() . ' a minute, bulk email last - it last ran '
return ['level' => '', 'key' => 'ok', 'title' => '', 'text' => 'Sent by the Mail Queue job each minute, up to ' . mailQueuePerMinute() . ' a minute - password links and invites first, bulk email last. It last ran '
. $ago($job['cron_job_last_run_at'] ?? null) . '. A failed email is tried ' . (MAIL_QUEUE_TRIES - 1) . ' more times over about '
. round(array_sum(MAIL_QUEUE_RETRY_AFTER) / 60) . ' hours, and one the mail server turns away for good isn\'t tried again. Email is kept ' . MAIL_QUEUE_KEEP_DAYS . ' days - with what it said, apart from one with a link or code that opens something, cleared once it has gone.', 'url' => '', 'action' => '', 'waiting' => 0];
}
@@ -529,12 +566,11 @@ function mailQueueSummary() {
if ($summary !== null) {
return $summary;
}
$tries = MAIL_QUEUE_TRIES;
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT
COALESCE(SUM(email_status = 0 AND email_queued_at <= NOW()), 0),
COALESCE(SUM(email_status = 2 AND email_attempts < $tries), 0),
COALESCE(SUM(email_status = 2 AND email_attempts >= $tries AND email_failed_at >= NOW() - INTERVAL 1 DAY), 0),
COALESCE(SUM(email_status = 2 AND email_attempts >= $tries AND email_failed_at >= NOW() - INTERVAL 7 DAY), 0),
COALESCE(SUM(" . mailQueueRetryingSql() . "), 0),
COALESCE(SUM(" . mailQueueFailedSql() . " AND email_failed_at >= NOW() - INTERVAL 1 DAY), 0),
COALESCE(SUM(" . mailQueueFailedSql() . " AND email_failed_at >= NOW() - INTERVAL 7 DAY), 0),
MAX(CASE WHEN email_status = 3 THEN email_sent_at END)
FROM email_queue WHERE email_queued_at >= NOW() - INTERVAL " . MAIL_QUEUE_KEEP_DAYS . " DAY"));
$summary = ['waiting' => intval($row[0] ?? 0), 'retrying' => intval($row[1] ?? 0), 'failed_day' => intval($row[2] ?? 0), 'failed_week' => intval($row[3] ?? 0), 'last_sent' => $row[4] ?? null];