Any chance to enable saving multiple attachments without prompting for each one?

69 views
Skip to first unread message

Claudius Mueller

unread,
Feb 2, 2015, 4:22:12 PM2/2/15
to mu-di...@googlegroups.com
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!

I know, Christmas is over. But I just can't keep myself from asking for a late present... :)

Claudius

Marcin Borkowski

unread,
Feb 2, 2015, 4:28:34 PM2/2/15
to mu-di...@googlegroups.com

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...

> I know, Christmas is over. But I just can't keep myself from asking for a
> late present... :)
>
> Claudius

Best,

--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

Alexis

unread,
Feb 9, 2015, 3:41:34 AM2/9/15
to mu-di...@googlegroups.com

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.
Message has been deleted

Andy Drew

unread,
Jul 11, 2015, 1:43:59 PM7/11/15
to mu-di...@googlegroups.com

Hi,

Not exactly what you are asking for, but there is an easy setup change
that I use that greatly reduces the pain:

(setq mu4e-attachment-dir
  (lambda (fname mtype)
    (cond
      ;; docfiles go to ~/Desktop
      ((and fname (string-match "\\.doc$" fname))  "~/downloads/attachments")
      ;; ... other cases  ...
      (t "~/downloads/attachments")))) ;; everything else

I took this from the mu4e manual.  As you can see I have the download
path default to an attachments folder inside my downloads folder.  You
can redirect attachments automatically using their extension or other
defining characteristic -- great for work if your incoming attachments
follow some pattern.
Reply all
Reply to author
Forward
0 new messages