diff options
| author | Eric Abrahamsen | 2015-01-27 05:46:15 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2015-01-27 05:46:15 +0000 |
| commit | 4f2ca8e5506de6f5be92bf50c45d5ed3987b5458 (patch) | |
| tree | 4f83f95767711ddefcfcf095a3a165c5346de6c5 | |
| parent | 9e0866e1219b7e49393014fe5d050603d885b111 (diff) | |
| download | emacs-4f2ca8e5506de6f5be92bf50c45d5ed3987b5458.tar.gz emacs-4f2ca8e5506de6f5be92bf50c45d5ed3987b5458.zip | |
lisp/gnus/nnir.el (nnir-run-imap): Enable non-ASCII IMAP searches
| -rw-r--r-- | lisp/gnus/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/gnus/nnir.el | 84 |
2 files changed, 59 insertions, 27 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index b4c5cea97ca..0d105a9b163 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 2015-01-27 Eric Abrahamsen <eric@ericabrahamsen.net> | 1 | 2015-01-27 Eric Abrahamsen <eric@ericabrahamsen.net> |
| 2 | 2 | ||
| 3 | * nnir.el (nnir-run-imap): Enable non-ASCII IMAP searches. | ||
| 4 | |||
| 3 | * nnmairix.el ("nnmairix"): Declare nnmairix as virtual. | 5 | * nnmairix.el ("nnmairix"): Declare nnmairix as virtual. |
| 4 | 6 | ||
| 5 | * gnus-bcklg.el (gnus-backlog-enter-article): No virtual groups should | 7 | * gnus-bcklg.el (gnus-backlog-enter-article): No virtual groups should |
diff --git a/lisp/gnus/nnir.el b/lisp/gnus/nnir.el index 08ca7c7e06b..dcb69aabcd7 100644 --- a/lisp/gnus/nnir.el +++ b/lisp/gnus/nnir.el | |||
| @@ -284,6 +284,8 @@ is `(valuefunc member)'." | |||
| 284 | (eval-when-compile | 284 | (eval-when-compile |
| 285 | (autoload 'nnimap-buffer "nnimap") | 285 | (autoload 'nnimap-buffer "nnimap") |
| 286 | (autoload 'nnimap-command "nnimap") | 286 | (autoload 'nnimap-command "nnimap") |
| 287 | (autoload 'nnimap-capability "nnimap") | ||
| 288 | (autoload 'nnimap-wait-for-line "nnimap") | ||
| 287 | (autoload 'nnimap-change-group "nnimap") | 289 | (autoload 'nnimap-change-group "nnimap") |
| 288 | (autoload 'nnimap-make-thread-query "nnimap") | 290 | (autoload 'nnimap-make-thread-query "nnimap") |
| 289 | (autoload 'gnus-registry-action "gnus-registry") | 291 | (autoload 'gnus-registry-action "gnus-registry") |
| @@ -968,33 +970,52 @@ details on the language and supported extensions." | |||
| 968 | (catch 'found | 970 | (catch 'found |
| 969 | (mapcar | 971 | (mapcar |
| 970 | #'(lambda (group) | 972 | #'(lambda (group) |
| 971 | (let (artlist) | 973 | (let (artlist) |
| 972 | (condition-case () | 974 | (condition-case () |
| 973 | (when (nnimap-change-group | 975 | (when (nnimap-change-group |
| 974 | (gnus-group-short-name group) server) | 976 | (gnus-group-short-name group) server) |
| 975 | (with-current-buffer (nnimap-buffer) | 977 | (with-current-buffer (nnimap-buffer) |
| 976 | (message "Searching %s..." group) | 978 | (message "Searching %s..." group) |
| 977 | (let ((arts 0) | 979 | (let* ((arts 0) |
| 978 | (result (nnimap-command "UID SEARCH %s" | 980 | (literal+ (nnimap-capability "LITERAL+")) |
| 979 | (if (string= criteria "") | 981 | (search (split-string |
| 980 | qstring | 982 | (if (string= criteria "") |
| 981 | (nnir-imap-make-query | 983 | qstring |
| 982 | criteria qstring))))) | 984 | (nnir-imap-make-query |
| 983 | (mapc | 985 | criteria qstring)) |
| 984 | (lambda (artnum) | 986 | "\n")) |
| 985 | (let ((artn (string-to-number artnum))) | 987 | (coding (upcase |
| 986 | (when (> artn 0) | 988 | (replace-regexp-in-string |
| 987 | (push (vector group artn 100) | 989 | "-\\(unix\\|dos\\|mac\\)" "" |
| 988 | artlist) | 990 | (symbol-name |
| 989 | (when (assq 'shortcut query) | 991 | (cdr default-process-coding-system))))) |
| 990 | (throw 'found (list artlist))) | 992 | call result) |
| 991 | (setq arts (1+ arts))))) | 993 | (setq call (nnimap-send-command |
| 992 | (and (car result) | 994 | "UID SEARCH CHARSET %s %s" coding (pop search))) |
| 993 | (cdr (assoc "SEARCH" (cdr result))))) | 995 | (while search ; Non-ascii search terms |
| 994 | (message "Searching %s... %d matches" group arts))) | 996 | (unless literal+ |
| 995 | (message "Searching %s...done" group)) | 997 | (nnimap-wait-for-line "^\\+\\(.*\\)\n")) |
| 996 | (quit nil)) | 998 | (process-send-string (get-buffer-process (current-buffer)) (pop search)) |
| 997 | (nreverse artlist))) | 999 | (process-send-string (get-buffer-process (current-buffer)) |
| 1000 | (if (nnimap-newlinep nnimap-object) | ||
| 1001 | "\n" | ||
| 1002 | "\r\n"))) | ||
| 1003 | (setq result (nnimap-get-response call)) | ||
| 1004 | (mapc | ||
| 1005 | (lambda (artnum) | ||
| 1006 | (let ((artn (string-to-number artnum))) | ||
| 1007 | (when (> artn 0) | ||
| 1008 | (push (vector group artn 100) | ||
| 1009 | artlist) | ||
| 1010 | (when (assq 'shortcut query) | ||
| 1011 | (throw 'found (list artlist))) | ||
| 1012 | (setq arts (1+ arts))))) | ||
| 1013 | (and (car result) | ||
| 1014 | (cdr (assoc "SEARCH" (cdr result))))) | ||
| 1015 | (message "Searching %s... %d matches" group arts))) | ||
| 1016 | (message "Searching %s...done" group)) | ||
| 1017 | (quit nil)) | ||
| 1018 | (nreverse artlist))) | ||
| 998 | groups)))))) | 1019 | groups)))))) |
| 999 | 1020 | ||
| 1000 | (defun nnir-imap-make-query (criteria qstring) | 1021 | (defun nnir-imap-make-query (criteria qstring) |
| @@ -1062,6 +1083,10 @@ In future the following will be added to the language: | |||
| 1062 | ;; Composite term: just the fax, mam | 1083 | ;; Composite term: just the fax, mam |
| 1063 | ((eq (car-safe expr) 'not) | 1084 | ((eq (car-safe expr) 'not) |
| 1064 | (format "NOT (%s)" (nnir-imap-query-to-imap criteria (rest expr)))) | 1085 | (format "NOT (%s)" (nnir-imap-query-to-imap criteria (rest expr)))) |
| 1086 | ;; Composite term: non-ascii search term | ||
| 1087 | ((numberp (car-safe expr)) | ||
| 1088 | (format "%s {%d%s}\n%s" criteria (car expr) | ||
| 1089 | (if literal+ "+" "") (second expr))) | ||
| 1065 | ;; Composite term: just expand it all. | 1090 | ;; Composite term: just expand it all. |
| 1066 | ((and (not (null expr)) (listp expr)) | 1091 | ((and (not (null expr)) (listp expr)) |
| 1067 | (format "(%s)" (nnir-imap-query-to-imap criteria expr))) | 1092 | (format "(%s)" (nnir-imap-query-to-imap criteria expr))) |
| @@ -1108,6 +1133,11 @@ that the search language can then understand and use." | |||
| 1108 | ((eq term 'and) 'and) | 1133 | ((eq term 'and) 'and) |
| 1109 | ;; negated term | 1134 | ;; negated term |
| 1110 | ((eq term 'not) (list 'not (nnir-imap-next-expr))) | 1135 | ((eq term 'not) (list 'not (nnir-imap-next-expr))) |
| 1136 | ;; non-ascii search string | ||
| 1137 | ((and (stringp term) | ||
| 1138 | (not (= (string-bytes term) | ||
| 1139 | (length term)))) | ||
| 1140 | (list (string-bytes term) term)) | ||
| 1111 | ;; generic term | 1141 | ;; generic term |
| 1112 | (t term)))) | 1142 | (t term)))) |
| 1113 | 1143 | ||