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 <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-07-25 14:32:28 -05:00 committed by Robin Jarry
parent d941960fe1
commit a1a549cb1e
1 changed files with 15 additions and 3 deletions

View File

@ -276,9 +276,8 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
case *types.RemoveDirectory: case *types.RemoveDirectory:
acct.dirlist.UpdateList(nil) acct.dirlist.UpdateList(nil)
case *types.FetchMessageHeaders: case *types.FetchMessageHeaders:
if acct.newConn && acct.AccountConfig().CheckMail.Minutes() > 0 { if acct.newConn {
acct.newConn = false acct.checkMailOnStartup()
acct.CheckMail()
} }
} }
case *types.DirectoryInfo: case *types.DirectoryInfo:
@ -307,6 +306,9 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
store.Update(msg) store.Update(msg)
acct.SetStatus(statusline.Threading(store.ThreadedView())) acct.SetStatus(statusline.Threading(store.ThreadedView()))
} }
if acct.newConn && len(msg.Uids) == 0 {
acct.checkMailOnStartup()
}
case *types.DirectoryThreaded: case *types.DirectoryThreaded:
if store, ok := acct.dirlist.SelectedMsgStore(); ok { if store, ok := acct.dirlist.SelectedMsgStore(); ok {
if acct.msglist.Store() == nil { if acct.msglist.Store() == nil {
@ -315,6 +317,9 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
store.Update(msg) store.Update(msg)
acct.SetStatus(statusline.Threading(store.ThreadedView())) acct.SetStatus(statusline.Threading(store.ThreadedView()))
} }
if acct.newConn && len(msg.Threads) == 0 {
acct.checkMailOnStartup()
}
case *types.FullMessage: case *types.FullMessage:
if store, ok := acct.dirlist.SelectedMsgStore(); ok { if store, ok := acct.dirlist.SelectedMsgStore(); ok {
store.Update(msg) 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) { func (acct *AccountView) CheckMailTimer(d time.Duration) {
ticker := time.NewTicker(d) ticker := time.NewTicker(d)
go func() { go func() {