Save multiple / all attachments without prompting (unless overwriting)

Pierre Neidhardt mail at
Wed Mar 20 02:11:19 PDT 2019

Is it possible to save all attachments at once to the default folder
(mm-default-directory) without prompting?
Better: only attachments in region?

So far, I've hacked around mm-decode and came up with the following:

--8<---------------cut here---------------start------------->8---
(defun mm-save-part (handle &optional prompt)
  "Write HANDLE to a file.
PROMPT overrides the default one used to ask user for a file name."
  (let ((filename (or (mail-content-type-get
		       (mm-handle-disposition handle) 'filename)
		       (mm-handle-type handle) 'name)))
	file directory)
    (when filename
      (setq filename (gnus-map-function mm-file-name-rewrite-functions
					(file-name-nondirectory filename))))
    (setq file mm-default-directory) ; <- ONLY CHANGE
    (if (file-directory-p file)
	(setq file (expand-file-name filename file))
      (setq file (expand-file-name
		  file (or mm-default-directory default-directory))))
    (setq mm-default-directory (file-name-directory file))
    (and (or (not (file-exists-p file))
	     (yes-or-no-p (format "File %s already exists; overwrite? "
	   (mm-save-part-to-file handle file)
--8<---------------cut here---------------end--------------->8---


Pierre Neidhardt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <>

More information about the notmuch mailing list