-
Notifications
You must be signed in to change notification settings - Fork 11
/
gnus.el
223 lines (191 loc) · 8.47 KB
/
gnus.el
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
;;; org-contacts
(require-and-exec 'org-contacts
(org-contacts-gnus-insinuate)
;; deactivate store last mail
(fset 'org-contacts-gnus-store-last-mail #'NOP)
(defvar cofi/org-contacts-ignore-mail-rx
(rx "@public.gmane.org" string-end))
;; override to include the ignore rx
(defun org-contacts-check-mail-address (mail)
"Add MAIL address to contact at point if it does not have it."
(let ((mails (org-entry-get (point) org-contacts-email-property)))
(unless (or (member mail (split-string mails))
(string-match-p cofi/org-contacts-ignore-mail-rx mail))
(when (yes-or-no-p
(format "Do you want to add this address to %s?" (org-get-heading t)))
(org-set-property org-contacts-email-property (concat mails " " mail)))))))
;;; methods
(setq imap-shell-program "/usr/lib/dovecot/imap -c ~/config/dovecot.conf"
nnimap-shell-program imap-shell-program
gnus-select-method '(nnimap "Mail"
(nnimap-stream shell))
gnus-secondary-select-methods '((nntp "news.gmane.org")
(nntp "news.eternal-september.org")))
;;; sending
(setq sendmail-program "msmtp"
message-sendmail-extra-arguments '("-a" "gmail")
message-send-mail-function 'message-send-mail-with-sendmail)
(defun cofi/mml-ask-if-send ()
"Ask for send with preview."
(save-window-excursion
(mml-preview)
(unless (y-or-n-p "Send message? ")
(error "Abort."))))
(add-all-to-hook 'message-send-hook
#'cofi/mml-ask-if-send
(lambda ()
;; only ask if there is no <#secure cookie
(unless (save-excursion
(goto-char 0)
(re-search-forward "<#secure" nil 'noerror))
(if (y-or-n-p "Sign message? ")
(mml-secure-message-sign))))
#'mail-attachment-check)
;;; writing
(add-hook 'message-mode-hook 'cofi/write-mail)
(setq gnus-add-to-list t)
(setq message-elide-ellipsis "\n[%l lines snipped]\n")
(setq message-kill-buffer-on-exit t
message-dont-reply-to-names user-mail-rx)
(setq gnus-gcc-mark-as-read t)
(setq gnus-group-line-format "%M%S%p%P%5y[%T]:%B%(%G%)\n")
;;; fancy summary
(setq gnus-summary-line-format "%U|%R|%z|%ur|%(%-20&user-date;|%-30B%[%5L: %-40n%] %s%)\n")
(setq gnus-summary-make-false-root 'dummy
gnus-sum-thread-tree-false-root "┈─►"
gnus-sum-thread-tree-single-indent "◈ "
gnus-sum-thread-tree-root "● "
gnus-sum-thread-tree-vertical "│ "
gnus-sum-thread-tree-leaf-with-other "├─►"
gnus-sum-thread-tree-single-leaf "╰─►"
gnus-sum-thread-tree-indent " ")
(setq gnus-cached-mark ?☍
gnus-canceled-mark ?↗
gnus-del-mark ?✗
gnus-dormant-mark ?⚐
gnus-expirable-mark ?♻
gnus-forwarded-mark ?↪
gnus-killed-mark ?☠
gnus-process-mark ?⚙
gnus-read-mark ?✓
gnus-recent-mark ?✩
gnus-replied-mark ?↺
gnus-unread-mark ?✉
gnus-unseen-mark ?★
gnus-ticked-mark ?⚑)
(setq mm-text-html-renderer 'gnus-w3m)
;;; search
(require 'nnir)
;;; washing
;; hide citations
(setq gnus-treat-hide-citation t
gnus-cited-lines-visible '(2 . 5))
(setq gnus-cited-closed-text-button-line-format "%(%{[%n lines snipped]%}%)\n")
;; fill long lines on first part or text/plain
(setq gnus-treat-fill-long-lines '(or first (typep "text/plain")))
;;; crypt
(setq gnus-message-replysign t
gnus-message-replyencrypt t
gnus-message-replysignencrypted t)
(setq gnus-message-replysign t)
(setq gnus-summary-force-verify-and-decrypt t)
(setq mm-verify-option 'always)
(setq mml2015-verbose t
mml2015-encrypt-to-self t
mml2015-signers '("B4523295"))
;;; mime
(setq gnus-mime-view-all-parts t
gnus-buttonized-mime-types nil
gnus-unbuttonized-mime-types '("text/plain"))
(setq mm-discouraged-alternatives '("text/html" "text/richtext"))
(dolist (type '("image/.*" "message/rfc822" "text/x-patch"))
(push type mm-attachment-override-types))
(setq mm-inline-large-images 'resize)
(setq mm-uu-diff-groups-regexp ".")
(defun cofi-gnus-copy-archived-at ()
"Copy archived-at url of current article to killring and clipboard."
(interactive)
(let ((archived (gnus-with-article-headers
(mail-extract-address-components
(mail-fetch-field "Archived-At")))))
(when archived
(let ((x-select-enable-clipboard t)
(field (second archived)))
(let ((url (if (not (begins-with field "http:"))
(concat "http:" (substring field 5))
field)))
(kill-new url)
(message "Copied: %s" url))))))
;;; keys
(add-hook 'gnus-summary-mode-hook
(gen-local-fill-keymap-hook "M-p" 'gnus-summary-prev-article
"M-n" 'gnus-summary-next-article
"r" 'gnus-summary-wide-reply-with-original
"B d" 'gnus-summary-delete-article
"C-M-n" 'gnus-summary-next-thread
"C-M-p" 'gnus-summary-prev-thread
"A t" 'gnus-summary-refer-thread
"M-t" 'gnus-summary-refer-thread
"y" 'cofi-gnus-copy-archived-at
"~" (cmd gnus-mark-as-read (gnus-summary-mark-article nil ?R))
"S-SPC" 'gnus-summary-prev-page))
(add-hook 'gnus-group-mode-hook
(gen-local-fill-keymap-hook
"C-w" nil))
(require 'offlineimap)
(add-hook 'gnus-group-mode-hook
(gen-local-fill-keymap-hook "<f12>" 'offlineimap))
(add-hook 'message-mode-hook
(gen-local-fill-keymap-hook "M-RET" 'yas/expand))
(setq message-citation-line-function #'message-insert-formatted-citation-line)
(setq message-citation-line-format "On %a, %b %d %Y (%H:%M), %f wrote: \n")
(defun gnus-user-format-function-r (headers)
"Classify headers on how I'm adressed."
(let ((to (gnus-extra-header 'To headers))
(all (remove-duplicates (flatten
(mapcar (lambda (h)
(split-string (gnus-extra-header h headers)
", " 'omit-nulls))
'(To Cc BCc)))
:test #'string=)))
(if (string-match user-mail-rx to)
(if (> (length all) 1)
;; other recipients
"»"
;; sole recipient
"!")
;; unadressed
"-")))
;;; scan for news every 10 minutes
(setq gnus-visible-headers (concat gnus-visible-headers "\\|^Archived-At:"))
(gnus-demon-add-handler 'gnus-demon-scan-news 10 t)
(setq gnus-notifications-use-google-contacts nil)
(require 'gnus-notifications)
(add-hook 'gnus-after-getting-new-news-hook 'gnus-notifications)
(defvar cofi--gnus-frame nil)
(add-hook 'gnus-started-hook (lambda () (setq cofi--gnus-frame (selected-frame))))
(defun cofi/set-mail-urgency ()
"Set urgency hint for frame most recently showing gnus."
(loop for (group . rest) in gnus-newsrc-alist
when (and (<= (gnus-group-level group) gnus-notifications-minimum-level)
(let ((unread (gnus-group-unread group)))
(and (numberp unread)
(> unread 0))))
do (prog1
(x-urgency-hint (if (frame-live-p cofi--gnus-frame)
cofi--gnus-frame
(setq cofi--gnus-frame nil)
(selected-frame))
t)
(return))))
(add-hook 'gnus-after-getting-new-news-hook #'cofi/set-mail-urgency)
(setq gnus-check-new-newsgroups nil)
(setq gnus-asynchronous t)
(gnus-add-configuration '(reply-yank (vertical 1.0
(horizontal 1.0
(message .5 point)
(article 1.0)))))
(gnus-add-configuration '(reply (vertical 1.0
(horizontal 1.0
(message .5 point)
(article 1.0)))))