From 795b7da16b89f7e7e0392700fdca967637b0485e Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 8 Nov 2020 16:32:10 -0800 Subject: [PATCH] Add more protections to gnus-search query parsing * lisp/gnus/gnus-group.el (gnus-group-make-search-group, gnus-group-read-ephemeral-search-group): If the query is coming in via the old 'nnir-query-spec key, we know not to parse it. * lisp/gnus/gnus-search.el (gnus-search-make-query-string): Check if the query was sent in as '(query "query"), and not '(query . "query). (gnus-search-imap-search-keys): Add x-gm-raw to imap search keys. (gnus-search-prepare-query): If we know this query should be raw, don't even try parsing it, as it probably won't work. --- lisp/gnus/gnus-group.el | 8 ++++++++ lisp/gnus/gnus-search.el | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el index 9db0e1897a3..c8b97c08524 100644 --- a/lisp/gnus/gnus-group.el +++ b/lisp/gnus/gnus-group.el @@ -3201,6 +3201,10 @@ non-nil SPECS arg must be an alist with `search-query-spec' and (cdr (assq 'search-query-spec specs)) (cdr (assq 'nnir-query-spec specs)) (gnus-search-make-spec no-parse)))) + ;; If our query came via an old call to nnir, we know not to + ;; parse the query. + (when (assq 'nnir-query-spec specs) + (setf (alist-get 'raw query-spec) t)) (gnus-group-make-group name (list 'nnselect "nnselect") @@ -3245,6 +3249,10 @@ non-nil SPECS arg must be an alist with `search-query-spec' and (or (cdr (assq 'search-query-spec specs)) (cdr (assq 'nnir-query-spec specs)) (gnus-search-make-spec no-parse)))) + ;; If our query came via an old call to nnir, we know not to parse + ;; the query. + (when (assq 'nnir-query-spec specs) + (setf (alist-get 'raw query-spec) t)) (gnus-group-read-ephemeral-group (concat "nnselect-" (message-unique-id)) (list 'nnselect "nnselect") diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el index fbed9029fbd..8b71daa9ff0 100644 --- a/lisp/gnus/gnus-search.el +++ b/lisp/gnus/gnus-search.el @@ -962,12 +962,18 @@ Responsible for handling and, or, and parenthetical expressions.") (cl-defmethod gnus-search-make-query-string ((engine gnus-search-engine) query-spec) - (if (and gnus-search-use-parsed-queries - (null (alist-get 'raw query-spec)) - (null (slot-value engine 'raw-queries-p))) - (gnus-search-transform - engine (alist-get 'parsed-query query-spec)) - (alist-get 'query query-spec))) + (let ((parsed-query (alist-get 'parsed-query query-spec)) + (raw-query (alist-get 'query query-spec))) + (if (and gnus-search-use-parsed-queries + (null (alist-get 'raw query-spec)) + (null (slot-value engine 'raw-queries-p)) + parsed-query) + (gnus-search-transform engine parsed-query) + (if (listp raw-query) + ;; Some callers are sending this in as (query "query"), not + ;; as a cons cell? + (car raw-query) + raw-query)))) (defsubst gnus-search-single-p (query) "Return t if QUERY is a search for a single message." @@ -1108,7 +1114,7 @@ Other capabilities could be tested here." ;; TODO: Don't exclude booleans and date keys, just check for them ;; before checking for general keywords. (defvar gnus-search-imap-search-keys - '(body cc bcc from header keyword larger smaller subject text to uid) + '(body cc bcc from header keyword larger smaller subject text to uid x-gm-raw) "Known IMAP search keys, excluding booleans and date keys.") (cl-defmethod gnus-search-transform ((_ gnus-search-imap) @@ -1952,7 +1958,8 @@ remaining string, then adds all that to the top-level spec." (setq query (string-trim (replace-match "" t t query 0))) (setf (alist-get 'query query-spec) query))) - (when gnus-search-use-parsed-queries + (when (and gnus-search-use-parsed-queries + (null (alist-get 'raw query-spec))) (setf (alist-get 'parsed-query query-spec) (gnus-search-parse-query query))) query-spec)) -- 2.39.2