5316506b75f9a53a4d1d570b6a422b95cb34bac4
[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 (local-set-key (kbd "Y s") 'wl-send-to-spam-folder)
103 (local-set-key (kbd "Y h") 'wl-send-to-ham-folder)
104 ))
105 (defun gpcf-decrypt-mail ()
106 "Decrypts mail in MIME preview buffer. Works with both PGP/MIME
107 and PGP-Inline. OBSOLETE FOR PGP/MIME, USE (setq mime-pgp-decrypt-when-preview t) instead."
108 (interactive)
109 (save-excursion
110 (beginning-of-buffer)
111 (cond
112 ;; PGP/MIME
113 ((search-forward "<application/pgp-encrypted" nil t)
114 (let ((id "") (mess ""))
115 (save-window-excursion
116 (mime-preview-extract-current-entity)
117 (when (string-match "-[0-9]+" (buffer-name))
118 (setq id (substring (buffer-name) (match-beginning 0) (match-end 0)))
119 ))
120 (search-forward "]")
121 (save-window-excursion
122 (switch-to-buffer (concat "*Preview- *WL:Message*" id "*"))
123 (let ((temp-point (point)))
124 (end-of-buffer)
125 (setq mess (buffer-substring temp-point (point)))
126 (kill-buffer))
127 )
128 (let ((temp-point (point)) (inhibit-read-only t))
129 (search-backward "This part is encrypted" nil t)
130 (delete-region (point) temp-point)
131 (insert mess)
132 )))
133 ;;; PGP/INLINE
134 ((search-forward "-----BEGIN PGP MESSAGE-----" nil t)
135 (let ((inhibit-read-only t))
136 (mc-decrypt)))
137 (t (error "No GPG encrypted message found in this file."))))
138 )
139
140
141 (defun gpcf-setup-mail ()
142 "This function prepares the draft mode.
143 It add headers and defines keyboard shortcuts. Before the
144 message is sent, it adds the user's signature."
145 (if (string-match-p "\\*draft\\*.*" (buffer-name))
146 (progn
147 (setq enc-color (face-remap-add-relative 'mode-line :background "dark red"))
148 ; (set-input-method "TeX")
149 (auto-fill-mode)
150 (setq default-justification 'full)
151 (sm-add-microsoft)
152 (sm-add-emacs-name)
153 (sm-put-header "X-PGP-Key" "http://en.gpcf.eu/key.asc")
154 (local-set-key (kbd "C-c e") 'mime-edit-set-sign-and-encrypt)
155 (local-set-key (kbd "C-c s") 'ispell-message)
156 (local-set-key (kbd "C-c m s") 'wl-display-math)
157 (local-set-key (kbd "C-c m h") 'wl-hide-math)
158 (local-set-key (kbd "C-c c") '(lambda ()
159 ;;; save email to queue and send it using SSH.
160 (interactive)
161 (check-encryption-capabilities)
162 (wl-draft-send-and-exit)
163 (call-process-shell-command
164 (concat (expand-file-name "~/software/mail/sendmail.sh") "&")
165 nil 0)
166 ))
167 (delete-other-windows))
168 (mail-signature) ;; add signature
169 ))
170 (defun mime-edit-set-sign-and-encrypt ()
171 (interactive)
172 (mime-edit-set-encrypt t)
173 (mime-edit-set-sign t)
174 (message
175 "This message will be signed and encrypted")
176 (face-remap-remove-relative enc-color)
177 )
178 (defun check-encryption-capabilities ()
179 "Checks if the recipient can receive encrypted e-mail, based on whether they have sent you encrypted e-mail before or not"
180 (interactive)
181 (save-excursion
182 (beginning-of-buffer)
183 (unless (search-forward-regexp "^To: .* <\\(.*\\)>$" nil t)
184 (unless (search-forward-regexp "^To: \\(.*\\)$" nil t)
185 (error "No To: address specified"))
186 ))
187 (when (and (not (memq 'encrypt mime-edit-pgp-processing))
188 (= (shell-command
189 ;; this person sent you encrypted email
190 (concat "mu find flag:encrypted from:" (match-string 1) " > /dev/null 2>&1")) 0 )
191 )
192 (when (yes-or-no-p "Do you want to encrypt and sign this message? ")
193 (mime-edit-set-sign-and-encrypt)
194 ))
195 )
196 (add-hook 'mime-edit-mode-hook 'gpcf-setup-mail)
197 ; single window mode.
198 (setq wl-stay-folder-window nil
199 wl-draft-use-frame nil
200 wl-summary-move-order 'new
201 )
202 ;; Prevent wl from splitting large messages
203 (setq mime-edit-split-message nil)
204
205 ;; my E-Mail addresses:
206 (setq wl-user-mail-address-list '("gabriel@gpcf.eu"
207 "gpcf@gpcf.eu"))
208 (setq wl-summary-showto-folder-regexp ".*sent.*")
209
210 ;; AUTO-REFILE rules
211 (load "~/.emacs.d/files/refile-rules.el")
212 (defadvice mime-preview-quit (after mime-preview-quit activate)
213 (delete-other-windows)
214 )
215 (defun wl-delete-other-windows ()
216 ; (wl-summary-jump-to-current-message)
217 (delete-other-windows)
218 )
219 (defadvice wl-summary-next (after wl-summary-next activate)
220 ;; Prevent message window from appearing when you mark a message
221 (wl-delete-other-windows)
222 )
223 (defadvice wl-summary-prev (after wl-summary-prev activate)
224 (wl-delete-other-windows)
225 )
226 ;; (defadvice wl-summary-incorporate (after wl-summary-incorporate activate)
227 ;; (call-process-shell-command "mu index >/dev/null 2>/dev/null" nil 0)
228 ;; )
229 (defun wl-next-message ()
230 "Jump to next message and open it"
231 (interactive)
232 (unless (string= (buffer-name) "Summary")
233 (mime-preview-quit))
234 (wl-summary-next)
235 (wl-summary-click-on-message))
236
237 (defun wl-prev-message ()
238 "Jump to previous message and open it"
239 (interactive)
240 (unless (string= (buffer-name) "Summary")
241 (mime-preview-quit))
242 (wl-summary-prev)
243 (wl-summary-click-on-message))
244
245 ;; Changes: removed newline
246 (defun wl-default-draft-cite ()
247 (let ((mail-yank-ignored-headers "[^:]+:")
248 (mail-yank-prefix "> ")
249 date from cite-title)
250 (save-restriction
251 (if (< (mark t) (point))
252 (exchange-point-and-mark))
253 (narrow-to-region (point)(point-max))
254 (setq date (std11-field-body "date")
255 from (std11-field-body "from")))
256 (when (or date from)
257 (insert (format "On %s, %s wrote:\n"
258 (or date "some time ago")
259 (if wl-default-draft-cite-decorate-author
260 (funcall wl-summary-from-function
261 (or from "you"))
262 (or from "you")))))
263 (mail-indent-citation)))
264 ;; mu-find search
265 (require 'elmo-search)
266 (elmo-search-register-engine
267 'mu 'local-file
268 :prog "/usr/bin/mu" ;; or wherever you've installed it
269 :args '("find" pattern "--fields" "l") :charset 'utf-8)
270
271 (setq elmo-search-default-engine 'mu)
272 ;; for when you type "g" in folder or summary.
273 (setq wl-default-spec "[")
274
275 (load "~/.emacs.d/lisp/latex-math-preview.el")
276 (defun wl-send-to-ham-folder ()
277 (interactive)
278 (wl-summary-auto-save "~/Maildir/ham/")
279 )
280 (defun wl-send-to-spam-folder ()
281 (interactive)
282 (wl-summary-auto-save "~/Maildir/spam/")
283 )
284 (defun wl-summary-auto-save (wl-save-dir)
285 "Save current message to disk."
286 (interactive)
287 (let ((filename)
288 (num (wl-summary-message-number)))
289 (unless wl-save-dir
290 (setq wl-save-dir wl-temporary-file-directory))
291 (if num
292 (save-excursion
293 (setq filename (concat wl-save-dir (number-to-string num) wl-summary-save-file-suffix))
294 (wl-summary-set-message-buffer-or-redisplay)
295 (set-buffer (wl-message-get-original-buffer))
296 ;(while (not (file-exists-p filename))
297 ; (setq filename (concat (number-to-string (+ num 1)) wl-summary-save-file-suffix)))
298 (write-region-as-binary (point-min) (point-max) filename))
299 (message "No message to save."))
300 num)
301 )
302