diff --git a/mu4e/mu4e-mime-parts.el b/mu4e/mu4e-mime-parts.el index dae3353ae..6e33033c2 100644 --- a/mu4e/mu4e-mime-parts.el +++ b/mu4e/mu4e-mime-parts.el @@ -284,6 +284,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. @@ -305,17 +318,7 @@ detect that, the function bails out and advises to use files." (interactive "P") (let* ((parts (mu4e-view-mime-parts)) - (candidates (seq-map - (lambda (fpart) - (let ((fname (plist-get fpart :filename))) - (when (and crm-separator (string-match-p crm-separator fname)) - (mu4e-warn (concat "File(s) match `crm-separator'; " - "use mu4e-view-mime-part-action instead"))) - ;; (filename . annotation) - (cons fname 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 @@ -334,6 +337,22 @@ files." (mm-save-part-to-file 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 '( ;;