;;; nnir.el --- search mail with various search engines
;; Copyright (C) 1998 Kai Großjohann
-;; $Id: nnir.el,v 1.1.2.1 2001/09/04 10:32:55 tsuchiya Exp $
-
;; Author: Kai Großjohann <grossjohann@ls6.cs.uni-dortmund.de>
-;; Keywords: news, mail, searching, ir, glimpse, wais, Namazu
+;; Keywords: news, mail, searching, ir, glimpse, wais
;; This file is not part of GNU Emacs.
;; For maximum searching efficiency I have a cron job set to run this
;; command every four hours.
-;; 3. Namazu
-;;
-;;
-
;; Developer information:
;; I have tried to make the code expandable. Basically, it is divided
;;; Setup Code:
-(defconst nnir-version "$Id: nnir.el,v 1.1.2.1 2001/09/04 10:32:55 tsuchiya Exp $"
+(defconst nnir-version "1.72"
"Version of NNIR.")
(require 'cl)
(defvar nnir-engines
'((glimpse nnir-run-glimpse
((group . "Group spec: ")))
- (namazu nnir-run-namazu
- ((group . "Group spec: ")))
(wais nnir-run-waissearch
())
(excite nnir-run-excite-search
;;; User Customizable Variables:
(defgroup nnir nil
- "Search nnmh and nnml groups in Gnus with Glimpse, freeWAIS-sf, Namazu,
-or EWS.")
+ "Search nnmh and nnml groups in Gnus with Glimpse, freeWAIS-sf, or EWS.")
;; Mail backend.
:type '(repeat (string))
:group 'nnir)
-;; Namazu engine.
-
-(defcustom nnir-namazu-program "namazu"
- "*Name of Namazu executable."
- :type '(string)
- :group 'nnir)
-
-(defcustom nnir-namazu-index (expand-file-name "Namazu/" (getenv "HOME"))
- "*Namazu index directory"
- :type '(directory)
- :group 'nnir)
-
-(defcustom nnir-namazu-remove-prefix (concat (getenv "HOME") "/Mail/")
- "*The prefix to remove from each file name returned by Namazu
-in order to get a group name (albeit with / instead of .)."
- :type '(directory)
- :group 'nnir)
-
;; freeWAIS-sf.
(defcustom nnir-wais-program "waissearch"
:type '(regexp)
:group 'nnir)
+(defcustom nnir-imap-default-charset nil
+ "*Name of the charset of the strings that appear in the search criteria."
+ :type '(choice (const nil) symbol)
+ :group 'nnir)
+
;; Swish++. Next three variables Copyright (C) 2000, 2001 Christoph
;; Conrad <christoph.conrad@gmx.de>.
;; Swish++ home page: http://homepage.mac.com/pauljlucas/software/swish/
(kbd "G G")
"GG") ; XEmacs 19 compat
'gnus-group-make-nnir-group))
-(add-hook 'gnus-group-mode-hook 'nnir-group-mode-hook)
+(add-hook 'gnus-group-mode-hook
+ (lambda ()
+ (unless (string-match "T-gnus" gnus-version)
+ (nnir-group-mode-hook))))
(nnir-artitem-number y))))))
)))
-;; Namazu interface
-(defun nnir-run-namazu (query &optional group)
- "Run given query against namazu. Returns a vector of (group name, file name)
-pairs (also vectors, actually)."
- (save-excursion
- (let ((artlist nil)
- (groupspec (cdr (assq 'group query)))
- (qstring (cdr (assq 'query query)))
- (coding-system-for-read 'euc-japan)
- (coding-system-for-write 'euc-japan))
- (when (and group groupspec)
- (error (concat "It does not make sense to use a group spec"
- " with process-marked groups.")))
- (when group
- (setq groupspec (gnus-group-real-name group)))
- (set-buffer (get-buffer-create nnir-tmp-buffer))
- (erase-buffer)
- (if groupspec
- (message "Doing namazu query %s on %s..." query groupspec)
- (message "Doing namazu query %s..." query))
- (let* ((cp-list
- `( ,nnir-namazu-program
- nil ; input from /dev/null
- t ; output
- nil ; don't redisplay
- "--all" "--list" "--early"
- ,(if groupspec
- (format "+uri:%s %s" groupspec qstring)
- (format "%s" qstring))
- ,nnir-namazu-index ; index
- ))
- (exitstatus
- (progn
- (message "%s args: %s" nnir-namazu-program
- (mapconcat 'identity (cddddr cp-list) " "))
- (apply 'call-process cp-list))))
- (unless (or (null exitstatus)
- (zerop exitstatus))
- (nnheader-report "Couldn't run namazu: %s" exitstatus)
- ;; Namazu failure reason is in this buffer, show it if
- ;; the user wants it.
- (when (> gnus-verbose 6)
- (display-buffer nnir-tmp-buffer))))
- (if groupspec
- (message "Doing namazu query %s on %s..." query groupspec)
- (message "Doing namazu query %s...done" query))
- (sit-for 0)
- ;; CCC: The following work of extracting group name and article
- ;; number from the Namazu output can probably better be done by
- ;; just going through the buffer once, and plucking out the
- ;; right information from each line.
- ;; remove superfluous stuff from namazu output
- (goto-char (point-min))
- (delete-non-matching-lines "/[0-9]+$")
- ;;(delete-matching-lines "\\.overview~?$")
- (goto-char (point-min))
- (while (re-search-forward (concat "^" nnir-namazu-remove-prefix) nil t)
- (replace-match ""))
- ;; separate group name from article number with \t
- ;; XEmacs compatible version
- (goto-char (point-max))
- (while (re-search-backward "/[0-9]+$" nil t)
- (delete-char 1 nil)
- (insert-char ?\t 1))
-; Emacs compatible version
-; (goto-char (point-min))
-; (while (re-search-forward "\\(/\\)[0-9]+$" nil t)
-; (replace-match "\t" t t nil 1))
- ;; replace / with . in group names
- (subst-char-in-region (point-min) (point-max) ?/ ?. t)
- ;; massage buffer to contain some Lisp;
- ;; this depends on the artlist encoding internals
- ;; maybe this dependency should be removed?
- (goto-char (point-min))
- (while (not (eobp))
- (insert "(\"")
- (skip-chars-forward "^\t")
- (insert "\" ")
- (end-of-line)
- (insert " 1000 )") ; 1000 = score
- (forward-line 1))
- (insert "))\n")
- (goto-char (point-min))
- (insert "(setq artlist '(\n")
- (eval-buffer)
- artlist
- )))
-
;; freeWAIS-sf interface.
(defun nnir-run-waissearch (query &optional group)
"Run given query agains waissearch. Returns vector of (group name, file name)
;; send queries as literals
;; handle errors
+(eval-when-compile
+ (defvar nnimap-server-buffer))
+
(defun nnir-run-imap (query &optional group)
(require 'imap)
(require 'nnimap)
+ (require 'mm-util)
(unless group
(error "Must specify groups for IMAP searching."))
(save-excursion
(setq buf nnimap-server-buffer) ;; xxx
(message "Searching %s..." group)
(let ((arts 0)
- (mbx (gnus-group-real-name group)))
+ (mbx (gnus-group-real-name group))
+ (multibyte-p (mm-multibyte-p))
+ charset coding-system)
(when (imap-mailbox-select mbx nil buf)
+ (with-temp-buffer
+ (if multibyte-p
+ (mm-enable-multibyte))
+ (insert qstring)
+ (setq charset (car (mm-find-mime-charset-region
+ (point-min)(point-max)))))
+ (unless charset
+ (setq charset nnir-imap-default-charset))
(mapcar
(lambda (artnum)
(push (vector mbx artnum 1) artlist)
(setq arts (1+ arts)))
- (imap-search (concat "TEXT \"" qstring "\"") buf))
+ (if (and (not (eq charset 'us-ascii))
+ (setq coding-system (mm-charset-to-coding-system
+ charset)))
+ (imap-search
+ (concat "CHARSET " (symbol-name charset) " TEXT \""
+ (mm-encode-coding-string qstring coding-system)
+ "\"") buf)
+ (imap-search (concat "TEXT \"" qstring "\"") buf)))
(message "Searching %s... %d matches" mbx arts)))
(message "Searching %s...done" group))
(quit nil))
,nnir-namazu-index-directory ; index directory
))
(exitstatus
- (progn
+ (let ((process-environment (copy-sequence process-environment)))
+ ;; Disable locale.
+ (setenv "LC_ALL" "C")
(message "%s args: %s" nnir-namazu-program
(mapconcat 'identity (cddddr cp-list) " "))
- (apply 'call-process cp-list))))
- (unless (or (null exitstatus)
+ (apply 'call-process cp-list))))
+ (unless (or (null exitstatus)
(zerop exitstatus))
(nnheader-report 'nnir "Couldn't run namazu: %s" exitstatus)
;; Namazu failure reason is in this buffer, show it if