180e82ad32217d3dcd4623da5e59d7ad7704a09b
[~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 ;; spam
125 ("X-Spam-Flag" "YES" "Junk")
126 ;; catch-all
127 "INBOX"))))
128 gnus-message-archive-group "nnimap+gnu:INBOX"
129 gnus-parameters
130 '(("l\\.atreus"
131 (to-address . "atreus@freelists.org")
132 (to-list . "atreus@freelists.org"))
133 ("l\\.deepspec"
134 (to-address . "deepspec@lists.cs.princeton.edu")
135 (to-list . "deepspec@lists.cs.princeton.edu")
136 (list-identifier . "\\[deepspec\\]"))
137 ("l\\.emacs-devel"
138 (to-address . "emacs-devel@gnu.org")
139 (to-list . "emacs-devel@gnu.org"))
140 ("l\\.help-gnu-emacs"
141 (to-address . "help-gnu-emacs@gnu.org")
142 (to-list . "help-gnu-emacs@gnu.org"))
143 ("l\\.info-gnu-emacs"
144 (to-address . "info-gnu-emacs@gnu.org")
145 (to-list . "info-gnu-emacs@gnu.org"))
146 ("l\\.emacs-orgmode"
147 (to-address . "emacs-orgmode@gnu.org")
148 (to-list . "emacs-orgmode@gnu.org")
149 (list-identifier . "\\[O\\]"))
150 ("l\\.emacs-tangents"
151 (to-address . "emacs-tangents@gnu.org")
152 (to-list . "emacs-tangents@gnu.org"))
153 ("l\\.emacsconf-committee"
154 (to-address . "emacsconf-committee@gnu.org")
155 (to-list . "emacsconf-committee@gnu.org"))
156 ("l\\.emacsconf-discuss"
157 (to-address . "emacsconf-discuss@gnu.org")
158 (to-list . "emacsconf-discuss@gnu.org"))
159 ("l\\.emacsconf-register"
160 (to-address . "emacsconf-register@gnu.org")
161 (to-list . "emacsconf-register@gnu.org"))
162 ("l\\.emacsconf-submit"
163 (to-address . "emacsconf-submit@gnu.org")
164 (to-list . "emacsconf-submit@gnu.org"))
165 ("l\\.fencepost-users"
166 (to-address . "fencepost-users@gnu.org")
167 (to-list . "fencepost-users@gnu.org")
168 (list-identifier . "\\[Fencepost-users\\]"))
169 ("l\\.gnewsense-art"
170 (to-address . "gnewsense-art@nongnu.org")
171 (to-list . "gnewsense-art@nongnu.org")
172 (list-identifier . "\\[gNewSense-art\\]"))
173 ("l\\.gnewsense-dev"
174 (to-address . "gnewsense-dev@nongnu.org")
175 (to-list . "gnewsense-dev@nongnu.org")
176 (list-identifier . "\\[Gnewsense-dev\\]"))
177 ("l\\.gnewsense-users"
178 (to-address . "gnewsense-users@nongnu.org")
179 (to-list . "gnewsense-users@nongnu.org")
180 (list-identifier . "\\[gNewSense-users\\]"))
181 ("l\\.gnunet-developers"
182 (to-address . "gnunet-developers@gnu.org")
183 (to-list . "gnunet-developers@gnu.org")
184 (list-identifier . "\\[GNUnet-developers\\]"))
185 ("l\\.help-gnunet"
186 (to-address . "help-gnunet@gnu.org")
187 (to-list . "help-gnunet@gnu.org")
188 (list-identifier . "\\[Help-gnunet\\]"))
189 ("l\\.bug-gnuzilla"
190 (to-address . "bug-gnuzilla@gnu.org")
191 (to-list . "bug-gnuzilla@gnu.org")
192 (list-identifier . "\\[Bug-gnuzilla\\]"))
193 ("l\\.gnuzilla-dev"
194 (to-address . "gnuzilla-dev@gnu.org")
195 (to-list . "gnuzilla-dev@gnu.org")
196 (list-identifier . "\\[Gnuzilla-dev\\]"))
197 ("l\\.guile-devel"
198 (to-address . "guile-devel@gnu.org")
199 (to-list . "guile-devel@gnu.org"))
200 ("l\\.guile-user"
201 (to-address . "guile-user@gnu.org")
202 (to-list . "guile-user@gnu.org"))
203 ("l\\.guix-devel"
204 (to-address . "guix-devel@gnu.org")
205 (to-list . "guix-devel@gnu.org"))
206 ("l\\.help-guix"
207 (to-address . "help-guix@gnu.org")
208 (to-list . "help-guix@gnu.org"))
209 ("l\\.info-guix"
210 (to-address . "info-guix@gnu.org")
211 (to-list . "info-guix@gnu.org"))
212 ("l\\.savannah-hackers-public"
213 (to-address . "savannah-hackers-public@gnu.org")
214 (to-list . "savannah-hackers-public@gnu.org"))
215 ("l\\.savannah-users"
216 (to-address . "savannah-users@gnu.org")
217 (to-list . "savannah-users@gnu.org"))
218 ("l\\.www-commits"
219 (to-address . "www-commits@gnu.org")
220 (to-list . "www-commits@gnu.org"))
221 ("l\\.www-discuss"
222 (to-address . "www-discuss@gnu.org")
223 (to-list . "www-discuss@gnu.org"))
224 ("l\\.haskell-art"
225 (to-address . "haskell-art@we.lurk.org")
226 (to-list . "haskell-art@we.lurk.org")
227 (list-identifier . "\\[haskell-art\\]"))
228 ("l\\.haskell-cafe"
229 (to-address . "haskell-cafe@haskell.org")
230 (to-list . "haskell-cafe@haskell.org")
231 (list-identifier . "\\[Haskell-cafe\\]"))
232 ("l\\.notmuch"
233 (to-address . "notmuch@notmuchmail.org")
234 (to-list . "notmuch@notmuchmail.org"))
235 ("l\\.parabola-dev"
236 (to-address . "dev@lists.parabola.nu")
237 (to-list . "dev@lists.parabola.nu")
238 (list-identifier . "\\[Dev\\]"))
239 ("l\\.~bandali\\.public-inbox"
240 (to-address . "~bandali/public-inbox@lists.sr.ht")
241 (to-list . "~bandali/public-inbox@lists.sr.ht"))
242 ("l\\.~sircmpwn\\.free-writers-club"
243 (to-address . "~sircmpwn/free-writers-club@lists.sr.ht")
244 (to-list . "~sircmpwn/free-writers-club@lists.sr.ht"))
245 ("l\\.~sircmpwn\\.srht-admins"
246 (to-address . "~sircmpwn/sr.ht-admins@lists.sr.ht")
247 (to-list . "~sircmpwn/sr.ht-admins@lists.sr.ht"))
248 ("l\\.~sircmpwn\\.srht-announce"
249 (to-address . "~sircmpwn/sr.ht-announce@lists.sr.ht")
250 (to-list . "~sircmpwn/sr.ht-announce@lists.sr.ht"))
251 ("l\\.~sircmpwn\\.srht-dev"
252 (to-address . "~sircmpwn/sr.ht-dev@lists.sr.ht")
253 (to-list . "~sircmpwn/sr.ht-dev@lists.sr.ht"))
254 ("l\\.~sircmpwn\\.srht-discuss"
255 (to-address . "~sircmpwn/sr.ht-discuss@lists.sr.ht")
256 (to-list . "~sircmpwn/sr.ht-discuss@lists.sr.ht"))
257 ("webmasters"
258 (to-address . "webmasters@gnu.org")
259 (to-list . "webmasters@gnu.org"))
260 ("gnu.*"
261 (gcc-self . t))
262 ("l\\."
263 (subscribed . t))
264 ("nnimap\\+uwaterloo:.*"
265 (gcc-self . t)))
266 gnus-large-newsgroup 50
267 gnus-home-directory (b/var "gnus/")
268 gnus-directory (concat gnus-home-directory "news/")
269 message-directory (concat gnus-home-directory "mail/")
270 nndraft-directory (concat gnus-home-directory "drafts/")
271 gnus-save-newsrc-file nil
272 gnus-read-newsrc-file nil
273 gnus-interactive-exit nil
274 gnus-gcc-mark-as-read t)
275 :config
276 (when (version< emacs-version "27")
277 (with-eval-after-load 'nnmail
278 (add-to-list
279 'nnmail-split-abbrev-alist
280 '(list . "list-id\\|list-post\\|x-mailing-list\\|x-beenthere\\|x-loop")
281 t)))
282
283 ;; (require 'gnus-registry)
284 ;; (setq gnus-registry-max-entries 2500)
285 ;; (setq gnus-registry-ignored-groups
286 ;; (append gnus-registry-ignored-groups
287 ;; '(("^nnimap:gnu\\.l" t)
288 ;; ("webmasters$" t))))
289 ;; (gnus-registry-initialize)
290
291 (with-eval-after-load 'recentf
292 (add-to-list 'recentf-exclude gnus-home-directory)))
293
294 (use-package gnus-art
295 :config
296 (setq
297 gnus-buttonized-mime-types '("multipart/\\(signed\\|encrypted\\)")
298 gnus-sorted-header-list '("^From:"
299 "^X-RT-Originator"
300 "^Newsgroups:"
301 "^Subject:"
302 "^Date:"
303 "^Envelope-To:"
304 "^Followup-To:"
305 "^Reply-To:"
306 "^Organization:"
307 "^Summary:"
308 "^Abstract:"
309 "^Keywords:"
310 "^To:"
311 "^[BGF]?Cc:"
312 "^Posted-To:"
313 "^Mail-Copies-To:"
314 "^Mail-Followup-To:"
315 "^Apparently-To:"
316 "^Resent-From:"
317 "^User-Agent:"
318 "^X-detected-operating-system:"
319 "^X-Spam_action:"
320 "^X-Spam_bar:"
321 "^Message-ID:"
322 ;; "^References:"
323 "^List-Id:"
324 "^Gnus-Warning:")
325 gnus-visible-headers (mapconcat 'identity
326 gnus-sorted-header-list
327 "\\|")
328 ;; local-lapsed article dates
329 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
330 gnus-article-date-headers '(user-defined)
331 gnus-article-time-format
332 (lambda (time)
333 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
334 (local (article-make-date-line date 'local))
335 (combined-lapsed (article-make-date-line date
336 'combined-lapsed))
337 (lapsed (progn
338 (string-match " (.+" combined-lapsed)
339 (match-string 0 combined-lapsed))))
340 (concat local lapsed))))
341 (bind-keys
342 :map gnus-article-mode-map
343 ("M-L" . org-store-link)))
344
345 (use-package gnus-sum
346 :bind (:map gnus-summary-mode-map
347 :prefix-map b/gnus-summary-prefix-map
348 :prefix "v"
349 ("r" . gnus-summary-reply)
350 ("w" . gnus-summary-wide-reply)
351 ("v" . gnus-summary-show-raw-article))
352 :config
353 (bind-keys
354 :map gnus-summary-mode-map
355 ("M-L" . org-store-link))
356 :hook (gnus-summary-mode . b/no-mouse-autoselect-window)
357 :custom
358 (gnus-thread-sort-functions '(gnus-thread-sort-by-number
359 gnus-thread-sort-by-subject
360 gnus-thread-sort-by-date)))
361
362 (use-package gnus-msg
363 :config
364 (defvar b/shemshak-signature "Amin Bandali
365 https://shemshak.org/~amin")
366 (defvar b/uwaterloo-signature "Amin Bandali, MMath Candidate
367 Cheriton School of Computer Science
368 University of Waterloo
369 https://bndl.org")
370 (defvar b/csc-signature "Amin Bandali
371 System Administrator, Systems Committee
372 Computer Science Club, University of Waterloo
373 https://csclub.uwaterloo.ca/~abandali")
374 (setq gnus-message-replysign t
375 gnus-posting-styles
376 '((".*"
377 (address "bandali@gnu.org"))
378 ("nnimap\\+gnu:l\\..*"
379 (signature nil))
380 ("nnimap\\+gnu:.*"
381 (organization "GNU"))
382 ((header "subject" "ThankCRM")
383 (to "webmasters-comment@gnu.org")
384 (body "")
385 (eval (setq b/message-cite-say-hi nil)))
386 ("nnimap\\+shemshak:.*"
387 (address "amin@shemshak.org")
388 (body "\nBest,\n")
389 (signature b/shemshak-signature)
390 (gcc "nnimap+shemshak:Sent")
391 (eval (setq b/message-cite-say-hi t)))
392 ("nnimap\\+uwaterloo:.*"
393 (address "bandali@uwaterloo.ca")
394 (body "\nBest,\n")
395 (signature b/uwaterloo-signature))
396 ("nnimap\\+uwaterloo:INBOX"
397 (gcc "\"nnimap+uwaterloo:Sent Items\""))
398 ("nnimap\\+csc:.*"
399 (address "bandali@csclub.uwaterloo.ca")
400 (signature b/csc-signature)
401 (gcc "nnimap+csc:Sent"))))
402 :hook (gnus-message-setup . (lambda ()
403 (unless (mml-secure-is-encrypted-p)
404 (mml-secure-message-sign)))))
405
406 (use-package gnus-topic
407 :hook (gnus-group-mode . gnus-topic-mode)
408 :config (setq gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n"))
409
410 (use-package gnus-agent
411 :config
412 (setq gnus-agent-synchronize-flags 'ask)
413 :hook (gnus-group-mode . gnus-agent-mode))
414
415 (use-package gnus-group
416 :config
417 (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
418
419 (comment
420 ;; problematic with ebdb's popup, *EBDB-Gnus*
421 (use-package gnus-win
422 :config
423 (setq gnus-use-full-window nil)))
424
425 (use-package gnus-dired
426 :commands gnus-dired-mode
427 :init
428 (add-hook 'dired-mode-hook 'gnus-dired-mode))
429
430 (comment
431 (use-package gnus-utils
432 :custom
433 (gnus-completing-read-function 'gnus-ido-completing-read)))
434
435 (use-package mm-decode
436 :config
437 (setq mm-discouraged-alternatives '("text/html" "text/richtext")
438 mm-decrypt-option 'known
439 mm-verify-option 'known))
440
441 (use-package mm-uu
442 :config
443 (when (version< "27" emacs-version)
444 (set-face-attribute 'mm-uu-extract nil :extend t))
445 :custom
446 (mm-uu-diff-groups-regexp
447 "\\(gmane\\|gnu\\|l\\)\\..*\\(diff\\|commit\\|cvs\\|bug\\|dev\\)"))
448
449 (use-package mml)
450
451 (use-package mml-sec
452 :custom
453 (mml-secure-openpgp-encrypt-to-self t)
454 (mml-secure-openpgp-sign-with-sender t))
455
456 (use-package gnus-article-treat-patch
457 :disabled
458 :demand
459 :load-path "lisp/"
460 :config
461 ;; note: be sure to customize faces with `:foreground "white"' when
462 ;; using a theme with a white/light background :)
463 (setq ft/gnus-article-patch-conditions
464 '("^@@ -[0-9]+,[0-9]+ \\+[0-9]+,[0-9]+ @@")))
465
466 (provide 'bandali-gnus)
467 ;;; bandali-gnus.el ends here