aboutsummaryrefslogtreecommitdiffstats
path: root/commands/account/cf.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-11-11 20:36:39 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-12 12:53:11 +0100
commit213d65d00fb963c42cb3fa2b9b21c1613ec316a2 (patch)
tree5c85658abc6874176d9ed7fb780117da3d005d7b /commands/account/cf.go
parentcf00d0b55f29929d0c5996026d770067d4b26aa8 (diff)
downloadaerc-213d65d00fb963c42cb3fa2b9b21c1613ec316a2.tar.gz
cf: fix over quoting of notmuch queries
Currently, :cf thread:\{id:{{.MessageId}}\} is broken because it is quoted before being interpreted by notmuch. The dynamic folder is created with this "query" (including the quotes): 'thread:{id:23627381....}' Notmuch queries use the xapian syntax and do not follow basic shell quotes interpretation. Change :cf only argument to preserve the command line as entered by the user without any interpretation. When the backend is notmuch, forward that as the dynamic folder name. For other backends, interpret shell quoting on the user entry and fail if it produces more than one argument. Link: https://xapian.org/docs/queryparser.html Fixes: 6613d9b555be ("cf: fix unexpected argument on notmuch") Reported-by: Inwit <inwit@sindominio.net> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands/account/cf.go')
-rw-r--r--commands/account/cf.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go
index d8d615aa..ff44c6a3 100644
--- a/commands/account/cf.go
+++ b/commands/account/cf.go
@@ -16,7 +16,7 @@ import (
var history map[string]string
type ChangeFolder struct {
- Folder []string `opt:"..." complete:"CompleteFolder"`
+ Folder string `opt:"..." complete:"CompleteFolder"`
}
func init() {
@@ -54,14 +54,17 @@ func (c ChangeFolder) Execute(args []string) error {
var target string
notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker))
- switch {
- case reflect.TypeOf(notmuch) == reflect.TypeOf(acct.Worker().Backend):
- // notmuch query may have arguments that require quoting
- target = opt.QuoteArgs(c.Folder...).String()
- case len(c.Folder) == 1:
- target = c.Folder[0]
- default:
- return errors.New("Unexpected argument(s). Usage: cf <folder>")
+ if reflect.TypeOf(notmuch) == reflect.TypeOf(acct.Worker().Backend) {
+ // With notmuch, :cf can change to a "dynamic folder" that
+ // contains the result of a query. Preserve the entered
+ // arguments verbatim.
+ target = c.Folder
+ } else {
+ parts := opt.SplitArgs(c.Folder)
+ if len(parts) != 1 {
+ return errors.New("Unexpected argument(s). Usage: cf <folder>")
+ }
+ target = parts[0]
}
previous := acct.Directories().Selected()