mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
Mail review stage 8 follow-up: a bounce naming an address the email was not sent to (mail sent on to another mailbox) or naming nobody is the recipient's on an email to one person, saying where it came back from, and on an email to several marks nobody on it, keeps the named address and has the reply say a bounce came back and from where; an invoice's or quote's history gets one line for a bounce, not one for each report; Ignored Senders takes a domain with an international ending (xn--); mailIgnoreAdd returns the new id; Try an Email names the From unknown senders too switch and says to clear the flag on an email left in the inbox; 26.12.3 changelog
This commit is contained in:
@@ -204,14 +204,18 @@ function mailQueueBounceColumns() {
|
||||
* A mail server's bounce (addBounce(), cron/ticket_email_parser.php) for the email it was about - found by its Message-ID
|
||||
* ($message_id, cleaned), else the latest sent in the last week to one of the addresses it failed for, with its subject
|
||||
* ($subject, raw) - only ones that went (Sent). $failed is [address => why]. Marked Bounced, for those addresses - and a
|
||||
* billing email's history says so. The row as it was, or null when none is found.
|
||||
* billing email's history says so, once for each address. The row as it was, or null when none is found.
|
||||
*
|
||||
* A report often names an address the email wasn't sent to - their mail is sent on to another mailbox, or the address is
|
||||
* an alias - or names nobody. On an email to one person it is theirs, saying where it came back from. On one to several,
|
||||
* which of them it was for can't be told: nobody on it is marked, and the address the report names is kept as it is.
|
||||
*/
|
||||
function mailQueueBounced($message_id, array $failed, $subject = '') {
|
||||
global $mysqli;
|
||||
if (!mailQueueBounceReady()) {
|
||||
return null;
|
||||
}
|
||||
$columns = "email_id, email_recipient, email_cc, email_subject, email_about, email_ticket_reply_id, email_bounce";
|
||||
$columns = "email_id, email_recipient, email_cc, email_subject, email_about, email_ticket_reply_id, email_bounced_at, email_bounce";
|
||||
$row = null;
|
||||
if (trim((string) $message_id) !== '') {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT $columns FROM email_queue WHERE email_status = 3 AND email_message_id = '" . mysqli_real_escape_string($mysqli, (string) $message_id) . "' ORDER BY email_id DESC LIMIT 1"));
|
||||
@@ -226,30 +230,43 @@ function mailQueueBounced($message_id, array $failed, $subject = '') {
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
// Who it bounced for - the addresses it was to that the report names, or everyone on it when it names none
|
||||
$on_it = array_merge([strtolower((string) $row['email_recipient'])], array_map(function ($person) {
|
||||
// Who it bounced for - the addresses it was to that the report names
|
||||
$on_it = array_values(array_unique(array_merge([strtolower((string) $row['email_recipient'])], array_map(function ($person) {
|
||||
return strtolower((string) $person['email']);
|
||||
}, mailQueueCc($row['email_cc'] ?? '')));
|
||||
$bounce = (array) json_decode((string) ($row['email_bounce'] ?? ''), true);
|
||||
foreach ($failed ?: array_fill_keys($on_it, '') as $address => $why) {
|
||||
}, mailQueueCc($row['email_cc'] ?? '')))));
|
||||
$was = (array) json_decode((string) ($row['email_bounce'] ?? ''), true);
|
||||
$bounce = $was;
|
||||
$elsewhere = [];
|
||||
foreach ($failed as $address => $why) {
|
||||
$address = strtolower((string) $address);
|
||||
if (in_array($address, $on_it, true)) {
|
||||
$bounce[$address] = mailQueueErrorText($why);
|
||||
} elseif ($address !== '') {
|
||||
$elsewhere[$address] = mailQueueErrorText($why);
|
||||
}
|
||||
}
|
||||
if (!$bounce) {
|
||||
$bounce = array_fill_keys($on_it, '');
|
||||
// It names an address the email didn't go to, or nobody (above)
|
||||
if ($elsewhere || !$failed) {
|
||||
if (count($on_it) > 1) {
|
||||
$bounce += $elsewhere;
|
||||
} elseif (($bounce[$on_it[0]] ?? '') === '') {
|
||||
$bounce[$on_it[0]] = implode('; ', array_map(function ($address, $why) {
|
||||
return $why !== '' ? "$address: $why" : "It came back from $address";
|
||||
}, array_keys($elsewhere), $elsewhere));
|
||||
}
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE email_queue SET email_bounced_at = NOW(), email_bounce = '" . mysqli_real_escape_string($mysqli, json_encode($bounce, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) . "'
|
||||
mysqli_query($mysqli, "UPDATE email_queue SET email_bounced_at = NOW(), email_bounce = '" . mysqli_real_escape_string($mysqli, json_encode((object) $bounce, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) . "'
|
||||
WHERE email_id = " . intval($row['email_id']));
|
||||
|
||||
// A billing email - its history says it bounced
|
||||
if (preg_match('/^(invoice|quote):(\d+)$/', (string) $row['email_about'], $about) && function_exists('billingLog')) {
|
||||
// A billing email - its history says it bounced: the first time, and for each address more
|
||||
$new = array_diff_key($bounce, $was);
|
||||
if (preg_match('/^(invoice|quote):(\d+)$/', (string) $row['email_about'], $about) && function_exists('billingLog') && (empty($row['email_bounced_at']) || $new)) {
|
||||
$status = (string) (mysqli_fetch_row(mysqli_query($mysqli, $about[1] === 'invoice'
|
||||
? "SELECT invoice_status FROM invoices WHERE invoice_id = " . intval($about[2]) : "SELECT quote_status FROM quotes WHERE quote_id = " . intval($about[2])))[0] ?? '');
|
||||
if ($status !== '') {
|
||||
$why = implode('; ', array_filter($bounce));
|
||||
billingLog($about[1], intval($about[2]), $status, 'Email to ' . implode(', ', array_keys($bounce)) . ' bounced' . ($why !== '' ? ' - ' . mb_strimwidth($why, 0, 300, '...') : ''));
|
||||
$told = $new ?: $bounce;
|
||||
$why = implode('; ', array_filter($told));
|
||||
billingLog($about[1], intval($about[2]), $status, ($told ? 'Email to ' . implode(', ', array_keys($told)) : 'Its email') . ' bounced' . ($why !== '' ? ' - ' . mb_strimwidth($why, 0, 300, '...') : ''));
|
||||
}
|
||||
}
|
||||
return $row;
|
||||
|
||||
Reference in New Issue
Block a user