prepare("INSERT INTO block_rules (keyword, enabled, created_at) VALUES (?, 1, ?)")
->execute([$kw, date('Y-m-d H:i:s')]);
$msg = "已添加拦截规则「{$kw}」";
$ok = true;
}
}
// 添加转发规则
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'add_forward') {
$kw = trim($_POST['keyword'] ?? '');
$channel = $_POST['channel'] ?? '';
$target = trim($_POST['target'] ?? '');
if ($kw === '') {
$msg = '转发关键词不能为空';
} elseif (!in_array($channel, ['telegram', 'webhook', 'serverchan'])) {
$msg = '推送渠道不正确';
} elseif ($target === '') {
$msg = '推送目标不能为空';
} else {
$db->prepare("INSERT INTO forward_rules (keyword, channel, target, enabled, created_at) VALUES (?, ?, ?, 1, ?)")
->execute([$kw, $channel, $target, date('Y-m-d H:i:s')]);
$msg = "已添加转发规则「{$kw}」";
$ok = true;
}
}
// 保存拉取范围
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'save_fetch_range') {
$days = max(1, (int)($_POST['days'] ?? 7));
$db->prepare("INSERT OR REPLACE INTO settings (key, value) VALUES ('fetch_days', ?)")
->execute([(string)$days]);
$msg = "已设置:每次拉取最近 {$days} 天的邮件";
$ok = true;
}
// 保存定时清理
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'save_auto_delete') {
$days = max(0, (int)($_POST['days'] ?? 0));
$db->prepare("INSERT OR REPLACE INTO settings (key, value) VALUES ('auto_delete_days', ?)")
->execute([(string)$days]);
$msg = $days > 0 ? "已设置:超过 {$days} 天的邮件将自动删除" : '已关闭自动清理';
$ok = true;
}
// 删除规则
if (($_GET['action'] ?? '') === 'delete' && !empty($_GET['id'])) {
$db->prepare("DELETE FROM block_rules WHERE id = ?")->execute([(int)$_GET['id']]);
header('Location: rules.php'); exit;
}
if (($_GET['action'] ?? '') === 'delete_forward' && !empty($_GET['id'])) {
$db->prepare("DELETE FROM forward_rules WHERE id = ?")->execute([(int)$_GET['id']]);
header('Location: rules.php'); exit;
}
if (($_GET['action'] ?? '') === 'toggle' && !empty($_GET['id'])) {
$db->prepare("UPDATE block_rules SET enabled = 1 - enabled WHERE id = ?")->execute([(int)$_GET['id']]);
header('Location: rules.php'); exit;
}
if (($_GET['action'] ?? '') === 'toggle_forward' && !empty($_GET['id'])) {
$db->prepare("UPDATE forward_rules SET enabled = 1 - enabled WHERE id = ?")->execute([(int)$_GET['id']]);
header('Location: rules.php'); exit;
}
$rules = $db->query("SELECT * FROM block_rules ORDER BY id")->fetchAll(PDO::FETCH_ASSOC);
$forwardRules = $db->query("SELECT * FROM forward_rules ORDER BY id")->fetchAll(PDO::FETCH_ASSOC);
$recentBlocked = $db->query("SELECT * FROM blocked_log ORDER BY id DESC LIMIT 30")->fetchAll(PDO::FETCH_ASSOC);
$totalBlocked = $db->query("SELECT COUNT(*) FROM blocked_log")->fetchColumn();
$autoDeleteDays = (int)($db->query("SELECT value FROM settings WHERE key='auto_delete_days'")->fetchColumn() ?: 0);
$fetchDays = (int)($db->query("SELECT value FROM settings WHERE key='fetch_days'")->fetchColumn() ?: 7);
if ($fetchDays <= 0) $fetchDays = 7;
// 统计已收邮件总数和磁盘占用
$totalMails = (int)$db->query("SELECT COUNT(*) FROM mails")->fetchColumn();
$attDirSize = 0;
$attCount = 0;
if (is_dir(__DIR__ . '/data/attachments')) {
$files = glob(__DIR__ . '/data/attachments/*');
foreach ($files as $f) {
if (is_file($f)) { $attDirSize += filesize($f); $attCount++; }
}
}
$attSizeStr = $attDirSize < 1024 * 1024
? round($attDirSize / 1024, 1) . ' KB'
: round($attDirSize / 1024 / 1024, 1) . ' MB';
$page_title = '拦截与转发';
$nav_active = 'rules';
require __DIR__ . '/includes/header.php';
?>
= htmlspecialchars($msg) ?>
拦截规则
邮件主题或正文包含这些关键词时,只在本地拦截,不会从云端删除。
自动转发规则
| 关键词 | 渠道 | 目标 | 状态 | 操作 |
= htmlspecialchars($f['keyword']) ?> |
'Telegram', 'serverchan' => 'Server酱', 'webhook' => 'Webhook'][$f['channel']] ?? $f['channel'];
echo htmlspecialchars($chLabel);
?>
|
= htmlspecialchars($f['target']) ?> |
= $f['enabled'] ? '启用' : '停用' ?>
|
= $f['enabled'] ? '停用' : '启用' ?>
删除
|
最近拦截记录(共 = $totalBlocked ?> 条,显示最近 30 条)
暂无拦截记录
| 时间 | 邮箱 | 发件人 | 主题 | 命中 |
| = htmlspecialchars($b['created_at']) ?> |
= htmlspecialchars($b['account']) ?> |
= htmlspecialchars($b['from_addr']) ?> |
= htmlspecialchars($b['subject']) ?> |
= htmlspecialchars($b['matched']) ?> |