mirror of https://github.com/djcb/mu.git
* mu4e: allow setting a function for mu4e-attachment-dir
This commit is contained in:
parent
6f3c738076
commit
f9c9e790a6
|
@ -80,27 +80,48 @@ parameter (which may be `nil'), and return the result."
|
||||||
(cond
|
(cond
|
||||||
((stringp folder) folder)
|
((stringp folder) folder)
|
||||||
((functionp folder) (funcall folder msg))
|
((functionp folder) (funcall folder msg))
|
||||||
(t (error "unsupported type for %S" folder)))))
|
(t (mu4e-error "unsupported type for %S" folder)))))
|
||||||
(or val (mu4e-error "%S evaluates to nil" foldervar))))
|
(or val (mu4e-error "%S evaluates to nil" foldervar))))
|
||||||
|
|
||||||
(defun mu4e-get-drafts-folder (msg)
|
(defun mu4e-get-drafts-folder (&optional msg)
|
||||||
"Get the sent folder. See `mu4e-drafts-folder'."
|
"Get the sent folder. See `mu4e-drafts-folder'."
|
||||||
(mu4e~get-folder 'mu4e-drafts-folder msg))
|
(mu4e~get-folder 'mu4e-drafts-folder msg))
|
||||||
|
|
||||||
(defun mu4e-get-refile-folder (msg)
|
(defun mu4e-get-refile-folder (&optional msg)
|
||||||
"Get the folder for refiling. See `mu4e-refile-folder'."
|
"Get the folder for refiling. See `mu4e-refile-folder'."
|
||||||
(mu4e~get-folder 'mu4e-refile-folder msg))
|
(mu4e~get-folder 'mu4e-refile-folder msg))
|
||||||
|
|
||||||
(defun mu4e-get-sent-folder (msg)
|
(defun mu4e-get-sent-folder (&optional msg)
|
||||||
"Get the sent folder. See `mu4e-sent-folder'."
|
"Get the sent folder. See `mu4e-sent-folder'."
|
||||||
(mu4e~get-folder 'mu4e-sent-folder msg))
|
(mu4e~get-folder 'mu4e-sent-folder msg))
|
||||||
|
|
||||||
(defun mu4e-get-trash-folder (msg)
|
(defun mu4e-get-trash-folder (&optional msg)
|
||||||
"Get the sent folder. See `mu4e-trash-folder'."
|
"Get the sent folder. See `mu4e-trash-folder'."
|
||||||
(mu4e~get-folder 'mu4e-trash-folder msg))
|
(mu4e~get-folder 'mu4e-trash-folder msg))
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; mu4e-attachment-dir is either a string or a function that takes a filename
|
||||||
|
;; and the mime-type as argument, either (or both) which can be nil
|
||||||
|
(defun mu4e~get-attachment-dir (&optional fname mimetype)
|
||||||
|
"Get the directory for saving attachments from
|
||||||
|
`mu4e-attachment-dir' (which can be either a string or a function,
|
||||||
|
see its docstring)."
|
||||||
|
(let
|
||||||
|
((dir
|
||||||
|
(cond
|
||||||
|
((stringp mu4e-attachment-dir)
|
||||||
|
mu4e-attachment-dir)
|
||||||
|
((functionp mu4e-attachment-dir)
|
||||||
|
(funcall mu4e-attachment-dir fname mimetype))
|
||||||
|
(t
|
||||||
|
(mu4e-error "unsupported type for mu4e-attachment-dir" )))))
|
||||||
|
(if dir
|
||||||
|
(expand-file-name dir)
|
||||||
|
(mu4e-error (mu4e-error "mu4e-attachment-dir evaluates to nil")))))
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -543,13 +564,10 @@ This is used by the completion function in mu4e-compose."
|
||||||
(mu4e-error "Please set `mu4e-maildir' to the full path to your
|
(mu4e-error "Please set `mu4e-maildir' to the full path to your
|
||||||
Maildir directory."))
|
Maildir directory."))
|
||||||
;; expand mu4e-maildir, mu4e-attachment-dir
|
;; expand mu4e-maildir, mu4e-attachment-dir
|
||||||
(setq
|
(setq mu4e-maildir (expand-file-name mu4e-maildir))
|
||||||
mu4e-maildir (expand-file-name mu4e-maildir)
|
|
||||||
mu4e-attachment-dir (expand-file-name mu4e-attachment-dir))
|
|
||||||
(unless (mu4e-create-maildir-maybe mu4e-maildir)
|
(unless (mu4e-create-maildir-maybe mu4e-maildir)
|
||||||
(mu4e-error "%s is not a valid maildir directory" mu4e-maildir))
|
(mu4e-error "%s is not a valid maildir directory" mu4e-maildir))
|
||||||
(dolist (var '(mu4e-sent-folder
|
(dolist (var '(mu4e-sent-folder mu4e-drafts-folder
|
||||||
mu4e-drafts-folder
|
|
||||||
mu4e-trash-folder))
|
mu4e-trash-folder))
|
||||||
(unless (and (boundp var) (symbol-value var))
|
(unless (and (boundp var) (symbol-value var))
|
||||||
(mu4e-error "Please set %S" var))
|
(mu4e-error "Please set %S" var))
|
||||||
|
|
|
@ -73,7 +73,10 @@ mu4e."
|
||||||
:safe 'integerp)
|
:safe 'integerp)
|
||||||
|
|
||||||
(defcustom mu4e-attachment-dir (expand-file-name "~/")
|
(defcustom mu4e-attachment-dir (expand-file-name "~/")
|
||||||
"Default directory for saving attachments."
|
"Default directory for saving attachments. This can be either a
|
||||||
|
string, or a function that takes a filename FNAME and MIMETYPE as
|
||||||
|
arguments, and returns the attachment dir. Note, either or both of
|
||||||
|
the arguments may be `nil'."
|
||||||
:type 'directory
|
:type 'directory
|
||||||
:group 'mu4e
|
:group 'mu4e
|
||||||
:safe 'stringp)
|
:safe 'stringp)
|
||||||
|
|
|
@ -891,14 +891,14 @@ number ATTNUM."
|
||||||
"Save attachment number ATTNUM (or ask if nil) from MSG (or
|
"Save attachment number ATTNUM (or ask if nil) from MSG (or
|
||||||
message-at-point if nil) to disk."
|
message-at-point if nil) to disk."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless mu4e-attachment-dir
|
|
||||||
(mu4e-error "`mu4e-attachment-dir' is not set"))
|
|
||||||
(let* ((msg (or msg (mu4e-message-at-point)))
|
(let* ((msg (or msg (mu4e-message-at-point)))
|
||||||
(attnum (or attnum
|
(attnum (or attnum
|
||||||
(mu4e~view-get-attach-num "Attachment to save" msg)))
|
(mu4e~view-get-attach-num "Attachment to save" msg)))
|
||||||
(att (mu4e~view-get-attach msg attnum))
|
(att (mu4e~view-get-attach msg attnum))
|
||||||
(path (concat mu4e-attachment-dir "/"))
|
|
||||||
(fname (plist-get att :name))
|
(fname (plist-get att :name))
|
||||||
|
(mtype (plist-get att :mime-type))
|
||||||
|
(path (concat
|
||||||
|
(mu4e~get-attachment-dir fname mtype) "/"))
|
||||||
(index (plist-get att :index))
|
(index (plist-get att :index))
|
||||||
(retry t))
|
(retry t))
|
||||||
(while retry
|
(while retry
|
||||||
|
@ -1053,7 +1053,7 @@ attachments) in response to a (mu4e~proc-extract 'temp ... )."
|
||||||
(defun mu4e~view-split-view-p ()
|
(defun mu4e~view-split-view-p ()
|
||||||
"Return t if we're in split-view, nil otherwise."
|
"Return t if we're in split-view, nil otherwise."
|
||||||
(member mu4e-split-view '(horizontal vertical)))
|
(member mu4e-split-view '(horizontal vertical)))
|
||||||
|
|
||||||
(defun mu4e-view-unmark-all ()
|
(defun mu4e-view-unmark-all ()
|
||||||
"If we're in split-view, unmark all messages. Otherwise, warn
|
"If we're in split-view, unmark all messages. Otherwise, warn
|
||||||
user that unmarking only works in the header list."
|
user that unmarking only works in the header list."
|
||||||
|
|
Loading…
Reference in New Issue