feat(imap): 新邮件实时推送(IDLE)+ 后台当前连接监控
- IMAP 推送:imapBackend 实现 backend.BackendUpdater,SMTP 本地投递 与 Web 写信投递成功后 NotifyNewMessage,挂起 IDLE 的客户端即时收到 新邮件 FETCH 通知(按用户名+INBOX 过滤广播,通道满非阻塞丢弃) - 当前连接:新增 internal/connhub 连接注册中心,SMTP/IMAP/POP3 三协议 注册/注销/用户名/TLS/活跃时间追踪;后台新增「当前连接」页 (/admin/connections,统计卡片+连接表格,每 5 秒自动刷新) - 新增测试:connhub 并发安全、推送内容/非阻塞/nil 安全、 后台页面渲染;全量 -race 通过
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"mail_go/internal/caddycert"
|
||||
"mail_go/internal/connhub"
|
||||
"mail_go/internal/db"
|
||||
"mail_go/internal/dkim"
|
||||
"mail_go/internal/outbound"
|
||||
@@ -32,12 +33,38 @@ type AdminHandler struct {
|
||||
outbound *outbound.Manager
|
||||
// protocolLogKeepDays SMTP/IMAP/POP3 协议日志保留天数(配置文件 [web])
|
||||
protocolLogKeepDays int
|
||||
// hub 当前协议连接注册中心(「当前连接」页)
|
||||
hub *connhub.Hub
|
||||
}
|
||||
|
||||
// NewAdminHandler creates a new AdminHandler with the given stores, attachment
|
||||
// storage, TLS directory, Caddy data directory and outbound delivery manager.
|
||||
func NewAdminHandler(stores *store.Stores, attStorage *storage.AttachmentStorage, tlsDir string, caddyDataDir string, ob *outbound.Manager, protocolLogKeepDays int) *AdminHandler {
|
||||
return &AdminHandler{stores: stores, storage: attStorage, tlsDir: tlsDir, caddyDataDir: caddyDataDir, outbound: ob, protocolLogKeepDays: protocolLogKeepDays}
|
||||
func NewAdminHandler(stores *store.Stores, attStorage *storage.AttachmentStorage, tlsDir string, caddyDataDir string, ob *outbound.Manager, protocolLogKeepDays int, hub *connhub.Hub) *AdminHandler {
|
||||
return &AdminHandler{stores: stores, storage: attStorage, tlsDir: tlsDir, caddyDataDir: caddyDataDir, outbound: ob, protocolLogKeepDays: protocolLogKeepDays, hub: hub}
|
||||
}
|
||||
|
||||
// ListConnections 渲染当前协议连接页面(SMTP/IMAP/POP3 实时连接)。
|
||||
func (h *AdminHandler) ListConnections(c *gin.Context) {
|
||||
conns := h.hub.List()
|
||||
counts := h.hub.Counts()
|
||||
|
||||
total := len(conns)
|
||||
smtpCount := counts["smtp"]
|
||||
imapCount := counts["imap"]
|
||||
pop3Count := counts["pop3"]
|
||||
|
||||
currentUser, _ := c.Get("currentUser")
|
||||
|
||||
c.HTML(200, "admin_connections", gin.H{
|
||||
"currentUser": currentUser,
|
||||
"conns": conns,
|
||||
"total": total,
|
||||
"smtpCount": smtpCount,
|
||||
"imapCount": imapCount,
|
||||
"pop3Count": pop3Count,
|
||||
"now": time.Now(),
|
||||
"activeFolder": "connections",
|
||||
})
|
||||
}
|
||||
|
||||
// Dashboard renders the admin dashboard with summary statistics.
|
||||
|
||||
Reference in New Issue
Block a user