88b05bd41d9d466b9bab6a896196a7c7d0f7a4d0
[~bandali/configs] / lisp / bandali-gnus.el
1 ;;; bandali-gnus.el --- bandali's Gnus setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: mail, news
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My trusty super awesome Gnus setup.
24
25 ;;; Code:
26
27 (defvar b/maildir (expand-file-name "~/mail/"))
28 (with-eval-after-load 'recentf
29 (add-to-list 'recentf-exclude b/maildir))
30
31 (defvar b/gnus-init-file (b/etc "gnus"))
32
33 (eval-when-compile
34 (progn
35 (defvar nndraft-directory)
36 (defvar gnus-read-newsrc-file)
37 (defvar gnus-save-newsrc-file)
38 (defvar gnus-gcc-mark-as-read)
39 (defvar nnmail-split-abbrev-alist)))
40
41 (declare-function article-make-date-line "gnus-art" (date type))
42
43 (setq
44 mail-user-agent 'gnus-user-agent
45 read-mail-command 'gnus)
46
47 (use-package gnus
48 :bind (("s-m" . gnus-plugged)
49 ("s-M" . gnus-unplugged)
50 ("C-c a m" . gnus-plugged)
51 ("C-c a M" . gnus-unplugged))
52 :init
53 (setq
54 gnus-select-method '(nnnil "")
55 gnus-secondary-select-methods
56 '((nnimap "shemshak"
57 (nnimap-stream plain)
58 (nnimap-address "127.0.0.1")
59 (nnimap-server-port 143)
60 (nnimap-authenticator plain)
61 (nnimap-user "bandali@shemshak.local"))
62 (nnimap "gnu"
63 (nnimap-stream plain)
64 (nnimap-address "127.0.0.1")
65 (nnimap-server-port 143)
66 (nnimap-authenticator plain)
67 (nnimap-user "bandali@gnu.local")
68 (nnimap-inbox "INBOX")
69 (nnimap-split-methods 'nnimap-split-fancy)
70 (nnimap-split-fancy (|
71 ;; (: gnus-registry-split-fancy-with-parent)
72 ;; (: gnus-group-split-fancy "INBOX" t "INBOX")
73 ;; gnu
74 (list ".*<\\(.*\\)\\.\\(non\\)?gnu\\.org>.*" "l.\\1")
75 ;; gnus
76 (list ".*<\\(.*\\)\\.gnus\\.org>.*" "l.\\1")
77 ;; libreplanet
78 (list ".*<\\(.*\\)\\.libreplanet\\.org>.*" "l.\\1")
79 ;; iana (e.g. tz-announce)
80 (list ".*<\\(.*\\)\\.iana\\.org>.*" "l.\\1")
81 ;; *.lists.sr.ht, omitting one dot if present
82 ;; add more \\.?\\([^.]*\\) if needed
83 (list ".*<~\\(.*\\)/\\([^.]*\\)\\.?\\([^.]*\\)\\.lists.sr.ht>.*" "l.~\\1.\\2\\3")
84 ;; webmasters
85 (from "webmasters\\(-comment\\)?@gnu\\.org" "webmasters")
86 ;; other
87 (list ".*atreus.freelists.org" "l.atreus")
88 (list ".*deepspec.lists.cs.princeton.edu" "l.deepspec")
89 ;; (list ".*haskell-art.we.lurk.org" "l.haskell.art") ;d
90 (list ".*haskell-cafe.haskell.org" "l.haskell-cafe")
91 ;; (list ".*notmuch.notmuchmail.org" "l.notmuch") ;u
92 ;; (list ".*dev.lists.parabola.nu" "l.parabola-dev") ;u
93 ;; ----------------------------------
94 ;; legend: (u)nsubscribed | (d)ead
95 ;; ----------------------------------
96 ;; spam
97 ("X-Spam_action" "reject" "Junk")
98 ;; otherwise, leave mail in INBOX
99 "INBOX")))
100 (nnimap "uwaterloo"
101 (nnimap-stream plain)
102 (nnimap-address "127.0.0.1")
103 (nnimap-server-port 143)
104 (nnimap-authenticator plain)
105 (nnimap-user "abandali@uwaterloo.local")
106 (nnimap-inbox "INBOX")
107 (nnimap-split-methods 'nnimap-split-fancy)
108 (nnimap-split-fancy (|
109 ;; (: gnus-registry-split-fancy-with-parent)
110 ;; se212-f19
111 ("subject" "SE\\s-?212" "course.se212-f19")
112 (from "SE\\s-?212" "course.se212-f19")
113 ;; catch-all
114 "INBOX")))
115 (nnimap "csc"
116 (nnimap-stream plain)
117 (nnimap-address "127.0.0.1")
118 (nnimap-server-port 143)
119 (nnimap-authenticator plain)
120 (nnimap-user "abandali@csclub.uwaterloo.local")
121 (nnimap-inbox "INBOX")
122 (nnimap-split-methods 'nnimap-split-fancy)
123 (nnimap-split-fancy (|
124 ;; cron reports and other messages from root
125 (from "root@\\(.*\\.\\)?csclub\\.uwaterloo\\.ca" "INBOX")
126 ;; spam
127 ("X-Spam-Flag" "YES" "Junk")
128 ;; catch-all
129 "INBOX"))))
130 gnus-message-archive-group "nnimap+gnu:INBOX"
131 gnus-parameters
132 '(("l\\.atreus"
133 (to-address . "atreus@freelists.org")
134 (to-list . "atreus@freelists.org"))
135 ("l\\.deepspec"
136 (to-address . "deepspec@lists.cs.princeton.edu")
137 (to-list . "deepspec@lists.cs.princeton.edu")
138 (list-identifier . "\\[deepspec\\]"))
139 ("l\\.emacs-devel"
140 (to-address . "emacs-devel@gnu.org")
141 (to-list . "emacs-devel@gnu.org"))
142 ("l\\.help-gnu-emacs"
143 (to-address . "help-gnu-emacs@gnu.org")
144 (to-list . "help-gnu-emacs@gnu.org"))
145 ("l\\.info-gnu-emacs"
146 (to-address . "info-gnu-emacs@gnu.org")
147 (to-list . "info-gnu-emacs@gnu.org"))
148 ("l\\.emacs-orgmode"
149 (to-address . "emacs-orgmode@gnu.org")
150 (to-list . "emacs-orgmode@gnu.org")
151 (list-identifier . "\\[O\\]"))
152 ("l\\.emacs-tangents"
153 (to-address . "emacs-tangents@gnu.org")
154 (to-list . "emacs-tangents@gnu.org"))
155 ("l\\.emacsconf-committee"
156 (to-address . "emacsconf-committee@gnu.org")
157 (to-list . "emacsconf-committee@gnu.org"))
158 ("l\\.emacsconf-discuss"
159 (to-address . "emacsconf-discuss@gnu.org")
160 (to-list . "emacsconf-discuss@gnu.org"))
161 ("l\\.emacsconf-register"
162 (to-address . "emacsconf-register@gnu.org")
163 (to-list . "emacsconf-register@gnu.org"))
164 ("l\\.emacsconf-submit"
165 (to-address . "emacsconf-submit@gnu.org")
166 (to-list . "emacsconf-submit@gnu.org"))
167 ("l\\.fencepost-users"
168 (to-address . "fencepost-users@gnu.org")
169 (to-list . "fencepost-users@gnu.org")
170 (list-identifier . "\\[Fencepost-users\\]"))
171 ("l\\.gnewsense-art"
172 (to-address . "gnewsense-art@nongnu.org")
173 (to-list . "gnewsense-art@nongnu.org")
174 (list-identifier . "\\[gNewSense-art\\]"))
175 ("l\\.gnewsense-dev"
176 (to-address . "gnewsense-dev@nongnu.org")
177 (to-list . "gnewsense-dev@nongnu.org")
178 (list-identifier . "\\[Gnewsense-dev\\]"))
179 ("l\\.gnewsense-users"
180 (to-address . "gnewsense-users@nongnu.org")
181 (to-list . "gnewsense-users@nongnu.org")
182 (list-identifier . "\\[gNewSense-users\\]"))
183 ("l\\.gnunet-developers"
184 (to-address . "gnunet-developers@gnu.org")
185 (to-list . "gnunet-developers@gnu.org")
186 (list-identifier . "\\[GNUnet-developers\\]"))
187 ("l\\.help-gnunet"
188 (to-address . "help-gnunet@gnu.org")
189 (to-list . "help-gnunet@gnu.org")
190 (list-identifier . "\\[Help-gnunet\\]"))
191 ("l\\.bug-gnuzilla"
192 (to-address . "bug-gnuzilla@gnu.org")
193 (to-list . "bug-gnuzilla@gnu.org")
194 (list-identifier . "\\[Bug-gnuzilla\\]"))
195 ("l\\.gnuzilla-dev"
196 (to-address . "gnuzilla-dev@gnu.org")
197 (to-list . "gnuzilla-dev@gnu.org")
198 (list-identifier . "\\[Gnuzilla-dev\\]"))
199 ("l\\.guile-devel"
200 (to-address . "guile-devel@gnu.org")
201 (to-list . "guile-devel@gnu.org"))
202 ("l\\.guile-user"
203 (to-address . "guile-user@gnu.org")
204 (to-list . "guile-user@gnu.org"))
205 ("l\\.guix-devel"
206 (to-address . "guix-devel@gnu.org")
207 (to-list . "guix-devel@gnu.org"))
208 ("l\\.help-guix"
209 (to-address . "help-guix@gnu.org")
210 (to-list . "help-guix@gnu.org"))
211 ("l\\.info-guix"
212 (to-address . "info-guix@gnu.org")
213 (to-list . "info-guix@gnu.org"))
214 ("l\\.savannah-hackers-public"
215 (to-address . "savannah-hackers-public@gnu.org")
216 (to-list . "savannah-hackers-public@gnu.org"))
217 ("l\\.savannah-users"
218 (to-address . "savannah-users@gnu.org")
219 (to-list . "savannah-users@gnu.org"))
220 ("l\\.www-commits"
221 (to-address . "www-commits@gnu.org")
222 (to-list . "www-commits@gnu.org"))
223 ("l\\.www-discuss"
224 (to-address . "www-discuss@gnu.org")
225 (to-list . "www-discuss@gnu.org"))
226 ("l\\.haskell-art"
227 (to-address . "haskell-art@we.lurk.org")
228 (to-list . "haskell-art@we.lurk.org")
229 (list-identifier . "\\[haskell-art\\]"))
230 ("l\\.haskell-cafe"
231 (to-address . "haskell-cafe@haskell.org")
232 (to-list . "haskell-cafe@haskell.org")
233 (list-identifier . "\\[Haskell-cafe\\]"))
234 ("l\\.notmuch"
235 (to-address . "notmuch@notmuchmail.org")
236 (to-list . "notmuch@notmuchmail.org"))
237 ("l\\.parabola-dev"
238 (to-address . "dev@lists.parabola.nu")
239 (to-list . "dev@lists.parabola.nu")
240 (list-identifier . "\\[Dev\\]"))
241 ("l\\.~bandali\\.public-inbox"
242 (to-address . "~bandali/public-inbox@lists.sr.ht")
243 (to-list . "~bandali/public-inbox@lists.sr.ht"))
244 ("l\\.~sircmpwn\\.free-writers-club"
245 (to-address . "~sircmpwn/free-writers-club@lists.sr.ht")
246 (to-list . "~sircmpwn/free-writers-club@lists.sr.ht"))
247 ("l\\.~sircmpwn\\.srht-admins"
248 (to-address . "~sircmpwn/sr.ht-admins@lists.sr.ht")
249 (to-list . "~sircmpwn/sr.ht-admins@lists.sr.ht"))
250 ("l\\.~sircmpwn\\.srht-announce"
251 (to-address . "~sircmpwn/sr.ht-announce@lists.sr.ht")
252 (to-list . "~sircmpwn/sr.ht-announce@lists.sr.ht"))
253 ("l\\.~sircmpwn\\.srht-dev"
254 (to-address . "~sircmpwn/sr.ht-dev@lists.sr.ht")
255 (to-list . "~sircmpwn/sr.ht-dev@lists.sr.ht"))
256 ("l\\.~sircmpwn\\.srht-discuss"
257 (to-address . "~sircmpwn/sr.ht-discuss@lists.sr.ht")
258 (to-list . "~sircmpwn/sr.ht-discuss@lists.sr.ht"))
259 ("webmasters"
260 (to-address . "webmasters@gnu.org")
261 (to-list . "webmasters@gnu.org"))
262 ("gnu.*"
263 (gcc-self . t))
264 ("l\\."
265 (subscribed . t))
266 ("nnimap\\+uwaterloo:.*"
267 (gcc-self . t)))
268 gnus-large-newsgroup 50
269 gnus-home-directory (b/var "gnus/")
270 gnus-directory (concat gnus-home-directory "news/")
271 message-directory (concat gnus-home-directory "mail/")
272 nndraft-directory (concat gnus-home-directory "drafts/")
273 gnus-save-newsrc-file nil
274 gnus-read-newsrc-file nil
275 gnus-interactive-exit nil
276 gnus-gcc-mark-as-read t)
277 :config
278 (when (version< emacs-version "27")
279 (with-eval-after-load 'nnmail
280 (add-to-list
281 'nnmail-split-abbrev-alist
282 '(list . "list-id\\|list-post\\|x-mailing-list\\|x-beenthere\\|x-loop")
283 t)))
284
285 ;; (require 'gnus-registry)
286 ;; (setq gnus-registry-max-entries 2500)
287 ;; (setq gnus-registry-ignored-groups
288 ;; (append gnus-registry-ignored-groups
289 ;; '(("^nnimap:gnu\\.l" t)
290 ;; ("webmasters$" t))))
291 ;; (gnus-registry-initialize)
292
293 (with-eval-after-load 'recentf
294 (add-to-list 'recentf-exclude gnus-home-directory)))
295
296 (use-package gnus-art
297 :config
298 (setq
299 gnus-buttonized-mime-types '("multipart/\\(signed\\|encrypted\\)")
300 gnus-sorted-header-list '("^From:"
301 "^X-RT-Originator"
302 "^Newsgroups:"
303 "^Subject:"
304 "^Date:"
305 "^Envelope-To:"
306 "^Followup-To:"
307 "^Reply-To:"
308 "^Organization:"
309 "^Summary:"
310 "^Abstract:"
311 "^Keywords:"
312 "^To:"
313 "^[BGF]?Cc:"
314 "^Posted-To:"
315 "^Mail-Copies-To:"
316 "^Mail-Followup-To:"
317 "^Apparently-To:"
318 "^Resent-From:"
319 "^User-Agent:"
320 "^X-detected-operating-system:"
321 "^X-Spam_action:"
322 "^X-Spam_bar:"
323 "^Message-ID:"
324 ;; "^References:"
325 "^List-Id:"
326 "^Gnus-Warning:")
327 gnus-visible-headers (mapconcat 'identity
328 gnus-sorted-header-list
329 "\\|")
330 ;; local-lapsed article dates
331 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
332 gnus-article-date-headers '(user-defined)
333 gnus-article-time-format
334 (lambda (time)
335 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
336 (local (article-make-date-line date 'local))
337 (combined-lapsed (article-make-date-line date
338 'combined-lapsed))
339 (lapsed (progn
340 (string-match " (.+" combined-lapsed)
341 (match-string 0 combined-lapsed))))
342 (concat local lapsed))))
343 (bind-keys
344 :map gnus-article-mode-map
345 ("M-L" . org-store-link)))
346
347 (use-package gnus-sum
348 :bind (:map gnus-summary-mode-map
349 :prefix-map b/gnus-summary-prefix-map
350 :prefix "v"
351 ("r" . gnus-summary-reply)
352 ("w" . gnus-summary-wide-reply)
353 ("v" . gnus-summary-show-raw-article))
354 :config
355 (bind-keys
356 :map gnus-summary-mode-map
357 ("M-L" . org-store-link))
358 :hook (gnus-summary-mode . b/no-mouse-autoselect-window)
359 :custom
360 (gnus-thread-sort-functions '(gnus-thread-sort-by-number
361 gnus-thread-sort-by-subject
362 gnus-thread-sort-by-date)))
363
364 (use-package gnus-msg
365 :config
366 (defvar b/shemshak-signature "Amin Bandali
367 https://shemshak.org/~bandali")
368 (defvar b/uwaterloo-signature "Amin Bandali, MMath
369 Cheriton School of Computer Science
370 University of Waterloo
371 https://bndl.org")
372 (defvar b/csc-signature "Amin Bandali | https://bndl.org
373 System Administrator, Systems Committee
374 Computer Science Club, University of Waterloo")
375 (setq gnus-message-replysign t
376 gnus-posting-styles
377 '((".*"
378 (address "bandali@gnu.org"))
379 ("nnimap\\+gnu:l\\..*"
380 (signature nil))
381 ("nnimap\\+gnu:.*"
382 (organization "GNU"))
383 ((header "subject" "ThankCRM")
384 (to "webmasters-comment@gnu.org")
385 (body "")
386 (eval (setq b/message-cite-say-hi nil)))
387 ("nnimap\\+shemshak:.*"
388 (address "amin@shemshak.org")
389 (body "\nBest,\n")
390 (signature b/shemshak-signature)
391 (gcc "nnimap+shemshak:Sent")
392 (eval (setq b/message-cite-say-hi t)))
393 ("nnimap\\+uwaterloo:.*"
394 (address "bandali@uwaterloo.ca")
395 (body "\nBest,\n")
396 (signature b/uwaterloo-signature))
397 ("nnimap\\+uwaterloo:INBOX"
398 (gcc "\"nnimap+uwaterloo:Sent Items\""))
399 ("nnimap\\+csc:.*"
400 (address "bandali@csclub.uwaterloo.ca")
401 (signature b/csc-signature)
402 (gcc "nnimap+csc:Sent"))))
403 :hook (gnus-message-setup . (lambda ()
404 (unless (mml-secure-is-encrypted-p)
405 (mml-secure-message-sign)))))
406
407 (use-package gnus-topic
408 :hook (gnus-group-mode . gnus-topic-mode)
409 :config (setq gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n"))
410
411 (use-package gnus-agent
412 :config
413 (setq gnus-agent-synchronize-flags 'ask)
414 :hook (gnus-group-mode . gnus-agent-mode))
415
416 (use-package gnus-group
417 :config
418 (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
419
420 (comment
421 ;; problematic with ebdb's popup, *EBDB-Gnus*
422 (use-package gnus-win
423 :config
424 (setq gnus-use-full-window nil)))
425
426 (use-package gnus-dired
427 :commands gnus-dired-mode
428 :init
429 (add-hook 'dired-mode-hook 'gnus-dired-mode))
430
431 (comment
432 (use-package gnus-utils
433 :custom
434 (gnus-completing-read-function 'gnus-ido-completing-read)))
435
436 (use-package mm-decode
437 :config
438 (setq mm-discouraged-alternatives '("text/html" "text/richtext")
439 mm-decrypt-option 'known
440 mm-verify-option 'known))
441
442 (use-package mm-uu
443 :config
444 (when (version< "27" emacs-version)
445 (set-face-attribute 'mm-uu-extract nil :extend t))
446 :custom
447 (mm-uu-diff-groups-regexp
448 "\\(gmane\\|gnu\\|l\\)\\..*\\(diff\\|commit\\|cvs\\|bug\\|dev\\)"))
449
450 (use-package mml)
451
452 (use-package mml-sec
453 :custom
454 (mml-secure-openpgp-encrypt-to-self t)
455 (mml-secure-openpgp-sign-with-sender t))
456
457 (use-package gnus-article-treat-patch
458 :disabled
459 :demand
460 :load-path "lisp/"
461 :config
462 ;; note: be sure to customize faces with `:foreground "white"' when
463 ;; using a theme with a white/light background :)
464 (setq ft/gnus-article-patch-conditions
465 '("^@@ -[0-9]+,[0-9]+ \\+[0-9]+,[0-9]+ @@")))
466
467 (provide 'bandali-gnus)
468 ;;; bandali-gnus.el ends here