aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Abrahamsen2021-06-26 10:16:19 -0700
committerEric Abrahamsen2021-07-10 20:22:34 -0700
commite7f6bb38ddb71bfe08bdca87119ff13cd40ecf62 (patch)
tree942e83ee58b0940e12678b8b34442a24ba62c87a
parent0897ade8f90e492b9506ec58fe872722d90b8148 (diff)
downloademacs-e7f6bb38ddb71bfe08bdca87119ff13cd40ecf62.tar.gz
emacs-e7f6bb38ddb71bfe08bdca87119ff13cd40ecf62.zip
Rework gnus-search-indexed-parse-output
* lisp/gnus/gnus-search.el (gnus-search-indexed-parse-output): Be more careful about matching filesystem paths to Gnus group names; make absolutely sure that we only return valid article numbers.
-rw-r--r--lisp/gnus/gnus-search.el95
1 files changed, 43 insertions, 52 deletions
diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el
index 70bde264c11..898b57bcef8 100644
--- a/lisp/gnus/gnus-search.el
+++ b/lisp/gnus/gnus-search.el
@@ -1351,68 +1351,59 @@ Returns a list of [group article score] vectors."
1351 1351
1352(cl-defmethod gnus-search-indexed-parse-output ((engine gnus-search-indexed) 1352(cl-defmethod gnus-search-indexed-parse-output ((engine gnus-search-indexed)
1353 server query &optional groups) 1353 server query &optional groups)
1354 (let ((prefix (slot-value engine 'remove-prefix)) 1354 (let ((prefix (or (slot-value engine 'remove-prefix)
1355 (group-regexp (when groups 1355 ""))
1356 (mapconcat 1356 artlist article group)
1357 (lambda (group-name)
1358 (mapconcat #'regexp-quote
1359 (split-string
1360 (gnus-group-real-name group-name)
1361 "[.\\/]")
1362 "[.\\\\/]"))
1363 groups
1364 "\\|")))
1365 artlist vectors article group)
1366 (goto-char (point-min)) 1357 (goto-char (point-min))
1358 ;; Prep prefix, we want to at least be removing the root
1359 ;; filesystem separator.
1360 (when (stringp prefix)
1361 (setq prefix (file-name-as-directory
1362 (expand-file-name prefix "/"))))
1367 (while (not (or (eobp) 1363 (while (not (or (eobp)
1368 (looking-at-p 1364 (looking-at-p
1369 "\\(?:[[:space:]\n]+\\)?Process .+ finished"))) 1365 "\\(?:[[:space:]\n]+\\)?Process .+ finished")))
1370 (pcase-let ((`(,f-name ,score) (gnus-search-indexed-extract engine))) 1366 (pcase-let ((`(,f-name ,score) (gnus-search-indexed-extract engine)))
1371 (when (and f-name 1367 (when (and f-name
1372 (file-readable-p f-name) 1368 (file-readable-p f-name)
1373 (null (file-directory-p f-name)) 1369 (null (file-directory-p f-name)))
1374 (or (null groups) 1370 (setq group
1375 (and (gnus-search-single-p query) 1371 (replace-regexp-in-string
1376 (alist-get 'thread query)) 1372 "[/\\]" "."
1377 (string-match-p group-regexp f-name))) 1373 (replace-regexp-in-string
1378 (push (list f-name score) artlist)))) 1374 "/?\\(cur\\|new\\|tmp\\)?/\\'" ""
1375 (replace-regexp-in-string
1376 "\\`\\." ""
1377 (string-remove-prefix
1378 prefix (file-name-directory f-name))
1379 nil t)
1380 nil t)
1381 nil t))
1382 (setq group (gnus-group-full-name group server))
1383 (setq article (file-name-nondirectory f-name)
1384 article
1385 ;; TODO: Provide a cleaner way of producing final
1386 ;; article numbers for the various backends.
1387 (if (string-match-p "\\`[[:digit:]]+\\'" article)
1388 (string-to-number article)
1389 (nnmaildir-base-name-to-article-number
1390 (substring article 0 (string-match ":" article))
1391 group (string-remove-prefix "nnmaildir:" server))))
1392 (when (and (numberp article)
1393 (or (null groups)
1394 (member group groups)))
1395 (push (list f-name article group score)
1396 artlist)))))
1379 ;; Are we running an additional grep query? 1397 ;; Are we running an additional grep query?
1380 (when-let ((grep-reg (alist-get 'grep query))) 1398 (when-let ((grep-reg (alist-get 'grep query)))
1381 (setq artlist (gnus-search-grep-search engine artlist grep-reg))) 1399 (setq artlist (gnus-search-grep-search engine artlist grep-reg)))
1382 ;; Prep prefix. 1400 ;; Munge into the list of vectors expected by nnselect.
1383 (when (and prefix (null (string-empty-p prefix))) 1401 (mapcar (pcase-lambda (`(,_ ,article ,group ,score))
1384 (setq prefix (file-name-as-directory (expand-file-name prefix)))) 1402 (vector group article
1385 ;; Turn (file-name score) into [group article score]. 1403 (if (numberp score)
1386 (pcase-dolist (`(,f-name ,score) artlist) 1404 score
1387 (setq article (file-name-nondirectory f-name) 1405 (string-to-number score))))
1388 group (file-name-directory f-name)) 1406 artlist)))
1389 ;; Remove prefix.
1390 (when prefix
1391 (setq group (string-remove-prefix prefix group)))
1392 ;; Break the directory name down until it's something that
1393 ;; (probably) can be used as a group name.
1394 (setq group
1395 (replace-regexp-in-string
1396 "[/\\]" "."
1397 (replace-regexp-in-string
1398 "/?\\(cur\\|new\\|tmp\\)?/\\'" ""
1399 (replace-regexp-in-string
1400 "^[./\\]" ""
1401 group nil t)
1402 nil t)
1403 nil t))
1404
1405 (push (vector (gnus-group-full-name group server)
1406 (if (string-match-p "\\`[[:digit:]]+\\'" article)
1407 (string-to-number article)
1408 (nnmaildir-base-name-to-article-number
1409 (substring article 0 (string-match ":" article))
1410 group (string-remove-prefix "nnmaildir:" server)))
1411 (if (numberp score)
1412 score
1413 (string-to-number score)))
1414 vectors))
1415 vectors))
1416 1407
1417(cl-defmethod gnus-search-indexed-extract ((_engine gnus-search-indexed)) 1408(cl-defmethod gnus-search-indexed-extract ((_engine gnus-search-indexed))
1418 "Base implementation treats the whole line as a filename, and 1409 "Base implementation treats the whole line as a filename, and