From 48e01bd51f1c7c27047ab8e64140778c7c833f1c Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Sun, 20 Feb 2022 00:09:30 +0100 Subject: 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 --- worker/imap/worker.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'worker/imap') diff --git a/worker/imap/worker.go b/worker/imap/worker.go index be04787f..019df8bb 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 -- cgit