notmuch: add search / filter capabilities
This commit is contained in:
parent
94b9d557de
commit
f13f9a8684
2 changed files with 39 additions and 9 deletions
|
@ -9,3 +9,13 @@ aerc-search(1)
|
||||||
*-r*: Search for read messages
|
*-r*: Search for read messages
|
||||||
|
|
||||||
*-u*: Search for unread messages
|
*-u*: Search for unread messages
|
||||||
|
|
||||||
|
# NOTMUCH
|
||||||
|
|
||||||
|
*search* <query...>
|
||||||
|
You can use the full notmuch query language as described in
|
||||||
|
*notmuch-search-terms*(7).
|
||||||
|
|
||||||
|
The query will only apply on top of the active folder query.
|
||||||
|
|
||||||
|
Example: jump to next unread `:search tag:unread`
|
||||||
|
|
|
@ -90,12 +90,12 @@ func (w *worker) handleMessage(msg types.WorkerMessage) error {
|
||||||
return w.handleFetchFullMessages(msg)
|
return w.handleFetchFullMessages(msg)
|
||||||
case *types.ReadMessages:
|
case *types.ReadMessages:
|
||||||
return w.handleReadMessages(msg)
|
return w.handleReadMessages(msg)
|
||||||
// TODO
|
case *types.SearchDirectory:
|
||||||
// return w.handleSearchDirectory(msg)
|
return w.handleSearchDirectory(msg)
|
||||||
// case *types.DeleteMessages:
|
|
||||||
|
|
||||||
// not implemented, they are generally not used
|
// not implemented, they are generally not used
|
||||||
// in a notmuch based workflow
|
// in a notmuch based workflow
|
||||||
|
// case *types.DeleteMessages:
|
||||||
// case *types.CopyMessages:
|
// case *types.CopyMessages:
|
||||||
// return w.handleCopyMessages(msg)
|
// return w.handleCopyMessages(msg)
|
||||||
// case *types.AppendMessage:
|
// case *types.AppendMessage:
|
||||||
|
@ -177,10 +177,10 @@ func (w *worker) handleListDirectories(msg *types.ListDirectories) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//query returns a query based on the query string on w.query.
|
//getQuery returns a query based on the provided query string.
|
||||||
//it also configures the query as specified on the worker
|
//It also configures the query as specified on the worker
|
||||||
func (w *worker) getQuery() (*notmuch.Query, error) {
|
func (w *worker) getQuery(query string) (*notmuch.Query, error) {
|
||||||
q := w.db.NewQuery(w.query)
|
q := w.db.NewQuery(query)
|
||||||
q.SetExcludeScheme(notmuch.EXCLUDE_TRUE)
|
q.SetExcludeScheme(notmuch.EXCLUDE_TRUE)
|
||||||
q.SetSortScheme(notmuch.SORT_OLDEST_FIRST)
|
q.SetSortScheme(notmuch.SORT_OLDEST_FIRST)
|
||||||
for _, t := range w.excludedTags {
|
for _, t := range w.excludedTags {
|
||||||
|
@ -200,7 +200,7 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error {
|
||||||
q = msg.Directory
|
q = msg.Directory
|
||||||
}
|
}
|
||||||
w.query = q
|
w.query = q
|
||||||
query, err := w.getQuery()
|
query, err := w.getQuery(w.query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error {
|
||||||
|
|
||||||
func (w *worker) handleFetchDirectoryContents(
|
func (w *worker) handleFetchDirectoryContents(
|
||||||
msg *types.FetchDirectoryContents) error {
|
msg *types.FetchDirectoryContents) error {
|
||||||
q, err := w.getQuery()
|
q, err := w.getQuery(w.query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -404,6 +404,26 @@ func (w *worker) handleReadMessages(msg *types.ReadMessages) error {
|
||||||
return nil
|
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 {
|
func (w *worker) loadQueryMap(acctConfig *config.AccountConfig) error {
|
||||||
raw, ok := acctConfig.Params["query-map"]
|
raw, ok := acctConfig.Params["query-map"]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in a new issue