Add CLI account check mode
This commit is contained in:
parent
b1f3df679f
commit
fbec60c356
2 changed files with 28 additions and 0 deletions
|
|
@ -124,6 +124,29 @@ func migrateAccount(a Account) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func CheckAccount(name string) error {
|
||||
a, err := GetAccount(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
src, err := OpenIMAPSource(a)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open source %s: %w", a.Name, err)
|
||||
}
|
||||
defer src.Close()
|
||||
msgs, err := src.Fetch("INBOX")
|
||||
if err != nil {
|
||||
return fmt.Errorf("fetch source INBOX %s: %w", a.Name, err)
|
||||
}
|
||||
dst, err := OpenIMAPTarget(a)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open target %s: %w", a.Name, err)
|
||||
}
|
||||
defer dst.Close()
|
||||
log.Printf("account %s ok: source INBOX messages=%d, target login ok", a.Name, len(msgs))
|
||||
return nil
|
||||
}
|
||||
|
||||
func startJob(accountID int64) (int64, error) {
|
||||
res, err := DB.Exec(`INSERT INTO jobs(account_id,state) VALUES(?, 'running')`, accountID)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue