Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
antoine-levitt opened this issue Sep 3, 2024 · 0 comments
Open

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

antoine-levitt opened this issue Sep 3, 2024 · 0 comments

Comments

@antoine-levitt
Copy link

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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant