根因:Status() 硬编码 UidValidity=1。数据库重建后消息 ID 空间 完全变化(uid 2-166 对应完全不同的邮件),但 UIDVALIDITY 不变, Thunderbird 认为本地缓存(旧 uid 1-166)仍然有效,只下载"新增" (uid 167:*)与"缺失"(2,4,8,9)的少数邮件——列表只剩 1-3 封, 每次刷新数量随机。 修复(RFC 3501 UIDVALIDITY 语义):新增 mailbox_states 表, 每(用户,文件夹)首次访问随机生成并持久化 UIDVALIDITY;数据库 重建后新值触发客户端丢弃缓存全量重同步。0 值修正,不同用户/ 文件夹互相独立。 新增 TestMailboxStateUidValidity 单元测试。
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package store
|
|
|
|
import (
|
|
"mail_go/internal/db"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Stores aggregates all store interfaces for convenient access.
|
|
type Stores struct {
|
|
Users UserStore
|
|
Mails MailStore
|
|
Domains DomainStore
|
|
Attachments AttachmentStore
|
|
Bans BanStore
|
|
Outbound OutboundStore
|
|
ProtocolLogs ProtocolLogStore
|
|
MailboxState MailboxStateStore
|
|
}
|
|
|
|
// NewStores creates a new Stores instance with all GORM-backed implementations.
|
|
func NewStores(database *gorm.DB) *Stores {
|
|
return &Stores{
|
|
Users: newUserStore(database),
|
|
Mails: newMailStore(database),
|
|
Domains: newDomainStore(database),
|
|
Attachments: newAttachmentStore(database),
|
|
Bans: newBanStore(database),
|
|
Outbound: newOutboundStore(database),
|
|
ProtocolLogs: newProtocolLogStore(database),
|
|
MailboxState: newMailboxStateStore(database),
|
|
}
|
|
}
|
|
|
|
// Ensure models are referenced (prevents unused import errors).
|
|
var _ = db.User{}
|
|
var _ = db.Domain{}
|
|
var _ = db.Message{}
|
|
var _ = db.Attachment{}
|
|
var _ = db.BanEntry{}
|
|
var _ = db.ProtocolLog{}
|
|
var _ = db.MailboxState{}
|