Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
From an mu4e view, without prompt, save all attachments to a directory and open dired.
(defvar bulk-saved-attachments-dir (expand-file-name "~/Documents/mu4e"))
(defun cleanse-subject (sub)
(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."
(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)
(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))
(setq fpath (concat attachdir "/" fname))
'save (mu4e-message-field msg :docid)
index mu4e-decryption-policy fpath)))
(dired attachdir)
(message "Nothing to extract."))))

This comment has been minimized.

Copy link

@sje30 sje30 commented Aug 30, 2021

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


This comment has been minimized.

Copy link
Owner Author

@philjackson philjackson commented Aug 30, 2021

@sje30 Thanks! I've put a note at the top of the gist - glad you've found it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment