aerc/lib/statusline/state.go
Tim Culverhouse 2551dd1bfa feat: add background mail polling option for all workers
Check for new mail (recent, unseen, exists counts) with an external
command, or for imap with the STATUS command, at start or on
reconnection and every X time duration

IMAP:
The selected folder is skipped, per specification. Additional config
options are included for including/excluding folders explicitly.

Maildir/Notmuch:
An external command will be run in the background to check for new mail.
An optional timeout can be used with maildir/notmuch. Default is 10s

New account options:
check-mail
check-mail-cmd (maildir/notmuch only)
check-mail-timeout (maildir/notmuch only), default 10s
check-mail-include (IMAP only)
check-mail-exclude (IMAP only)

If unset, or set less than or equal to 0, check-mail will be ignored

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-31 14:32:51 +02:00

136 lines
2.8 KiB
Go

package statusline
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
)
type State struct {
separator string
renderer renderFunc
acct *accountState
fldr map[string]*folderState
width int
}
type accountState struct {
Name string
Multiple bool
ConnActivity string
Connected bool
Passthrough bool
}
type folderState struct {
Name string
Search string
Filter string
FilterActivity string
Sorting bool
Threading bool
}
func NewState(name string, multipleAccts bool, conf config.StatuslineConfig) *State {
return &State{separator: conf.Separator,
renderer: newRenderer(conf.RenderFormat, conf.DisplayMode),
acct: &accountState{Name: name, Multiple: multipleAccts},
fldr: make(map[string]*folderState),
}
}
func (s *State) StatusLine(folder string) string {
return s.renderer(renderParams{
width: s.width,
sep: s.separator,
acct: s.acct,
fldr: s.folderState(folder),
})
}
func (s *State) folderState(folder string) *folderState {
if _, ok := s.fldr[folder]; !ok {
s.fldr[folder] = &folderState{Name: folder}
}
return s.fldr[folder]
}
func (s *State) SetWidth(w int) bool {
changeState := false
if s.width != w {
s.width = w
changeState = true
}
return changeState
}
func (s *State) Connected() bool {
return s.acct.Connected
}
type SetStateFunc func(s *State, folder string)
func SetConnected(state bool) SetStateFunc {
return func(s *State, folder string) {
s.acct.ConnActivity = ""
s.acct.Connected = state
}
}
func ConnectionActivity(desc string) SetStateFunc {
return func(s *State, folder string) {
s.acct.ConnActivity = desc
}
}
func SearchFilterClear() SetStateFunc {
return func(s *State, folder string) {
s.folderState(folder).Search = ""
s.folderState(folder).FilterActivity = ""
s.folderState(folder).Filter = ""
}
}
func FilterActivity(str string) SetStateFunc {
return func(s *State, folder string) {
s.folderState(folder).FilterActivity = str
}
}
func FilterResult(str string) SetStateFunc {
return func(s *State, folder string) {
s.folderState(folder).FilterActivity = ""
s.folderState(folder).Filter = concatFilters(s.folderState(folder).Filter, str)
}
}
func concatFilters(existing, next string) string {
if existing == "" {
return next
}
return fmt.Sprintf("%s && %s", existing, next)
}
func Search(desc string) SetStateFunc {
return func(s *State, folder string) {
s.folderState(folder).Search = desc
}
}
func Sorting(on bool) SetStateFunc {
return func(s *State, folder string) {
s.folderState(folder).Sorting = on
}
}
func Threading(on bool) SetStateFunc {
return func(s *State, folder string) {
s.folderState(folder).Threading = on
}
}
func Passthrough(on bool) SetStateFunc {
return func(s *State, folder string) {
s.acct.Passthrough = on
}
}