prepare("SELECT label FROM accounts WHERE id = ?"); $stmt->execute([(int)$_GET['id']]); $label = $stmt->fetchColumn(); if ($label) { $db->prepare("DELETE FROM accounts WHERE id = ?")->execute([(int)$_GET['id']]); $msg = "已删除账户「{$label}」。已收邮件仍保留在邮件库中。"; $ok = true; } } if (($_GET['action'] ?? '') === 'toggle' && !empty($_GET['id'])) { $db->prepare("UPDATE accounts SET enabled = 1 - enabled WHERE id = ?")->execute([(int)$_GET['id']]); header('Location: accounts.php'); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'edit') { $id = (int)$_POST['id']; $label = trim($_POST['label'] ?? ''); $host = trim($_POST['host'] ?? ''); $user = trim($_POST['user'] ?? ''); $password = $_POST['password'] ?? ''; $enabled = isset($_POST['enabled']) ? 1 : 0; if ($label === '' || $host === '' || $user === '') { $msg = '显示名称、IMAP 地址、账号不能为空'; } else { if ($password !== '') { $db->prepare("UPDATE accounts SET label=?, host=?, user=?, password=?, enabled=? WHERE id=?") ->execute([$label, $host, $user, $password, $enabled, $id]); } else { $db->prepare("UPDATE accounts SET label=?, host=?, user=?, enabled=? WHERE id=?") ->execute([$label, $host, $user, $enabled, $id]); } $msg = '已保存修改'; $ok = true; } } $testResult = null; if (($_GET['action'] ?? '') === 'test' && !empty($_GET['id'])) { $stmt = $db->prepare("SELECT * FROM accounts WHERE id = ?"); $stmt->execute([(int)$_GET['id']]); $a = $stmt->fetch(PDO::FETCH_ASSOC); if ($a) { $mbox = @imap_open($a['host'], $a['user'], $a['password'], 0, 1); if ($mbox) { $testResult = ['id' => $a['id'], 'ok' => true, 'msg' => '连接成功']; imap_close($mbox); } else { $testResult = ['id' => $a['id'], 'ok' => false, 'msg' => imap_last_error()]; } } } $editAcct = null; if (($_GET['action'] ?? '') === 'edit' && !empty($_GET['id'])) { $stmt = $db->prepare("SELECT * FROM accounts WHERE id = ?"); $stmt->execute([(int)$_GET['id']]); $editAcct = $stmt->fetch(PDO::FETCH_ASSOC); } $accounts = $db->query("SELECT * FROM accounts ORDER BY id")->fetchAll(PDO::FETCH_ASSOC); $counts = []; foreach ($db->query("SELECT account, COUNT(*) as cnt FROM mails GROUP BY account") as $row) { $counts[$row['account']] = $row['cnt']; } $page_title = '邮箱账户管理'; $nav_active = 'accounts'; require __DIR__ . '/includes/header.php'; ?>
| 名称 | 账号 | 邮件数 | 状态 | 最近拉取 | 操作 |
|---|---|---|---|---|---|
= htmlspecialchars($a['label']) ?>= htmlspecialchars($a['key_name']) ?>
|
= htmlspecialchars($a['user']) ?> | = $counts[$a['key_name']] ?? 0 ?> | = $a['enabled'] ? '启用' : '停用' ?> | = htmlspecialchars($a['last_fetch'] ?? '从未') ?> | 测试 编辑 = $a['enabled'] ? '停用' : '启用' ?> 删除 |
|
= $testResult['ok'] ? 'OK' : 'ERR' ?> = htmlspecialchars($testResult['msg']) ?>
| |||||