aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolaus Rath2017-01-25 00:46:13 +0100
committerLars Ingebrigtsen2017-01-25 00:46:13 +0100
commit4e9baea6aba1633074889339dcc7cdc9d73880d3 (patch)
tree93b25067072b68ef98d51a19ff43ba7a75871a99
parentb6fa58072304c2a24f1fe8a0e06a4739a7f8211b (diff)
downloademacs-4e9baea6aba1633074889339dcc7cdc9d73880d3.tar.gz
emacs-4e9baea6aba1633074889339dcc7cdc9d73880d3.zip
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 (bug#20670).
-rw-r--r--doc/misc/gnus.texi16
-rw-r--r--etc/NEWS10
-rw-r--r--lisp/gnus/nnimap.el87
3 files changed, 73 insertions, 40 deletions
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 05159d4b2f7..e8524fb03f0 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -14273,9 +14273,19 @@ specific login method to be used, you can set this variable to either
14273@code{plain} or @code{cram-md5}. 14273@code{plain} or @code{cram-md5}.
14274 14274
14275@item nnimap-expunge 14275@item nnimap-expunge
14276If non-@code{nil}, expunge articles after deleting them. This is always done 14276When to expunge deleted messages. If @code{never}, deleted articles
14277if the server supports UID EXPUNGE, but it's not done by default on 14277are marked with the IMAP @code{\\Delete} flag but not automatically
14278servers that doesn't support that command. 14278expunged. If @code{immediately}, deleted articles are immediately expunged
14279(this requires the server to support the UID EXPUNGE command). If
14280@code{on-exit}, deleted articles are flagged, and all flagged articles are
14281expunged when the group is closed.
14282
14283For backwards compatibility, this variable may also be set to t
14284or nil. If the server supports UID EXPUNGE, both t and nil are
14285equivalent to @code{immediately}. If the server does not support UID
14286EXPUNGE nil is equivalent to @code{never}, while t will immediately
14287expunge ALL articles that are currently flagged as deleted
14288(i.e., potentially not only the article that was just deleted).
14279 14289
14280@item nnimap-streaming 14290@item nnimap-streaming
14281Virtually all @acronym{IMAP} server support fast streaming of data. 14291Virtually all @acronym{IMAP} server support fast streaming of data.
diff --git a/etc/NEWS b/etc/NEWS
index ca66df62610..e5ee40cbe4b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -81,6 +81,16 @@ for '--daemon'.
81* Changes in Emacs 26.1 81* Changes in Emacs 26.1
82 82
83+++ 83+++
84** The Gnus user variable 'nnimap-expunge' supports three new values:
85'never' for never expunging messages, 'immediately' for immediately
86expunging deleted messages, and 'on-exit' to expunge deleted articles
87when exiting the group's summary buffer. Setting 'nnimap-expunge' to
88'nil' or 't' is still supported but not recommended, since it may
89result in Gnus expunging all messages that have been flagged as
90deleted by any IMAP client (rather than just those that have been
91deleted by Gnus).
92
93+++
84** The new function 'mapbacktrace' applies a function to all frames of 94** The new function 'mapbacktrace' applies a function to all frames of
85the current stack trace. 95the current stack trace.
86 96
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 700e86a0c57..931ec312083 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -92,10 +92,21 @@ Uses the same syntax as `nnmail-split-methods'.")
92Possible choices are nil (use default methods), `anonymous', 92Possible choices are nil (use default methods), `anonymous',
93`login', `plain' and `cram-md5'.") 93`login', `plain' and `cram-md5'.")
94 94
95(defvoo nnimap-expunge t 95(defvoo nnimap-expunge 'on-exit
96 "If non-nil, expunge articles after deleting them. 96 "When to expunge deleted messages.
97This is always done if the server supports UID EXPUNGE, but it's 97If 'never, deleted articles are marked with the IMAP \\Delete
98not done by default on servers that doesn't support that command.") 98flag but not automatically expunged. If 'immediately, deleted
99articles are immediately expunged (this requires the server to
100support the UID EXPUNGE command). If 'on-exit, deleted articles
101are flagged, and all flagged articles are expunged when the
102group is closed.
103
104For backwards compatibility, this variable may also be set to t
105or nil. If the server supports UID EXPUNGE, both t and nil are
106equivalent to 'immediately. If the server does not support UID
107EXPUNGE nil is equivalent to 'never, while t will immediately
108expunge ALL articles that are currently flagged as deleted
109(i.e., potentially not only the article that was just deleted).")
99 110
100(defvoo nnimap-streaming t 111(defvoo nnimap-streaming t
101 "If non-nil, try to use streaming commands with IMAP servers. 112 "If non-nil, try to use streaming commands with IMAP servers.
@@ -910,8 +921,12 @@ textual parts.")
910 articles))) 921 articles)))
911 (nreverse articles))) 922 (nreverse articles)))
912 923
913(deffoo nnimap-close-group (_group &optional _server) 924(deffoo nnimap-close-group (_group &optional server)
914 t) 925 (when (eq nnimap-expunge 'on-exit)
926 (nnoo-change-server 'nnimap server nil)
927 (with-current-buffer (nnimap-buffer)
928 (nnimap-wait-for-response
929 (nnimap-send-command "EXPUNGE")))))
915 930
916(deffoo nnimap-request-move-article (article group server accept-form 931(deffoo nnimap-request-move-article (article group server accept-form
917 &optional _last 932 &optional _last
@@ -960,8 +975,7 @@ textual parts.")
960 articles) 975 articles)
961 ((and force 976 ((and force
962 (eq nnmail-expiry-target 'delete)) 977 (eq nnmail-expiry-target 'delete))
963 (unless (nnimap-delete-article (gnus-compress-sequence articles)) 978 (nnimap-delete-article (gnus-compress-sequence articles))
964 (nnheader-message 7 "Article marked for deletion, but not expunged."))
965 nil) 979 nil)
966 (t 980 (t
967 (let ((deletable-articles 981 (let ((deletable-articles
@@ -1084,21 +1098,38 @@ If LIMIT, first try to limit the search to the N last articles."
1084 (when (and limit number-of-article) 1098 (when (and limit number-of-article)
1085 (nnimap-find-article-by-message-id group server message-id)))))))) 1099 (nnimap-find-article-by-message-id group server message-id))))))))
1086 1100
1087(defun nnimap-delete-article (articles) 1101(defun nnimap-delete-article (articles &optional sync)
1102 "Delete ARTICLES.
1103
1104If sync is non-nil, wait for server response."
1088 (with-current-buffer (nnimap-buffer) 1105 (with-current-buffer (nnimap-buffer)
1089 (nnimap-command "UID STORE %s +FLAGS.SILENT (\\Deleted)" 1106 (nnimap-command "UID STORE %s +FLAGS.SILENT (\\Deleted)"
1090 (nnimap-article-ranges articles)) 1107 (nnimap-article-ranges articles))
1108 (let ((sequence
1091 (cond 1109 (cond
1092 ((nnimap-capability "UIDPLUS") 1110 ((eq nnimap-expunge 'immediately)
1111 (if (nnimap-capability "UIDPLUS")
1093 (nnimap-command "UID EXPUNGE %s" 1112 (nnimap-command "UID EXPUNGE %s"
1094 (nnimap-article-ranges articles)) 1113 (nnimap-article-ranges articles))
1095 t) 1114 (nnheader-message
1115 3 (concat "nnimap-expunge set to 'immediately, but "
1116 "server doesn't support UIDPLUS"))))
1117
1118 ((memq nnimap-expunge '(on-exit never)) nil)
1119
1120 ((nnimap-capability "UIDPLUS")
1121 (nnimap-command "UID EXPUNGE %s"
1122 (nnimap-article-ranges articles)))
1123
1096 (nnimap-expunge 1124 (nnimap-expunge
1097 (nnimap-command "EXPUNGE") 1125 (nnimap-command "EXPUNGE"))
1098 t) 1126
1099 (t (gnus-message 7 (concat "nnimap: nnimap-expunge is not set and the " 1127 (t
1100 "server doesn't support UIDPLUS, so we won't " 1128 (nnheader-message
1101 "delete this article now")))))) 1129 7 "Article marked for deletion, but not expunged.")))))
1130
1131 (if (and sync sequence)
1132 (nnimap-wait-for-response sequence)))))
1102 1133
1103(deffoo nnimap-request-scan (&optional group server) 1134(deffoo nnimap-request-scan (&optional group server)
1104 (when group 1135 (when group
@@ -2118,27 +2149,9 @@ Return the server's response to the SELECT or EXAMINE command."
2118 (nnimap-wait-for-response (caar sequences)) 2149 (nnimap-wait-for-response (caar sequences))
2119 ;; And then mark the successful copy actions as deleted, 2150 ;; And then mark the successful copy actions as deleted,
2120 ;; and possibly expunge them. 2151 ;; and possibly expunge them.
2121 (nnimap-mark-and-expunge-incoming 2152 (nnimap-delete-article
2122 (nnimap-parse-copied-articles sequences))) 2153 (nnimap-parse-copied-articles sequences) t))
2123 (nnimap-mark-and-expunge-incoming junk-articles))))))) 2154 (nnimap-delete-article junk-articles t)))))))
2124
2125(defun nnimap-mark-and-expunge-incoming (range)
2126 (when range
2127 (setq range (nnimap-article-ranges range))
2128 (erase-buffer)
2129 (let ((sequence
2130 (nnimap-send-command
2131 "UID STORE %s +FLAGS.SILENT (\\Deleted)" range)))
2132 (cond
2133 ;; If the server supports it, we now delete the message we have
2134 ;; just copied over.
2135 ((nnimap-capability "UIDPLUS")
2136 (setq sequence (nnimap-send-command "UID EXPUNGE %s" range)))
2137 ;; If it doesn't support UID EXPUNGE, then we only expunge if the
2138 ;; user has configured it.
2139 (nnimap-expunge
2140 (setq sequence (nnimap-send-command "EXPUNGE"))))
2141 (nnimap-wait-for-response sequence))))
2142 2155
2143(defun nnimap-parse-copied-articles (sequences) 2156(defun nnimap-parse-copied-articles (sequences)
2144 (let (sequence copied range) 2157 (let (sequence copied range)