diff options
author | Glenn Morris <rgm@gnu.org> | 2009-09-15 02:33:58 +0000 |
---|---|---|
committer | Glenn Morris <rgm@gnu.org> | 2009-09-15 02:33:58 +0000 |
commit | fe6793d4f8a038fe0a8932a2c3979350e1712ca4 (patch) | |
tree | 6cdef8ca3a1482281d78061985c4a779eeffc0ba /lisp/mail | |
parent | fbc88440ddf307a6ec5d0254740b09314abf1ad0 (diff) | |
download | emacs-fe6793d4f8a038fe0a8932a2c3979350e1712ca4.tar.gz |
(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.
Diffstat (limited to 'lisp/mail')
-rw-r--r-- | lisp/mail/rmailmm.el | 29 |
1 files changed, 13 insertions, 16 deletions
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 () |