mirror of
https://github.com/mjl-/mox.git
synced 2025-07-13 05:34:38 +03:00
Improve expunged message/UID tracking in IMAP sessions, track synchronization history for mailboxes/annotations.
Keeping the message files around, and the message details in the database, is useful for IMAP sessions that haven't seen/processed the removal of a message yet and try to fetch it. Before, we would return errors. Similarly, a session that has a mailbox selected that is removed can (at least in theory) still read messages. The mechanics to do this need keeping removed mailboxes around too. JMAP needs that anyway, so we now keep modseq/createseq/expunged history for mailboxes too. And while we're at it, for annotations as well. For future JMAP support, we now also keep the mailbox parent id around for a mailbox, with an upgrade step to set the field for existing mailboxes and fixing up potential missing parents (which could possibly have happened in an obscure corner case that I doubt anyone ran into).
This commit is contained in:
8
main.go
8
main.go
@ -3340,6 +3340,7 @@ open, or is not running.
|
||||
}
|
||||
|
||||
q := bstore.QueryTx[store.Mailbox](tx)
|
||||
q.FilterEqual("Expunged", false)
|
||||
if len(args) == 2 {
|
||||
q.FilterEqual("Name", args[1])
|
||||
}
|
||||
@ -3398,7 +3399,8 @@ 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, but doesn't hurt.
|
||||
// modseq. Not strictly needed, but doesn't hurt. It's also why we assign a UID to
|
||||
// expunged messages.
|
||||
modseq, err := a.NextModSeq(tx)
|
||||
xcheckf(err, "assigning next modseq")
|
||||
|
||||
@ -3424,7 +3426,7 @@ open, or is not running.
|
||||
}
|
||||
|
||||
// Now update the uidnext, uidvalidity and modseq for each mailbox.
|
||||
err = bstore.QueryTx[store.Mailbox](tx).ForEach(func(mb store.Mailbox) error {
|
||||
err = bstore.QueryTx[store.Mailbox](tx).FilterEqual("Expunged", false).ForEach(func(mb store.Mailbox) error {
|
||||
// Assign each mailbox a completely new uidvalidity.
|
||||
uidvalidity, err := a.NextUIDValidity(tx)
|
||||
if err != nil {
|
||||
@ -3491,7 +3493,7 @@ open, or is not running.
|
||||
err = a.DB.Write(context.Background(), func(tx *bstore.Tx) error {
|
||||
// We look at each mailbox, retrieve its max UID and compare against the mailbox
|
||||
// UIDNEXT.
|
||||
err := bstore.QueryTx[store.Mailbox](tx).ForEach(func(mb store.Mailbox) error {
|
||||
err := bstore.QueryTx[store.Mailbox](tx).FilterEqual("Expunged", false).ForEach(func(mb store.Mailbox) error {
|
||||
if mb.UIDValidity > maxUIDValidity {
|
||||
maxUIDValidity = mb.UIDValidity
|
||||
}
|
||||
|
Reference in New Issue
Block a user