feat(mu4e): reimplement attachment opening command

This can be done via 'a', but it's a nice convenience to have,
particularly as it filters out non-attachment MIME parts.

Closes #5027.
This commit is contained in:
TEC 2021-09-11 22:16:02 +08:00
parent 47be8e292e
commit 251705149b
No known key found for this signature in database
GPG key ID: 779591AFDB81F06C

View file

@ -183,9 +183,29 @@
;; Functionality otherwise obscured in mu4e 1.6
(when (version<= "1.6" mu4e-mu-version)
(defun +mu4e-select-attachment ()
"Use completing-read to select a single attachment.
Acts like a singular `mu4e-view-save-attachments', without the saving."
(let ((parts (mu4e~view-gather-mime-parts)) files)
(dolist (part parts)
(let ((fname (cdr (assoc 'filename (assoc "attachment" (cdr part))))))
(when fname
(push (cons fname part) files))))
(if files
(cdr (assoc (completing-read "Select attachment: " (mapcar #'car files))
files))
(user-error (mu4e-format "No attached files found")))))
(defun +mu4e-open-attachment ()
"Select an attachment, and open it."
(interactive)
(mu4e~view-open-file
(mu4e~view-mime-part-to-temp-file (cdr (+mu4e-select-attachment)))))
(map! :map mu4e-view-mode-map
:ne "A" #'mu4e-view-mime-part-action
:ne "p" #'mu4e-view-save-attachments))
:ne "p" #'mu4e-view-save-attachments
:ne "o" #'+mu4e-open-attachment))
(map! :localleader
:map mu4e-compose-mode-map