mu icon indicating copy to clipboard operation
mu copied to clipboard

Save multiple attachments mu4e 1.5.11

Open mfauvel opened this issue 3 years ago • 4 comments

Hello,

I am using mu4e 1.5.11 with the gnus-based message view. I can save one attachement at time using e but the function to save all the attachments at once is no more available. @djcb provides a solution with helm here: https://github.com/djcb/mu/issues/1283#issuecomment-818067006

Is there another solution to save all attachments at once ?

I am using ivy (ivy-20210311.1638) for completion and my emacs version is GNU Emacs 28.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo version 1.16.0) of 2021-03-19

Otherwise, thanks a lot for mu and mu4e !

mfauvel avatar Apr 13 '21 08:04 mfauvel

It's possible to save multiple attachments with ivy -- e TAB , now select an attachment C-j, add a comma , and repeat. But not currently all attachments at once.

djcb avatar Apr 13 '21 11:04 djcb

Thanks for the input, it works.

mfauvel avatar Apr 13 '21 13:04 mfauvel

Indeed, this is useful but I would like to be able to save all attachments at once. Thanks @djcb for adding this feature as a rfe.

averter avatar Nov 13 '21 07:11 averter

Hi. I'm not using ivy, and I really miss this old functionality. Can we get it back? I'm attaching a patch that does this. With any prefix argument the patched mu4e-saved-attachment saves all the attachments to the default attachment directory. This changes the meaning of the prefix argument, which maybe is OK, since its documented meaning was completely different from what it actually did. Something like this would be very welcome. Thanks!

mu4e-save-attachment-all.txt

dkogan avatar Jul 27 '22 20:07 dkogan

credit is for someone in the www

    (defun mu4e-view-save-all-attachments (&optional arg)
      "Save all MIME parts from current mu4e gnus view buffer."
      ;; Copied from mu4e-view-save-attachments
      (interactive "P")
      (cl-assert (and (eq major-mode 'mu4e-view-mode)
                      (derived-mode-p 'gnus-article-mode)))
      (let* ((msg (mu4e-message-at-point))
             (id (cleanse-subject (mu4e-message-field msg :subject)))
             (attachdir (concat bulk-saved-attachments-dir "/" id))
             (parts (mu4e~view-gather-mime-parts))
             (handles '())
             (files '())
             dir)
        (mkdir attachdir t)
        (dolist (part parts)
          (let ((fname (or 
                        (cdr (assoc 'filename (assoc "attachment" (cdr part))))
                        (seq-find #'stringp
                                  (mapcar (lambda (item) (cdr (assoc 'name item)))
                                          (seq-filter 'listp (cdr part)))))))
            (when fname
              (push `(,fname . ,(cdr part)) handles)
              (push fname files))))
        (if files
            (progn
              (setq dir
                    (if arg (read-directory-name "Save to directory: ")
                      attachdir))
              (cl-loop for (f . h) in handles
                       when (member f files)
                       do (mm-save-part-to-file h
                                                (sje-next-free
                                                 (expand-file-name f dir)))))
          (mu4e-message "No attached files found"))))

averter avatar Mar 12 '23 17:03 averter

original credit for that code above comes from Phil Jackson. I just edited it a bit.

& I see now if you are on mu 1.10.0 you will need to update the code a bit:

change mu4e~view-gather-mime-parts to mu4e--view-gather-mime-parts

see updated code at

https://github.com/sje30/emacs/blob/master/mu4e-view-save-all-attachments.el

sje30 avatar Mar 30 '23 14:03 sje30

I pushed an implementation for this to master; basically, C-c C-a will complete to all attachments. There's some documentation as well in the manual (see NEWS.org).

It should work with various completion frameworks --- helm is a bit "special" and does its own thing, as before.

djcb avatar Jul 17 '23 20:07 djcb