From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/86048 Path: news.gmane.org!not-for-mail From: Nikolaus Rath Newsgroups: gmane.emacs.gnus.general Subject: Re: [PATCH] Use IMAP MOVE extension if available Date: Wed, 08 Jul 2015 19:13:03 -0700 Message-ID: <87io9udqog.fsf@vostro.rath.org> References: <87twv0junf.fsf@vostro.rath.org> <87vbdwoeer.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1436408039 6099 80.91.229.3 (9 Jul 2015 02:13:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 9 Jul 2015 02:13:59 +0000 (UTC) To: ding@gnus.org, 20671@debbugs.gnu.org Original-X-From: ding-owner+M34283@lists.math.uh.edu Thu Jul 09 04:13:48 2015 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from lists1.math.uh.edu ([129.7.128.208]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZD1LO-0003m5-0y for ding-account@gmane.org; Thu, 09 Jul 2015 04:13:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.85) (envelope-from ) id 1ZD1Ku-0003nb-3v; Wed, 08 Jul 2015 21:13:16 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by lists1.math.uh.edu with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1ZD1Kr-0003nB-Tc for ding@lists.math.uh.edu; Wed, 08 Jul 2015 21:13:14 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.84) (envelope-from ) id 1ZD1Kq-0004FG-5u for ding@lists.math.uh.edu; Wed, 08 Jul 2015 21:13:13 -0500 Original-Received: from ebox.rath.org ([23.92.25.96]) by quimby.gnus.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1ZD1Ko-0003n9-C8 for ding@gnus.org; Thu, 09 Jul 2015 04:13:10 +0200 Original-Received: from vostro ([192.168.12.4] helo=vostro.rath.org) by ebox.rath.org with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.80) (envelope-from ) id 1ZD1Ki-0007tD-I7; Thu, 09 Jul 2015 02:13:04 +0000 Original-Received: by vostro.rath.org (Postfix, from userid 1000) id 06F28EC53AA; Wed, 8 Jul 2015 19:13:03 -0700 (PDT) Mail-Copies-To: never Mail-Followup-To: ding@gnus.org, 20671@debbugs.gnu.org In-Reply-To: <87vbdwoeer.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Tue, 07 Jul 2015 11:05:48 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Spam-Score: -1.8 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:86048 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Jul 06 2015, Eric Abrahamsen wrote: > Nikolaus Rath writes: > >> Hello, >> >> Currently Gnus uses a combination of COPY, STORE + EXPUNGE to move >> messages from one imap group into another. >> >> The attached patch enables the use of the MOVE command instead if the >> server supports it. >> >> Thanks for considering. >> >> (Is this the right place to post patches, or should it go to >> bug-gnu-emacs@gnu.org?) >> >> Best, >> -Nikolaus > > and `nnimap-process-expiry-target', sorry... Updated patch is attached. Note that the changes to nnimap-split-incoming-mail are untested (I don't use that function). Best, -Nikolaus --=20 GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F =C2=BBTime flies like an arrow, fruit flies like a Banana.=C2= =AB --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Use-IMAP-MOVE-extension-if-available.patch >From 2cd9616461e3551e3e2e556879fb3e83846754b7 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Wed, 8 Jul 2015 19:10:46 -0700 Subject: [PATCH] Use IMAP MOVE extension if available Currently Gnus uses a combination of COPY, STORE + EXPUNGE to move messages from one IMAP group into another. This patch enables the use of the MOVE command instead if the server supports it. --- lisp/nnimap.el | 59 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/lisp/nnimap.el b/lisp/nnimap.el index cc1691b..db1a91a 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -960,17 +960,19 @@ If non-nil, articles flagged as deleted (using the IMAP ;; way. (let ((message-id (message-field-value "message-id"))) (if internal-move-group - (let ((result - (with-current-buffer (nnimap-buffer) - (nnimap-command "UID COPY %d %S" - article - (utf7-encode internal-move-group t))))) - (when (car result) - (nnimap-delete-article article) - (cons internal-move-group - (or (nnimap-find-uid-response "COPYUID" (cadr result)) - (nnimap-find-article-by-message-id - internal-move-group server message-id + (with-current-buffer (nnimap-buffer) + (let* ((can-move (nnimap-capability "MOVE")) + (command (if can-move + "UID MOVE %d %S" + "UID COPY %d %S")) + (result (nnimap-command command article + (utf7-encode internal-move-group t)))) + (when (and (car result) (not can-move)) + (nnimap-delete-article article)) + (cons internal-move-group + (or (nnimap-find-uid-response "COPYUID" (cadr result)) + (nnimap-find-article-by-message-id + internal-move-group server message-id nnimap-request-articles-find-limit))))) ;; Move the article to a different method. (let ((result (eval accept-form))) @@ -1009,11 +1011,12 @@ If non-nil, articles flagged as deleted (using the IMAP (gnus-sorted-complement articles deletable-articles)))))) (defun nnimap-process-expiry-targets (articles group server) - (let ((deleted-articles nil)) + (let ((deleted-articles nil) + (articles-to-delete nil)) (cond ;; shortcut further processing if we're going to delete the articles ((eq nnmail-expiry-target 'delete) - (setq deleted-articles articles) + (setq articles-to-delete articles) t) ;; or just move them to another folder on the same IMAP server ((and (not (functionp nnmail-expiry-target)) @@ -1023,11 +1026,14 @@ If non-nil, articles flagged as deleted (using the IMAP (and (nnimap-change-group group server) (with-current-buffer (nnimap-buffer) (nnheader-message 7 "Expiring articles from %s: %s" group articles) - (nnimap-command - "UID COPY %s %S" - (nnimap-article-ranges (gnus-compress-sequence articles)) - (utf7-encode (gnus-group-real-name nnmail-expiry-target) t)) - (setq deleted-articles articles))) + (let ((can-move (nnimap-capability "MOVE"))) + (nnimap-command + (if can-move + "UID MOVE %s %S" + "UID COPY %s %S") + (nnimap-article-ranges (gnus-compress-sequence articles)) + (utf7-encode (gnus-group-real-name nnmail-expiry-target) t)) + (set (if can-move 'deleted-articles 'articles-to-delete) articles)))) t) (t (dolist (article articles) @@ -1048,11 +1054,13 @@ If non-nil, articles flagged as deleted (using the IMAP (setq target nil)) (nnheader-message 7 "Expiring article %s:%d" group article)) (when target - (push article deleted-articles)))))) - (setq deleted-articles (nreverse deleted-articles)))) + (push article articles-to-delete)))))) + (setq articles-to-delete (nreverse articles-to-delete)))) ;; Change back to the current group again. (nnimap-change-group group server) - (nnimap-delete-article (gnus-compress-sequence deleted-articles)) + (when articles-to-delete + (nnimap-delete-article (gnus-compress-sequence articles-to-delete)) + (setq deleted-articles articles-to-delete)) deleted-articles)) (defun nnimap-find-expired-articles (group) @@ -2103,6 +2111,7 @@ Return the server's response to the SELECT or EXAMINE command." nnmail-split-fancy)) (nnmail-inhibit-default-split-group t) (groups (nnimap-get-groups)) + (can-move (nnimap-capability "MOVE")) new-articles) (erase-buffer) (nnimap-command "SELECT %S" nnimap-inbox) @@ -2137,14 +2146,16 @@ Return the server's response to the SELECT or EXAMINE command." ;; Don't copy if the message is already in its ;; target group. (unless (string= group nnimap-inbox) - (push (list (nnimap-send-command - "UID COPY %s %S" + (push (list (nnimap-send-command + (if can-move + "UID MOVE %d %S" + "UID COPY %s %S") (nnimap-article-ranges ranges) (utf7-encode group t)) ranges) sequences))))) ;; Wait for the last COPY response... - (when sequences + (when (and (not can-move) sequences) (nnimap-wait-for-response (caar sequences)) ;; And then mark the successful copy actions as deleted, ;; and possibly expunge them. -- 2.1.4 --=-=-=--