From: Glenn Morris Date: Tue, 15 Sep 2009 02:33:58 +0000 (+0000) Subject: (rmail-mime-save): If file exists, don't try to be clever and add a X-Git-Tag: emacs-pretest-23.1.90~1318 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fe6793d4f8a038fe0a8932a2c3979350e1712ca4;p=emacs.git (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. --- diff --git a/lisp/mail/rmailmm.el b/lisp/mail/rmailmm.el index 0ba6fe2c88b..5cb0d24f459 100644 --- a/lisp/mail/rmailmm.el +++ b/lisp/mail/rmailmm.el @@ -80,28 +80,25 @@ If more than 3, offer a way to save all attachments at once.") "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 @@ MIME-Version: 1.0 (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 ()