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

Add a way of choosing destination file for attachments #2730

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions mu4e/mu4e-mime-parts.el
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,19 @@ Optionally,
(mu4e-view-completion-minor-mode))
(mu4e--completing-read-real prompt candidates multi))))

(defun mu4e--attachments-alist (parts)
"Build an alist of attachments from PARTS.

Each element has the form (filename . annotation)."
(seq-map
(lambda (fpart)
(cons
(plist-get fpart :filename)
fpart))
(seq-filter
(lambda (part) (plist-get part :attachment-like))
parts)))

(defun mu4e-view-save-attachments (&optional ask-dir)
"Save files from the current view buffer.
This applies to all MIME-parts that are \"attachment-like\" (have a filename),
Expand All @@ -289,14 +302,7 @@ 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))
(candidates (seq-map
(lambda (fpart)
(cons ;; (filename . annotation)
(plist-get fpart :filename)
fpart))
(seq-filter
(lambda (part) (plist-get part :attachment-like))
parts)))
(candidates (mu4e--attachments-alist parts))
(candidates (or candidates
(mu4e-warn "No attachments for this message")))
(files (mu4e--completing-read "Save file(s): " candidates
Expand All @@ -313,6 +319,22 @@ one is determined using `mu4e-attachment-dir'."
(mm-save-part-to-file (plist-get part :handle) path)))
files)))

(defun mu4e-view-save-one-attachment ()
"Save one file from the current view buffer.

Unlike `mu4e-view-save-attachments', prompt for the destination file
name--not only the directory--of the attachment."
(interactive)
(let* ((parts (mu4e-view-mime-parts))
(candidates (mu4e--attachments-alist parts))
(candidates (or candidates
(mu4e-warn "No attachments for this message")))
(file (mu4e--completing-read "Save file: " candidates
'attachment))
(mm-handle (plist-get (cdr (assoc file candidates)) :handle))
(dest (read-file-name "Destination: " mu4e-attachment-dir)))
(mm-save-part-to-file mm-handle dest)))

(defvar mu4e-view-mime-part-actions
'(
;;
Expand Down
Loading