mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 18:24:35 +03:00
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:
@ -232,6 +232,7 @@ func (c *conn) cmdSetmetadata(tag, cmd string, p *parser) {
|
||||
// Store the annotations, possibly removing/inserting/updating them.
|
||||
c.account.WithWLock(func() {
|
||||
var changes []store.Change
|
||||
var modseq store.ModSeq
|
||||
|
||||
c.xdbwrite(func(tx *bstore.Tx) {
|
||||
var mb store.Mailbox // mb.ID as 0 is used in query below.
|
||||
@ -256,7 +257,15 @@ func (c *conn) cmdSetmetadata(tag, cmd string, p *parser) {
|
||||
continue
|
||||
}
|
||||
|
||||
if modseq == 0 {
|
||||
var err error
|
||||
modseq, err = c.account.NextModSeq(tx)
|
||||
xcheckf(err, "get next modseq")
|
||||
}
|
||||
|
||||
a.MailboxID = mb.ID
|
||||
a.ModSeq = modseq
|
||||
a.CreateSeq = modseq
|
||||
|
||||
oa, err := q.Get()
|
||||
if err == bstore.ErrAbsent {
|
||||
@ -266,9 +275,7 @@ func (c *conn) cmdSetmetadata(tag, cmd string, p *parser) {
|
||||
continue
|
||||
}
|
||||
xcheckf(err, "looking up existing annotation for entry name")
|
||||
if oa.IsString != a.IsString || (oa.Value == nil) != (a.Value == nil) || !bytes.Equal(oa.Value, a.Value) {
|
||||
changes = append(changes, a.Change(mailboxName))
|
||||
}
|
||||
changes = append(changes, a.Change(mailboxName))
|
||||
oa.Value = a.Value
|
||||
err = tx.Update(&oa)
|
||||
xcheckf(err, "updating metadata annotation")
|
||||
@ -293,6 +300,13 @@ func (c *conn) cmdSetmetadata(tag, cmd string, p *parser) {
|
||||
return nil
|
||||
})
|
||||
xcheckf(err, "checking metadata annotation size")
|
||||
|
||||
// ../rfc/7162:1335
|
||||
if mb.ID != 0 && modseq != 0 {
|
||||
mb.ModSeq = modseq
|
||||
err := tx.Update(&mb)
|
||||
xcheckf(err, "updating mailbox with modseq")
|
||||
}
|
||||
})
|
||||
|
||||
c.broadcast(changes)
|
||||
|
Reference in New Issue
Block a user