* .emacs.d/lisp/bandali-erc.el: Don't set erc-lurker-hide-list.
[~bandali/configs] / .emacs.d / lisp / bandali-gnus.el
1 ;;; bandali-gnus.el --- bandali's Gnus setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2021 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 (csetq
44 mail-user-agent 'gnus-user-agent
45 read-mail-command 'gnus
46
47 gnus-select-method '(nnnil "")
48 gnus-secondary-select-methods
49 '((nnimap "shemshak"
50 (nnimap-stream plain)
51 (nnimap-address "127.0.0.1")
52 (nnimap-server-port 143)
53 (nnimap-authenticator plain)
54 (nnimap-user "bandali@shemshak.local"))
55 (nnimap "gnu"
56 (nnimap-stream plain)
57 (nnimap-address "127.0.0.1")
58 (nnimap-server-port 143)
59 (nnimap-authenticator plain)
60 (nnimap-user "bandali@gnu.local")
61 (nnimap-inbox "INBOX")
62 (nnimap-split-methods 'nnimap-split-fancy)
63 (nnimap-split-fancy (|
64 ;; (: gnus-registry-split-fancy-with-parent)
65 ;; (: gnus-group-split-fancy "INBOX" t "INBOX")
66 ;; keep debbugs emails in INBOX
67 (list ".*<\\(.*\\)\\.debbugs\\.gnu\\.org>.*" "INBOX")
68 ;; list moderation emails
69 (from ".+-\\(owner\\|bounces\\)@\\(non\\)?gnu\\.org" "listmod")
70 ;; gnu
71 (list ".*<\\(.*\\)\\.\\(non\\)?gnu\\.org>.*" "l.\\1")
72 ;; gnus
73 (list ".*<\\(.*\\)\\.gnus\\.org>.*" "l.\\1")
74 ;; libreplanet
75 (list ".*<\\(.*\\)\\.libreplanet\\.org>.*" "l.\\1")
76 ;; iana (e.g. tz-announce)
77 (list ".*<\\(.*\\)\\.iana\\.org>.*" "l.\\1")
78 ;; haskell
79 (list ".*<\\(.*\\)\\.haskell\\.org>.*" "l.\\1")
80 ;; *.lists.sr.ht, omitting one dot if present
81 ;; add more \\.?\\([^.]*\\) if needed
82 (list ".*<~\\(.*\\)/\\([^.]*\\)\\.?\\([^.]*\\)\\.lists\\.sr\\.ht>.*" "l.~\\1.\\2\\3")
83 ;; webmasters
84 (from "webmasters\\(-comment\\)?@gnu\\.org" "webmasters")
85 ;; other
86 ("subject" "nagios-fsf:.*" "nagios-fsf")
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 ".*notmuch.notmuchmail.org" "l.notmuch") ;u
91 (list ".*dev.lists.parabola.nu" "l.parabola-dev")
92 ;; ----------------------------------
93 ;; legend: (u)nsubscribed | (d)ead
94 ;; ----------------------------------
95 ;; spam
96 ("X-Spam_action" "reject" "Junk")
97 ;; otherwise, leave mail in INBOX
98 "INBOX")))
99 (nnimap "uwaterloo"
100 (nnimap-stream plain)
101 (nnimap-address "127.0.0.1")
102 (nnimap-server-port 143)
103 (nnimap-authenticator plain)
104 (nnimap-user "abandali@uwaterloo.local")
105 (nnimap-inbox "INBOX")
106 (nnimap-split-methods 'nnimap-split-fancy)
107 (nnimap-split-fancy (|
108 ;; (: gnus-registry-split-fancy-with-parent)
109 ;; se212-f19
110 ("subject" "SE\\s-?212" "course.se212-f19")
111 (from "SE\\s-?212" "course.se212-f19")
112 ;; catch-all
113 "INBOX")))
114 (nnimap "csc"
115 (nnimap-stream plain)
116 (nnimap-address "127.0.0.1")
117 (nnimap-server-port 143)
118 (nnimap-authenticator plain)
119 (nnimap-user "abandali@csclub.uwaterloo.local")
120 (nnimap-inbox "INBOX")
121 (nnimap-split-methods 'nnimap-split-fancy)
122 (nnimap-split-fancy (|
123 ;; cron reports and other messages from root
124 (from "root@\\(.*\\.\\)?csclub\\.uwaterloo\\.ca" "INBOX")
125 ;; spam
126 ("X-Spam-Flag" "YES" "Junk")
127 ;; catch-all
128 "INBOX")))
129 (nnimap "sfl"
130 (nnimap-stream tls)
131 (nnimap-address "mail.savoirfairelinux.com")
132 (nnimap-user "amin.bandali")))
133 gnus-message-archive-group "nnimap+gnu:INBOX"
134 gnus-parameters
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\\.fencepost-users"
140 (to-address . "fencepost-users@gnu.org")
141 (to-list . "fencepost-users@gnu.org")
142 (list-identifier . "\\[Fencepost-users\\]"))
143 ("l\\.haskell-cafe"
144 (to-address . "haskell-cafe@haskell.org")
145 (to-list . "haskell-cafe@haskell.org")
146 (list-identifier . "\\[Haskell-cafe\\]"))
147 ("gnu.*"
148 (gcc-self . t))
149 ;; ("l\\."
150 ;; (subscribed . t))
151 ("nnimap\\+uwaterloo:.*"
152 (gcc-self . t)))
153 ;; nnimap-record-commands t
154 gnus-large-newsgroup 50
155 gnus-home-directory (b/var "gnus/")
156 gnus-directory (concat gnus-home-directory "news/")
157 message-directory (concat gnus-home-directory "mail/")
158 nndraft-directory (concat gnus-home-directory "drafts/")
159 gnus-save-newsrc-file nil
160 gnus-read-newsrc-file nil
161 gnus-search-use-parsed-queries t
162 gnus-interactive-exit nil
163 gnus-gcc-mark-as-read t)
164
165 (with-eval-after-load 'gnus
166 (when (version< emacs-version "27")
167 (with-eval-after-load 'nnmail
168 (add-to-list
169 'nnmail-split-abbrev-alist
170 '(list . "list-id\\|list-post\\|x-mailing-list\\|x-beenthere\\|x-loop")
171 t)))
172
173 ;; (require 'gnus-registry)
174 ;; (setq gnus-registry-max-entries 2500)
175 ;; (setq gnus-registry-ignored-groups
176 ;; (append gnus-registry-ignored-groups
177 ;; '(("^nnimap:gnu\\.l" t)
178 ;; ("webmasters$" t))))
179 ;; (gnus-registry-initialize)
180
181 (with-eval-after-load 'recentf
182 (add-to-list 'recentf-exclude gnus-home-directory))
183
184 ;; hooks
185 (add-hook 'gnus-group-mode-hook #'gnus-topic-mode)
186 (add-hook 'gnus-group-mode-hook #'gnus-agent-mode))
187 ;; global key bindings
188 (global-set-key (kbd "C-c m") #'gnus-plugged)
189 (global-set-key (kbd "C-c M") #'gnus-unplugged)
190
191 (with-eval-after-load 'gnus-art
192 (csetq
193 gnus-buttonized-mime-types '("multipart/\\(signed\\|encrypted\\)")
194 gnus-sorted-header-list '("^From:"
195 "^X-RT-Originator"
196 "^Newsgroups:"
197 "^Subject:"
198 "^Date:"
199 "^Envelope-To:"
200 "^Followup-To:"
201 "^Reply-To:"
202 "^Organization:"
203 "^Summary:"
204 "^Abstract:"
205 "^Keywords:"
206 "^To:"
207 "^[BGF]?Cc:"
208 "^Posted-To:"
209 "^Mail-Copies-To:"
210 "^Mail-Followup-To:"
211 "^Apparently-To:"
212 "^Resent-From:"
213 "^User-Agent:"
214 "^X-detected-operating-system:"
215 "^X-Spam_action:"
216 "^X-Spam_bar:"
217 "^Message-ID:"
218 ;; "^References:"
219 "^List-Id:"
220 "^Gnus-Warning:")
221 gnus-visible-headers (mapconcat 'identity
222 gnus-sorted-header-list
223 "\\|")
224 ;; local-lapsed article dates
225 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
226 gnus-article-date-headers '(user-defined)
227 gnus-article-time-format
228 (lambda (time)
229 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
230 (local (article-make-date-line date 'local))
231 (combined-lapsed (article-make-date-line date
232 'combined-lapsed))
233 (lapsed (progn
234 (string-match " (.+" combined-lapsed)
235 (match-string 0 combined-lapsed))))
236 (concat local lapsed))))
237 ;; local key bindings
238 (define-key gnus-article-mode-map (kbd "M-L") #'org-store-link))
239
240 (with-eval-after-load 'gnus-sum
241 (csetq gnus-thread-sort-functions '(gnus-thread-sort-by-number
242 gnus-thread-sort-by-subject
243 gnus-thread-sort-by-date))
244 ;; local key bindings
245 (define-key gnus-summary-mode-map (kbd "M-L") #'org-store-link)
246 (define-key gnus-summary-mode-map (kbd "r")
247 #'gnus-summary-reply-with-original)
248 (define-key gnus-summary-mode-map (kbd "R")
249 #'gnus-summary-wide-reply-with-original)
250 (defvar b/gnus-summary-prefix-map)
251 (define-prefix-command 'b/gnus-summary-prefix-map)
252 (define-key gnus-summary-mode-map (kbd "v")
253 'b/gnus-summary-prefix-map)
254 (define-key b/gnus-summary-prefix-map (kbd "r")
255 #'gnus-summary-reply)
256 (define-key b/gnus-summary-prefix-map (kbd "w")
257 #'gnus-summary-wide-reply)
258 (define-key b/gnus-summary-prefix-map (kbd "v")
259 #'gnus-summary-show-raw-article))
260 ;; hooks
261 (add-hook 'gnus-summary-mode-hook #'b/no-mouse-autoselect-window)
262
263 (defvar b/sfl-p nil)
264 (with-eval-after-load 'gnus-msg
265 (defvar b/shemshak-signature "Amin Bandali
266 https://shemshak.org/~bandali")
267 (defvar b/uwaterloo-signature "Amin Bandali, MMath
268 https://shemshak.org/~bandali")
269 (defvar b/csc-signature "Amin Bandali (https://shemshak.org/~bandali)
270 Systems Committee <syscom@csclub.uwaterloo.ca>
271 Computer Science Club of the University of Waterloo")
272 (defvar b/sfl-signature "Amin Bandali
273 Free Software Consultant
274 Savoir-faire Linux
275 jami:bandali")
276 (csetq
277 gnus-message-replysign t
278 gnus-posting-styles
279 '((".*"
280 (address "bandali@gnu.org"))
281 ("nnimap\\+gnu:l\\..*"
282 (signature nil))
283 ((header "subject" "ThankCRM")
284 (to "webmasters-comment@gnu.org")
285 (body "")
286 (eval (setq b/message-cite-say-hi nil)))
287 ("nnimap\\+shemshak:.*"
288 (address "amin@shemshak.org")
289 (body "\nBest,\n")
290 (signature b/shemshak-signature)
291 (gcc "nnimap+shemshak:Sent")
292 (eval (setq b/message-cite-say-hi t)))
293 ("nnimap\\+uwaterloo:.*"
294 (address "bandali@uwaterloo.ca")
295 (body "\nBest,\n")
296 (signature b/uwaterloo-signature))
297 ("nnimap\\+uwaterloo:INBOX"
298 (gcc "\"nnimap+uwaterloo:Sent Items\""))
299 ("nnimap\\+csc:.*"
300 (address "bandali@csclub.uwaterloo.ca")
301 (signature b/csc-signature)
302 (gcc "nnimap+csc:Sent"))
303 ("nnimap\\+sfl:.*"
304 (address "amin.bandali@savoirfairelinux.com")
305 (signature b/sfl-signature)
306 (gcc "nnimap+sfl:Sent")
307 ;; (eval (setq-local b/sfl-p t))
308 ))))
309 ;; hooks
310 ;; (with-eval-after-load 'gnus
311 ;; (add-hook 'gnus-message-setup-hook
312 ;; (lambda ()
313 ;; (unless (or (mml-secure-is-encrypted-p)
314 ;; b/sfl-p)
315 ;; (mml-secure-message-sign)))))
316
317 (with-eval-after-load 'gnus-topic
318 (csetq gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n"))
319
320 (with-eval-after-load 'gnus-agent
321 (csetq gnus-agent-synchronize-flags 'ask))
322
323 (with-eval-after-load 'gnus-group
324 (csetq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
325
326 ;; problematic with ebdb's popup, *EBDB-Gnus*
327 ;; (with-eval-after-load 'gnus-win
328 ;; (csetq gnus-use-full-window nil))
329
330 (with-eval-after-load 'gnus-dired
331 (add-hook 'dired-mode-hook 'gnus-dired-mode))
332
333 ;; (with-eval-after-load 'gnus-utils
334 ;; (csetq gnus-completing-read-function 'gnus-ido-completing-read))
335
336 (with-eval-after-load 'mm-decode
337 (csetq mm-discouraged-alternatives '("text/html" "text/richtext")
338 mm-decrypt-option 'known
339 mm-verify-option 'known))
340
341 (with-eval-after-load 'mm-uu
342 (when (version< "27" emacs-version)
343 (set-face-attribute 'mm-uu-extract nil :extend t))
344 (when (version< emacs-version "27")
345 (csetq mm-uu-diff-groups-regexp ".")))
346
347 (with-eval-after-load 'mml-sec
348 (csetq mml-secure-openpgp-encrypt-to-self t
349 mml-secure-openpgp-sign-with-sender t))
350
351 ;; (require 'gnus-article-treat-patch)
352 ;; ;; note: be sure to customize faces with `:foreground "white"' when
353 ;; ;; using a theme with a white/light background :)
354 ;; (setq ft/gnus-article-patch-conditions
355 ;; '("^@@ -[0-9]+,[0-9]+ \\+[0-9]+,[0-9]+ @@"))
356
357 (provide 'bandali-gnus)
358 ;;; bandali-gnus.el ends here