Marcin Borkowski writes:
> On 2015-02-02, at 22:22, Claudius Mueller
> <
claudius...@gmail.com> wrote:
>
>> Hello,
>>
>> One thing that is really a killer for me is the necessity to
>> specify a filename and location for each attachment. Even if I
>> save all attachments (C-u e a), I am prompted for each
>> filename and location. I get multiple attachments regularly
>> during work. If the "save all attachments" function would
>> prompt me once for the location and then just save all
>> attachments using their respective original filename that
>> would be a huge benefit!
>
> Agreed. Not something I use on a daily basis, but this would be
> definitely nice. Just as an exercise, I'll try to look at the
> code tomorrow, maybe my elisp-fu will be enough to help with
> this one...
Well, here's how i've redefined a couple of mu4e functions to add
this functionality:
#+begin_src emacs-lisp
(defun mu4e-view-save-attachment-single (&optional msg attnum
path)
"Save attachment number ATTNUM from MSG.
If MSG is nil use the message returned by `message-at-point'.
If ATTNUM is nil ask for the attachment number."
(interactive) (let* ((msg (or msg (mu4e-message-at-point)))
(attnum (or attnum
(mu4e~view-get-attach-num "Attachment to
save" msg)))
(att (mu4e~view-get-attach msg attnum)) (fname
(plist-get att :name)) (mtype (plist-get att
:mime-type)) (index (plist-get att :index)) (retry t)
(fpath))
(while retry
(if (not path)
(setq fpath (mu4e~view-request-attachment-path
fname (concat
(mu4e~get-attachment-dir fname mtype)
"/")))
(setq fpath (concat path "/" fname)))
(setq retry
(and (file-exists-p fpath)
(not (y-or-n-p (mu4e-format "Overwrite '%s'?"
fpath))))))
(mu4e~proc-extract
'save (mu4e-message-field msg :docid) index
mu4e-decryption-policy fpath)))
(defun mu4e-view-save-attachment-multi (&optional msg)
"Offer to save multiple email attachments from the current
message.
Default is to save all messages, [1..n], where n is the number
of attachments. You can type multiple values separated by
space, e.g.
1 3-6 8
will save attachments 1,3,4,5,6 and 8.
Furthermore, there is a shortcut \"a\" which so means all
attachments, but as this is the default, you may not need it."
(interactive) (let* ((msg (or msg (mu4e-message-at-point)))
(attachstr (mu4e~view-get-attach-num
"Attachment number range (or 'a' for
'all')" msg t))
(count (hash-table-count mu4e~view-attach-map))
(attachnums (mu4e-split-ranges-to-numbers attachstr
count)) (path (if (y-or-n-p "Save all attachments to
same location? ")
(mu4e~view-request-attachment-path ""
(mu4e~get-attachment-dir)))))
(dolist (num attachnums)
(if path
(mu4e-view-save-attachment-single msg num path)
(mu4e-view-save-attachment-single msg num)))))
#+end_src
Alexis.