From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Vitaly Mayatskikh Newsgroups: gmane.emacs.devel Subject: [PATCH] RFC4731 for lisp/net/imap.el Date: Thu, 14 Aug 2008 11:10:17 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1218705109 17754 80.91.229.12 (14 Aug 2008 09:11:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Aug 2008 09:11:49 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 14 11:12:41 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KTYsq-00072s-Kp for ged-emacs-devel@m.gmane.org; Thu, 14 Aug 2008 11:12:40 +0200 Original-Received: from localhost ([127.0.0.1]:48479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTYrt-000522-Ut for ged-emacs-devel@m.gmane.org; Thu, 14 Aug 2008 05:11:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KTYqe-0004Rb-Qr for emacs-devel@gnu.org; Thu, 14 Aug 2008 05:10:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KTYqc-0004PS-Pj for emacs-devel@gnu.org; Thu, 14 Aug 2008 05:10:23 -0400 Original-Received: from [199.232.76.173] (port=49327 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTYqc-0004P3-0j for emacs-devel@gnu.org; Thu, 14 Aug 2008 05:10:22 -0400 Original-Received: from fg-out-1718.google.com ([72.14.220.154]:53801) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KTYqb-0003A7-Ke for emacs-devel@gnu.org; Thu, 14 Aug 2008 05:10:21 -0400 Original-Received: by fg-out-1718.google.com with SMTP id l26so278278fgb.30 for ; Thu, 14 Aug 2008 02:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:user-agent:mime-version:content-type; bh=q2d7CqswafuzeRnw0IYeVwq872oERMYvhFlu6CevOqk=; b=YCCaxQ1NKbrGuQdzHCpDckqxLsKG5asiHwQ4ZAuInyM+Iwa1v6t27Tx6nJJHdL79Ud EH4m7SrIPn687w3uD/GtJGKjrAMeBSpTTBgNrpE3HfpQ+oKDlJLMQ3dF+5TwtuxxYjWC sF6eC21R6relJSMvpWe/HeRkpz/DgbYc0n9jc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; b=JsXpoYIw12ZcrNWaonL1OxJA7v5dhGrX+4ly5d8NGRzrdaTXHzrPjvTclpdqp3bFFH sHm0/BYKRaYgEYAZpK8sChCaaEeyEZqOiVC0uGOyy/tPKi+9Xed046z3O4FXBQauLpau jK2+C3Pd51cluHsoPLpk7Yq4oSzvWdfEwmH6A= Original-Received: by 10.86.82.6 with SMTP id f6mr1702619fgb.38.1218705020042; Thu, 14 Aug 2008 02:10:20 -0700 (PDT) Original-Received: from gravicappa.englab.brq.redhat.com ( [62.40.79.66]) by mx.google.com with ESMTPS id l19sm2455885fgb.7.2008.08.14.02.10.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 14 Aug 2008 02:10:19 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:102433 Archived-At: --=-=-= 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. --=-=-= Content-Disposition: inline; filename=rfc4731.patch Content-Description: support for rfc4731 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 --=-=-= Thanks! -- wbr, Vitaly --=-=-=--