Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 172 lines (129 sloc) 5.812 kB
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
1 ;;; mu4e-actions.el -- part of mu4e, the mu mail user agent
2 ;;
3 ;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema
4
5 ;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
6 ;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
7
8 ;; This file is not part of GNU Emacs.
9 ;;
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; Example actions for messages, attachments (see chapter 'Actions' in the
26 ;; manual)
27
28 ;;; Code:
8b4dd81 @djcb * mu4e: fix byte-compilation warnings
authored
29 (eval-when-compile (byte-compile-disable-warning 'cl-functions))
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
30 (require 'cl)
8b4dd81 @djcb * mu4e: fix byte-compilation warnings
authored
31
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
32 (require 'mu4e-utils)
5c2025a @djcb * mu4e: mu4e-message part 3
authored
33 (require 'mu4e-message)
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
34 (require 'mu4e-meta)
35
5c2025a @djcb * mu4e: mu4e-message part 3
authored
36
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
37
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
39 (defun mu4e-action-count-lines (msg)
40 "Count the number of lines in the e-mail message. Works for
41 headers view and message-view."
42 (message "Number of lines: %s"
43 (shell-command-to-string
5c2025a @djcb * mu4e: mu4e-message part 3
authored
44 (concat "wc -l < " (shell-quote-argument (mu4e-message-field msg :path))))))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
46
47
b893b16 @djcb * minor / cosmetic
authored
48
49
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
50
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
52 (defvar mu4e-msg2pdf (concat mu4e-builddir "/toys/msg2pdf/msg2pdf")
53 "Path to the msg2pdf toy.")
54
55 (defun mu4e-action-view-as-pdf (msg)
56 "Convert the message to pdf, then show it. Works for the message
57 view."
58 (unless (file-executable-p mu4e-msg2pdf)
985d534 @djcb * add/use mu4e-error
authored
59 (mu4e-error "msg2pdf not found; please set `mu4e-msg2pdf'"))
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
60 (let* ((pdf
61 (shell-command-to-string
62 (concat mu4e-msg2pdf " "
5c2025a @djcb * mu4e: mu4e-message part 3
authored
63 (shell-quote-argument (mu4e-message-field msg :path))
ea9e4ef @djcb * make the msg2pdf action a bit more robust
authored
64 " 2> /dev/null")))
65 (pdf (and pdf (> (length pdf) 5)
66 (substring pdf 0 -1)))) ;; chop \n
67 (unless (and pdf (file-exists-p pdf))
5c2025a @djcb * mu4e: mu4e-message part 3
authored
68 (mu4e-warn "Failed to create PDF file"))
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
69 (find-file pdf)))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71
72
73
74
75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 (defun mu4e-action-view-in-browser (msg)
1c8f12c @djcb * mu4e-actions.el: use the improved mu4e-action-view-in-browser
authored
77 "View the body of the message in a web browser. You can influence
78 the browser to use with the variable `browse-url-generic-program'."
5c2025a @djcb * mu4e: mu4e-message part 3
authored
79 (let* ((html (mu4e-message-field msg :body-html))
80 (txt (mu4e-message-field msg :body-txt))
81f7421 @djcb * fix mu4e-action-view-in-browser (thanks semente!)
authored
81 (tmpfile (format "%s%x.html" temporary-file-directory (random t))))
90290a1 @djcb * mu4e: improve mu4e-action-view-in-browser
authored
82 (unless (or html txt)
83 (mu4e-error "No body part for this message"))
84 (with-temp-buffer
81f7421 @djcb * fix mu4e-action-view-in-browser (thanks semente!)
authored
85 ;; simplistic -- but note that it's only an example...
90290a1 @djcb * mu4e: improve mu4e-action-view-in-browser
authored
86 (insert (or html (concat "<pre>" txt "</pre>")))
81f7421 @djcb * fix mu4e-action-view-in-browser (thanks semente!)
authored
87 (write-file tmpfile)
88 (browse-url (concat "file://" tmpfile)))))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
89 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90
91
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
92
90290a1 @djcb * mu4e: improve mu4e-action-view-in-browser
authored
93
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90290a1 @djcb * mu4e: improve mu4e-action-view-in-browser
authored
95 (defconst mu4e-text2speech-command "festival --tts"
96 "Program that speaks out text it receives on standard-input.")
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
97
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
98 (defun mu4e-action-message-to-speech (msg)
99 "Pronounce the message text using `mu4e-text2speech-command'."
5c2025a @djcb * mu4e: mu4e-message part 3
authored
100 (unless (mu4e-message-field msg :body-txt)
101 (mu4e-warn "No text body for this message"))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
102 (with-temp-buffer
5c2025a @djcb * mu4e: mu4e-message part 3
authored
103 (insert (mu4e-message-field msg :body-txt))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
104 (shell-command-on-region (point-min) (point-max)
105 mu4e-text2speech-command)))
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
107
b893b16 @djcb * minor / cosmetic
authored
108
109
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
110
111
112
113
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b893b16 @djcb * minor / cosmetic
authored
115 (defvar mu4e-captured-message nil
116 "The last-captured message (the s-expression).")
117
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
118 (defun mu4e-action-capture-message (msg)
119 "Remember MSG; we can create a an attachment based on this msg
b893b16 @djcb * minor / cosmetic
authored
120 with `mu4e-compose-attach-captured-message'."
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
121 (interactive)
122 (setq mu4e-captured-message msg)
123 (message "Message has been captured"))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
125
126
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
127
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
129 (defvar mu4e-org-contacts-file nil
130 "File to store contact information for org-contacts. Needed by
131 `mu4e-action-add-org-contact'.")
132
133 (eval-when-compile ;; silence compiler warning about free variable
134 (unless (require 'org-capture nil 'noerror)
135 (defvar org-capture-templates nil)))
136
137 (defun mu4e-action-add-org-contact (msg)
138 "Add an org-contact entry based on the From: address of the
139 current message (in headers or view). You need to set
140 `mu4e-org-contacts-file' to the full path to the file where you
141 store your org-contacts."
0bd4787 @djcb * mu4e: don't require org directly
authored
142 (unless (require 'org-capture nil 'noerror)
985d534 @djcb * add/use mu4e-error
authored
143 (mu4e-error "org-capture is not available."))
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
144 (unless mu4e-org-contacts-file
985d534 @djcb * add/use mu4e-error
authored
145 (mu4e-error "`mu4e-org-contacts-file' is not defined."))
5c2025a @djcb * mu4e: mu4e-message part 3
authored
146 (let* ((sender (car-safe (mu4e-message-field msg :from)))
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
147 (name (car-safe sender)) (email (cdr-safe sender))
148 (blurb
149 (format
150 (concat
151 "* %s%%?\n"
152 ":PROPERTIES:\n"
153 ":EMAIL:%s\n"
154 ":NICK:\n"
155 ":BIRTHDAY:\n"
156 ":END:\n\n")
157 (or name email "")
158 (or email "")))
159 (key "mu4e-add-org-contact-key")
160 (org-capture-templates
161 (append org-capture-templates
162 (list (list key "contacts" 'entry
163 (list 'file mu4e-org-contacts-file) blurb)))))
164 (message "%S" org-capture-templates)
5946499 @djcb * silence some more compiler warnings
authored
165 (when (fboundp 'org-capture)
166 (org-capture nil key))))
2b002c5 @djcb * mu4e-actions.el: add some example actions for showing messages in a…
authored
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168
169
6950ef4 @djcb * mu4e-actions: split of the example actions (i.e..,
authored
170
171 (provide 'mu4e-actions)
Something went wrong with that request. Please try again.