-
-
Save jsrjenkins/196cdfea06dbbb198107f6e5f897bf83 to your computer and use it in GitHub Desktop.
From an mu4e view, without prompt, save all attachments to a directory and open dired.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar bulk-saved-attachments-dir (expand-file-name "~/Documents/Attachments")) | |
(defun cleanse-subject (sub) | |
(replace-regexp-in-string | |
"[^A-Z0-9]+" | |
"-" | |
(downcase sub))) | |
(defun view-attachments-dired (&optional msg) | |
"Saves all of the attachments in `msg' to a directory under | |
`bulk-saved-attachments-dir' which is derived from the subject | |
beloning to `msg'. Existing filenames will be overwritten without | |
prompt. The directories are not cleaned up in any way." | |
(interactive) | |
(let* ((msg (or msg (mu4e-message-at-point))) | |
(id (cleanse-subject (mu4e-message-field msg :subject))) | |
(attachdir (concat bulk-saved-attachments-dir "/" id)) | |
(count (hash-table-count mu4e~view-attach-map))) | |
(if (> count 0) | |
(progn | |
(mkdir attachdir t) | |
(dolist (num (number-sequence 1 count)) | |
(let* ((att (mu4e~view-get-attach msg num)) | |
(fname (plist-get att :name)) | |
(index (plist-get att :index)) | |
fpath) | |
(setq fpath (concat attachdir "/" fname)) | |
(mu4e~proc-extract | |
'save (mu4e-message-field msg :docid) | |
index mu4e-decryption-policy fpath))) | |
(dired attachdir) | |
(revert-buffer)) | |
(message "Nothing to extract.")))) | |
(add-to-list 'mu4e-view-attachment-actions '("DDired" . view-attachments-dired) t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment