all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] RFC4731 for lisp/net/imap.el
@ 2008-08-14  9:10 Vitaly Mayatskikh
  2008-10-29 13:10 ` Simon Josefsson
  0 siblings, 1 reply; 4+ messages in thread
From: Vitaly Mayatskikh @ 2008-08-14  9:10 UTC (permalink / raw
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Hi!

I've added support for "IMAP4 Extension to SEARCH Command for Controlling
What Kind of Information Is Returned". It allows Gnus to uses some nice
features like very fast searching of minuid/maxuid or retrieving results
for SEARCH command in sequence-set. Also patch automatically routes query
from imap-search routine to the new imap-esearch when possible, as it
significantly reduces amount of consumed traffic.

Patch was tested with Zimbra server and it works well so far.


[-- Attachment #2: support for rfc4731 --]
[-- Type: text/plain, Size: 2628 bytes --]

diff -puw lisp/net/imap.el.orig lisp/net/imap.el
--- lisp/net/imap.el.orig	2008-05-06 09:31:46.000000000 +0200
+++ lisp/net/imap.el	2008-08-14 10:40:31.000000000 +0200
@@ -1721,6 +1721,8 @@ is non-nil return these properties."
      (imap-message-get ,uid 'BODY)))
 
 (defun imap-search (predicate &optional buffer)
+  (if (imap-capability 'ESEARCH)
+      (car (imap-esearch (concat "UID SEARCH RETURN (ALL) " predicate) '(ALL)))
   (with-current-buffer (or buffer (current-buffer))
     (imap-mailbox-put 'search 'dummy)
     (when (imap-ok-p (imap-send-command-wait (concat "UID SEARCH " predicate)))
@@ -1728,7 +1730,39 @@ is non-nil return these properties."
 	  (progn
 	    (message "Missing SEARCH response to a SEARCH command (server not RFC compliant)...")
 	    nil)
-	(imap-mailbox-get-1 'search imap-current-mailbox)))))
+	  (imap-mailbox-get-1 'search imap-current-mailbox))))))
+
+(defun imap-esearch (query tags &optional buffer)
+  (with-current-buffer (or buffer (current-buffer))
+    (imap-mailbox-put 'esearch 'dummy)
+    (when (imap-ok-p (imap-send-command-wait query))
+      (if (eq (imap-mailbox-get-1 'esearch imap-current-mailbox) 'dummy)
+	  (progn
+	    (message "Missing ESEARCH response to a SEARCH command (server not RFC compliant)...")
+	    nil)
+	(let ((answer (imap-mailbox-get-1 'esearch imap-current-mailbox))
+	      tag result)
+	  (while answer
+	    (setq tag (intern (upcase (car answer))))
+	    (cond ((eq tag 'UID)
+		   nil)
+		  ((memq tag tags)
+		   (setq result
+			 (append result
+				 (list
+				  (if (eq tag 'ALL)
+				      (gnus-uncompress-range 
+				       (mapcar #'(lambda (x)
+						   (let ((y (split-string x ":")))
+						     (if (null (cdr y))
+							 (string-to-number (car y))
+						       (cons (string-to-number (car y))
+							     (string-to-number (cadr y))))))
+					       (split-string (cadr answer) "\,")))
+				    (string-to-number (cadr answer)))))))
+		  (t nil))
+	    (setq answer (cdr answer)))
+	  result)))))
 
 (defun imap-message-flag-permanent-p (flag &optional mailbox buffer)
   "Return t if FLAG can be permanently (between IMAP sessions) saved on articles, in MAILBOX on server in BUFFER."
@@ -2265,6 +2299,9 @@ Return nil if no complete line has arriv
 	   (SEARCH     (imap-mailbox-put
 			'search
 			(read (concat "(" (buffer-substring (point) (point-max)) ")"))))
+	   (ESEARCH     (imap-mailbox-put
+			 'esearch
+			 (cddr (split-string (buffer-substring (point) (point-max)) " " "\,"))))
 	   (STATUS     (imap-parse-status))
 	   (CAPABILITY (setq imap-capability
 			       (read (concat "(" (upcase (buffer-substring

[-- Attachment #3: Type: text/plain, Size: 25 bytes --]


Thanks!
-- 
wbr, Vitaly

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-03  8:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-14  9:10 [PATCH] RFC4731 for lisp/net/imap.el Vitaly Mayatskikh
2008-10-29 13:10 ` Simon Josefsson
2008-11-01 16:03   ` Vitaly Mayatskikh
2008-11-03  8:47     ` Simon Josefsson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.