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