From c21d060e5b2b1749993df4345532d87a675f97bf Mon Sep 17 00:00:00 2001 From: dmaus Date: Sun, 3 Jul 2011 13:28:56 +0000 Subject: [PATCH] Prevent accidental loss of messages when renaming IMAP4 mailbox * 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 | 2 ++ elmo/ChangeLog | 6 ++++++ elmo/elmo-imap4.el | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/NEWS b/NEWS index 863c00f..c28552b 100644 --- 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. diff --git a/elmo/ChangeLog b/elmo/ChangeLog index 15e36c7..4c9e946 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,3 +1,9 @@ +2011-07-03 David Maus + + * 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 * elmo-imap4.el (elmo-imap4-fetch-callback-1-subr): Don't mark diff --git a/elmo/elmo-imap4.el b/elmo/elmo-imap4.el index c118af6..58c0546 100644 --- a/elmo/elmo-imap4.el +++ b/elmo/elmo-imap4.el @@ -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 -- 1.7.10.4