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:
2026-08-19 19:40:05 +08:00
parent b158b8f1f5
commit ede85e0698
27 changed files with 783 additions and 53 deletions
+9 -2
View File
@@ -13,6 +13,7 @@ import (
"mail_go/internal/db"
"mail_go/internal/outbound"
"mail_go/internal/smtp_server"
"mail_go/internal/storage"
"mail_go/internal/store"
@@ -49,12 +50,14 @@ type MailHandler struct {
stores *store.Stores
storage *storage.AttachmentStorage
outbound *outbound.Manager
// notify 本地投递成功通知(IMAP 新邮件推送),可空
notify smtp_server.NewMailNotify
}
// NewMailHandler creates a new MailHandler with the given stores, attachment
// storage and outbound delivery manager.
func NewMailHandler(stores *store.Stores, attStorage *storage.AttachmentStorage, ob *outbound.Manager) *MailHandler {
return &MailHandler{stores: stores, storage: attStorage, outbound: ob}
func NewMailHandler(stores *store.Stores, attStorage *storage.AttachmentStorage, ob *outbound.Manager, notify smtp_server.NewMailNotify) *MailHandler {
return &MailHandler{stores: stores, storage: attStorage, outbound: ob, notify: notify}
}
// folderCounts returns sidebar badge counts for the current user.
@@ -382,6 +385,10 @@ func (h *MailHandler) DoSend(c *gin.Context) {
})
return
}
// 本地投递成功 → IMAP 新邮件推送(IDLE 客户端实时收到通知)
if h.notify != nil {
h.notify(rcptUser.Username+"@"+rcptUser.Domain.Name, inboxMsg)
}
}
// Save to Sent folder