mu4e: add mu4e-view-fetch-url for downloading URLs

Add mu4e-view-fetch-url for fetching (downloading) URIs linked to in
e-mails. Add the 'f' keybinding for this, and document it.

Based on code by inigoserna.
This commit is contained in:
djcb 2016-01-10 13:06:10 +02:00
parent aad5708d49
commit 82e7ba051f
3 changed files with 20 additions and 2 deletions

View File

@ -118,8 +118,7 @@ better with e.g. offlineimap."
"Default directory for saving attachments.
This can be either a string (a file system path), or a function
that takes a filename and the mime-type as arguments, and returns
the attachment dir. See Info node `(mu4e) Opening and saving
attachments' for details."
the attachment dir. See Info node `(mu4e) Attachments' for details."
:type 'directory
:group 'mu4e
:safe 'stringp)

View File

@ -687,6 +687,11 @@ FUNC should be a function taking two arguments:
'("Open attachment" . mu4e-view-open-attachment))
(define-key menumap [extract-att]
'("Extract attachment" . mu4e-view-save-attachment))
(define-key menumap [save-url]
'("Save URL to kill-ring" . mu4e-view-save-url))
(define-key menumap [fetch-url]
'("Fetch URL" . mu4e-view-fetch-url))
(define-key menumap [goto-url]
'("Visit URL" . mu4e-view-go-to-url))
@ -1381,6 +1386,18 @@ to save a range of URLs."
(kill-new url)
(mu4e-message "Saved %s to the kill-ring" url))))
(defun mu4e-view-fetch-url (&optional multi)
"Offer to fetch (download) urls(s). If MULTI (prefix-argument) is nil,
download a single one, otherwise, offer to fetch a range of
URLs. The urls are fetched to `mu4e-attachment-dir'."
(interactive "P")
(mu4e~view-handle-urls "URL to fetch" multi
(lambda (url)
(let ((target (concat (mu4e~get-attachment-dir url) "/"
(file-name-nondirectory url))))
(url-copy-file url target)
(mu4e-message "Fetched %s -> %s" url target)))))
(defun mu4e~view-handle-urls (prompt multi urlfunc)
"If MULTI is nil, apply URLFUNC to a single uri, otherwise, apply
it to a range of uris. PROMPT is the query to present to the user."

View File

@ -1173,6 +1173,8 @@ actions
g go to (visit) numbered URL (using `browse-url')
(or: <mouse-1> or M-RET with point on url)
C-u g visits multiple URLs
f fetch (download )the numbered URL.
C-u f fetches multiple URLs
k save the numbered URL in the kill-ring.
C-u k saves multiple URLs