summaryrefslogtreecommitdiff
path: root/worker
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-07-05 14:48:40 -0500
committerRobin Jarry <robin@jarry.cc>2022-07-10 21:15:12 +0200
commitc2f4404fca15be37228545b1893f5fa335168337 (patch)
tree2bfc788a7e38510f1d5057c4b47d2460a548cb44 /worker
parentccd042889f6d8aa78b70c01395ef69aec48ac48c (diff)
downloadaerc-c2f4404fca15be37228545b1893f5fa335168337.zip
threading: enable filtering of server-side threads
This patch enables the filtering of a threaded view which uses server-built threads. Filtering is done server-side, in order to preserve the use of server-built threads. In adding this feature, the filtering of notmuch folders was brought up to feature parity with the other workers. The filters function the same (ie: they can be stacked). The notmuch filters, however, still use notmuch syntax for the filtering. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/open.go25
-rw-r--r--worker/imap/search.go3
-rw-r--r--worker/maildir/worker.go23
-rw-r--r--worker/notmuch/worker.go19
-rw-r--r--worker/types/messages.go6
5 files changed, 58 insertions, 18 deletions
diff --git a/worker/imap/open.go b/worker/imap/open.go
index a0607d0..b52a3c6 100644
--- a/worker/imap/open.go
+++ b/worker/imap/open.go
@@ -3,7 +3,6 @@ package imap
import (
"sort"
- "github.com/emersion/go-imap"
sortthread "github.com/emersion/go-imap-sortthread"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -29,11 +28,13 @@ func (imapw *IMAPWorker) handleFetchDirectoryContents(
imapw.worker.Logger.Printf("Fetching UID list")
- seqSet := &imap.SeqSet{}
- seqSet.AddRange(1, imapw.selected.Messages)
-
- searchCriteria := &imap.SearchCriteria{
- SeqNum: seqSet,
+ searchCriteria, err := parseSearch(msg.FilterCriteria)
+ if err != nil {
+ imapw.worker.PostMessage(&types.Error{
+ Message: types.RespondTo(msg),
+ Error: err,
+ }, nil)
+ return
}
sortCriteria := translateSortCriterions(msg.SortCriteria)
@@ -98,10 +99,16 @@ func (imapw *IMAPWorker) handleDirectoryThreaded(
msg *types.FetchDirectoryThreaded) {
imapw.worker.Logger.Printf("Fetching threaded UID list")
- seqSet := &imap.SeqSet{}
- seqSet.AddRange(1, imapw.selected.Messages)
+ searchCriteria, err := parseSearch(msg.FilterCriteria)
+ if err != nil {
+ imapw.worker.PostMessage(&types.Error{
+ Message: types.RespondTo(msg),
+ Error: err,
+ }, nil)
+ return
+ }
threads, err := imapw.client.thread.UidThread(sortthread.References,
- &imap.SearchCriteria{SeqNum: seqSet})
+ searchCriteria)
if err != nil {
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
diff --git a/worker/imap/search.go b/worker/imap/search.go
index f866b1c..46a25c7 100644
--- a/worker/imap/search.go
+++ b/worker/imap/search.go
@@ -11,6 +11,9 @@ import (
func parseSearch(args []string) (*imap.SearchCriteria, error) {
criteria := imap.NewSearchCriteria()
+ if len(args) == 0 {
+ return criteria, nil
+ }
opts, optind, err := getopt.Getopts(args, "rubax:X:t:H:f:c:")
if err != nil {
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index 0862838..cc03ec8 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -406,10 +406,25 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error {
func (w *Worker) handleFetchDirectoryContents(
msg *types.FetchDirectoryContents) error {
- uids, err := w.c.UIDs(*w.selected)
- if err != nil {
- w.worker.Logger.Printf("error scanning uids: %v", err)
- return err
+ var (
+ uids []uint32
+ err error
+ )
+ if len(msg.FilterCriteria) > 0 {
+ filter, err := parseSearch(msg.FilterCriteria)
+ if err != nil {
+ return err
+ }
+ uids, err = w.search(filter)
+ if err != nil {
+ return err
+ }
+ } else {
+ uids, err = w.c.UIDs(*w.selected)
+ if err != nil {
+ w.worker.Logger.Printf("error scanning uids: %v", err)
+ return err
+ }
}
sortedUids, err := w.sort(uids, msg.SortCriteria)
if err != nil {
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 35e6840..27be73d 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -550,7 +550,14 @@ func (w *worker) loadExcludeTags(
}
func (w *worker) emitDirectoryContents(parent types.WorkerMessage) error {
- uids, err := w.uidsFromQuery(w.query)
+ query := w.query
+ if msg, ok := parent.(*types.FetchDirectoryContents); ok {
+ s := strings.Join(msg.FilterCriteria[1:], " ")
+ if s != "" {
+ query = fmt.Sprintf("(%v) and (%v)", query, s)
+ }
+ }
+ uids, err := w.uidsFromQuery(query)
if err != nil {
return fmt.Errorf("could not fetch uids: %v", err)
}
@@ -567,12 +574,18 @@ func (w *worker) emitDirectoryContents(parent types.WorkerMessage) error {
}
func (w *worker) emitDirectoryThreaded(parent types.WorkerMessage) error {
- threads, err := w.db.ThreadsFromQuery(w.query)
+ query := w.query
+ if msg, ok := parent.(*types.FetchDirectoryThreaded); ok {
+ s := strings.Join(msg.FilterCriteria[1:], " ")
+ if s != "" {
+ query = fmt.Sprintf("(%v) and (%v)", query, s)
+ }
+ }
+ threads, err := w.db.ThreadsFromQuery(query)
if err != nil {
return err
}
w.w.PostMessage(&types.DirectoryThreaded{
- Message: types.RespondTo(parent),
Threads: threads,
}, nil)
return nil
diff --git a/worker/types/messages.go b/worker/types/messages.go
index e303ade..a414eb2 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -87,12 +87,14 @@ type OpenDirectory struct {
type FetchDirectoryContents struct {
Message
- SortCriteria []*SortCriterion
+ SortCriteria []*SortCriterion
+ FilterCriteria []string
}
type FetchDirectoryThreaded struct {
Message
- SortCriteria []*SortCriterion
+ SortCriteria []*SortCriterion
+ FilterCriteria []string
}
type SearchDirectory struct {