Split 2004-04-05 entry. Fix attribution.
[gnus] / contrib / nnir.el
index 27e0f3d..b6c074f 100644 (file)
 
 ;;; Setup Code:
 
-(require 'cl)
 (require 'nnoo)
 (require 'gnus-group)
 (require 'gnus-sum)
 (require 'message)
+(require 'gnus-util)
 (eval-and-compile
-  (require 'gnus-util))
-(eval-when-compile
-  (require 'nnimap)
-  (autoload 'read-kbd-macro "edmacro" nil t))
+  (require 'cl))
 
 (nnoo-declare nnir)
 (nnoo-define-basics nnir)
@@ -668,9 +665,6 @@ that it is for Namazu, not Wais."
            gnus-current-window-configuration)
      nil)))
 
-;; Emacs 19 compatibility?
-(or (fboundp 'kbd) (defalias 'kbd 'read-kbd-macro))
-
 (defun nnir-group-mode-hook ()
   (define-key gnus-group-mode-map (kbd "G G")
     'gnus-group-make-nnir-group))
@@ -766,15 +760,8 @@ and show thread that contains this article."
 (deffoo nnir-retrieve-headers (articles &optional group server fetch-old)
   (save-excursion
     (let ((artlist (copy-sequence articles))
-          (art nil)
-          (artitem nil)
-          (artgroup nil) (artno nil)
-          (artrsv nil)
-          (artfullgroup nil)
-          (novitem nil)
-          (novdata nil)
-          (foo nil)
-         server)
+          art artitem artgroup artno artrsv artfullgroup
+          novitem novdata foo server)
       (while (not (null artlist))
         (setq art (car artlist))
         (or (numberp art)
@@ -828,7 +815,7 @@ and show thread that contains this article."
         (setq artlist (cdr artlist)))
       (setq novdata (nreverse novdata))
       (set-buffer nntp-server-buffer) (erase-buffer)
-      (mapcar 'nnheader-insert-nov novdata)
+      (mapc 'nnheader-insert-nov novdata)
       'nov)))
 
 (deffoo nnir-request-article (article
@@ -866,6 +853,7 @@ and if it is non-nil, add it to artlist."
      (when (not (null result))
        (push result artlist))))
 
+(autoload 'nnmaildir-base-name-to-article-number "nnmaildir")
 
 ;; Helper function currently used by the Swish++ and Namazu backends;
 ;; perhaps useful for other backends as well
@@ -877,25 +865,24 @@ ready to be added to the list of search results."
   (when (string-match (concat "^" prefix) dirnam)
     (setq dirnam (replace-match "" t t dirnam)))
 
-  (if (not (file-readable-p (concat prefix dirnam article)))
-      nil
+  (when (file-readable-p (concat prefix dirnam article))
     ;; remove trailing slash and, for nnmaildir, cur/new/tmp
     (setq dirnam
          (substring dirnam 0 (if (string= server "nnmaildir:") -5 -1)))
 
-    ;; eliminate all ".", "/", "\" from beginning. Always matches.
-    (string-match "^[./\\]*\\(.*\\)$" dirnam)
-    (setq group (substitute ?. ?/ (match-string 1 dirnam))) ;; "/" -> "."
-    (setq group (substitute ?. ?\\ group)) ;; "\\" -> "."
+    ;; Set group to dirnam without any leading dots or slashes,
+    ;; and with all subsequent slashes replaced by dots
+    (let ((group (gnus-replace-in-string
+                 (gnus-replace-in-string dirnam "^[./\\]" "" t)
+                 "[/\\]" "." t)))
 
     (vector (nnir-group-full-name group server)
            (if (string= server "nnmaildir:")
                (nnmaildir-base-name-to-article-number
                 (substring article 0 (string-match ":" article))
                 group nil)
-             (string-to-int article))
-           (string-to-int score))))
-
+             (string-to-number article))
+           (string-to-number score)))))
 
 ;;; Search Engine Interfaces:
 
@@ -908,8 +895,7 @@ pairs (also vectors, actually)."
   (save-excursion
     (let ((qstring (cdr (assq 'query query)))
          (prefix (nnir-read-server-parm 'nnir-wais-remove-prefix server))
-          (artlist nil)
-          (score nil) (artno nil) (dirnam nil) (group nil))
+          artlist score artno dirnam group)
       (set-buffer (get-buffer-create nnir-tmp-buffer))
       (erase-buffer)
       (message "Doing WAIS query %s..." query)
@@ -934,8 +920,8 @@ pairs (also vectors, actually)."
                            dirnam prefix))
         (setq group (substitute ?. ?/ (replace-match "" t t dirnam)))
         (push (vector (nnir-group-full-name group server)
-                      (string-to-int artno)
-                      (string-to-int score))
+                      (string-to-number artno)
+                      (string-to-number score))
               artlist))
       (message "Massaging waissearch output...done")
       (apply 'vector
@@ -952,12 +938,15 @@ pairs (also vectors, actually)."
 ;; send queries as literals
 ;; handle errors
 
+(autoload 'nnimap-open-server "nnimap")
+(autoload 'imap-mailbox-select "imap")
+(autoload 'imap-search "imap")
+(autoload 'imap-quote-specials "imap")
+
 (defun nnir-run-imap (query srv &optional group-option)
   "Run a search against an IMAP back-end server.
 This uses a custom query language parser; see `nnir-imap-make-query' for
 details on the language and supported extensions"
-  (require 'imap)
-  (require 'nnimap)
   (save-excursion
     (let ((qstring (cdr (assq 'query query)))
          (server (cadr (gnus-server-to-method srv)))
@@ -974,7 +963,7 @@ details on the language and supported extensions"
             (let ((arts 0)
                   (mbx (gnus-group-real-name group)))
               (when (imap-mailbox-select mbx nil buf)
-                (mapcar
+                (mapc
                  (lambda (artnum)
                    (push (vector group artnum 1) artlist)
                    (setq arts (1+ arts)))
@@ -1179,7 +1168,7 @@ Windows NT 4.0."
     (let ( (qstring (cdr (assq 'query query)))
           (groupspec (cdr (assq 'group query)))
           (prefix (nnir-read-server-parm 'nnir-swish++-remove-prefix server))
-           (artlist nil)
+           artlist
           ;; nnml-use-compressed-files might be any string, but probably this
           ;; is sufficient.  Note that we can't only use the value of
           ;; nnml-use-compressed-files because old articles might have been
@@ -1187,7 +1176,7 @@ Windows NT 4.0."
           (article-pattern (if (string= server "nnmaildir:")
                                ":[0-9]+"
                              "^[0-9]+\\(\\.[a-z0-9]+\\)?$"))
-           (score nil) (artno nil) (dirnam nil) (group nil) )
+           score artno dirnam group filenam )
 
       (when (equal "" qstring)
         (error "swish++: You didn't enter anything."))
@@ -1269,8 +1258,7 @@ Tested with swish-e-2.0.1 on Windows NT 4.0."
          (prefix
           (or (nnir-read-server-parm 'nnir-swish-e-remove-prefix server)
               (error "Missing parameter `nnir-swish-e-remove-prefix'")))
-         (artlist nil)
-         (score nil) (artno nil) (dirnam nil) (group nil) )
+          artlist score artno dirnam group )
 
       (when (equal "" qstring)
         (error "swish-e: You didn't enter anything."))
@@ -1334,8 +1322,8 @@ Tested with swish-e-2.0.1 on Windows NT 4.0."
             (setq group (substitute ?. ?\\ group))
 
             (push (vector (nnir-group-full-name group server)
-                          (string-to-int artno)
-                          (string-to-int score))
+                          (string-to-number artno)
+                          (string-to-number score))
                   artlist))))
 
       (message "Massaging swish-e output...done")
@@ -1411,8 +1399,8 @@ Tested with swish-e-2.0.1 on Windows NT 4.0."
        (when (string-match prefix dirnam)
          (setq dirnam (replace-match "" t t dirnam)))
        (push (vector (nnir-group-full-name (substitute ?. ?/ dirnam) server)
-                     (string-to-int artno)
-                     (string-to-int score))
+                     (string-to-number artno)
+                     (string-to-number score))
              artlist))
       (message "Massaging hyrex-search output...done.")
       (apply 'vector
@@