changeset 102910:3d4fe9d9e9e6

Don't query before visiting a Babyl file. Instead, query before modifications that would save it. * mail/rmail.el (rmail-was-converted): New variable. (rmail-seriously-modified): New variable. (rmail-perm-variables): Set them to nil. (rmail-convert-babyl-to-mbox): Don't query about converting Babyl file. Instead, set rmail-was-converted. (rmail-modify-format): New function. Query if save will change format. (rmail-dont-modify-format): New function. (rmail-duplicate-message, rmail-get-new-mail): Call rmail-modify-format. (rmail-set-header): Call rmail-dont-modify-format. (rmail-set-attribute): Likewise. (rmail-expunge-confirmed): Call rmail-modify-format. * mail/rmailout.el (rmail-output-to-rmail-buffer): Call rmail-modify-format.
author Richard M. Stallman <rms@gnu.org>
date Thu, 09 Apr 2009 16:43:02 +0000
parents 64294c07cca6
children e25ee95fb5b0
files lisp/ChangeLog lisp/mail/rmail.el lisp/mail/rmailout.el
diffstat 3 files changed, 67 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Apr 09 16:33:41 2009 +0000
+++ b/lisp/ChangeLog	Thu Apr 09 16:43:02 2009 +0000
@@ -1,5 +1,21 @@
 2009-04-09  Richard M Stallman  <rms@gnu.org>
 
+	* mail/rmailout.el (rmail-output-to-rmail-buffer):
+	Call rmail-modify-format..
+
+	* mail/rmail.el (rmail-was-converted): New variable.
+	(rmail-seriously-modified): New variable.
+	(rmail-perm-variables): Set them to nil.
+	(rmail-convert-babyl-to-mbox): Don't query about converting Babyl file.
+	Instead, set rmail-was-converted.
+	(rmail-modify-format): New function.  Query if save will change format.
+	(rmail-dont-modify-format): New function.
+	(rmail-duplicate-message, rmail-get-new-mail):
+	Call rmail-modify-format.
+	(rmail-set-header): Call rmail-dont-modify-format.
+	(rmail-set-attribute): Likewise.
+	(rmail-expunge-confirmed): Call rmail-modify-format.
+
 	* mail/sendmail.el (sendmail-send-it): Replace any
 	pre-existing Content-type header if we insert one.
 
--- a/lisp/mail/rmail.el	Thu Apr 09 16:33:41 2009 +0000
+++ b/lisp/mail/rmail.el	Thu Apr 09 16:43:02 2009 +0000
@@ -544,6 +544,14 @@
 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
 (put 'rmail-buffer 'permanent-local t)
 
+(defvar rmail-was-converted nil
+  "Non-nil in an Rmail buffer that was just converted from Babyl format.")
+(put 'rmail-was-converted 'permanent-local t)
+
+(defvar rmail-seriously-modified nil
+  "Non-nil in an Rmail buffer that has been modified in a major way.")
+(put 'rmail-seriously-modified 'permanent-local t)
+
 ;; Message counters and markers.  Deleted flags.
 
 (defvar rmail-current-message nil
@@ -939,9 +947,6 @@
 (defun rmail-convert-babyl-to-mbox ()
   "Convert the mail file from Babyl version 5 to mbox.
 This function also reinitializes local variables used by Rmail."
-  (unless (y-or-n-p "Babyl mail file detected.  Rmail now uses mbox format for mail files.
-Convert Babyl mail file to mbox format? ")
-    (error "Aborted"))
   (let ((old-file (make-temp-file "rmail"))
 	(new-file (make-temp-file "rmail")))
     (unwind-protect
@@ -961,6 +966,7 @@
 	    (rmail-mode-1)
 	    (rmail-perm-variables)
 	    (rmail-variables)
+	    (setq rmail-was-converted t)
 	    (goto-char (point-max))
 	    (rmail-set-message-counters))
 	  (message "Replacing BABYL format with mbox format...done"))
@@ -1334,6 +1340,24 @@
       (rmail-swap-buffers)
       (setq rmail-buffer-swapped nil))))
 
+(defun rmail-modify-format ()
+  "Warn if important modifications would change Rmail file's format."
+  (with-current-buffer rmail-buffer
+    (and rmail-was-converted
+	 ;; If it's already modified, don't warn again.
+	 (not rmail-seriously-modified)
+	 (not
+	  (yes-or-no-p
+	   (message "After this, %s would be saved in mbox format.  Proceed? "
+		    (buffer-name))))
+	 (error "Aborted"))
+    (setq rmail-seriously-modified t)))
+
+(defun rmail-dont-modify-format ()
+  (when (and rmail-was-converted (not rmail-seriously-modified))
+    (set-buffer-modified-p nil)
+    (message "Marking buffer unmodified to avoid rewriting Babyl file as mbox file")))
+
 (defun rmail-mode-kill-buffer-hook ()
   (if (buffer-live-p rmail-view-buffer) (kill-buffer rmail-view-buffer)))
 
