diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-02-20 00:09:30 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-02-20 22:04:16 +0100 |
commit | 48e01bd51f1c7c27047ab8e64140778c7c833f1c (patch) | |
tree | 168c4ef98c169bfcceeb15883d812836dc68051c /worker | |
parent | 8ed9ae7f0a70518b9af4786ad0f48b344861a67e (diff) | |
download | aerc-48e01bd51f1c7c27047ab8e64140778c7c833f1c.zip |
imap: start reconnect when initial connect fails
Start the reconnect cycle when the initial connect fails. Make the
connection observer send a connection error when the imap client is nil.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/worker.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/worker/imap/worker.go b/worker/imap/worker.go index be04787..019df8b 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -191,6 +191,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { w.autoReconnect = true c, err := w.connect() if err != nil { + checkConn(0) reterr = err break } @@ -335,13 +336,20 @@ func (w *IMAPWorker) exponentialBackoff() (time.Duration, string) { } func (w *IMAPWorker) startConnectionObserver() { + emitConnErr := func(errMsg string) { + w.worker.PostMessage(&types.ConnError{ + Error: fmt.Errorf(errMsg), + }, nil) + } + if w.client == nil { + emitConnErr("imap client not connected") + return + } go func() { select { case <-w.client.LoggedOut(): if w.autoReconnect { - w.worker.PostMessage(&types.ConnError{ - Error: fmt.Errorf("imap: logged out"), - }, nil) + emitConnErr("imap: logged out") } case <-w.done: return |