diff options
author | Robin Jarry <robin@jarry.cc> | 2021-11-01 21:38:26 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2021-11-05 10:45:31 +0100 |
commit | e41ed82cf3dbb4a1152a562ab754a9dc4a6c57b3 (patch) | |
tree | 098cc67f60eb3e0d7c16ad82adb4c988aa08c61e /worker | |
parent | 20752df89c3bef0aca23493bfe8a668b93db9947 (diff) | |
download | aerc-e41ed82cf3dbb4a1152a562ab754a9dc4a6c57b3.tar.gz |
imap: add manual {dis,}connect support
Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/worker.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 82b81bdc..cd525369 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -59,7 +59,7 @@ func NewIMAPWorker(worker *types.Worker) (types.Backend, error) { } func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { - if w.idleStop != nil { + if w.client != nil && w.client.State() == imap.SelectedState { close(w.idleStop) if err := <-w.idleDone; err != nil { w.worker.PostMessage(&types.Error{Error: err}, nil) @@ -110,6 +110,9 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { c *client.Client err error ) + if w.client != nil { + return fmt.Errorf("Already connected") + } switch w.config.scheme { case "imap": c, err = client.Dial(w.config.addr) @@ -157,6 +160,15 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { c.Updates = w.updates w.client = &imapClient{c, sortthread.NewSortClient(c)} w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) + case *types.Disconnect: + if w.client == nil { + 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) case *types.OpenDirectory: @@ -189,7 +201,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { reterr = errUnsupported } - if w.idleStop != nil { + if w.client != nil && w.client.State() == imap.SelectedState { w.idleStop = make(chan struct{}) go func() { w.idleDone <- w.client.Idle(w.idleStop, &client.IdleOptions{0, 0}) |