mirror of
https://github.com/mjl-/mox.git
synced 2025-07-14 19:34:36 +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:
@ -37,12 +37,12 @@ func testCondstoreQresync(t *testing.T, qresync bool) {
|
||||
tc.client.Login("mjl@mox.example", password0)
|
||||
tc.client.Enable(capability)
|
||||
tc.transactf("ok", "Select inbox")
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(1), More: "x"}})
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(2), More: "x"}})
|
||||
|
||||
// First some tests without any messages.
|
||||
|
||||
tc.transactf("ok", "Status inbox (Highestmodseq)")
|
||||
tc.xuntagged(imapclient.UntaggedStatus{Mailbox: "Inbox", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusHighestModSeq: 1}})
|
||||
tc.xuntagged(imapclient.UntaggedStatus{Mailbox: "Inbox", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusHighestModSeq: 2}})
|
||||
|
||||
// No messages, no matches.
|
||||
tc.transactf("ok", "Uid Fetch 1:* (Flags) (Changedsince 12345)")
|
||||
@ -111,12 +111,13 @@ func testCondstoreQresync(t *testing.T, qresync bool) {
|
||||
tc3.client.Enable(capability)
|
||||
tc3.client.Select("inbox")
|
||||
|
||||
var clientModseq int64 = 1 // We track the client-side modseq for inbox. Not a store.ModSeq.
|
||||
var clientModseq int64 = 2 // We track the client-side modseq for inbox. Not a store.ModSeq.
|
||||
|
||||
// Add messages to: inbox, otherbox, inbox, inbox.
|
||||
// We have these messages in order of modseq: 2+1 in inbox, 1 in otherbox, 2 in inbox.
|
||||
// The original two in inbox appear to have modseq 1 (with 0 stored in the database).
|
||||
// The ones we insert below will start with modseq 2. So we'll have modseq 1-5.
|
||||
// Creation of otherbox got modseq 2.
|
||||
// The ones we insert below will start with modseq 3. So we'll have messages with modseq 1 and 3-6.
|
||||
tc.transactf("ok", "Append inbox () \" 1-Jan-2022 10:10:00 +0100\" {1+}\r\nx")
|
||||
tc.xuntagged(imapclient.UntaggedExists(4))
|
||||
tc.xcodeArg(imapclient.CodeAppendUID{UIDValidity: 1, UID: 4})
|
||||
@ -154,23 +155,23 @@ func testCondstoreQresync(t *testing.T, qresync bool) {
|
||||
tc.transactf("bad", `Fetch 1 Flags (Changedsince 0)`) // 0 not allowed in syntax.
|
||||
mox.SetPedantic(false)
|
||||
tc.transactf("ok", "Uid fetch 1 (Flags) (Changedsince 0)")
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(clientModseq)}})
|
||||
|
||||
clientModseq += 4 // Four messages, over two mailboxes, modseq is per account.
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(1)}})
|
||||
|
||||
// Check highestmodseq for mailboxes.
|
||||
tc.transactf("ok", "Status inbox (highestmodseq)")
|
||||
tc.xuntagged(imapclient.UntaggedStatus{Mailbox: "Inbox", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusHighestModSeq: clientModseq}})
|
||||
tc.xuntagged(imapclient.UntaggedStatus{Mailbox: "Inbox", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusHighestModSeq: clientModseq + 4}})
|
||||
|
||||
tc.transactf("ok", "Status otherbox (highestmodseq)")
|
||||
tc.xuntagged(imapclient.UntaggedStatus{Mailbox: "otherbox", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusHighestModSeq: 3}})
|
||||
tc.xuntagged(imapclient.UntaggedStatus{Mailbox: "otherbox", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusHighestModSeq: clientModseq + 2}})
|
||||
|
||||
// Check highestmodseq when we select.
|
||||
tc.transactf("ok", "Examine otherbox")
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(3), More: "x"}})
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(clientModseq + 2), More: "x"}})
|
||||
|
||||
tc.transactf("ok", "Select inbox")
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(clientModseq), More: "x"}})
|
||||
tc.xuntaggedOpt(false, imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(clientModseq + 4), More: "x"}})
|
||||
|
||||
clientModseq += 4
|
||||
|
||||
// Check fetch modseq response and changedsince.
|
||||
tc.transactf("ok", `Fetch 1 (Modseq)`)
|
||||
@ -193,7 +194,7 @@ func testCondstoreQresync(t *testing.T, qresync bool) {
|
||||
tc.transactf("ok", `Fetch 1 Flags (Changedsince 1)`)
|
||||
tc.xuntagged()
|
||||
tc.transactf("ok", `Fetch 1,4 Flags (Changedsince 1)`)
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(4), noflags, imapclient.FetchModSeq(2)}})
|
||||
tc.xuntagged(imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(4), noflags, imapclient.FetchModSeq(3)}})
|
||||
tc.transactf("ok", `Fetch 2 Flags (Changedsince 2)`)
|
||||
tc.xuntagged()
|
||||
|
||||
@ -308,25 +309,25 @@ func testCondstoreQresync(t *testing.T, qresync bool) {
|
||||
|
||||
tc.transactf("ok", `Fetch 1:* (Modseq)`)
|
||||
tc.xuntagged(
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 2, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(2), imapclient.FetchModSeq(1)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), imapclient.FetchModSeq(6)}},
|
||||
)
|
||||
// Expunged messages, with higher modseq, should not show up.
|
||||
tc.transactf("ok", "Uid Fetch 1:* (flags) (Changedsince 7)")
|
||||
tc.transactf("ok", "Uid Fetch 1:* (flags) (Changedsince 8)")
|
||||
tc.xuntagged()
|
||||
|
||||
// search
|
||||
tc.transactf("ok", "Search Modseq 7")
|
||||
tc.xsearchmodseq(7, 1)
|
||||
tc.transactf("ok", "Search Modseq 8")
|
||||
tc.xsearchmodseq(8, 1)
|
||||
tc.transactf("ok", "Search Modseq 9")
|
||||
tc.xsearch()
|
||||
|
||||
// esearch
|
||||
tc.transactf("ok", "Search Return (Min Max All) 1:* Modseq 7")
|
||||
tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 1, All: esearchall0("1"), ModSeq: 7})
|
||||
tc.transactf("ok", "Search Return (Min Max All) 1:* Modseq 8")
|
||||
tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 1, All: esearchall0("1"), ModSeq: 8})
|
||||
tc.transactf("ok", "Search Return (Min Max All) 1:* Modseq 9")
|
||||
tc.xuntagged(imapclient.UntaggedEsearch{Correlator: tc.client.LastTag})
|
||||
|
||||
// store, cannot modify expunged messages.
|
||||
@ -543,8 +544,8 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
noflags := imapclient.FetchFlags(nil)
|
||||
tc.xuntagged(
|
||||
imapclient.UntaggedVanished{Earlier: true, UIDs: xparseNumSet("3:4")},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), noflags, imapclient.FetchModSeq(clientModseq)}},
|
||||
)
|
||||
|
||||
@ -596,8 +597,8 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedVanished{Earlier: true, UIDs: xparseNumSet("3:4")},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), noflags, imapclient.FetchModSeq(clientModseq)}},
|
||||
)...,
|
||||
)
|
||||
@ -613,8 +614,8 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedVanished{Earlier: true, UIDs: xparseNumSet("3:4")},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), noflags, imapclient.FetchModSeq(clientModseq)}},
|
||||
)...,
|
||||
)
|
||||
@ -624,8 +625,8 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
tc.transactf("ok", "Select inbox (Qresync (1 1 1,2,5:6))")
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), noflags, imapclient.FetchModSeq(clientModseq)}},
|
||||
)...,
|
||||
)
|
||||
@ -635,7 +636,7 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
tc.transactf("ok", "Select inbox (Qresync (1 1 5))")
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(5)}},
|
||||
)...,
|
||||
)
|
||||
|
||||
@ -667,8 +668,8 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedVanished{Earlier: true, UIDs: xparseNumSet("3:4")},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(4)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(5), noflags, imapclient.FetchModSeq(5)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), noflags, imapclient.FetchModSeq(clientModseq)}},
|
||||
)...,
|
||||
)
|
||||
@ -679,13 +680,13 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedVanished{Earlier: true, UIDs: xparseNumSet("3:4")},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(7)}},
|
||||
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), noflags, imapclient.FetchModSeq(8)}},
|
||||
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(6), noflags, imapclient.FetchModSeq(clientModseq)}},
|
||||
)...,
|
||||
)
|
||||
|
||||
tc.transactf("ok", "Close")
|
||||
tc.transactf("ok", "Select inbox (Qresync (1 8 (1,3,6 1,3,6)))")
|
||||
tc.transactf("ok", "Select inbox (Qresync (1 9 (1,3,6 1,3,6)))")
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedVanished{Earlier: true, UIDs: xparseNumSet("3:4")},
|
||||
@ -697,7 +698,7 @@ func testQresync(t *testing.T, tc *testconn, clientModseq int64) {
|
||||
// since that time. Server detects this, sends full vanished history and continues
|
||||
// working with modseq changed to 1 before the expunged uid.
|
||||
tc.transactf("ok", "Close")
|
||||
tc.transactf("ok", "Select inbox (Qresync (1 9 (1,3,6 1,3,6)))")
|
||||
tc.transactf("ok", "Select inbox (Qresync (1 10 (1,3,6 1,3,6)))")
|
||||
tc.xuntagged(
|
||||
makeUntagged(
|
||||
imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "ALERT", More: "Synchronization inconsistency in client detected. Client tried to sync with a UID that was removed at or after the MODSEQ it sent in the request. Sending all historic message removals for selected mailbox. Full synchronization recommended."}},
|
||||
|
@ -238,8 +238,9 @@ func (c *conn) cmdxFetch(isUID bool, tag, cmdstr string, p *parser) {
|
||||
}
|
||||
|
||||
var zeromc store.MailboxCounts
|
||||
if cmd.deltaCounts != zeromc {
|
||||
if cmd.deltaCounts != zeromc || cmd.modseq != 0 {
|
||||
mb.Add(cmd.deltaCounts) // Unseen/Unread will be <= 0.
|
||||
mb.ModSeq = cmd.modseq
|
||||
err := tx.Update(&mb)
|
||||
xcheckf(err, "updating mailbox counts")
|
||||
cmd.changes = append(cmd.changes, mb.ChangeCounts())
|
||||
|
@ -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)
|
||||
|
@ -674,19 +674,6 @@ func (c *conn) xreadliteral(size int64, sync bool) []byte {
|
||||
return buf
|
||||
}
|
||||
|
||||
func (c *conn) xhighestModSeq(tx *bstore.Tx, mailboxID int64) store.ModSeq {
|
||||
qms := bstore.QueryTx[store.Message](tx)
|
||||
qms.FilterNonzero(store.Message{MailboxID: mailboxID})
|
||||
qms.SortDesc("ModSeq")
|
||||
qms.Limit(1)
|
||||
m, err := qms.Get()
|
||||
if err == bstore.ErrAbsent {
|
||||
return store.ModSeq(0)
|
||||
}
|
||||
xcheckf(err, "looking up highest modseq for mailbox")
|
||||
return m.ModSeq
|
||||
}
|
||||
|
||||
var cleanClose struct{} // Sentinel value for panic/recover indicating clean close of connection.
|
||||
|
||||
// serve handles a single IMAP connection on nc.
|
||||
@ -2461,15 +2448,16 @@ func (c *conn) xensureCondstore(tx *bstore.Tx) {
|
||||
if c.mailboxID <= 0 {
|
||||
return
|
||||
}
|
||||
var modseq store.ModSeq
|
||||
if tx != nil {
|
||||
modseq = c.xhighestModSeq(tx, c.mailboxID)
|
||||
} else {
|
||||
|
||||
var mb store.Mailbox
|
||||
if tx == nil {
|
||||
c.xdbread(func(tx *bstore.Tx) {
|
||||
modseq = c.xhighestModSeq(tx, c.mailboxID)
|
||||
mb = c.xmailboxID(tx, c.mailboxID)
|
||||
})
|
||||
} else {
|
||||
mb = c.xmailboxID(tx, c.mailboxID)
|
||||
}
|
||||
c.bwritelinef("* OK [HIGHESTMODSEQ %d] after condstore-enabling command", modseq.Client())
|
||||
c.bwritelinef("* OK [HIGHESTMODSEQ %d] after condstore-enabling command", mb.ModSeq.Client())
|
||||
}
|
||||
}
|
||||
|
||||
@ -2591,7 +2579,7 @@ func (c *conn) cmdSelectExamine(isselect bool, tag, cmd string, p *parser) {
|
||||
|
||||
// Condstore extension, find the highest modseq.
|
||||
if c.enabled[capCondstore] {
|
||||
highestModSeq = c.xhighestModSeq(tx, mb.ID)
|
||||
highestModSeq = mb.ModSeq
|
||||
}
|
||||
// For QRESYNC, we need to know the highest modset of deleted expunged records to
|
||||
// maintain synchronization.
|
||||
@ -2935,6 +2923,8 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) {
|
||||
c.xdbwrite(func(tx *bstore.Tx) {
|
||||
srcMB := c.xmailbox(tx, src, "NONEXISTENT")
|
||||
|
||||
var modseq store.ModSeq
|
||||
|
||||
// Inbox is very special. Unlike other mailboxes, its children are not moved. And
|
||||
// unlike a regular move, its messages are moved to a newly created mailbox. We do
|
||||
// indeed create a new destination mailbox and actually move the messages.
|
||||
@ -2952,19 +2942,21 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) {
|
||||
uidval, err := c.account.NextUIDValidity(tx)
|
||||
xcheckf(err, "next uid validity")
|
||||
|
||||
modseq, err = c.account.NextModSeq(tx)
|
||||
xcheckf(err, "assigning next modseq")
|
||||
|
||||
dstMB := store.Mailbox{
|
||||
Name: dst,
|
||||
UIDValidity: uidval,
|
||||
UIDNext: 1,
|
||||
Keywords: srcMB.Keywords,
|
||||
ModSeq: modseq,
|
||||
CreateSeq: modseq,
|
||||
HaveCounts: true,
|
||||
}
|
||||
err = tx.Insert(&dstMB)
|
||||
xcheckf(err, "create new destination mailbox")
|
||||
|
||||
modseq, err := c.account.NextModSeq(tx)
|
||||
xcheckf(err, "assigning next modseq")
|
||||
|
||||
changes = make([]store.Change, 2) // Placeholders filled in below.
|
||||
|
||||
// Move existing messages, with their ID's and on-disk files intact, to the new
|
||||
@ -3007,6 +2999,7 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) {
|
||||
err = tx.Update(&dstMB)
|
||||
xcheckf(err, "updating uidnext and counts in destination mailbox")
|
||||
|
||||
srcMB.ModSeq = modseq
|
||||
err = tx.Update(&srcMB)
|
||||
xcheckf(err, "updating counts for inbox")
|
||||
|
||||
@ -3021,12 +3014,14 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) {
|
||||
for i := range annotations {
|
||||
annotations[i].ID = 0
|
||||
annotations[i].MailboxID = dstMB.ID
|
||||
annotations[i].ModSeq = modseq
|
||||
annotations[i].CreateSeq = modseq
|
||||
err := tx.Insert(&annotations[i])
|
||||
xcheckf(err, "copy annotation to destination mailbox")
|
||||
}
|
||||
|
||||
changes[0] = store.ChangeRemoveUIDs{MailboxID: srcMB.ID, UIDs: oldUIDs, ModSeq: modseq}
|
||||
changes[1] = store.ChangeAddMailbox{Mailbox: dstMB, Flags: dstFlags}
|
||||
changes[1] = store.ChangeAddMailbox{Mailbox: dstMB, Flags: dstFlags, ModSeq: modseq}
|
||||
// changes[2:...] are ChangeAddUIDs
|
||||
changes = append(changes, srcMB.ChangeCounts(), dstMB.ChangeCounts())
|
||||
for _, a := range annotations {
|
||||
@ -3038,7 +3033,7 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) {
|
||||
|
||||
var notExists, alreadyExists bool
|
||||
var err error
|
||||
changes, _, notExists, alreadyExists, err = c.account.MailboxRename(tx, srcMB, dst)
|
||||
changes, _, notExists, alreadyExists, err = c.account.MailboxRename(tx, srcMB, dst, &modseq)
|
||||
if notExists {
|
||||
// ../rfc/9051:5140
|
||||
xusercodeErrorf("NONEXISTENT", "%s", err)
|
||||
@ -3265,7 +3260,7 @@ func (c *conn) xstatusLine(tx *bstore.Tx, mb store.Mailbox, attrs []string) stri
|
||||
status = append(status, A, "NIL")
|
||||
case "HIGHESTMODSEQ":
|
||||
// ../rfc/7162:366
|
||||
status = append(status, A, fmt.Sprintf("%d", c.xhighestModSeq(tx, mb.ID).Client()))
|
||||
status = append(status, A, fmt.Sprintf("%d", mb.ModSeq.Client()))
|
||||
case "DELETED-STORAGE":
|
||||
// ../rfc/9208:394
|
||||
// How much storage space could be reclaimed by expunging messages with the
|
||||
@ -3660,7 +3655,7 @@ func (c *conn) xexpunge(uidSet *numSet, missingMailboxOK bool) (remove []store.M
|
||||
xcheckf(err, "listing messages to delete")
|
||||
|
||||
if len(remove) == 0 {
|
||||
highestModSeq = c.xhighestModSeq(tx, c.mailboxID)
|
||||
highestModSeq = mb.ModSeq
|
||||
return
|
||||
}
|
||||
|
||||
@ -3668,6 +3663,7 @@ func (c *conn) xexpunge(uidSet *numSet, missingMailboxOK bool) (remove []store.M
|
||||
modseq, err = c.account.NextModSeq(tx)
|
||||
xcheckf(err, "assigning next modseq")
|
||||
highestModSeq = modseq
|
||||
mb.ModSeq = modseq
|
||||
|
||||
removeIDs := make([]int64, len(remove))
|
||||
anyIDs := make([]any, len(remove))
|
||||
@ -3944,6 +3940,11 @@ func (c *conn) cmdxCopy(isUID bool, tag, cmd string, p *parser) {
|
||||
var err error
|
||||
modseq, err = c.account.NextModSeq(tx)
|
||||
xcheckf(err, "assigning next modseq")
|
||||
mbSrc.ModSeq = modseq
|
||||
mbDst.ModSeq = modseq
|
||||
|
||||
err = tx.Update(&mbSrc)
|
||||
xcheckf(err, "updating source mailbox for modseq")
|
||||
|
||||
// Reserve the uids in the destination mailbox.
|
||||
uidFirst := mbDst.UIDNext
|
||||
@ -4133,6 +4134,8 @@ func (c *conn) cmdxMove(isUID bool, tag, cmd string, p *parser) {
|
||||
var err error
|
||||
modseq, err = c.account.NextModSeq(tx)
|
||||
xcheckf(err, "assigning next modseq")
|
||||
mbSrc.ModSeq = modseq
|
||||
mbDst.ModSeq = modseq
|
||||
|
||||
// Update existing record with new UID and MailboxID in database for messages. We
|
||||
// add a new but expunged record again in the original/source mailbox, for qresync.
|
||||
@ -4202,7 +4205,7 @@ func (c *conn) cmdxMove(isUID bool, tag, cmd string, p *parser) {
|
||||
}
|
||||
|
||||
err = tx.Update(&mbSrc)
|
||||
xcheckf(err, "updating source mailbox counts")
|
||||
xcheckf(err, "updating source mailbox counts and modseq")
|
||||
|
||||
err = tx.Update(&mbDst)
|
||||
xcheckf(err, "updating destination mailbox for uids, keywords and counts")
|
||||
@ -4416,7 +4419,8 @@ func (c *conn) cmdxStore(isUID bool, tag, cmd string, p *parser) {
|
||||
})
|
||||
xcheckf(err, "storing flags in messages")
|
||||
|
||||
if mb.MailboxCounts != origmb.MailboxCounts {
|
||||
if mb.MailboxCounts != origmb.MailboxCounts || modseq != 0 {
|
||||
mb.ModSeq = modseq
|
||||
err := tx.Update(&mb)
|
||||
xcheckf(err, "updating mailbox counts")
|
||||
|
||||
|
Reference in New Issue
Block a user