diff --git a/lisp/nnir.el b/lisp/nnir.el index 3739cb8..4e8a97b 100644 --- a/lisp/nnir.el +++ b/lisp/nnir.el @@ -339,6 +339,12 @@ (eval-when-compile (require 'cl)) + +(eval-when-compile + (autoload 'nnimap-buffer "nnimap") + (autoload 'nnimap-command "nnimap") + (autoload 'nnimap-possibly-change-group "nnimap")) + (nnoo-declare nnir) (nnoo-define-basics nnir) @@ -346,15 +352,15 @@ (defvar nnir-imap-search-field "TEXT" "The IMAP search item when doing an nnir search. To use raw - imap queries by default set this to \"\"") + imap queries by default set this to \"Imap\"") (defvar nnir-imap-search-arguments '(("Whole message" . "TEXT") ("Subject" . "SUBJECT") ("To" . "TO") ("From" . "FROM") - ("Head" . "HEADER \"%s\"") - (nil . "")) + ("Imap" . "") + (nil . "HEADER \"%s\"")) "Mapping from user readable strings to IMAP search items for use in nnir") (defvar nnir-imap-search-argument-history () @@ -375,9 +381,8 @@ result, `gnus-retrieve-headers' will be called instead.") ()) (imap nnir-run-imap ((criteria - "Search in: " ; Prompt + "Search in" ; Prompt ,nnir-imap-search-arguments ; alist for completing - nil ; no filtering nil ; allow any user input nil ; initial value nnir-imap-search-argument-history ; the history to use @@ -703,19 +708,30 @@ and show thread that contains this article." (let* ((cur (gnus-summary-article-number)) (group (nnir-artlist-artitem-group nnir-artlist cur)) (backend-number (nnir-artlist-artitem-number nnir-artlist cur)) - server backend-group) - (setq server (nnir-group-server group)) - (setq backend-group (gnus-group-real-name group)) - (gnus-group-read-ephemeral-group - backend-group - (gnus-server-to-method server) - t ; activate - (cons (current-buffer) - 'summary) ; window config - nil - (list backend-number)) - (gnus-summary-limit (list backend-number)) - (gnus-summary-refer-thread))) + (id (mail-header-id (gnus-summary-article-header))) + (refs (split-string + (mail-header-references (gnus-summary-article-header))))) + (if (string= (car (gnus-group-method group)) "nnimap") + (with-current-buffer (nnimap-buffer) + (let* ((cmd (let ((value + (format + "(OR HEADER REFERENCES %s HEADER Message-Id %s)" + id id))) + (dolist (refid refs value) + (setq value (format + "(OR (OR HEADER Message-Id %s HEADER REFERENCES %s) %s)" + refid refid value))))) + (result (nnimap-command + "UID SEARCH %s" cmd))) + (gnus-summary-read-group-1 group t t gnus-summary-buffer nil + (and (car result) + (delete 0 (mapcar #'string-to-number + (cdr (assoc "SEARCH" (cdr result))))))))) + (gnus-summary-read-group-1 group t t gnus-summary-buffer + nil (list backend-number)) + (gnus-summary-limit (list backend-number)) + (gnus-summary-refer-thread)))) + (if (fboundp 'eval-after-load) (eval-after-load "gnus-sum" @@ -937,22 +953,9 @@ pairs (also vectors, actually)." ;; IMAP interface. ;; todo: -;; nnir invokes this two (2) times???! -;; we should not use nnimap at all but open our own server connection -;; we should not LIST * but use nnimap-list-pattern from defs ;; send queries as literals ;; handle errors -(autoload 'nnimap-open-server "nnimap") -(defvar nnimap-server-buffer) ;; nnimap.el -(autoload 'imap-mailbox-select "imap") -(autoload 'imap-search "imap") -(autoload 'imap-quote-specials "imap") - -(eval-when-compile - (autoload 'nnimap-buffer "nnimap") - (autoload 'nnimap-command "nnimap") - (autoload 'nnimap-possibly-change-group "nnimap")) (defun nnir-run-imap (query srv &optional group-option) "Run a search against an IMAP back-end server. @@ -1045,7 +1048,7 @@ In future the following will be added to the language: (cond ;; Simple string term ((stringp expr) - (format "%s \"%s\"" criteria (imap-quote-specials expr))) + (format "%s \"%s\"" criteria (nnir-imap-quote-specials expr))) ;; Trivial term: and ((eq expr 'and) nil) ;; Composite term: or expression @@ -1579,7 +1582,7 @@ Tested with Namazu 2.0.6 on a GNU/Linux system." (let ((sym (car parmspec)) (prompt (cdr parmspec))) (if (listp prompt) - (let* ((result (gnus-completing-read prompt nil)) + (let* ((result (apply 'gnus-completing-read prompt)) (mapping (or (assoc result nnir-imap-search-arguments) (assoc nil nnir-imap-search-arguments)))) (cons sym (format (cdr mapping) result))) @@ -1693,6 +1696,16 @@ The Gnus backend/server information is added." with-dups) res)) +(defun nnir-imap-quote-specials (string) + (with-temp-buffer + (insert string) + (goto-char (point-min)) + (while (re-search-forward "[\\\"]" nil t) + (forward-char -1) + (insert "\\") + (forward-char 1)) + (buffer-string))) + ;; The end. (provide 'nnir)