Added command that checks if contact can receive encrypted emails, changed citation...
[dotfiles.git] / .wl
1 ; mode: -*-emacs-lisp-*-
2 ;
3 (load "silly-mail" nil t)
4 (setq wl-stay-folder-window t
5 wl-local-domain "gpcf.eu"
6 wl-message-id-domain "aubergine.gpcf.eu"
7 wl-from (concat user-full-name " <" user-mail-address ">")
8 ;; here starts all the maildir stuff
9 elmo-maildir-folder-path "~/Maildir"
10 wl-fcc ".sent"
11 wl-trash-folder ".trash"
12 wl-queue-folder ".queue"
13 signature-file-name "~/.signature"
14 signature-insert-at-eof t
15 signature-delete-blank-lines-at-eof t
16 wl-draft-send-mail-function 'wl-draft-send-mail-with-sendmail
17 default-mime-charset 'utf8
18 wl-fcc-force-as-read t
19 wl-interactive-send nil
20 wl-summary-width 120
21 mime-pgp-decrypt-when-preview t
22 )
23 (defun wl-display-math ()
24 "Toggle display of math in buffer"
25 (interactive)
26 (let ((inhibit-read-only t))
27 (latex-math-preview-all-formulae)))
28 (defun wl-hide-math ()
29 "Toggle display of math in buffer"
30 (interactive)
31 (let ((inhibit-read-only t))
32 (latex-math-preview-remove-images)))
33
34
35 (add-hook 'mime-view-mode-hook
36 '(lambda () (local-set-key (kbd "ä") 'wl-next-message)
37 (local-set-key (kbd "ö") 'wl-prev-message)
38 (local-set-key (kbd "m") 'wl-display-math)
39 (local-set-key (kbd "h") 'wl-hide-math)
40 (local-set-key (kbd "d") '(lambda ()
41 (interactive)
42 (mime-preview-quit)
43 (wl-summary-dispose)))
44 (local-set-key (kbd "f") '(lambda ()
45 (interactive)
46 (mime-preview-quit)
47 (wl-summary-forward)))
48 (local-set-key (kbd "K") 'extract-gpg-key)
49 ))
50 (setq mime-edit-insert-user-agent-field nil)
51
52 (setq wl-generate-mailer-string-function
53 ; set X-Mailer string
54 (function
55 (lambda ()
56 (format "GNU Emacs Version 24.3, %s, GNU/Linux" (product-string-1 'wl-version)))))
57
58 (setq wl-demo-display-logo nil)
59 (mc-install-read-mode)
60
61
62 (defun mc-wl-verify-signature ()
63 (interactive)
64 (save-window-excursion
65 (wl-summary-jump-to-current-message)
66 (mc-verify)))
67
68 (eval-after-load "mailcrypt"
69 '(setq mc-modes-alist
70 (append
71 (quote
72 ((wl-draft-mode (encrypt . mc-encrypt-message)
73 (sign . mc-sign-message))
74 (wl-summary-mode (decrypt . mc-wl-decrypt-message)
75 (verify . mc-wl-verify-signature))))
76 mc-modes-alist)))
77 (defun wl-summary-click-on-message ()
78 (interactive) (wl-summary-redisplay)
79 (wl-summary-jump-to-current-message)
80 (delete-other-windows))
81 (add-hook 'wl-summary-mode-hook
82 ;; Set keybindings for
83 ;; PGP-Inline
84 '(lambda ()
85 (local-set-key "k" '(lambda ()
86 (interactive)
87 (save-window-excursion
88 (wl-summary-jump-to-current-message)
89 (gpcf-decrypt-mail))))
90 (local-set-key "0" 'mc-wl-verify-signature)
91 (local-set-key (kbd "ä") 'wl-next-message)
92 (local-set-key (kbd "ö") 'wl-prev-message)
93 (local-set-key (kbd "<return>") 'wl-summary-click-on-message )
94 (local-set-key "X" '(lambda ()
95 ; checks for mail remotely using rsync.
96 (interactive)
97 (if (= (shell-command
98 (concat (expand-file-name "~/software/mail/getmail.sh") " > /dev/null 2>&1")) 0 )
99 (wl-summary-incorporate)
100 (error "Fetching mail failed")
101 )))
102 ))
103 (defun gpcf-decrypt-mail ()
104 "Decrypts mail in MIME preview buffer. Works with both PGP/MIME
105 and PGP-Inline. OBSOLETE FOR PGP/MIME, USE (setq mime-pgp-decrypt-when-preview t) instead."
106 (interactive)
107 (save-excursion
108 (beginning-of-buffer)
109 (cond
110 ;; PGP/MIME
111 ((search-forward "<application/pgp-encrypted" nil t)
112 (let ((id "") (mess ""))
113 (save-window-excursion
114 (mime-preview-extract-current-entity)
115 (when (string-match "-[0-9]+" (buffer-name))
116 (setq id (substring (buffer-name) (match-beginning 0) (match-end 0)))
117 ))
118 (search-forward "]")
119 (save-window-excursion
120 (switch-to-buffer (concat "*Preview- *WL:Message*" id "*"))
121 (let ((temp-point (point)))
122 (end-of-buffer)
123 (setq mess (buffer-substring temp-point (point)))
124 (kill-buffer))
125 )
126 (let ((temp-point (point)) (inhibit-read-only t))
127 (search-backward "This part is encrypted" nil t)
128 (delete-region (point) temp-point)
129 (insert mess)
130 )))
131 ;;; PGP/INLINE
132 ((search-forward "-----BEGIN PGP MESSAGE-----" nil t)
133 (let ((inhibit-read-only t))
134 (mc-decrypt)))
135 (t (error "No GPG encrypted message found in this file."))))
136 )
137
138
139 (defun gpcf-setup-mail ()
140 "This function prepares the draft mode.
141 It add headers and defines keyboard shortcuts. Before the
142 message is sent, it adds the user's signature."
143 (if (string-match-p "\\*draft\\*.*" (buffer-name))
144 (progn
145 (setq enc-color (face-remap-add-relative 'mode-line :background "dark red"))
146 ; (set-input-method "TeX")
147 (auto-fill-mode)
148 (setq default-justification 'full)
149 (sm-add-microsoft)
150 (sm-add-emacs-name)
151 (sm-put-header "X-PGP-Key" "http://en.gpcf.eu/key.asc")
152 (local-set-key (kbd "C-c e") 'mime-edit-set-sign-and-encrypt)
153 (local-set-key (kbd "C-c s") 'ispell-message)
154 (local-set-key (kbd "C-c m s") 'wl-display-math)
155 (local-set-key (kbd "C-c m h") 'wl-hide-math)
156 (local-set-key (kbd "C-c c") '(lambda ()
157 ;;; save email to queue and send it using SSH.
158 (interactive)
159 (check-encryption-capabilities)
160 (wl-draft-send-and-exit)
161 (call-process-shell-command
162 (concat (expand-file-name "~/software/mail/sendmail.sh") "&")
163 nil 0)
164 ))
165 (delete-other-windows))
166 (mail-signature) ;; add signature
167 ))
168 (defun mime-edit-set-sign-and-encrypt ()
169 (interactive)
170 (mime-edit-set-encrypt t)
171 (mime-edit-set-sign t)
172 (message
173 "This message will be signed and encrypted")
174 (face-remap-remove-relative enc-color)
175 )
176 (defun check-encryption-capabilities ()
177 "Checks if the recipient can receive encrypted e-mail, based on whether they have sent you encrypted e-mail before or not"
178 (interactive)
179 (save-excursion
180 (beginning-of-buffer)
181 (unless (search-forward-regexp "^To: .* <\\(.*\\)>$" nil t)
182 (unless (search-forward-regexp "^To: \\(.*\\)$" nil t)
183 (error "No To: address specified"))
184 ))
185 (when (and (not (memq 'encrypt mime-edit-pgp-processing))
186 (= (shell-command
187 ;; this person sent you encrypted email
188 (concat "mu find flag:encrypted from:" (match-string 1) " > /dev/null 2>&1")) 0 )
189 )
190 (when (yes-or-no-p "Do you want to encrypt and sign this message? ")
191 (mime-edit-set-sign-and-encrypt)
192 ))
193 )
194 (add-hook 'mime-edit-mode-hook 'gpcf-setup-mail)
195 ; single window mode.
196 (setq wl-stay-folder-window nil
197 wl-draft-use-frame nil
198 wl-summary-move-order 'new
199 )
200 ;; Prevent wl from splitting large messages
201 (setq mime-edit-split-message nil)
202
203 ;; my E-Mail addresses:
204 (setq wl-user-mail-address-list '("gabriel@gpcf.eu"
205 "gpcf@gpcf.eu"))
206 (setq wl-summary-showto-folder-regexp ".*sent.*")
207
208 ;; AUTO-REFILE rules
209 (load "~/.emacs.d/files/refile-rules.el")
210 (defadvice mime-preview-quit (after mime-preview-quit activate)
211 (delete-other-windows)
212 )
213 (defun wl-delete-other-windows ()
214 ; (wl-summary-jump-to-current-message)
215 (delete-other-windows)
216 )
217 (defadvice wl-summary-next (after wl-summary-next activate)
218 ;; Prevent message window from appearing when you mark a message
219 (wl-delete-other-windows)
220 )
221 (defadvice wl-summary-prev (after wl-summary-prev activate)
222 (wl-delete-other-windows)
223 )
224 ;; (defadvice wl-summary-incorporate (after wl-summary-incorporate activate)
225 ;; (call-process-shell-command "mu index >/dev/null 2>/dev/null" nil 0)
226 ;; )
227 (defun wl-next-message ()
228 "Jump to next message and open it"
229 (interactive)
230 (unless (string= (buffer-name) "Summary")
231 (mime-preview-quit))
232 (wl-summary-next)
233 (wl-summary-click-on-message))
234
235 (defun wl-prev-message ()
236 "Jump to previous message and open it"
237 (interactive)
238 (unless (string= (buffer-name) "Summary")
239 (mime-preview-quit))
240 (wl-summary-prev)
241 (wl-summary-click-on-message))
242
243 ;; Changes: removed newline
244 (defun wl-default-draft-cite ()
245 (let ((mail-yank-ignored-headers "[^:]+:")
246 (mail-yank-prefix "> ")
247 date from cite-title)
248 (save-restriction
249 (if (< (mark t) (point))
250 (exchange-point-and-mark))
251 (narrow-to-region (point)(point-max))
252 (setq date (std11-field-body "date")
253 from (std11-field-body "from")))
254 (when (or date from)
255 (insert (format "On %s, %s wrote:\n"
256 (or date "some time ago")
257 (if wl-default-draft-cite-decorate-author
258 (funcall wl-summary-from-function
259 (or from "you"))
260 (or from "you")))))
261 (mail-indent-citation)))
262 ;; mu-find search
263 (require 'elmo-search)
264 (elmo-search-register-engine
265 'mu 'local-file
266 :prog "/usr/bin/mu" ;; or wherever you've installed it
267 :args '("find" pattern "--fields" "l") :charset 'utf-8)
268
269 (setq elmo-search-default-engine 'mu)
270 ;; for when you type "g" in folder or summary.
271 (setq wl-default-spec "[")
272
273 (load "~/.emacs.d/lisp/latex-math-preview.el")