elmo-imap4.el (elmo-imap4-session-deselect-mailbox): New function.
authordmaus <dmaus>
Wed, 4 Aug 2010 16:33:35 +0000 (16:33 +0000)
committerdmaus <dmaus>
Wed, 4 Aug 2010 16:33:35 +0000 (16:33 +0000)
Leave selected state without causing silent EXPUNGE.
(elmo-imap4-folder-status-plugged, elmo-folder-rename-internal): Use
function.

elmo/ChangeLog
elmo/elmo-imap4.el

index 8e3052b..d73c05b 100644 (file)
@@ -1,3 +1,10 @@
+2010-08-04  David Maus  <dmaus@ictsoc.de>
+
+       * elmo-imap4.el (elmo-imap4-session-deselect-mailbox): New
+       function.  Leave selected state without causing silent EXPUNGE.
+       (elmo-imap4-folder-status-plugged, elmo-folder-rename-internal):
+       Use function.
+
 2010-07-18  David Maus  <dmaus@ictsoc.de>
 
        * elmo-imap4.el (elmo-imap4-mailbox-size-update-maybe): Ignore
index 6aae78d..a8a97d4 100644 (file)
@@ -763,6 +763,19 @@ Returns response value if selecting folder succeed. "
                         (format "Select %s failed" mailbox)))))))
       (and result response))))
 
+(defun elmo-imap4-session-deselect-mailbox (session mailbox)
+  "Deselect 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"))
+  (elmo-imap4-session-set-current-mailbox-internal session nil)
+  (elmo-imap4-session-set-current-mailbox-size-internal session nil))
+
 (defun elmo-imap4-check-validity (spec validity-file)
 ;;; Not used.
 ;;;(elmo-imap4-send-command-wait
@@ -1981,9 +1994,9 @@ Return nil if no complete line has arrived."
       (setq elmo-imap4-status-callback-data nil))
     (cond
      ((and selected (not elmo-imap4-use-select-to-update-status))
-      (elmo-imap4-send-command-wait session "close")
-      (elmo-imap4-session-set-current-mailbox-internal session nil)
-      (elmo-imap4-session-set-current-mailbox-size-internal session nil))
+      (elmo-imap4-session-deselect-mailbox
+       session
+       (elmo-imap4-folder-mailbox-internal folder)))
      ((and (not selected) elmo-imap4-use-select-to-update-status)
       ;; This will result in a violation of RFC3501: calling STATUS on
       ;; a selected mailbox.
@@ -2193,11 +2206,11 @@ Return nil if no complete line has arrived."
 (luna-define-method elmo-folder-rename-internal ((folder elmo-imap4-folder)
                                                 new-folder)
   (let ((session (elmo-imap4-get-session folder)))
-    ;; make sure the folder is selected.
-    (elmo-imap4-session-select-mailbox session
-                                      (elmo-imap4-folder-mailbox-internal
-                                       folder))
-    (elmo-imap4-send-command-wait session "close")
+    (if (elmo-imap4-mailbox-selected-p
+        (elmo-imap4-folder-mailbox-internal folder) session)
+       (elmo-imap4-session-deselect-mailbox
+        session
+        (elmo-imap4-folder-mailbox-internal folder)))
     (elmo-imap4-send-command-wait
      session
      (list "rename "