aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/account.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-07-29 13:30:02 -0500
committerRobin Jarry <robin@jarry.cc>2022-08-01 10:37:28 +0200
commitdb195bebf061d793ff34ba209059fe3f43e189e2 (patch)
tree37e6a23f7d2e1d728bab7bf0827519520fa531de /widgets/account.go
parent44651b43b3a59d35b98936e0bcd4edf797f68b42 (diff)
downloadaerc-db195bebf061d793ff34ba209059fe3f43e189e2.tar.gz
commands: add check-mail command
Add :check-mail command for ad-hoc checking of mail. Reset timer for automatic checking if it is enabled. Suggested-by: staceee Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets/account.go')
-rw-r--r--widgets/account.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 50b0fab1..e5087ef5 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -33,6 +33,10 @@ type AccountView struct {
state *statusline.State
newConn bool // True if this is a first run after a new connection/reconnection
uiConf *config.UIConfig
+
+ // Check-mail ticker
+ ticker *time.Ticker
+ checkingMail bool
}
func (acct *AccountView) UiConfig() *config.UIConfig {
@@ -407,6 +411,9 @@ func (acct *AccountView) GetSortCriteria() []*types.SortCriterion {
}
func (acct *AccountView) CheckMail() {
+ if acct.checkingMail {
+ return
+ }
// Exclude selected mailbox, per IMAP specification
exclude := append(acct.AccountConfig().CheckMailExclude, acct.dirlist.Selected())
dirs := acct.dirlist.List()
@@ -419,11 +426,21 @@ func (acct *AccountView) CheckMail() {
Command: acct.acct.CheckMailCmd,
Timeout: acct.acct.CheckMailTimeout,
}
+ acct.checkingMail = true
acct.worker.PostAction(msg, func(_ types.WorkerMessage) {
acct.SetStatus(statusline.ConnectionActivity(""))
+ acct.checkingMail = false
})
}
+// CheckMailReset resets the check-mail timer
+func (acct *AccountView) CheckMailReset() {
+ if acct.ticker != nil {
+ d := acct.AccountConfig().CheckMail
+ acct.ticker = time.NewTicker(d)
+ }
+}
+
func (acct *AccountView) checkMailOnStartup() {
if acct.AccountConfig().CheckMail.Minutes() > 0 {
acct.newConn = false
@@ -432,9 +449,9 @@ func (acct *AccountView) checkMailOnStartup() {
}
func (acct *AccountView) CheckMailTimer(d time.Duration) {
- ticker := time.NewTicker(d)
+ acct.ticker = time.NewTicker(d)
go func() {
- for range ticker.C {
+ for range acct.ticker.C {
if !acct.state.Connected() {
continue
}