@@ -1342,6 +1366,10 @@
   (make-local-variable 'rmail-last-regexp)
   (make-local-variable 'rmail-deleted-vector)
   (make-local-variable 'rmail-buffer)
+  (make-local-variable 'rmail-was-converted)
+  (setq rmail-was-converted nil)
+  (make-local-variable 'rmail-seriously-modified)
+  (setq rmail-seriously-modified nil)
   (setq rmail-buffer (current-buffer))
   (set-buffer-multibyte nil)
   (with-current-buffer (setq rmail-view-buffer (rmail-generate-viewer-buffer))
@@ -1483,6 +1511,7 @@
   ;; If we are in a summary buffer, switch to the Rmail buffer.
   ;; FIXME simpler to swap the contents, not the buffers?
   (set-buffer rmail-buffer)
+  (rmail-modify-format)
   (let ((buff (current-buffer))
         (n rmail-current-message)
         (beg (rmail-msgbeg rmail-current-message))
@@ -1629,6 +1658,7 @@
   (or (verify-visited-file-modtime (current-buffer))
       (find-file (buffer-file-name)))
   (set-buffer rmail-buffer)
+  (rmail-modify-format)
   (rmail-swap-buffers-maybe)
   (rmail-maybe-set-message-counters)
   (widen)
@@ -2049,10 +2079,13 @@
 If MSGNUM is nil, use the current message.  NAME and VALUE are strings.
 VALUE may also be nil, meaning to remove the header."
   (rmail-apply-in-message msgnum 'rmail-set-header-1 name value)
-  ;; Ensure header changes get saved.
-  ;; (Note replacing a header with an identical copy modifies.)
-  (with-current-buffer rmail-buffer (set-buffer-modified-p t)))
-
+  (with-current-buffer rmail-buffer
+    ;; Ensure header changes get saved.
+    ;; (Note replacing a header with an identical copy modifies.)
+    (set-buffer-modified-p t)
+    ;; However: don't save in mbox format over a Babyl file
+    ;; merely because of this.
+    (rmail-dont-modify-format)))
 
 ;;;; *** Rmail Attributes and Keywords ***
 
@@ -2188,10 +2221,9 @@
               (rmail-apply-in-message msgnum 'rmail-set-attribute-1 attr state)
             (if (= msgnum rmail-current-message)
                 (rmail-display-labels)))
-          ;; If we made a significant change in an attribute, mark
-          ;; rmail-buffer modified, so it will be (1) saved and (2)
-          ;; displayed in the mode line.
-          (set-buffer-modified-p t)))))
+	  ;; Don't save in mbox format over a Babyl file
+	  ;; merely because of this.
+	  (rmail-dont-modify-format)))))
 
 (defun rmail-message-attr-p (msg attrs)
   "Return non-nil if message number MSG has attributes matching regexp ATTRS."
@@ -2564,9 +2596,10 @@
 	    (t (setq rmail-current-message msg)))
       (with-current-buffer rmail-buffer
 	(setq header-style rmail-header-style)
-	;; Mark the message as seen, bracket the message in the mail
+	;; Mark the message as seen
+	(rmail-set-attribute rmail-unseen-attr-index nil)
+	;; bracket the message in the mail
 	;; buffer and determine the coding system the transfer encoding.
-	(rmail-set-attribute rmail-unseen-attr-index nil)
 	(rmail-swap-buffers-maybe)
 	(setq beg (rmail-msgbeg msg)
 	      end (rmail-msgend msg))
@@ -3179,9 +3212,10 @@
   ;; Eg to save rmail-expunge wasting its time?
   (or (not (stringp rmail-deleted-vector))
       (not (string-match "D" rmail-deleted-vector))
-      (null rmail-confirm-expunge)
-      (funcall rmail-confirm-expunge
-	       "Erase deleted messages from Rmail file? ")))
+      (if rmail-confirm-expunge
+	  (funcall rmail-confirm-expunge
+		   "Erase deleted messages from Rmail file? ")
+	(progn (rmail-modify-format) t))))
 
 (defun rmail-only-expunge (&optional dont-show)
   "Actually erase all deleted messages in the file."
--- a/lisp/mail/rmailout.el	Thu Apr 09 16:33:41 2009 +0000
+++ b/lisp/mail/rmailout.el	Thu Apr 09 16:43:02 2009 +0000
@@ -366,6 +366,7 @@
 display message number MSG."
   (save-excursion
     (rmail-swap-buffers-maybe)
+    (rmail-modify-format)
     ;; Turn on Auto Save mode, if it's off in this buffer but enabled
     ;; by default.
     (and (not buffer-auto-save-file-name)