fix(imap): 序号按到达顺序(id ASC)分配,INTERNALDATE 使用到达时间

- ListAllByUserAndFolder 由 date DESC 改为 id ASC:新邮件永远追加到末尾
  (seq = EXISTS 数),与 Dovecot/Courier 一致;带旧 Date 头的新邮件不再
  插入中间导致既有邮件序号位移,seq 增量同步客户端不会漏收/标错
- INTERNALDATE 改用 CreatedAt(服务器接收时间, RFC 3501 §2.3.4),
  零值降级用 Date 头;不再返回可被伪造的 Date 头
- Web 分页排序补 id DESC tiebreak,与 IMAP 全链路一致
- ListDeletedByUserAndFolder 同步改为 id ASC
- 测试:TestSeqStoreClientSelfNumbered 替换为 TestSeqOrderArrival,
  断言到达顺序序号映射、旧 Date 头新邮件落在末尾、INTERNALDATE=CreatedAt
This commit is contained in:
2026-08-20 15:18:55 +08:00
parent cca7e4f092
commit 17d8dc1567
3 changed files with 65 additions and 25 deletions
+7 -1
View File
@@ -497,7 +497,13 @@ func (s *imapSession) Fetch(w *imapserver.FetchWriter, numSet imap.NumSet, optio
fw.WriteRFC822Size(int64(len(raw)))
}
if options.InternalDate {
fw.WriteInternalDate(msg.Date)
// INTERNALDATE 是服务器接收时间(RFC 3501 §2.3.4),不是 Date
// 头;使用 CreatedAt(到达时间),旧数据为零时降级为 Date。
arrival := msg.CreatedAt
if arrival.IsZero() {
arrival = msg.Date
}
fw.WriteInternalDate(arrival)
}
if options.Envelope {
var env *imap.Envelope