mirror of https://github.com/djcb/mu.git
* mu4e-actions: split of the example actions (i.e..,
mu4e-(view|view-attachment|header)-actions into their own file
This commit is contained in:
parent
259310c7e0
commit
6950ef4836
|
@ -24,6 +24,7 @@ mu4e_TEXINFOS=fdl.texi
|
|||
lispdir=${prefix}/share/emacs/site-lisp/mu4e/
|
||||
|
||||
dist_lisp_LISP= \
|
||||
mu4e-actions.el \
|
||||
mu4e-compose.el \
|
||||
mu4e-hdrs.el \
|
||||
mu4e-main.el \
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
;;; mu4e-actions.el -- part of mu4e, the mu mail user agent
|
||||
;;
|
||||
;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema
|
||||
|
||||
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;; GNU Emacs is free software: you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; GNU Emacs is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Example actions for messages, attachments (see chapter 'Actions' in the
|
||||
;; manual)
|
||||
|
||||
;;; Code:
|
||||
(require 'cl)
|
||||
(require 'mu4e-utils)
|
||||
(require 'mu4e-meta)
|
||||
|
||||
|
||||
(defun mu4e-action-count-lines (msg)
|
||||
"Count the number of lines in the e-mail message. Works for
|
||||
headers view and message-view."
|
||||
(message "Number of lines: %s"
|
||||
(shell-command-to-string
|
||||
(concat "wc -l < " (shell-quote-argument (plist-get msg :path))))))
|
||||
|
||||
|
||||
(defvar mu4e-msg2pdf (concat mu4e-builddir "/toys/msg2pdf/msg2pdf")
|
||||
"Path to the msg2pdf toy.")
|
||||
|
||||
(defun mu4e-action-view-as-pdf (msg)
|
||||
"Convert the message to pdf, then show it. Works for the message
|
||||
view."
|
||||
(unless (file-executable-p mu4e-msg2pdf)
|
||||
(error "msg2pdf not found; please set `mu4e-msg2pdf'"))
|
||||
(let* ((pdf
|
||||
(shell-command-to-string
|
||||
(concat mu4e-msg2pdf " "
|
||||
(shell-quote-argument (plist-get msg :path)))))
|
||||
(pdf (and pdf (substring pdf 0 -1)))) ;; chop \n
|
||||
(unless (file-exists-p pdf)
|
||||
(error "Failed to create PDF file"))
|
||||
(find-file pdf)))
|
||||
|
||||
|
||||
|
||||
(defun mu4e-action-capture-message (msg)
|
||||
"Remember MSG; we can create a an attachment based on this msg
|
||||
with `mu4e-insert-captured-message-as-attachment'."
|
||||
(interactive)
|
||||
(setq mu4e-captured-message msg)
|
||||
(message "Message has been captured"))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defvar mu4e-org-contacts-file nil
|
||||
"File to store contact information for org-contacts. Needed by
|
||||
`mu4e-action-add-org-contact'.")
|
||||
|
||||
(eval-when-compile ;; silence compiler warning about free variable
|
||||
(unless (require 'org-capture nil 'noerror)
|
||||
(defvar org-capture-templates nil)))
|
||||
|
||||
(defun mu4e-action-add-org-contact (msg)
|
||||
"Add an org-contact entry based on the From: address of the
|
||||
current message (in headers or view). You need to set
|
||||
`mu4e-org-contacts-file' to the full path to the file where you
|
||||
store your org-contacts."
|
||||
(unless (require 'org-capture nil 'noerror)
|
||||
(error "org-capture is not available."))
|
||||
(unless mu4e-org-contacts-file
|
||||
(error "`mu4e-org-contacts-file' is not defined."))
|
||||
(let* ((sender (car-safe (mu4e-msg-field msg :from)))
|
||||
(name (car-safe sender)) (email (cdr-safe sender))
|
||||
(blurb
|
||||
(format
|
||||
(concat
|
||||
"* %s%%?\n"
|
||||
":PROPERTIES:\n"
|
||||
":EMAIL:%s\n"
|
||||
":NICK:\n"
|
||||
":BIRTHDAY:\n"
|
||||
":END:\n\n")
|
||||
(or name email "")
|
||||
(or email "")))
|
||||
(key "mu4e-add-org-contact-key")
|
||||
(org-capture-templates
|
||||
(append org-capture-templates
|
||||
(list (list key "contacts" 'entry
|
||||
(list 'file mu4e-org-contacts-file) blurb)))))
|
||||
(message "%S" org-capture-templates)
|
||||
(org-capture nil key)))
|
||||
|
||||
|
||||
|
||||
(provide 'mu4e-actions)
|
|
@ -259,35 +259,6 @@ http://cr.yp.to/proto/maildir.html "
|
|||
((< size 1000) (format "%d" size))
|
||||
(t (propertize "?" 'face 'mu4e-system-face))))
|
||||
|
||||
;; functions for org-contacts
|
||||
(defun mu4e-view-snarf-from (name-or-email)
|
||||
"Get the From:-data for the current message; NAME-OR-EMAIL should
|
||||
be a symbol 'name or 'email to get the corresponding field. If the
|
||||
field is not found, \"\" is returned.
|
||||
|
||||
You can use this with e.g. org-contact with a template like:
|
||||
(\"c\" \"Contacts\" entry (file \"~/Org/contacts.org\")
|
||||
\"* %(mu4e-view-snarf-from 'name)
|
||||
:PROPERTIES:
|
||||
:EMAIL: %(mu4e-view-snarf-from 'email)
|
||||
:END:\")))
|
||||
|
||||
See the `org-contacts' documentation for more details."
|
||||
;; FIXME: we need to explictly go to some view buffer, since when using this
|
||||
;; from org-capture, we'll be taken to the capture buffer instead.
|
||||
(with-current-buffer mu4e-view-buffer-name
|
||||
(unless (eq major-mode 'mu4e-view-mode)
|
||||
(error "Not in mu4e-view mode."))
|
||||
(unless mu4e-current-msg
|
||||
(error "No current message."))
|
||||
(let ((from (car-safe (plist-get mu4e-current-msg :from))))
|
||||
(cond
|
||||
((not from) "") ;; nothing found
|
||||
((eq name-or-email 'name)
|
||||
(or (car-safe from) ""))
|
||||
((eq name-or-email 'email)
|
||||
(or (cdr-safe from) ""))
|
||||
(t (error "Not supported: %S" name-or-email))))))
|
||||
|
||||
|
||||
(defun mu4e-body-text (msg)
|
||||
|
@ -453,36 +424,6 @@ action (function) to invoke, or nil. "
|
|||
(nth 2 action))))) ;; return func
|
||||
|
||||
|
||||
(defun mu4e-count-lines (msg)
|
||||
"Demonstration function for `mu4e-view-actions'. Count the number
|
||||
of lines in the e-mail message."
|
||||
(message "Number of lines: %s"
|
||||
(shell-command-to-string
|
||||
(concat "wc -l < " (shell-quote-argument (plist-get msg :path))))))
|
||||
|
||||
|
||||
(defun mu4e-show-as-pdf (msg)
|
||||
"Demonstration function for `mu4e-view-actions'. Show attachment as PDF."
|
||||
(unless (file-executable-p mu4e-msg2pdf)
|
||||
(error "msg2pdf not found; please set `mu4e-msg2pdf'"))
|
||||
(let* ((pdf
|
||||
(shell-command-to-string
|
||||
(concat mu4e-msg2pdf " "
|
||||
(shell-quote-argument (plist-get msg :path)))))
|
||||
(pdf (and pdf (substring pdf 0 -1)))) ;; chop \n
|
||||
(unless (file-exists-p pdf)
|
||||
(error "Failed to create PDF file"))
|
||||
(find-file pdf)
|
||||
(doc-view-fit-width-to-window)
|
||||
(rename-buffer "*mu4e-view-pdf*")))
|
||||
|
||||
(defun mu4e-capture-message (msg)
|
||||
"Remember MSG; we can create a an attachment based on this msg
|
||||
with `mu4e-insert-captured-message-as-attachment'."
|
||||
(interactive)
|
||||
(setq mu4e-captured-message msg)
|
||||
(message "Message has been captured"))
|
||||
|
||||
|
||||
(defun mu4e-select-other-view ()
|
||||
"When the headers view is selected, select the message view (if
|
||||
|
|
Loading…
Reference in New Issue