From 213d65d00fb963c42cb3fa2b9b21c1613ec316a2 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sat, 11 Nov 2023 20:36:39 +0100 Subject: 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 Signed-off-by: Robin Jarry Tested-by: Inwit --- commands/account/cf.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'commands/account/cf.go') 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 ") + 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 ") + } + target = parts[0] } previous := acct.Directories().Selected() -- cgit