idle rather than pol
Robert Ismo me@robertismo.com
Fri, 26 Jun 2026 14:21:38 -0500
3 files changed,
35 insertions(+),
10 deletions(-)
M
app.go
→
app.go
@@ -87,15 +87,6 @@ app.Log("Update failed: %v", err).Stdout().StatusLine()
} } }() - go func() { - ticker := time.NewTicker(5 * time.Second) - defer ticker.Stop() - for range ticker.C { - if err := app.syncMessages(); err != nil { - app.Log("Sync failed: %v", err).Stdout().StatusLine() - } - } - }() app.EstablishMailConnections() return }
M
mailaccount.go
→
mailaccount.go
@@ -157,7 +157,8 @@ Stdout()
continue } - go app.keepIMAPAlive(key) + // go app.keepIMAPAlive(key) + go app.watchMailbox(key, conn) if conn.SmtpClient != nil { conn.SmtpClient.Close()@@ -413,3 +414,35 @@ }
} } } +func (app *App) watchMailbox(email string, conn MailAccountConnection) { + mailbox := SourceMailboxes[0] + for { + if _, err := conn.ImapClient.Select(mailbox, nil).Wait(); err != nil { + app.Log("Select failed: %v", err).Stdout() + return + } + idleCmd, err := conn.ImapClient.Idle() + if err != nil { + app.Log("IDLE start failed: %v", err).Stdout() + return + } + waitChan := make(chan error, 1) + go func() { + waitChan <- idleCmd.Wait() + }() + select { + case err := <-waitChan: + if err != nil { + app.Log("IDLE ended with error: %v", err).Stdout() + } + idleCmd.Close() + case <-time.After(1 * time.Minute): + app.Log("IDLE timeout – restarting", nil).Stdout() + idleCmd.Close() + } + ImapSyncMutex.Unlock() + if err := app.syncMessages(); err != nil { + app.Log("Sync error: %v", err).Stdout() + } + }} +