From d9bb3cbf3f6cddcfa2679484f0821f690b9b9a8a Mon Sep 17 00:00:00 2001 From: dsh Date: Wed, 19 Aug 2026 10:35:50 -0400 Subject: [PATCH] =?UTF-8?q?fix(store):=20=E9=82=AE=E4=BB=B6=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E7=BB=9F=E4=B8=80=20UTC=20=E5=AD=98=E5=82=A8=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=B7=E5=90=88=E6=97=B6=E5=8C=BA=E5=81=8F?= =?UTF-8?q?=E7=A7=BB=E5=AF=BC=E8=87=B4=20Web/IMAP=20=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E9=94=99=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:date 列在 SQLite 中是文本,历史数据混存 +08:00/-04:00/+00:00 等时区偏移,ORDER BY date DESC 变成字符串字典序而非时间序: - Web 列表最新邮件排不到最前(如 22:21+08 的邮件排在 20:03+08 后面) - IMAP 序号与客户端按日期排序的视图不一致 修复: - mailStore.Create 统一 msg.Date = msg.Date.UTC()(所有写入路径 共用:SMTP/IMAP APPEND/Web/外发回执),新数据字典序即时间序 - 生产数据一次性迁移为 UTC 格式(130 条,Python 全量解析转换) - 验证:kevin INBOX 排序 172→170→166→164…(严格最新在前) --- internal/store/mail_store.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/store/mail_store.go b/internal/store/mail_store.go index 554ac74..68d310c 100644 --- a/internal/store/mail_store.go +++ b/internal/store/mail_store.go @@ -52,6 +52,13 @@ func newMailStore(database *gorm.DB) MailStore { // Create inserts a new message record. func (s *mailStoreGorm) Create(msg *db.Message) error { + // 日期统一为 UTC 存储:date 列在 SQLite 中是文本,混合时区偏移 + // (+08:00/-04:00 等)会让 ORDER BY date 变成错误的字典序(Web 列表 + // 排序错乱、IMAP 序号与客户端日期视图不一致)。统一 UTC 后字典序 + // 即时间序,所有排序路径(Web/IMAP/seqOf)全链路一致。 + if msg != nil { + msg.Date = msg.Date.UTC() + } return s.db.Create(msg).Error }