--- /usr/share/emacs/site-lisp/gnus-bonus-el/nnir.el 2003-04-04 23:16:09.000000000 +0300 +++ /home/adept/.emacs-lisp/nnir.el 2004-02-06 00:11:27.000000000 +0200 @@ -318,6 +318,8 @@ (swish-e nnir-run-swish-e ((group . "Group spec: "))) (namazu nnir-run-namazu + ()) + (mairix nnir-run-mairix ())) "Alist of supported search engines. Each element in the alist is a three-element list (ENGINE FUNCTION ARGS). @@ -577,6 +567,39 @@ :type '(directory) :group 'nnir) +;; Mairix engine, see + +(defcustom nnir-mairix-program "mairix" + "*Name of Mairix search executable." + :type '(string) + :group 'nnir) + +(defcustom nnir-mairix-additional-switches '() + "*A list of strings, to be given as additional arguments to mairix. +The switche `-r' is always used, very few other switches (except `-t') +make any sense in this context. + +Note that this should be a list. Ie, do NOT use the following: + (setq nnir-mairix-additional-switches \"-t -t\") ; wrong +Instead, use this: + (setq nnir-mairix-additional-switches '(\"-t\" \"-t\"))" + :type '(repeat (string)) + :group 'nnir) + +(defcustom nnir-mairix-config-file (expand-file-name "~/.mairixrc") + "*Config file for Mairix." + :type '(file) + :group 'nnir) + +(defcustom nnir-mairix-remove-prefix (concat (getenv "HOME") "/Mail[^/]*/") + "*The prefix to remove from each file name returned by Mairix +in order to get a group name (albeit with / instead of .). + +This variable is very similar to `nnir-glimpse-remove-prefix', except +that it is for Mairix, not Glimpse." + :type '(directory) + :group 'nnir) + ;;; Internal Variables: (defvar nnir-current-query nil @@ -1271,6 +1293,78 @@ (> (nnir-artitem-rsv x) (nnir-artitem-rsv y))))))))) +;; Mairix interface +(defun nnir-run-mairix (query &optional group) + "Run given query against Mairix. Returns a vector of (group name, file name) +pairs (also vectors, actually). + +Tested with Mairix 0.11 on a Debian GNU/Linux system, unstable distribution." + (when group + (error "The Mairix backend cannot search specific groups")) + (save-excursion + (let ( + (artlist nil) + (qstring (cdr (assq 'query query))) + (group nil) + (article nil) + (process-environment (copy-sequence process-environment)) + ) + (setenv "LC_MESSAGES" "C") + (set-buffer (get-buffer-create nnir-tmp-buffer)) + (erase-buffer) + (let* ((cp-list + `( ,nnir-mairix-program + nil ; input from /dev/null + t ; output + nil ; don't redisplay + "-f" + ,nnir-mairix-config-file + "-r" ; produce raw output, do not link articles to + ; into result dir (see Mairix doc for info) + ,@nnir-mairix-additional-switches + ,@(split-string qstring) ; the query, in mairix format + )) + (exitstatus + (progn + (message "%s args: %s" nnir-mairix-program + (mapconcat 'identity (cddddr cp-list) " ")) + (apply 'call-process cp-list)))) + (unless (or (null exitstatus) + (zerop exitstatus)) + (nnheader-report 'nnir "Couldn't run mairix: %s" exitstatus) + ;; Mairix failure reason is in this buffer, show it if + ;; the user wants it. + (when (> gnus-verbose 6) + (display-buffer nnir-tmp-buffer)))) + + ;; Mairix output looks something like this: + ;; /home/henrik/Mail/mail/sent/1310 + ;; + ;; Matched 1 message + + (goto-char (point-min)) + (while (re-search-forward + "^\\/.+" + nil t) + (setq group (file-name-directory (match-string 0)) + article (file-name-nondirectory (match-string 0))) + + ;; make sure article and group is sane + (when (and (string-match "^[0-9]+$" article) + (not (null group))) + (when (string-match (concat "^" nnir-mairix-remove-prefix) group) + (setq group (replace-match "" t t group))) + + ;; remove trailing slash from groupname + (setq group (substring group 0 -1)) + + ;; stuff results into artlist vector + (push (vector (substitute ?. ?/ group) + (string-to-int article) + 1000) artlist))) + + (apply 'vector artlist)))) + ;;; Util Code: (defun nnir-read-parms (query)