Create numbered backup of attached file when already exists #2090

This commit is contained in:
Thierry Volpiatto 2021-08-16 13:29:07 +02:00
parent d6658c49b8
commit 58cff913fe
No known key found for this signature in database
GPG Key ID: 08FDB07A7433A7F2
1 changed files with 13 additions and 1 deletions

View File

@ -503,7 +503,19 @@ containing commas."
dir (if arg (read-directory-name "Save to directory: ") mu4e-attachment-dir))
(cl-loop for (f . h) in handles
when (member f files)
do (mm-save-part-to-file h (expand-file-name f dir))))
do (mm-save-part-to-file
h (let ((file (expand-file-name f dir)))
(if (file-exists-p file)
(let (newname
(count 1))
(while (progn
(setq newname (concat (file-name-sans-extension file)
(format "(%s)" count)
(file-name-extension file t)))
(file-exists-p newname))
(cl-incf count))
newname)
file)))))
(mu4e-message "No attached files found"))))