Prevent accidental loss of messages when renaming IMAP4 mailbox
authordmaus <dmaus>
Sun, 3 Jul 2011 13:28:56 +0000 (13:28 +0000)
committerdmaus <dmaus>
Sun, 3 Jul 2011 13:28:56 +0000 (13:28 +0000)
* elmo-imap4.el (elmo-imap4-session-unselect-mailbox): New
function. Leave selected state without silent EXPUNGE.
(elmo-folder-rename-internal): Use function.

CLOSE silently triggers EXPUNGE. Use UNSELECT (RFC3691) if the server
supports this extension, otherwise open mailbox read-only
(i.e. EXAMIME) before calling CLOSE.

Ported from branch elmo-imap4-compliance, deal with merge conflicts
later.

NEWS
elmo/ChangeLog
elmo/elmo-imap4.el

diff --git a/NEWS b/NEWS
index 863c00f..c28552b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ Wanderlust NEWS -- User-visible changes in Wanderlust.
 
 * Changes in 2.16.0 from 2.14.x
 
+** Prevent accidental loss of messages when renaming IMAP folder
+
 ** Put spam mark on the message registered as spam.
 
 ** Remove spam mark from the message registered as non-spam.
index 15e36c7..4c9e946 100644 (file)
@@ -1,3 +1,9 @@
+2011-07-03  David Maus  <dmaus@ictsoc.de>
+
+       * elmo-imap4.el (elmo-imap4-session-unselect-mailbox): New
+       function. Leave selected state without silent EXPUNGE.
+       (elmo-folder-rename-internal): Use function.
+
 2011-06-03  David Maus  <dmaus@ictsoc.de>
 
        * elmo-imap4.el (elmo-imap4-fetch-callback-1-subr): Don't mark
index c118af6..58c0546 100644 (file)
@@ -738,6 +738,17 @@ Returns response value if selecting folder succeed. "
                         (format "Select %s failed" mailbox)))))))
       (and result response))))
 
+(defun elmo-imap4-session-unselect-mailbox (session mailbox)
+  "Unselect MAILBOX in SESSION.
+Deselecting will exit selected state without causing silent
+EXPUNGE for deleted messages."
+  (if (elmo-imap4-session-capable-p session 'unselect)
+      (elmo-imap4-send-command-wait session "unselect")
+    (elmo-imap4-send-command-wait
+     session
+     (list "examine " (elmo-imap4-mailbox mailbox)))
+    (elmo-imap4-send-command-wait session "close")))
+
 (defun elmo-imap4-check-validity (spec validity-file)
 ;;; Not used.
 ;;;(elmo-imap4-send-command-wait
@@ -2172,6 +2183,9 @@ Return nil if no complete line has arrived."
     (elmo-imap4-session-select-mailbox session
                                       (elmo-imap4-folder-mailbox-internal
                                        folder))
+    (elmo-imap4-session-unselect-mailbox session
+                                        (elmo-imap4-folder-mailbox-internal
+                                         folder))
     (elmo-imap4-send-command-wait session "close")
     (elmo-imap4-send-command-wait
      session