Last active
August 30, 2021 19:13
-
-
Save philjackson/aecfab1706f05079aec7000e328fd183 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
;; DEPRECATED - see https://pitch-io.slack.com/archives/CBKNRBRHA/p1630054796006400 | |
(defvar bulk-saved-attachments-dir (expand-file-name "~/Documents/mu4e")) | |
(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.")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this -- I've been using this regularly until the recent mu4e updates to 1.6.x which removed a couple of the internal u4e~ functions.
my replacement is https://github.com/sje30/emacs/blob/master/mu4e-view-save-all-attachments.el