From 2027223ab302f803952c486ec40f1e859638a273 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 3 Jun 2022 13:34:01 -0500 Subject: [PATCH] fix: clear dirlist on disconnect A message of Done:Disconnect will trigger an update of the dirlist. An update of the dirlist will issue a ListDirectories message, which causes an imap: client not ready error by trying to use the imap connection - which is disconnected. By not issuing the update, we prevent using a disconnected client. This patch checks for connection state prior to updating the dirlist. A disconnected state will clear out the dirlist. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- widgets/account.go | 2 ++ widgets/dirlist.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/widgets/account.go b/widgets/account.go index 2d3b0d2..9340370 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -246,6 +246,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { case *types.Connect, *types.Reconnect: acct.SetStatus(statusline.ConnectionActivity("Listing mailboxes...")) acct.logger.Println("Listing mailboxes...") + acct.dirlist.SetConnected(true) acct.dirlist.UpdateList(func(dirs []string) { var dir string for _, _dir := range dirs { @@ -266,6 +267,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.newConn = true }) case *types.Disconnect: + acct.dirlist.SetConnected(false) acct.dirlist.UpdateList(nil) acct.msglist.SetStore(nil) acct.logger.Println("Disconnected.") diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 60bd7fa..8448e4a 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -31,6 +31,7 @@ type DirectoryLister interface { UpdateList(func([]string)) List() []string + SetConnected(bool) NextPrev(int) @@ -57,6 +58,7 @@ type DirectoryList struct { spinner *Spinner worker *types.Worker skipSelect chan bool + connected bool } func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig, @@ -91,11 +93,24 @@ func (dirlist *DirectoryList) UiConfig() config.UIConfig { }) } +func (dirlist *DirectoryList) SetConnected(c bool) { + dirlist.connected = c +} + func (dirlist *DirectoryList) List() []string { return dirlist.store.List() } func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) { + // Clear out dirlist if not connected + if !dirlist.connected { + // Only dirlist.dirs is used for the UI. No need to update dirstore + dirlist.dirs = []string{} + dirlist.Invalidate() + // Call callback with empty array for dirtree + done(dirlist.dirs) + return + } // TODO: move this logic into dirstore var dirs []string dirlist.worker.PostAction(