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