extract search criteria parsing into the backends

This commit is contained in:
Reto Brunner 2019-08-28 06:39:07 +02:00 committed by Drew DeVault
parent ac99d9ed62
commit 94b9d557de
8 changed files with 70 additions and 48 deletions
commands/account

View file

@ -3,9 +3,6 @@ package account
import (
"errors"
"git.sr.ht/~sircmpwn/getopt"
"github.com/emersion/go-imap"
"git.sr.ht/~sircmpwn/aerc/widgets"
)
@ -24,28 +21,6 @@ func (_ SearchFilter) Complete(aerc *widgets.Aerc, args []string) []string {
}
func (_ SearchFilter) Execute(aerc *widgets.Aerc, args []string) error {
var (
criteria *imap.SearchCriteria = imap.NewSearchCriteria()
)
opts, optind, err := getopt.Getopts(args, "ruH:")
if err != nil {
return err
}
for _, opt := range opts {
switch opt.Option {
case 'r':
criteria.WithFlags = append(criteria.WithFlags, imap.SeenFlag)
case 'u':
criteria.WithoutFlags = append(criteria.WithoutFlags, imap.SeenFlag)
case 'H':
// TODO
}
}
for _, arg := range args[optind:] {
criteria.Header.Add("Subject", arg)
}
acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
@ -73,6 +48,6 @@ func (_ SearchFilter) Execute(aerc *widgets.Aerc, args []string) error {
acct.Messages().Scroll()
}
}
store.Search(criteria, cb)
store.Search(args, cb)
return nil
}