feat(mailbox): 文件夹数据驱动,Web 通过 IMAP 共享服务层操作邮箱
- 新增 mailboxes 表与 MailboxStore(系统文件夹幂等创建,自定义文件夹 CRUD) - 提取 MailboxService:IMAP 会话与 Web handler 共用,LIST 返回什么 Web 就显示什么 - IMAP 支持 CREATE/DELETE/RENAME/SUBSCRIBE(系统文件夹禁删改、非空禁删) - Web 删除改为 IMAP 语义:移入 Trash,新增恢复/彻底删除/清空 - 新增通用 /folder/:name 页面与动态侧边栏,/inbox /sent /drafts 保留兼容重定向
This commit is contained in:
22 files changed
+1440
-639
No files matched your search
+1
-1
@@ -56,7 +56,7 @@ func InitDB(cfg config.DatabaseConfig, storageCfg config.StorageConfig) (*gorm.D
|
||||
}
|
||||
|
||||
// Auto-migrate all models
|
||||
if err := db.AutoMigrate(&User{}, &Domain{}, &Message{}, &Attachment{}, &BanEntry{}, &OutboundMessage{}, &ProtocolLog{}, &MailboxState{}); err != nil {
|
||||
if err := db.AutoMigrate(&User{}, &Domain{}, &Message{}, &Attachment{}, &BanEntry{}, &OutboundMessage{}, &ProtocolLog{}, &MailboxState{}, &Mailbox{}); err != nil {
|
||||
return nil, fmt.Errorf("数据库迁移失败: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,39 @@ func (Attachment) TableName() string {
|
||||
return "attachments"
|
||||
}
|
||||
|
||||
// SystemMailbox 定义一个系统预置文件夹(RFC 6154 SPECIAL-USE 角色)。
|
||||
type SystemMailbox struct {
|
||||
Name string // 规范名(INBOX 大小写不敏感)
|
||||
SpecialUse string // Sent / Drafts / Trash;INBOX 为 ""
|
||||
}
|
||||
|
||||
// SystemMailboxes 是系统预置文件夹清单:IMAP LIST 与 Web 侧边栏
|
||||
// 共用此定义,保证「IMAP 返回什么,Web 就显示什么」。
|
||||
var SystemMailboxes = []SystemMailbox{
|
||||
{Name: "INBOX", SpecialUse: ""},
|
||||
{Name: "Sent", SpecialUse: "Sent"},
|
||||
{Name: "Drafts", SpecialUse: "Drafts"},
|
||||
{Name: "Trash", SpecialUse: "Trash"},
|
||||
}
|
||||
|
||||
// Mailbox 表示一个用户文件夹(IMAP mailbox / Web 侧边栏条目)。
|
||||
// 系统文件夹在首次访问时由 MailboxStore.EnsureSystem 幂等创建;
|
||||
// 自定义文件夹经 IMAP CREATE 创建。
|
||||
type Mailbox struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
UserID uint `gorm:"uniqueIndex:idx_mailbox_user_name;not null" json:"user_id"`
|
||||
Name string `gorm:"size:64;uniqueIndex:idx_mailbox_user_name;not null" json:"name"`
|
||||
SpecialUse string `gorm:"size:16" json:"special_use"` // 自定义文件夹为空
|
||||
IsSubscribed bool `gorm:"default:true" json:"is_subscribed"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName specifies the table name for Mailbox.
|
||||
func (Mailbox) TableName() string {
|
||||
return "mailboxes"
|
||||
}
|
||||
|
||||
// MailboxState 记录每个邮箱(用户+文件夹)的持久化 IMAP 状态。
|
||||
// UidValidity 在首次访问时随机生成并持久化:数据库重建(消息 ID 空间
|
||||
// 变化)后该值随之改变,客户端(Thunderbird 等)会据此丢弃本地缓存
|
||||
|
||||
Reference in New Issue
Block a user