From a1a549cb1e10d18e071695249b995e2dddfdac2a Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 25 Jul 2022 14:32:28 -0500 Subject: [PATCH] check-mail: fix startup when default folder is empty check-mail was triggered to run at startup after a Done:FetchHeaders message. This message would only occur if there were messages in the default folder. In the case where there are no messages, check-mail would not run at startup as intended. Run check-mail even if there are no messages found in the default folder at startup. Fixes: https://todo.sr.ht/~rjarry/aerc/60 Reported-by: ~foutrelis Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- widgets/account.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/widgets/account.go b/widgets/account.go index 3172a30..ff51636 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -276,9 +276,8 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { case *types.RemoveDirectory: acct.dirlist.UpdateList(nil) case *types.FetchMessageHeaders: - if acct.newConn && acct.AccountConfig().CheckMail.Minutes() > 0 { - acct.newConn = false - acct.CheckMail() + if acct.newConn { + acct.checkMailOnStartup() } } case *types.DirectoryInfo: @@ -307,6 +306,9 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { store.Update(msg) acct.SetStatus(statusline.Threading(store.ThreadedView())) } + if acct.newConn && len(msg.Uids) == 0 { + acct.checkMailOnStartup() + } case *types.DirectoryThreaded: if store, ok := acct.dirlist.SelectedMsgStore(); ok { if acct.msglist.Store() == nil { @@ -315,6 +317,9 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { store.Update(msg) acct.SetStatus(statusline.Threading(store.ThreadedView())) } + if acct.newConn && len(msg.Threads) == 0 { + acct.checkMailOnStartup() + } case *types.FullMessage: if store, ok := acct.dirlist.SelectedMsgStore(); ok { store.Update(msg) @@ -418,6 +423,13 @@ func (acct *AccountView) CheckMail() { }) } +func (acct *AccountView) checkMailOnStartup() { + if acct.AccountConfig().CheckMail.Minutes() > 0 { + acct.newConn = false + acct.CheckMail() + } +} + func (acct *AccountView) CheckMailTimer(d time.Duration) { ticker := time.NewTicker(d) go func() {