update modseq when changing mailbox/server metadata, and also for specialuse changes, and keep track of modseq for mailboxes

i added the metadata extension to the imapserver recently. then i wondered how
a client would efficiently find changed metadata. turns out the qresync rfc
mentions that metadata changes should set a new modseq on the mailbox.
shouldn't be hard, except that we were not explicitly keeping track of modseqs
per mailbox. we only kept them for messages, and we were just looking up the
latest message modseq when we needed the modseq (we keep db entries for
expunged messages, so this worked out fine). that approach isn't enough
anymore. so know we keep track of modseq & createseq for mailboxes, just as for
messages. and we also track modseq/createseq for annotations. there's a good
chance jmap is going to need it.

this also adds consistency checks for modseq/createseq on mailboxes and
annotations to the account storage. it helped spot cases i missed where the
values need to be updated.
This commit is contained in:
Mechiel Lukkien
2025-02-22 22:44:15 +01:00
parent 7c7473ef0e
commit 9f3cb7340b
19 changed files with 443 additions and 174 deletions

View File

@ -3404,7 +3404,7 @@ open, or is not running.
// Reassign UIDs, going per mailbox. We assign starting at 1, only changing the
// message if it isn't already at the intended UID. Doing it in this order ensures
// we don't get into trouble with duplicate UIDs for a mailbox. We assign a new
// modseq. Not strictly needed, for doesn't hurt.
// modseq. Not strictly needed, but doesn't hurt.
modseq, err := a.NextModSeq(tx)
xcheckf(err, "assigning next modseq")
@ -3429,7 +3429,7 @@ open, or is not running.
return fmt.Errorf("reading through messages: %v", err)
}
// Now update the uidnext and uidvalidity for each mailbox.
// Now update the uidnext, uidvalidity and modseq for each mailbox.
err = bstore.QueryTx[store.Mailbox](tx).ForEach(func(mb store.Mailbox) error {
// Assign each mailbox a completely new uidvalidity.
uidvalidity, err := a.NextUIDValidity(tx)
@ -3449,6 +3449,7 @@ open, or is not running.
mb.UIDValidity = uidvalidity
}
mb.UIDNext = uidlasts[mb.ID] + 1
mb.ModSeq = modseq
if err := tx.Update(&mb); err != nil {
return fmt.Errorf("updating uidvalidity and uidnext for mailbox: %v", err)
}