mirror of https://github.com/djcb/mu.git
Merge pull request #909 from sachdevaprash/master
mu4e: Adding eshell/mu4e-attach allowing attachments from eshell.
This commit is contained in:
commit
5097dd8e1b
|
@ -160,6 +160,56 @@ For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
|
|||
(shell-command command))
|
||||
(mu4e-view-mark-for-something))
|
||||
|
||||
;;; end of spam-filtering functions
|
||||
;;; end of spam-filtering functions
|
||||
|
||||
;;; eshell functions
|
||||
;; Code for 'gnus-dired-attached' modifed to run from eshell, allowing files to
|
||||
;; be attached to an email via mu4e using the eshell. Does not depend on gnus.
|
||||
(defun eshell/mu4e-attach (&rest args)
|
||||
"Attach files to a mu4e message using eshell. If no mu4e
|
||||
buffers found, compose a new message and then attach the file."
|
||||
(let ((destination nil)
|
||||
(files-str nil)
|
||||
(bufs nil)
|
||||
;; Remove directories from the list
|
||||
(files-to-attach
|
||||
(delq nil (mapcar
|
||||
(lambda (f) (if (or (not (file-exists-p f)) (file-directory-p f))
|
||||
nil
|
||||
(expand-file-name f)))
|
||||
(eshell-flatten-list (reverse args))))))
|
||||
;; warn if user tries to attach without any files marked
|
||||
(if (null files-to-attach)
|
||||
(error "No files to attach")
|
||||
(setq files-str
|
||||
(mapconcat
|
||||
(lambda (f) (file-name-nondirectory f))
|
||||
files-to-attach ", "))
|
||||
(setq bufs (mu4e~active-composition-buffers))
|
||||
;; set up destination mail composition buffer
|
||||
(if (and bufs
|
||||
(y-or-n-p "Attach files to existing mail composition buffer? "))
|
||||
(setq destination
|
||||
(if (= (length bufs) 1)
|
||||
(get-buffer (car bufs))
|
||||
(let ((prompt (mu4e-format "%s" "Attach to buffer")))
|
||||
(funcall mu4e-completing-read-function prompt
|
||||
bufs))))
|
||||
;; setup a new mail composition buffer
|
||||
(if (y-or-n-p "Compose new mail and attach this file? ")
|
||||
(progn (mu4e-compose-new)
|
||||
(setq destination (current-buffer)))))
|
||||
;; if buffer was found, set buffer to destination buffer, and attach files
|
||||
(if (not (eq destination 'nil))
|
||||
(progn (set-buffer destination)
|
||||
(goto-char (point-max)) ;attach at end of buffer
|
||||
(while files-to-attach
|
||||
(mml-attach-file (car files-to-attach)
|
||||
(or (mm-default-file-encoding (car files-to-attach))
|
||||
"application/octet-stream") nil)
|
||||
(setq files-to-attach (cdr files-to-attach)))
|
||||
(message "Attached file(s) %s" files-str))
|
||||
(message "No buffer to attach file to.")))))
|
||||
;;; end of eshell functions
|
||||
|
||||
(provide 'mu4e-contrib)
|
||||
|
|
|
@ -1289,6 +1289,17 @@ the view and compose modes."
|
|||
"Quote a string to be used literally in the modeline."
|
||||
(replace-regexp-in-string "%" "%%" str t t))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun mu4e~active-composition-buffers ()
|
||||
"Return all active mu4e composition buffers"
|
||||
(let (buffers)
|
||||
(save-excursion
|
||||
(dolist (buffer (buffer-list t))
|
||||
(set-buffer buffer)
|
||||
(when (eq major-mode 'mu4e-compose-mode)
|
||||
(push (buffer-name buffer) buffers))))
|
||||
(nreverse buffers)))
|
||||
|
||||
(provide 'mu4e-utils)
|
||||
;;; End of mu4e-utils.el
|
||||
|
|
Loading…
Reference in New Issue