sje30/emacs

Update mu4e-view-save-all-attachments for recent mu

Opened this issue · 0 comments

Hi,

I use your function, had to adapt it for recent changes in mu, here's my hacked updated version in case it saves you some minutes figuring out the new API

(defun mu4e-view-save-all-attachments (&optional ask-dir)
  "Save files from the current view buffer.
This applies to all MIME-parts that are \"attachment-like\" (have a filename),
regardless of their disposition.

With ASK-DIR is non-nil, user can specify the target-directory; otherwise
one is determined using `mu4e-attachment-dir'."
  (interactive "P")
  (let* ((parts (mu4e-view-mime-parts))
         (id (cleanse-subject (mu4e-message-field (mu4e-message-at-point) :subject)))
         (attachdir (concat bulk-saved-attachments-dir "/" id))
         (candidates  (seq-map
                         (lambda (fpart)
                           (cons ;; (filename . annotation)
                            (plist-get fpart :filename)
                            fpart))
                         (seq-filter
                          (lambda (part) (plist-get part :attachment-like))
                          parts)))
         (candidates (or candidates
                         (mu4e-warn "No attachments for this message")))
         (files (seq-map (lambda (c) (car c)) candidates))
         )
    (pp candidates)
    ;; we have determined what files to save, and where.
    (seq-do (lambda (fname)
              (let* ((part (cdr (assoc fname candidates)))
                     (path (mu4e--uniqify-file-name
                            (mu4e-join-paths
                             attachdir
                             (plist-get part :filename)))))
                (mm-save-part-to-file (plist-get part :handle) path)))
            files)
    (dired attachdir)))