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