]> code.delx.au - gnu-emacs/commitdiff
lisp/gnus/nnir.el (nnir-run-imap): Enable non-ASCII IMAP searches
authorEric Abrahamsen <eric@ericabrahamsen.net>
Tue, 27 Jan 2015 05:46:15 +0000 (05:46 +0000)
committerKatsumi Yamaoka <yamaoka@jpl.org>
Tue, 27 Jan 2015 05:46:15 +0000 (05:46 +0000)
lisp/gnus/ChangeLog
lisp/gnus/nnir.el

index b4c5cea97cad914b06c5207a71bfed60ff636744..0d105a9b1635dc3fe07a6374167282d2562205d4 100644 (file)
@@ -1,5 +1,7 @@
 2015-01-27  Eric Abrahamsen  <eric@ericabrahamsen.net>
 
+       * nnir.el (nnir-run-imap): Enable non-ASCII IMAP searches.
+
        * nnmairix.el ("nnmairix"): Declare nnmairix as virtual.
 
        * gnus-bcklg.el (gnus-backlog-enter-article): No virtual groups should
index 08ca7c7e06b317fc6e0bcd591aed3cc95d6efc46..dcb69aabcd7b1398960a18fa1e995df36af4c160 100644 (file)
@@ -284,6 +284,8 @@ is `(valuefunc member)'."
 (eval-when-compile
   (autoload 'nnimap-buffer "nnimap")
   (autoload 'nnimap-command "nnimap")
+  (autoload 'nnimap-capability "nnimap")
+  (autoload 'nnimap-wait-for-line "nnimap")
   (autoload 'nnimap-change-group "nnimap")
   (autoload 'nnimap-make-thread-query "nnimap")
   (autoload 'gnus-registry-action "gnus-registry")
@@ -968,33 +970,52 @@ details on the language and supported extensions."
        (catch 'found
          (mapcar
           #'(lambda (group)
-            (let (artlist)
-              (condition-case ()
-                  (when (nnimap-change-group
-                         (gnus-group-short-name group) server)
-                    (with-current-buffer (nnimap-buffer)
-                      (message "Searching %s..." group)
-                      (let ((arts 0)
-                            (result (nnimap-command "UID SEARCH %s"
-                                                    (if (string= criteria "")
-                                                        qstring
-                                                      (nnir-imap-make-query
-                                                       criteria qstring)))))
-                        (mapc
-                         (lambda (artnum)
-                           (let ((artn (string-to-number artnum)))
-                             (when (> artn 0)
-                               (push (vector group artn 100)
-                                     artlist)
-                               (when (assq 'shortcut query)
-                                 (throw 'found (list artlist)))
-                               (setq arts (1+ arts)))))
-                         (and (car result)
-                             (cdr (assoc "SEARCH" (cdr result)))))
-                        (message "Searching %s... %d matches" group arts)))
-                    (message "Searching %s...done" group))
-                (quit nil))
-              (nreverse artlist)))
+             (let (artlist)
+               (condition-case ()
+                   (when (nnimap-change-group
+                          (gnus-group-short-name group) server)
+                     (with-current-buffer (nnimap-buffer)
+                       (message "Searching %s..." group)
+                       (let* ((arts 0)
+                              (literal+ (nnimap-capability "LITERAL+"))
+                              (search (split-string
+                                       (if (string= criteria "")
+                                           qstring
+                                         (nnir-imap-make-query
+                                         criteria qstring))
+                                       "\n"))
+                              (coding (upcase
+                                       (replace-regexp-in-string
+                                        "-\\(unix\\|dos\\|mac\\)" ""
+                                        (symbol-name
+                                         (cdr default-process-coding-system)))))
+                              call result)
+                         (setq call (nnimap-send-command
+                                       "UID SEARCH CHARSET %s %s" coding (pop search)))
+                         (while search ; Non-ascii search terms
+                           (unless literal+
+                             (nnimap-wait-for-line "^\\+\\(.*\\)\n"))
+                           (process-send-string (get-buffer-process (current-buffer)) (pop search))
+                           (process-send-string (get-buffer-process (current-buffer))
+                              (if (nnimap-newlinep nnimap-object)
+                                  "\n"
+                                "\r\n")))
+                         (setq result (nnimap-get-response call))
+                         (mapc
+                          (lambda (artnum)
+                            (let ((artn (string-to-number artnum)))
+                              (when (> artn 0)
+                                (push (vector group artn 100)
+                                      artlist)
+                                (when (assq 'shortcut query)
+                                  (throw 'found (list artlist)))
+                                (setq arts (1+ arts)))))
+                          (and (car result)
+                               (cdr (assoc "SEARCH" (cdr result)))))
+                         (message "Searching %s... %d matches" group arts)))
+                     (message "Searching %s...done" group))
+                 (quit nil))
+               (nreverse artlist)))
           groups))))))
 
 (defun nnir-imap-make-query (criteria qstring)
@@ -1062,6 +1083,10 @@ In future the following will be added to the language:
    ;; Composite term: just the fax, mam
    ((eq (car-safe expr) 'not)
     (format "NOT (%s)" (nnir-imap-query-to-imap criteria (rest expr))))
+   ;; Composite term: non-ascii search term
+   ((numberp (car-safe expr))
+    (format "%s {%d%s}\n%s" criteria (car expr)
+           (if literal+ "+" "") (second expr)))
    ;; Composite term: just expand it all.
    ((and (not (null expr)) (listp expr))
     (format "(%s)" (nnir-imap-query-to-imap criteria expr)))
@@ -1108,6 +1133,11 @@ that the search language can then understand and use."
      ((eq term 'and) 'and)
      ;; negated term
      ((eq term 'not) (list 'not (nnir-imap-next-expr)))
+     ;; non-ascii search string
+     ((and (stringp term)
+          (not (= (string-bytes term)
+                  (length term))))
+      (list (string-bytes term) term))
      ;; generic term
      (t term))))