mirror of
https://github.com/mjl-/mox.git
synced 2025-07-19 00:46:36 +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:
22
backup.go
22
backup.go
@ -532,8 +532,7 @@ func backupctl(ctx context.Context, ctl *ctl) {
|
||||
}
|
||||
}()
|
||||
|
||||
// Link/copy known message files. If a message has been removed while we read the
|
||||
// database, our backup is not consistent and the backup will be marked failed.
|
||||
// Link/copy known message files.
|
||||
tmMsgs := time.Now()
|
||||
seen := map[string]struct{}{}
|
||||
var maxID int64
|
||||
@ -565,6 +564,15 @@ func backupctl(ctx context.Context, ctl *ctl) {
|
||||
slog.Duration("duration", time.Since(tmMsgs)))
|
||||
}
|
||||
|
||||
eraseIDs := map[int64]struct{}{}
|
||||
err = bstore.QueryDB[store.MessageErase](ctx, db).ForEach(func(me store.MessageErase) error {
|
||||
eraseIDs[me.ID] = struct{}{}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
xerrx("listing erased messages", err)
|
||||
}
|
||||
|
||||
// Read through all files in queue directory and warn about anything we haven't
|
||||
// handled yet. Message files that are newer than we expect from our consistent
|
||||
// database snapshot are ignored.
|
||||
@ -586,9 +594,13 @@ func backupctl(ctx context.Context, ctl *ctl) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip any messages that were added since we started on our consistent snapshot.
|
||||
// We don't want to cause spurious backup warnings.
|
||||
if id, err := strconv.ParseInt(l[len(l)-1], 10, 64); err == nil && id > maxID && mp == store.MessagePath(id) {
|
||||
// Skip any messages that were added since we started on our consistent snapshot,
|
||||
// or messages that will be erased. We don't want to cause spurious backup
|
||||
// warnings.
|
||||
id, err := strconv.ParseInt(l[len(l)-1], 10, 64)
|
||||
if err == nil && id > maxID && mp == store.MessagePath(id) {
|
||||
return nil
|
||||
} else if _, ok := eraseIDs[id]; err == nil && ok {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user