make "mailbox" parameter to unlisted command "bumpuidvalidity" optional, to update the uidvalidity for all mailboxes

useful after a database restore.
This commit is contained in:
Mechiel Lukkien 2023-05-22 18:11:42 +02:00
parent d18983d9a6
commit 753ec56b3d
No known key found for this signature in database

19
main.go
View file

@ -1935,10 +1935,10 @@ func cmdMessageParse(c *cmd) {
func cmdBumpUIDValidity(c *cmd) { func cmdBumpUIDValidity(c *cmd) {
c.unlisted = true c.unlisted = true
c.params = "account mailbox" c.params = "account [mailbox]"
c.help = "Change the IMAP UID validity of the mailbox, causing IMAP clients to refetch messages." c.help = "Change the IMAP UID validity of the mailbox, causing IMAP clients to refetch messages."
args := c.Parse() args := c.Parse()
if len(args) != 2 { if len(args) != 1 && len(args) != 2 {
c.Usage() c.Usage()
} }
@ -1953,20 +1953,29 @@ func cmdBumpUIDValidity(c *cmd) {
var uidvalidity uint32 var uidvalidity uint32
err = a.DB.Write(context.Background(), func(tx *bstore.Tx) error { err = a.DB.Write(context.Background(), func(tx *bstore.Tx) error {
mb, err := bstore.QueryTx[store.Mailbox](tx).FilterEqual("Name", args[1]).Get() q := bstore.QueryTx[store.Mailbox](tx)
if len(args) == 2 {
q.FilterEqual("Name", args[1])
}
mbl, err := q.SortAsc("Name").List()
if err != nil { if err != nil {
return fmt.Errorf("looking up mailbox: %v", err) return fmt.Errorf("looking up mailbox: %v", err)
} }
if len(args) == 2 && len(mbl) != 1 {
return fmt.Errorf("looking up mailbox %q, found %d mailboxes", args[1], len(mbl))
}
for _, mb := range mbl {
mb.UIDValidity++ mb.UIDValidity++
uidvalidity = mb.UIDValidity uidvalidity = mb.UIDValidity
err = tx.Update(&mb) err = tx.Update(&mb)
if err != nil { if err != nil {
return fmt.Errorf("updating uid validity for mailbox: %v", err) return fmt.Errorf("updating uid validity for mailbox: %v", err)
} }
fmt.Printf("uid validity for %q updated to %d\n", mb.Name, uidvalidity)
}
return nil return nil
}) })
xcheckf(err, "updating uidvalidity for mailbox: %v", err) xcheckf(err, "updating database")
fmt.Printf("uid validity for %q is now %d\n", args[1], uidvalidity)
} }
var submitconf struct { var submitconf struct {