diff options
| author | Glenn Morris | 2009-09-15 02:33:58 +0000 |
|---|---|---|
| committer | Glenn Morris | 2009-09-15 02:33:58 +0000 |
| commit | fe6793d4f8a038fe0a8932a2c3979350e1712ca4 (patch) | |
| tree | 6cdef8ca3a1482281d78061985c4a779eeffc0ba | |
| parent | fbc88440ddf307a6ec5d0254740b09314abf1ad0 (diff) | |
| download | emacs-fe6793d4f8a038fe0a8932a2c3979350e1712ca4.tar.gz emacs-fe6793d4f8a038fe0a8932a2c3979350e1712ca4.zip | |
(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.
| -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.") | |||
| 80 | "Save the attachment using info in the BUTTON." | 80 | "Save the attachment using info in the BUTTON." |
| 81 | (let* ((filename (button-get button 'filename)) | 81 | (let* ((filename (button-get button 'filename)) |
| 82 | (directory (button-get button 'directory)) | 82 | (directory (button-get button 'directory)) |
| 83 | (data (button-get button 'data))) | 83 | (data (button-get button 'data)) |
| 84 | (while (file-exists-p (expand-file-name filename directory)) | 84 | (ofilename filename)) |
| 85 | (let* ((f (file-name-sans-extension filename)) | ||
| 86 | (i 1)) | ||
| 87 | (when (string-match "-\\([0-9]+\\)$" f) | ||
| 88 | (setq i (1+ (string-to-number (match-string 1 f))) | ||
| 89 | f (substring f 0 (match-beginning 0)))) | ||
| 90 | (setq filename (concat f "-" (number-to-string i) "." | ||
| 91 | (file-name-extension filename))))) | ||
| 92 | (setq filename (expand-file-name | 85 | (setq filename (expand-file-name |
| 93 | (read-file-name (format "Save as (default: %s): " filename) | 86 | (read-file-name (format "Save as (default: %s): " filename) |
| 94 | directory | 87 | directory |
| 95 | (expand-file-name filename directory)) | 88 | (expand-file-name filename directory)) |
| 96 | directory)) | 89 | directory)) |
| 97 | (when (file-regular-p filename) | 90 | ;; If arg is just a directory, use the default file name, but in |
| 98 | (error (message "File `%s' already exists" filename))) | 91 | ;; that directory (copied from write-file). |
| 99 | (with-temp-file filename | 92 | (if (file-directory-p filename) |
| 93 | (setq filename (expand-file-name | ||
| 94 | (file-name-nondirectory ofilename) | ||
| 95 | (file-name-as-directory filename)))) | ||
| 96 | (with-temp-buffer | ||
| 100 | (set-buffer-file-coding-system 'no-conversion) | 97 | (set-buffer-file-coding-system 'no-conversion) |
| 101 | (insert data)))) | 98 | (insert data) |
| 99 | (write-region nil nil filename nil nil nil t)))) | ||
| 102 | 100 | ||
| 103 | (define-button-type 'rmail-mime-save | 101 | (define-button-type 'rmail-mime-save 'action 'rmail-mime-save) |
| 104 | 'action 'rmail-mime-save) | ||
| 105 | 102 | ||
| 106 | ;;; Handlers | 103 | ;;; Handlers |
| 107 | 104 | ||
| @@ -154,7 +151,7 @@ MIME-Version: 1.0 | |||
| 154 | (insert-button filename | 151 | (insert-button filename |
| 155 | :type 'rmail-mime-save | 152 | :type 'rmail-mime-save |
| 156 | 'filename filename | 153 | 'filename filename |
| 157 | 'directory directory | 154 | 'directory (file-name-as-directory directory) |
| 158 | 'data data))) | 155 | 'data data))) |
| 159 | 156 | ||
| 160 | (defun test-rmail-mime-bulk-handler () | 157 | (defun test-rmail-mime-bulk-handler () |