mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
68 lines
3.0 KiB
PHP
68 lines
3.0 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Admin > 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("<strong>" . escapeHtml(trim((string) ($_POST['ignored_sender_match'] ?? ''))) . "</strong> 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("<strong>" . escapeHtml($rule['match']) . "</strong> 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 <strong>" . escapeHtml($rule['kind'] === 'domain' ? '@' . $rule['match'] : $rule['match']) . "</strong> 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 <strong>" . escapeHtml($match) . "</strong> is read as usual again", 'error');
|
|
|
|
redirect();
|
|
|
|
}
|