diff lisp/mail/rmailmm.el @ 105019:a4b91a313ddf

(rmail-mime-save): If file exists, don't try to be clever and add a suffix to make a unique name, just let the user decide whether or not to overwrite it. If the input is a directory, write the default filename to that directory. (Bug#4388) (rmail-mime-bulk-handler): Ensure the save button's 'directory property is a filename-as-a-directory.
author Glenn Morris <rgm@gnu.org>
date Tue, 15 Sep 2009 02:33:58 +0000
parents 6a35503cf20b
children 721db724bb12
line wrap: on
line diff
--- a/lisp/mail/rmailmm.el	Tue Sep 15 01:21:41 2009 +0000
+++ b/lisp/mail/rmailmm.el	Tue Sep 15 02:33:58 2009 +0000
@@ -80,28 +80,25 @@
   "Save the attachment using info in the BUTTON."
   (let* ((filename (button-get button 'filename))
 	 (directory (button-get button 'directory))
-	 (data (button-get button 'data)))
-    (while (file-exists-p (expand-file-name filename directory))
-      (let* ((f (file-name-sans-extension filename))
-	     (i 1))
-	(when (string-match "-\\([0-9]+\\)$" f)
-	  (setq i (1+ (string-to-number (match-string 1 f)))
-		f (substring f 0 (match-beginning 0))))
-	(setq filename (concat f "-" (number-to-string i) "."
-			       (file-name-extension filename)))))
+	 (data (button-get button 'data))
+	 (ofilename filename))
     (setq filename (expand-file-name
 		    (read-file-name (format "Save as (default: %s): " filename)
 				    directory
 				    (expand-file-name filename directory))
 		    directory))
-    (when (file-regular-p filename)
-      (error (message "File `%s' already exists" filename)))
-    (with-temp-file filename
+    ;; If arg is just a directory, use the default file name, but in
+    ;; that directory (copied from write-file).
+    (if (file-directory-p filename)
+	(setq filename (expand-file-name
+			(file-name-nondirectory ofilename)
+			(file-name-as-directory filename))))
+    (with-temp-buffer
       (set-buffer-file-coding-system 'no-conversion)
-      (insert data))))
+      (insert data)
+      (write-region nil nil filename nil nil nil t))))
 
-(define-button-type 'rmail-mime-save
-  'action 'rmail-mime-save)
+(define-button-type 'rmail-mime-save 'action 'rmail-mime-save)
 
 ;;; Handlers
 
@@ -154,7 +151,7 @@
     (insert-button filename
 		   :type 'rmail-mime-save
 		   'filename filename
-		   'directory directory
+		   'directory (file-name-as-directory directory)
 		   'data data)))
 
 (defun test-rmail-mime-bulk-handler ()