[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

imap patches for nnir



Some patches for the latest nnir to make it work with current
imap.el/nnimap.el. (Once the nnimap.el rewrite is finished the API
will be frozen).

It still performs the same search more than once though, making it
somewhat inefficient. This is with nnir 1.40.

Warning!  Don't use nnir/imap with UW based servers. It searches =all=
groups, and this is a Bad Thing with UW based servers. To be
practically usable, nnir/imap need to use group process marks or
something to limit the groups it should search anyway.

(Is this the best MIME type for elisp patches?  I'm not sure how this
MIME stuff will turn out...)

--- nnir.el-	Wed Mar  3 14:41:03 1999
+++ nnir.el	Wed Mar  3 15:17:58 1999
@@ -690,42 +690,38 @@
 ;; IMAP interface.  The following function is Copyright (C) 1998 Simon
 ;; Josefsson <jas@pdc.kth.se>.
 ;; todo:
-;; it does the same search three (3) times???!
+;; 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
-;; utf7 encode queries
+;; send queries as literals
 ;; handle errors
 (defun nnir-run-imap (query)
   (require 'imap)
   (require 'nnimap)
   (save-excursion
     (let ((qstring (cdr (assq 'query query)))
-          (server (cadr nnir-mail-backend))
-          (defs (caddr nnir-mail-backend)))
+	  (server (cadr nnir-mail-backend))
+	  (defs (caddr nnir-mail-backend))
+	  artlist buf)
       (message "Opening server %s" server)
-      (when (nnimap-open-server server defs) ;; xxx
-       (let ((artlist nil)
-             (buf nnimap-server-buffer)) ;; xxx
-         (message "Fetching mailbox list from %s" server)
-         (imap-send-command-wait "LIST \"\" *" buf) ;; xxx
-         (message "Searching mailboxes...")
-         (mapatoms (lambda (sym)
-                     (let ((group (symbol-name sym))
-                           (arts 0))
-                       (setq imap-current-folder group)
-                       (imap-send-command-wait (format "SELECT %s" group) buf)
-                       (imap-send-command-wait (format "UID SEARCH TEXT %s"
-                                                       qstring) buf)
-                       (mapcar (lambda (artnum)
-                                 (push (vector group artnum 1) artlist)
-                                 (setq arts (1+ arts)))
-                               (imap-folder-get 'search nil buf))
-                       (message "%d matching articles in mailbox %s"
-                                arts group)))
-                   (with-current-buffer buf imap-data-folder))
-         (message "Searching mailboxes...done")
-        (reverse artlist))))))
-
+      (condition-case ()
+	  (when (nnimap-open-server server defs) ;; xxx
+	    (setq buf nnimap-server-buffer) ;; xxx
+	    (message "Searching mailboxes...")
+	    (mapcar
+	     (lambda (group)
+	       (let ((arts 0))
+		 (when (imap-mailbox-select group buf)
+		   (mapcar
+		    (lambda (artnum)
+		      (push (vector group artnum 1) artlist)
+		      (setq arts (1+ arts)))
+		    (imap-search (concat "TEXT \"" qstring "\"") buf))
+		   (message "%d matching articles in mailbox %s" arts group))))
+	     (imap-mailbox-list buf "*"))
+	    (message "Searching mailboxes...done"))
+	(quit nil))
+      (reverse artlist))))
 
 ;;; Util Code: