Ignored Senders (admin/email_ignored_senders.php, functions/mail_ignore.php): add_ignored_sender and
* edit_ignored_sender keep an address or a domain whose email the ticket mailbox sets aside, and why - an address or
* domain that isn't one, or one there already, comes back saying so; delete_ignored_sender stops ignoring it. One
* that takes contacts' or a client's email is saved, saying so.
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
if (isset($_POST['add_ignored_sender']) || isset($_POST['edit_ignored_sender'])) {
validateCSRFToken();
if (!mailIgnoreReady()) {
flashAlert("Ignored senders need the database update", 'error');
redirect('email_ignored_senders.php');
}
$editing = isset($_POST['edit_ignored_sender']);
$id = $editing ? intval($_POST['ignored_sender_id'] ?? 0) : 0;
$rule = mailIgnoreClean($_POST['ignored_sender_match'] ?? '');
$note = mb_substr(trim((string) ($_POST['ignored_sender_note'] ?? '')), 0, 255);
if (!$rule) {
flashAlert("" . escapeHtml(trim((string) ($_POST['ignored_sender_match'] ?? ''))) . " isn't an email address or a domain", 'error');
redirect();
}
$match_sql = escapeSql($rule['match']);
if (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM email_ignored_senders WHERE ignored_sender_match = '$match_sql' AND ignored_sender_id <> $id"))) {
flashAlert("" . escapeHtml($rule['match']) . " is ignored already", 'error');
redirect();
}
if ($editing) {
mysqli_query($mysqli, "UPDATE email_ignored_senders SET ignored_sender_match = '$match_sql', ignored_sender_note = '" . escapeSql($note) . "' WHERE ignored_sender_id = $id");
} else {
$id = mailIgnoreAdd($rule, $note, $session_user_id);
}
$reach = mailIgnoreReachText(mailIgnoreReach($rule['match']));
logAudit("Settings", $editing ? "Edit" : "Create", "$session_name set email from $match_sql to be ignored");
flashAlert("Email from " . escapeHtml($rule['kind'] === 'domain' ? '@' . $rule['match'] : $rule['match']) . " is set aside from now on" . ($reach !== '' ? " - $reach" : ''), $reach !== '' ? 'warning' : 'success');
redirect();
}
if (isset($_GET['delete_ignored_sender'])) {
validateCSRFToken();
$id = intval($_GET['delete_ignored_sender']);
$match = (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT ignored_sender_match FROM email_ignored_senders WHERE ignored_sender_id = $id"))[0] ?? '');
if ($match === '') {
flashAlert("That ignored sender isn't there any more", 'error');
redirect();
}
mysqli_query($mysqli, "DELETE FROM email_ignored_senders WHERE ignored_sender_id = $id");
logAudit("Settings", "Delete", "$session_name stopped ignoring email from " . escapeSql($match));
flashAlert("Email from " . escapeHtml($match) . " is read as usual again", 'error');
redirect();
}