blob: 184c5f69bedb9ce45483407da651e6b618488cd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
;; ===================================================================
;; Generic mail stuff
(setq user-full-name "tslil clingman"
user-mail-address "email"
mail-signature-file "~/.signature")
(setq notmuch-fcc-dirs '(("email" . "folder")))
;; ===================================================================
;; SMTP server configuration
(setq message-send-mail-function 'smtpmail-send-it
send-mail-function 'smtpmail-send-it
mail-user-agent 'message-user-agent
smtpmail-auth-credentials "~/.authinfo.gpg"
smtpmail-smtp-server "server"
smtpmail-smtp-service 465
smtpmail-stream-type 'ssl)
(defconst smtp-from-server-alist '(("account" . "server")))
(defun set-smtp-server ()
(let ((server (or (cdr (assoc (save-restriction
(message-narrow-to-headers)
(message-fetch-field "from"))
smtp-from-server-alist)) "server")))
(setq smtpmail-smtp-server server
smtpmail-stream-type 'ssl
smtpmail-smtp-service 465)
(when (string-equal server "other server")
(setq smtpmail-stream-type 'starttls
smtpmail-smtp-service 587))
(message "SMTP server changed to %s" server)))
;; ===================================================================
;; Crypto and related
(setq gnutls-min-prime-bits 2048
mm-verify-option 'always
mm-decrypt-option 'always
mml-secure-method "pgpmime"
mml-default-sign-method "pgpmime"
mml-secure-openpgp-sign-with-sender nil
mml-secure-openpgp-signers '("me@server.tld")
notmuch-crypto-process-mime t)
(defmacro secure-or-send (&rest body)
`(quote (lambda (arg)
(interactive "P")
(set-smtp-server)
(unless arg
,@(mapcar #'list body))
(notmuch-mua-send-and-exit))))
(define-key notmuch-message-mode-map (kbd "C-c C-S-c") 'message-send-and-exit)
(define-key notmuch-message-mode-map (kbd "C-c C-c") (secure-or-send mml-secure-sign))
(define-key notmuch-message-mode-map (kbd "C-c M-c") (secure-or-send mml-secure-encrypt))
;; ===================================================================
;; notmuch-hello bindings
(setq notmuch-saved-searches '((:name "flagged" :query "tag:flagged")
(:name "sent" :query "tag:sent")
(:name "drafts" :query "tag:draft")))
(defvar notmuch-hello-tree-searches '(("u" . "tag:unread")
("d" . "tag:drafts")
("s" . "tag:sent")
("f" . "tag:flagged")
("i" . "tag:inbox")
("*" . "*"))
"List of (key . query) pairs to bind in notmuch-hello.")
(defvar notmuch-tag-keys '(("d" . '("+deleted"))
("u" . '("-deleted"))
("t" . nil))
"List of (key . '(tags list)) pairs to bind in tree and search modes.")
(defmacro make-binds (mode-map binds argfunc &rest body)
"Create keybindings in `mode-map' using a list of (keystr . arg)
pairs in `binds' of the form ( ... (argfunc arg) body)."
`(progn ,@(mapcar (lambda (pair)
`(define-key ,mode-map (kbd ,(car pair))
(lambda () (interactive) (,argfunc ,(cdr pair)) ,@body)))
(eval binds))))
(define-key notmuch-hello-mode-map (kbd "q")
(lambda ()
(interactive)
(when (timerp offlineimap--timer)
(cancel-timer offlineimap--timer))
(notmuch-bury-or-kill-this-buffer)))
(define-key notmuch-search-mode-map (kbd "R") 'notmuch-search-reply-to-thread)
(define-key notmuch-search-mode-map (kbd "r") 'notmuch-search-reply-to-thread-sender)
(define-key notmuch-tree-mode-map (kbd "R") (lambda ()
(interactive)
(notmuch-tree-close-message-window)
(notmuch-show-reply)))
(define-key notmuch-tree-mode-map (kbd "r") (lambda ()
(interactive)
(notmuch-tree-close-message-window)
(notmuch-show-reply-sender)))
(make-binds notmuch-hello-mode-map
notmuch-hello-tree-searches
notmuch-tree)
(make-binds notmuch-show-mode-map
notmuch-tag-keys
notmuch-show-tag
(notmuch-show-next-message))
(make-binds notmuch-tree-mode-map
notmuch-tag-keys
notmuch-tree-tag
(notmuch-tree-next-message))
;; ===================================================================
;; I want signatures before quoted text
(defun notmuch-signature-before-body (query-string &optional prompt-for-sender reply-all)
(save-excursion
(message-goto-body)
(newline)
(message-goto-signature)
(when (re-search-backward message-signature-separator nil t)
(if message-signature-insert-empty-line
(forward-line -1))
(delete-region (point) (point-max))
(message-goto-body)
(mail-signature t))))
(advice-add 'notmuch-mua-new-reply :after #'notmuch-signature-before-body)
;; ===================================================================
;; notmuch-hello widgets and offlineimap integration
(defun notmuch-hello-header-new ()
(setq fill-column (window-width))
(let ((widget-link-prefix "")
(widget-link-suffix "")
(unread (string-to-number (car (process-lines
notmuch-command "count" "tag:unread"))))
(total (string-to-number (car (process-lines
notmuch-command "count")))))
(widget-insert "You have ")
(widget-create 'link :notify (lambda (&rest nope) (notmuch-hello-update))
:help-echo "Update notmuch view"
(notmuch-hello-nice-number total))
(widget-insert " emails,")
(center-line) (widget-insert "\n")
(widget-create 'link :notify (lambda (&rest nope) (notmuch-tree "tag:unread"))
:help-echo "View unread emails"
(notmuch-hello-nice-number unread))
(widget-insert (format " of which %s unread."
(if (= 1 unread) "is" "are")))
(center-line) (widget-insert "\n")))
(setq notmuch-hello-sections '(notmuch-hello-header-new
;; notmuch-hello-offlineimap
notmuch-hello-insert-saved-searches
notmuch-hello-insert-search
notmuch-hello-insert-alltags))
(add-hook 'notmuch-hello-refresh-hook
(lambda ()
(goto-char (point-min))
(search-forward "You have" nil t)
(forward-word)))
(defvar offlineimap--timer nil "Timer for running offlineimap.")
(defvar offlineimap-use-timer nil "Whether to use a timer for
running offlineimap (t) or manual (nil).")
(add-hook 'notmuch-hello-mode-hook
(lambda ()
(when offlineimap-use-timer
(when (timerp offlineimap--timer)
(cancel-timer offlineimap--timer))
(setq offlineimap--timer
(run-with-timer 0 300 'offlineimap-run)))))
;; ===================================================================
;; Message displaying and so on
(add-to-list 'mm-discouraged-alternatives "text/html")
(add-to-list 'mm-discouraged-alternatives "text/richtext")
(use-package w3m :ensure t :defer t)
(setq mm-text-html-renderer 'w3m)
(add-hook 'message-mode-hook (lambda ()
(turn-on-auto-fill)
(spell-fu-mode 1)
(company-mode)))
(setq notmuch-tree-result-format '(("date" . "%12s | ")
("authors" . "%-20s")
((("tree" . "%s")
("subject" . "%-10s"))
. " | %-54s")
("tags" . "(%s)")))
|