feat(GODT-2759): CLI debug commands

Add debug commands to CLI to diagnose potential bride problems.
Currently we only have a command which validates whether the state of
all the mailboxes reported by IMAP matches what is currently available
on the proton servers.
This commit is contained in:
Leander Beernaert
2023-07-05 09:51:55 +02:00
parent f545f30ec0
commit 7d838375bb
5 changed files with 438 additions and 17 deletions

View File

@ -0,0 +1,42 @@
// Copyright (c) 2023 Proton AG
//
// This file is part of Proton Mail Bridge.
//
// Proton Mail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Proton Mail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
package cli
import (
"context"
"github.com/abiosoft/ishell"
)
func (f *frontendCLI) debugMailboxState(c *ishell.Context) {
f.ShowPrompt(false)
defer f.ShowPrompt(true)
checkFlags := f.yesNoQuestion("Also check message flags")
c.Println("Starting state check. Note that depending on your message count this may take a while.")
if err := f.bridge.CheckClientState(context.Background(), checkFlags, func(s string) {
c.Println(s)
}); err != nil {
c.Printf("State check failed : %v", err)
return
}
c.Println("State check finished, see log for more details.")
}

View File

@ -312,6 +312,19 @@ func New(
})
fe.AddCmd(telemetryCmd)
dbgCmd := &ishell.Cmd{
Name: "debug",
Help: "Debug diagnostics ",
}
dbgCmd.AddCmd(&ishell.Cmd{
Name: "mailbox-state",
Help: "Verify local mailbox state against proton server state",
Func: fe.debugMailboxState,
})
fe.AddCmd(dbgCmd)
go fe.watchEvents(eventCh)
go func() {