diff options
Diffstat (limited to 'worker/imap/worker.go')
-rw-r--r-- | worker/imap/worker.go | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 2c0e6a60..c427e60a 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -111,7 +111,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { c *client.Client err error ) - if w.client != nil { + if w.client != nil && w.client.State() == imap.SelectedState { return fmt.Errorf("Already connected") } switch w.config.scheme { @@ -162,13 +162,12 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)} w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) case *types.Disconnect: - if w.client == nil { + if w.client == nil || w.client.State() != imap.SelectedState { return fmt.Errorf("Not connected") } if err := w.client.Logout(); err != nil { return err } - w.client = nil w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) case *types.ListDirectories: w.handleListDirectories(msg) |