aboutsummaryrefslogtreecommitdiff
path: root/worker
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-08-28 06:39:08 +0200
committerDrew DeVault <sir@cmpwn.com>2019-08-29 08:44:11 +0900
commitf13f9a86849ff8b4616aa7b462ed171833e02a95 (patch)
tree8ab9521d83b9c7486c5cd902f6111d2572de40ac /worker
parent94b9d557dee0fd13853b1883cc2730c5cbdbcd3f (diff)
notmuch: add search / filter capabilities
Diffstat (limited to 'worker')
-rw-r--r--worker/notmuch/worker.go38
1 files changed, 29 insertions, 9 deletions
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index d4c196c..58a63ec 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -90,12 +90,12 @@ func (w *worker) handleMessage(msg types.WorkerMessage) error {
return w.handleFetchFullMessages(msg)
case *types.ReadMessages:
return w.handleReadMessages(msg)
- // TODO
- // return w.handleSearchDirectory(msg)
- // case *types.DeleteMessages:
+ case *types.SearchDirectory:
+ return w.handleSearchDirectory(msg)
// not implemented, they are generally not used
// in a notmuch based workflow
+ // case *types.DeleteMessages:
// case *types.CopyMessages:
// return w.handleCopyMessages(msg)
// case *types.AppendMessage:
@@ -177,10 +177,10 @@ func (w *worker) handleListDirectories(msg *types.ListDirectories) error {
return nil
}
-//query returns a query based on the query string on w.query.
-//it also configures the query as specified on the worker
-func (w *worker) getQuery() (*notmuch.Query, error) {
- q := w.db.NewQuery(w.query)
+//getQuery returns a query based on the provided query string.
+//It also configures the query as specified on the worker
+func (w *worker) getQuery(query string) (*notmuch.Query, error) {
+ q := w.db.NewQuery(query)
q.SetExcludeScheme(notmuch.EXCLUDE_TRUE)
q.SetSortScheme(notmuch.SORT_OLDEST_FIRST)
for _, t := range w.excludedTags {
@@ -200,7 +200,7 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error {
q = msg.Directory
}
w.query = q
- query, err := w.getQuery()
+ query, err := w.getQuery(w.query)
if err != nil {
return err
}
@@ -226,7 +226,7 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error {
func (w *worker) handleFetchDirectoryContents(
msg *types.FetchDirectoryContents) error {
- q, err := w.getQuery()
+ q, err := w.getQuery(w.query)
if err != nil {
return err
}
@@ -404,6 +404,26 @@ func (w *worker) handleReadMessages(msg *types.ReadMessages) error {
return nil
}
+func (w *worker) handleSearchDirectory(msg *types.SearchDirectory) error {
+ // the first item is the command (search / filter)
+ s := strings.Join(msg.Argv[1:], " ")
+ // we only want to search in the current query, so merge the two together
+ search := fmt.Sprintf("(%v) and (%v)", w.query, s)
+ query, err := w.getQuery(search)
+ if err != nil {
+ return err
+ }
+ uids, err := w.uidsFromQuery(query)
+ if err != nil {
+ return err
+ }
+ w.w.PostMessage(&types.SearchResults{
+ Message: types.RespondTo(msg),
+ Uids: uids,
+ }, nil)
+ return nil
+}
+
func (w *worker) loadQueryMap(acctConfig *config.AccountConfig) error {
raw, ok := acctConfig.Params["query-map"]
if !ok {