From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/87347 Path: news.gmane.org!.POSTED!not-for-mail From: Nikolaus Rath Newsgroups: gmane.emacs.bugs,gmane.emacs.gnus.general Subject: bug#20670: [PATCH] nnimap: enable additional expunge options (v3) Date: Tue, 24 Jan 2017 15:37:29 -0800 Message-ID: <87k29kyqpy.fsf@vostro.rath.org> References: <556538A5.3050302@rath.org> <87oajs38kf.fsf@vostro.rath.org> <87pojcp7y7.fsf@gnus.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1485301102 2474 195.159.176.226 (24 Jan 2017 23:38:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 24 Jan 2017 23:38:22 +0000 (UTC) User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/24.5 (gnu/linux) Cc: 20670@debbugs.gnu.org, ding@gnus.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 25 00:38:17 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWAfF-0008HV-1X for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Jan 2017 00:38:13 +0100 Original-Received: from localhost ([::1]:56402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWAfK-0006fP-0f for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Jan 2017 18:38:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWAfB-0006fI-KL for bug-gnu-emacs@gnu.org; Tue, 24 Jan 2017 18:38:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cWAf7-0006OU-Vc for bug-gnu-emacs@gnu.org; Tue, 24 Jan 2017 18:38:09 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42912) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cWAf7-0006O4-Qr for bug-gnu-emacs@gnu.org; Tue, 24 Jan 2017 18:38:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cWAf4-000153-BJ; Tue, 24 Jan 2017 18:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Nikolaus Rath Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bugs@gnus.org Resent-Date: Tue, 24 Jan 2017 23:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20670 X-GNU-PR-Package: emacs,gnus X-GNU-PR-Keywords: patch Original-Received: via spool by 20670-submit@debbugs.gnu.org id=B20670.14853010574123 (code B ref 20670); Tue, 24 Jan 2017 23:38:02 +0000 Original-Received: (at 20670) by debbugs.gnu.org; 24 Jan 2017 23:37:37 +0000 Original-Received: from localhost ([127.0.0.1]:41111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWAed-00014P-OI for submit@debbugs.gnu.org; Tue, 24 Jan 2017 18:37:37 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:55997) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWAeZ-00014E-9q for 20670@debbugs.gnu.org; Tue, 24 Jan 2017 18:37:34 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id CE18620975; Tue, 24 Jan 2017 18:37:30 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Tue, 24 Jan 2017 18:37:30 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=5u3PUVVCP4fNYH wYa1QRaeC0N6w=; b=lquoqYUxP4KJYvFL+oucU6Ben7JXVM6WzGTsnbDO+Ku5Q8 P2xfl9L90BO2Msq8dVg4Lb9o/yKYgrEykmX1D20OQiCTPotbeD1Kd9deFTovaNMs z3I1sX3AKFZDmFIweVoucXcaR4wtE6uB0UZ+wXS2XtiN8ZnvWc75KMX08TwYc= X-ME-Sender: X-Sasl-enc: zENOO4Uylvbd9fCB8KsTHbuPMMW83zS+MornbwnJLqx4 1485301050 Original-Received: from ebox.rath.org (ebox.rath.org [45.79.69.51]) by mail.messagingengine.com (Postfix) with ESMTPA id 7A8C87E2DE; Tue, 24 Jan 2017 18:37:30 -0500 (EST) Original-Received: from vostro.rath.org (vostro [192.168.12.4]) by ebox.rath.org (Postfix) with ESMTPS id AF8F2398; Tue, 24 Jan 2017 23:37:29 +0000 (UTC) Original-Received: by vostro.rath.org (Postfix, from userid 1000) id 782F410219D; Tue, 24 Jan 2017 15:37:29 -0800 (PST) Mail-Copies-To: never Mail-Followup-To: Lars Ingebrigtsen , 20670@debbugs.gnu.org, ding@gnus.org In-Reply-To: <87pojcp7y7.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 24 Jan 2017 20:35:28 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128418 gmane.emacs.gnus.general:87347 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Jan 24 2017, Lars Ingebrigtsen wrote: > Nikolaus Rath writes: > >> If the IMAP server supports the UID EXPUNGE command, the nnimap backend >> currently always expunges deleted articles. >> >> If the IMAP server does not support this command, articles are either >> not expunged at all (nnimap-expunge is nil), or ALL articles that are >> currently flagged as deleted will be expunged when any one article is >> deleted in Gnus. >> >> This patch introduces three new settings for nnimap-expunge: > > Looks good. Two minor comments: > > + (nnheader-message 3 (concat "nnimap-expunge set to 'immed= iately, but " > + "server doesn't support UIDPL= US")))) > + > > You've probably done this to make the lines short enough, but the first > one is still more than 80 chars wide. > > + (nnheader-message 7 "Article marked for deletion, but not e= xpunged."))))) > > And so is this. It's probably better to just reflow by breaking the > line after `nnheader-message'. > > This change should also be documented in the "Customizing the IMAP > Connection" node in the Gnus manual, and get an entry in the NEWS > file. Thanks! Attached is an updated patch. Btw, is there any way to generate the list of affected functions in the commit message automatically? Doing this by hand is rather cumbersome... 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: inline; filename=0001-nnimap.el-support-additional-expunge-options.patch >From 3421d2b8c8d3eb20052432d1ba331be886d812a6 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Tue, 24 Jan 2017 15:31:46 -0800 Subject: [PATCH] nnimap.el: support additional expunge options * lisp/gnus/nnimap.el (nnimap-close-group, nnimap-request-expire-articles, nnimap-delete-article, nnimap-request-scan): add new 'never, 'immediate, and 'on-exit settings for nnimap-expunge. --- doc/misc/gnus.texi | 16 ++++++++-- etc/NEWS | 10 +++++++ lisp/gnus/nnimap.el | 85 ++++++++++++++++++++++++++++++----------------------- 3 files changed, 72 insertions(+), 39 deletions(-) diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi index 05159..e8524 100644 --- a/doc/misc/gnus.texi +++ b/doc/misc/gnus.texi @@ -14273,9 +14273,19 @@ Customizing the IMAP Connection @code{plain} or @code{cram-md5}. @item nnimap-expunge -If non-@code{nil}, expunge articles after deleting them. This is always done -if the server supports UID EXPUNGE, but it's not done by default on -servers that doesn't support that command. +When to expunge deleted messages. If @code{never}, deleted articles +are marked with the IMAP @code{\\Delete} flag but not automatically +expunged. If @code{immediately}, deleted articles are immediately expunged +(this requires the server to support the UID EXPUNGE command). If +@code{on-exit}, deleted articles are flagged, and all flagged articles are +expunged when the group is closed. + +For backwards compatibility, this variable may also be set to t +or nil. If the server supports UID EXPUNGE, both t and nil are +equivalent to @code{immediately}. If the server does not support UID +EXPUNGE nil is equivalent to @code{never}, while t will immediately +expunge ALL articles that are currently flagged as deleted +(i.e., potentially not only the article that was just deleted). @item nnimap-streaming Virtually all @acronym{IMAP} server support fast streaming of data. diff --git a/etc/NEWS b/etc/NEWS index ca66d..e5ee4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -81,6 +81,16 @@ for '--daemon'. * Changes in Emacs 26.1 +++ +** The Gnus user variable 'nnimap-expunge' supports three new values: +'never' for never expunging messages, 'immediately' for immediately +expunging deleted messages, and 'on-exit' to expunge deleted articles +when exiting the group's summary buffer. Setting 'nnimap-expunge' to +'nil' or 't' is still supported but not recommended, since it may +result in Gnus expunging all messages that have been flagged as +deleted by any IMAP client (rather than just those that have been +deleted by Gnus). + ++++ ** The new function 'mapbacktrace' applies a function to all frames of the current stack trace. diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el index 700e86..e7e64 100644 --- a/lisp/gnus/nnimap.el +++ b/lisp/gnus/nnimap.el @@ -92,10 +92,21 @@ nnimap-authenticator Possible choices are nil (use default methods), `anonymous', `login', `plain' and `cram-md5'.") -(defvoo nnimap-expunge t - "If non-nil, expunge articles after deleting them. -This is always done if the server supports UID EXPUNGE, but it's -not done by default on servers that doesn't support that command.") +(defvoo nnimap-expunge 'on-exit + "When to expunge deleted messages. +If 'never, deleted articles are marked with the IMAP \\Delete +flag but not automatically expunged. If 'immediately, deleted +articles are immediately expunged (this requires the server to +support the UID EXPUNGE command). If 'on-exit, deleted articles +are flagged, and all flagged articles are expunged when the +group is closed. + +For backwards compatibility, this variable may also be set to t +or nil. If the server supports UID EXPUNGE, both t and nil are +equivalent to 'immediately. If the server does not support UID +EXPUNGE nil is equivalent to 'never, while t will immediately +expunge ALL articles that are currently flagged as deleted +(i.e., potentially not only the article that was just deleted).") (defvoo nnimap-streaming t "If non-nil, try to use streaming commands with IMAP servers. @@ -911,7 +922,11 @@ nnimap-get-flags (nreverse articles))) (deffoo nnimap-close-group (_group &optional _server) - t) + (when (eq nnimap-expunge 'on-exit) + (nnoo-change-server 'nnimap server nil) + (with-current-buffer (nnimap-buffer) + (nnimap-wait-for-response + (nnimap-send-command "EXPUNGE"))))) (deffoo nnimap-request-move-article (article group server accept-form &optional _last @@ -960,8 +975,7 @@ nnimap-request-expire-articles articles) ((and force (eq nnmail-expiry-target 'delete)) - (unless (nnimap-delete-article (gnus-compress-sequence articles)) - (nnheader-message 7 "Article marked for deletion, but not expunged.")) + (nnimap-delete-article (gnus-compress-sequence articles)) nil) (t (let ((deletable-articles @@ -1084,21 +1098,38 @@ nnimap-find-article-by-message-id (when (and limit number-of-article) (nnimap-find-article-by-message-id group server message-id)))))))) -(defun nnimap-delete-article (articles) +(defun nnimap-delete-article (articles &optional sync) + "Delete ARTICLES. + +If sync is non-nil, wait for server response." (with-current-buffer (nnimap-buffer) (nnimap-command "UID STORE %s +FLAGS.SILENT (\\Deleted)" (nnimap-article-ranges articles)) + (let ((sequence (cond - ((nnimap-capability "UIDPLUS") + ((eq nnimap-expunge 'immediately) + (if (nnimap-capability "UIDPLUS") (nnimap-command "UID EXPUNGE %s" (nnimap-article-ranges articles)) - t) + (nnheader-message + 3 (concat "nnimap-expunge set to 'immediately, but " + "server doesn't support UIDPLUS")))) + + ((memq nnimap-expunge '(on-exit never)) nil) + + ((nnimap-capability "UIDPLUS") + (nnimap-command "UID EXPUNGE %s" + (nnimap-article-ranges articles))) + (nnimap-expunge - (nnimap-command "EXPUNGE") - t) - (t (gnus-message 7 (concat "nnimap: nnimap-expunge is not set and the " - "server doesn't support UIDPLUS, so we won't " - "delete this article now")))))) + (nnimap-command "EXPUNGE")) + + (t + (nnheader-message + 7 "Article marked for deletion, but not expunged."))))) + + (if (and sync sequence) + (nnimap-wait-for-response sequence))))) (deffoo nnimap-request-scan (&optional group server) (when group @@ -2118,27 +2149,9 @@ nnimap-split-incoming-mail (nnimap-wait-for-response (caar sequences)) ;; And then mark the successful copy actions as deleted, ;; and possibly expunge them. - (nnimap-mark-and-expunge-incoming - (nnimap-parse-copied-articles sequences))) - (nnimap-mark-and-expunge-incoming junk-articles))))))) - -(defun nnimap-mark-and-expunge-incoming (range) - (when range - (setq range (nnimap-article-ranges range)) - (erase-buffer) - (let ((sequence - (nnimap-send-command - "UID STORE %s +FLAGS.SILENT (\\Deleted)" range))) - (cond - ;; If the server supports it, we now delete the message we have - ;; just copied over. - ((nnimap-capability "UIDPLUS") - (setq sequence (nnimap-send-command "UID EXPUNGE %s" range))) - ;; If it doesn't support UID EXPUNGE, then we only expunge if the - ;; user has configured it. - (nnimap-expunge - (setq sequence (nnimap-send-command "EXPUNGE")))) - (nnimap-wait-for-response sequence)))) + (nnimap-delete-article + (nnimap-parse-copied-articles sequences) t)) + (nnimap-delete-article junk-articles t))))))) (defun nnimap-parse-copied-articles (sequences) (let (sequence copied range) -- 2.1.4 --=-=-=--