feat: 新增 SMTP/IMAP/POP3 协议调用日志(含攻击分析筛选)

- 每个连接记录一条日志:协议、端口、来源 IP、用户名、成功/失败、
  失败原因(密码错误/IP封禁/中继被拒/发件人伪造/未认证发信等)、
  操作摘要、消息数与会话时长
- 管理后台新增「协议日志」页:按协议/状态/IP/用户名/时间筛选,
  今日与历史成功/失败统计卡片,分页查看,可手动清理
- 后台每 6 小时自动清理超出 protocol_log_keep_days(默认30天)
  的日志;新增 [web] protocol_log_keep_days 配置项
- 修复 POP3 认证既有 bug:handleUSER 丢弃邮箱域名导致 PASS 永远失败
- 新增 store 单测、SMTP/POP3 端到端测试与模板渲染测试
This commit is contained in:
2026-08-19 18:49:29 +08:00
parent 8ea4a623a9
commit 353bfa88f2
30 changed files with 1233 additions and 59 deletions
+9 -2
View File
@@ -36,6 +36,9 @@ type WebConfig struct {
// 默认 true;仅当应用直接以 HTTP 提供服务(本地调试、内网明文)时
// 才应改为 false。
CookieSecure bool `toml:"cookie_secure"`
// ProtocolLogKeepDays SMTP/IMAP/POP3 协议调用日志保留天数,
// 超过该天数的记录会被后台任务自动清理。
ProtocolLogKeepDays int `toml:"protocol_log_keep_days"`
}
// SecretKeyEnvVar 是覆盖会话签名密钥的环境变量名。
@@ -197,8 +200,9 @@ func defaultConfig() *Config {
AttachDir: filepath.Join(bd, "attachments"),
},
Web: WebConfig{
Addr: DefaultWebPort,
CookieSecure: true,
Addr: DefaultWebPort,
CookieSecure: true,
ProtocolLogKeepDays: DefaultProtocolLogKeepDays,
},
SMTP: SMTPConfig{
Addr: fmt.Sprintf(":%d", DefaultSMTPPort),
@@ -262,6 +266,9 @@ func mergeDefaults(cfg *Config, defaults *Config) *Config {
if cfg.Web.Addr == "" {
cfg.Web.Addr = defaults.Web.Addr
}
if cfg.Web.ProtocolLogKeepDays == 0 {
cfg.Web.ProtocolLogKeepDays = defaults.Web.ProtocolLogKeepDays
}
if cfg.SMTP.Addr == "" {
cfg.SMTP.Addr = defaults.SMTP.Addr
}
+3
View File
@@ -36,5 +36,8 @@ const (
DefaultQuotaBytes int64 = 5 * 1024 * 1024 * 1024 // 5GB
)
// DefaultProtocolLogKeepDays 是 SMTP/IMAP/POP3 协议调用日志的默认保留天数。
const DefaultProtocolLogKeepDays = 30
// ConfigFileName is the name of the configuration file
const ConfigFileName = "mail_go.toml"