Skip to content

Commit

Permalink
in "mox uidbumpvalidity", bump to the next uidvalidity, otherwise we …
Browse files Browse the repository at this point in the history
…likely leave the uidvalidities in inconsistent state

the inconsistent state isn't really harmful, but we don't want inconsistencies.

pointed out in issue #61 by x8x
  • Loading branch information
mjl- committed Sep 23, 2023
1 parent 85cef2a commit 0707f53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ Change the IMAP UID validity of the mailbox, causing IMAP clients to refetch mes
This can be useful after manually repairing metadata about the account/mailbox.
Opens account database file directly. Ensure mox does not have the account
+open, or is not running.
open, or is not running.
usage: mox bumpuidvalidity account [mailbox]
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ func cmdBumpUIDValidity(c *cmd) {
This can be useful after manually repairing metadata about the account/mailbox.
Opens account database file directly. Ensure mox does not have the account
+open, or is not running.
open, or is not running.
`
args := c.Parse()
if len(args) != 1 && len(args) != 2 {
Expand All @@ -2118,8 +2118,12 @@ Opens account database file directly. Ensure mox does not have the account
}
}()

var uidvalidity uint32
err = a.DB.Write(context.Background(), func(tx *bstore.Tx) error {
uidvalidity, err := a.NextUIDValidity(tx)
if err != nil {
return fmt.Errorf("assigning next uid validity: %v", err)
}

q := bstore.QueryTx[store.Mailbox](tx)
if len(args) == 2 {
q.FilterEqual("Name", args[1])
Expand All @@ -2132,8 +2136,7 @@ Opens account database file directly. Ensure mox does not have the account
return fmt.Errorf("looking up mailbox %q, found %d mailboxes", args[1], len(mbl))
}
for _, mb := range mbl {
mb.UIDValidity++
uidvalidity = mb.UIDValidity
mb.UIDValidity = uidvalidity
err = tx.Update(&mb)
if err != nil {
return fmt.Errorf("updating uid validity for mailbox: %v", err)
Expand Down

0 comments on commit 0707f53

Please sign in to comment.