| 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 | "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")))))) |
| 144 | gnus-message-archive-group "nnimap+gnu:INBOX" |
| 145 | gnus-parameters |
| 146 | '(("l\\.deepspec" |
| 147 | (to-address . "deepspec@lists.cs.princeton.edu") |
| 148 | (to-list . "deepspec@lists.cs.princeton.edu") |
| 149 | (list-identifier . "\\[deepspec\\]")) |
| 150 | ("l\\.fencepost-users" |
| 151 | (to-address . "fencepost-users@gnu.org") |
| 152 | (to-list . "fencepost-users@gnu.org") |
| 153 | (list-identifier . "\\[Fencepost-users\\]")) |
| 154 | ("l\\.haskell-cafe" |
| 155 | (to-address . "haskell-cafe@haskell.org") |
| 156 | (to-list . "haskell-cafe@haskell.org") |
| 157 | (list-identifier . "\\[Haskell-cafe\\]")) |
| 158 | ("gnu.*" |
| 159 | (gcc-self . t)) |
| 160 | ;; ("l\\." |
| 161 | ;; (subscribed . t)) |
| 162 | ("nnimap\\+uwaterloo:.*" |
| 163 | (gcc-self . t))) |
| 164 | ;; nnimap-record-commands t |
| 165 | ;; gnus-large-newsgroup 50 |
| 166 | ;; gnus-process-mark-toggle t |
| 167 | gnus-home-directory (b/var "gnus/") |
| 168 | gnus-directory (concat gnus-home-directory "news/") |
| 169 | message-directory (concat gnus-home-directory "mail/") |
| 170 | nndraft-directory (concat gnus-home-directory "drafts/") |
| 171 | gnus-save-newsrc-file nil |
| 172 | gnus-read-newsrc-file nil |
| 173 | gnus-search-use-parsed-queries t |
| 174 | gnus-interactive-exit nil |
| 175 | gnus-gcc-mark-as-read t) |
| 176 | |
| 177 | (with-eval-after-load 'gnus |
| 178 | (when (version< emacs-version "27") |
| 179 | (with-eval-after-load 'nnmail |
| 180 | (add-to-list |
| 181 | 'nnmail-split-abbrev-alist |
| 182 | '(list . "list-id\\|list-post\\|x-mailing-list\\|x-beenthere\\|x-loop") |
| 183 | t))) |
| 184 | |
| 185 | ;; (require 'gnus-registry) |
| 186 | ;; (setq gnus-registry-max-entries 2500) |
| 187 | ;; (setq gnus-registry-ignored-groups |
| 188 | ;; (append gnus-registry-ignored-groups |
| 189 | ;; '(("^nnimap:gnu\\.l" t) |
| 190 | ;; ("webmasters$" t)))) |
| 191 | ;; (gnus-registry-initialize) |
| 192 | |
| 193 | (with-eval-after-load 'recentf |
| 194 | (add-to-list 'recentf-exclude gnus-home-directory)) |
| 195 | |
| 196 | ;; hooks |
| 197 | (add-hook 'gnus-group-mode-hook #'gnus-topic-mode) |
| 198 | (add-hook 'gnus-group-mode-hook #'gnus-agent-mode)) |
| 199 | ;; global key bindings |
| 200 | (global-set-key (kbd "C-c m") #'gnus-plugged) |
| 201 | (global-set-key (kbd "C-c M") #'gnus-unplugged) |
| 202 | |
| 203 | (with-eval-after-load 'gnus-art |
| 204 | (setq |
| 205 | gnus-buttonized-mime-types '("multipart/\\(signed\\|encrypted\\)") |
| 206 | gnus-sorted-header-list '("^From:" |
| 207 | "^X-RT-Originator" |
| 208 | "^Newsgroups:" |
| 209 | "^Subject:" |
| 210 | "^Date:" |
| 211 | "^Envelope-To:" |
| 212 | "^Followup-To:" |
| 213 | "^Reply-To:" |
| 214 | "^Organization:" |
| 215 | "^Summary:" |
| 216 | "^Abstract:" |
| 217 | "^Keywords:" |
| 218 | "^To:" |
| 219 | "^[BGF]?Cc:" |
| 220 | "^Posted-To:" |
| 221 | "^Mail-Copies-To:" |
| 222 | "^Mail-Followup-To:" |
| 223 | "^Apparently-To:" |
| 224 | "^Resent-From:" |
| 225 | "^User-Agent:" |
| 226 | "^X-detected-operating-system:" |
| 227 | "^X-Spam_action:" |
| 228 | "^X-Spam_bar:" |
| 229 | "^Message-ID:" |
| 230 | ;; "^References:" |
| 231 | "^List-Id:" |
| 232 | "^Gnus-Warning:") |
| 233 | gnus-visible-headers (mapconcat 'identity |
| 234 | gnus-sorted-header-list |
| 235 | "\\|") |
| 236 | ;; local-lapsed article dates |
| 237 | ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11 |
| 238 | gnus-article-date-headers '(user-defined) |
| 239 | gnus-article-time-format |
| 240 | (lambda (time) |
| 241 | (let* ((date (format-time-string "%a, %d %b %Y %T %z" time)) |
| 242 | (local (article-make-date-line date 'local)) |
| 243 | (combined-lapsed (article-make-date-line date |
| 244 | 'combined-lapsed)) |
| 245 | (lapsed (progn |
| 246 | (string-match " (.+" combined-lapsed) |
| 247 | (match-string 0 combined-lapsed)))) |
| 248 | (concat local lapsed)))) |
| 249 | ;; local key bindings |
| 250 | (declare-function org-store-link "ol" (arg &optional interactive?)) |
| 251 | (define-key gnus-article-mode-map (kbd "M-L") #'org-store-link)) |
| 252 | |
| 253 | (with-eval-after-load 'gnus-sum |
| 254 | (setq gnus-thread-sort-functions '(gnus-thread-sort-by-number |
| 255 | gnus-thread-sort-by-subject |
| 256 | gnus-thread-sort-by-date)) |
| 257 | ;; local key bindings |
| 258 | (define-key gnus-summary-mode-map (kbd "M-L") #'org-store-link) |
| 259 | ;; (define-key gnus-summary-mode-map (kbd "r") |
| 260 | ;; #'gnus-summary-reply-with-original) |
| 261 | ;; (define-key gnus-summary-mode-map (kbd "R") |
| 262 | ;; #'gnus-summary-wide-reply-with-original) |
| 263 | (defvar b/gnus-summary-prefix-map) |
| 264 | (define-prefix-command 'b/gnus-summary-prefix-map) |
| 265 | (define-key gnus-summary-mode-map (kbd "v") |
| 266 | 'b/gnus-summary-prefix-map) |
| 267 | (define-key b/gnus-summary-prefix-map (kbd "r") |
| 268 | #'gnus-summary-reply) |
| 269 | (define-key b/gnus-summary-prefix-map (kbd "w") |
| 270 | #'gnus-summary-wide-reply) |
| 271 | (define-key b/gnus-summary-prefix-map (kbd "v") |
| 272 | #'gnus-summary-show-raw-article)) |
| 273 | ;; hooks |
| 274 | (add-hook 'gnus-summary-mode-hook #'b/no-mouse-autoselect-window) |
| 275 | |
| 276 | (defvar b/sfl-p nil) |
| 277 | (with-eval-after-load 'gnus-msg |
| 278 | (defvar b/shemshak-signature "Amin Bandali |
| 279 | https://shemshak.org/~bandali") |
| 280 | (defvar b/uwaterloo-signature "Amin Bandali, MMath |
| 281 | https://shemshak.org/~bandali") |
| 282 | (defvar b/csc-signature "Amin Bandali (https://shemshak.org/~bandali) |
| 283 | Systems Committee <syscom@csclub.uwaterloo.ca> |
| 284 | Computer Science Club of the University of Waterloo") |
| 285 | (defvar b/sfl-signature "Amin Bandali |
| 286 | Free Software Consultant |
| 287 | Savoir-faire Linux |
| 288 | jami:bandali") |
| 289 | (setq |
| 290 | gnus-message-replysign t |
| 291 | gnus-posting-styles |
| 292 | '((".*" |
| 293 | (address "bandali@gnu.org") |
| 294 | ("X-Message-SMTP-Method" "smtp fencepost.gnu.org 587")) |
| 295 | ;; ("nnimap\\+gnu:l\\..*" |
| 296 | ;; (signature nil)) |
| 297 | ((header "subject" "ThankCRM") |
| 298 | (to "webmasters-comment@gnu.org") |
| 299 | (body "") |
| 300 | (eval (setq b/message-cite-say-hi nil))) |
| 301 | ("nnimap\\+shemshak:.*" |
| 302 | (address "amin@shemshak.org") |
| 303 | ("X-Message-SMTP-Method" "smtp mail.shemshak.org 587") |
| 304 | (body "\nBest,\n") |
| 305 | (signature b/shemshak-signature) |
| 306 | (gcc "nnimap+shemshak:Sent") |
| 307 | (eval (setq b/message-cite-say-hi t))) |
| 308 | ("nnimap\\+uwaterloo:.*" |
| 309 | (address "bandali@uwaterloo.ca") |
| 310 | ("X-Message-SMTP-Method" "smtp connect.uwaterloo.ca 587") |
| 311 | (body "\nBest,\n") |
| 312 | (signature b/uwaterloo-signature)) |
| 313 | ("nnimap\\+uwaterloo:INBOX" |
| 314 | (gcc "\"nnimap+uwaterloo:Sent Items\"")) |
| 315 | ("nnimap\\+csc:.*" |
| 316 | (address "bandali@csclub.uwaterloo.ca") |
| 317 | ("X-Message-SMTP-Method" "smtp mail.csclub.uwaterloo.ca 587") |
| 318 | (signature b/csc-signature) |
| 319 | (gcc "nnimap+csc:Sent")) |
| 320 | ("nnimap\\+sfl:.*" |
| 321 | (address "amin.bandali@savoirfairelinux.com") |
| 322 | (signature b/sfl-signature) |
| 323 | ("X-Message-SMTP-Method" "smtp mail.savoirfairelinux.com 587") |
| 324 | (gcc "nnimap+sfl:Sent") |
| 325 | (eval (setq-local b/sfl-p t)))))) |
| 326 | ;; hooks |
| 327 | ;; (with-eval-after-load 'gnus |
| 328 | ;; (add-hook 'gnus-message-setup-hook |
| 329 | ;; (lambda () |
| 330 | ;; (unless (or (mml-secure-is-encrypted-p) |
| 331 | ;; b/sfl-p) |
| 332 | ;; (mml-secure-message-sign))))) |
| 333 | |
| 334 | (with-eval-after-load 'gnus-topic |
| 335 | (setq |
| 336 | gnus-topic-line-format "%i[ %A: %(%{%n%}%) ]%v\n" |
| 337 | gnus-topic-topology |
| 338 | `(("Gnus" visible nil nil) |
| 339 | (("misc" visible nil nil)) |
| 340 | ,@(cond |
| 341 | ((string= (system-name) "jirud") |
| 342 | '((("sfl" visible nil nil)))) |
| 343 | ((string= (system-name) "langa") |
| 344 | '((("csc" visible nil nil)) |
| 345 | (("uwaterloo" visible nil nil)) |
| 346 | (("shemshak" visible nil nil)) |
| 347 | (("gnu" visible nil nil)) |
| 348 | (("old-gnu" visible nil nil)))))))) |
| 349 | |
| 350 | (with-eval-after-load 'gnus-agent |
| 351 | (setq gnus-agent-synchronize-flags 'ask)) |
| 352 | |
| 353 | (with-eval-after-load 'gnus-group |
| 354 | (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)")) |
| 355 | |
| 356 | (with-eval-after-load 'gnus-win |
| 357 | (setq gnus-use-full-window nil)) |
| 358 | |
| 359 | (with-eval-after-load 'gnus-dired |
| 360 | (add-hook 'dired-mode-hook 'gnus-dired-mode)) |
| 361 | |
| 362 | (with-eval-after-load 'mm-decode |
| 363 | (setq |
| 364 | ;; mm-attachment-override-types `("text/x-diff" "text/x-patch" |
| 365 | ;; ,@mm-attachment-override-types) |
| 366 | mm-discouraged-alternatives '("text/html" "text/richtext") |
| 367 | mm-decrypt-option 'known |
| 368 | mm-verify-option 'known)) |
| 369 | |
| 370 | (with-eval-after-load 'mm-uu |
| 371 | (when (version< "27" emacs-version) |
| 372 | (set-face-attribute 'mm-uu-extract nil :extend t)) |
| 373 | (when (version< emacs-version "27") |
| 374 | (setq mm-uu-diff-groups-regexp "."))) |
| 375 | |
| 376 | (with-eval-after-load 'mml-sec |
| 377 | (setq mml-secure-openpgp-encrypt-to-self t |
| 378 | mml-secure-openpgp-sign-with-sender t)) |
| 379 | |
| 380 | (provide 'bandali-gnus) |
| 381 | ;;; bandali-gnus.el ends here |