From 75d6cbdf9538b4f384d30b42fac42968c1669008 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 2 Feb 2019 17:49:38 +0100 Subject: [PATCH] [Gnus] Move setting of mail related variables to db-mail --- gnus.el | 66 ------------------------------------ init.el | 1 + site-lisp/db-mail.el | 79 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 74 insertions(+), 72 deletions(-) diff --git a/gnus.el b/gnus.el index e01af18..4c2318c 100644 --- a/gnus.el +++ b/gnus.el @@ -17,75 +17,9 @@ (require 'db-mail) -;; Accounts - -(setq gnus-select-method '(nnnil "") - ;; XXX: this should be set by the customize interface of - ;; `db/mail-accounts’ - gnus-secondary-select-methods - (append - ;; immutable account definitions - `((nntp "etsep" - (nntp-open-connection-function nntp-open-tls-stream) - (nntp-port-number 563) - (nntp-address "news.eternal-september.org")) - (nntp "gmane" - (nntp-open-connection-function nntp-open-network-stream) - (nntp-address "news.gmane.org")) - (nnimap "algebra20" - (nnimap-stream shell) - (nnimap-shell-program "/usr/lib/dovecot/imap -o mail_location=maildir:$HOME/Mail/algebra20") - (nnimap-split-methods nnimap-split-fancy) - (nnimap-inbox "INBOX") - (nnimap-split-fancy ,db/personal-gnus-filter-rules)) - (nnml "local" - (nnmail-split-methods nnmail-split-fancy) - (nnmail-split-fancy - (| ("subject" ".*Tiger Auditing Report for.*" "mail.tiger") - "mail.misc"))) - (nnmaildir "archive" - (directory "~/Mail/archive/") - (directory-files nnheader-directory-files-safe) - (nnir-search-engine notmuch) - (nnir-notmuch-remove-prefix ,(expand-file-name "~/Mail/archive/")))) - - ;; automatically add accounts when address is not nil and not the empty string - ;; XXX: this should be abstracted away in some kind of function - (remove-if #'null - (mapcar (lambda (account) - (let ((account-name (nth 1 account)) - (account-address (nth 2 account))) - (when (and account-address - (stringp account-address) - (< 0 (length account-address))) - `(nnimap ,account-name - (nnimap-address ,account-address) - (nnimap-inbox "INBOX"))))) - db/mail-accounts)))) - ;;; Mail Formatting -;; XXX: This should actually be set by the customize setter of -;; `db/mail-accounts’ -(setq gnus-posting-styles - (append - `((".*" - (name ,user-full-name) - (address ,user-mail-address) - (signature-file "~/.signature") - ("X-Jabber-ID" ,db/jabber-id))) - ;; XXX: this should be abstracted away in some kind of function - (mapcar (lambda (account) - (let ((account-name (nth 1 account)) - (account-address (nth 0 account))) - `(,(concat account-name ":") - (name ,user-full-name) - (address ,account-address) - (signature-file "~/.signature") - ("X-Jabber-ID" ,db/jabber-id)))) - db/mail-accounts))) - ;; http://mbork.pl/2015-11-28_Fixing_mml-attach-file_using_advice (defun db/mml-attach-file--go-to-eob (orig-fun &rest args) "Go to the end of buffer before attaching files." diff --git a/init.el b/init.el index aa15d09..46f38ef 100644 --- a/init.el +++ b/init.el @@ -1265,6 +1265,7 @@ gnus-use-full-window nil gnus-always-force-window-configuration t gnus-fetch-old-headers nil + gnus-select-method '(nnnil "") gnus-visible-headers (regexp-opt '("From:" "Newsgroups:" diff --git a/site-lisp/db-mail.el b/site-lisp/db-mail.el index a329ba1..cfc265b 100644 --- a/site-lisp/db-mail.el +++ b/site-lisp/db-mail.el @@ -11,6 +11,77 @@ (require 'mml-sec) (require 'gnus) +(defcustom db/personal-gnus-filter-rules nil + "Default filter rules as used by Gnus for `user-mail-address’." + :group 'personal-settings + :type 'sexp) + +(defun db/mail-accounts--set-value (symbol value) + "Set SYMBOL to VALUE, as needed for `db/mail-accounts’." + (cl-assert (eq symbol 'db/mail-accounts) + "Only use `db/mail-accounts--set-value’ only for setting `db/mail-accounts’.") + (set-default symbol value) + + ;; Set `gnus-secondary-select-methods’ + (setq gnus-secondary-select-methods + (append + ;; immutable account definitions; TODO: move into customizable variable + `((nntp "etsep" + (nntp-open-connection-function nntp-open-tls-stream) + (nntp-port-number 563) + (nntp-address "news.eternal-september.org")) + (nntp "gmane" + (nntp-open-connection-function nntp-open-network-stream) + (nntp-address "news.gmane.org")) + (nnimap "algebra20" + (nnimap-stream shell) + (nnimap-shell-program "/usr/lib/dovecot/imap -o mail_location=maildir:$HOME/Mail/algebra20") + (nnimap-split-methods nnimap-split-fancy) + (nnimap-inbox "INBOX") + (nnimap-split-fancy ,db/personal-gnus-filter-rules)) + (nnml "local" + (nnmail-split-methods nnmail-split-fancy) + (nnmail-split-fancy + (| ("subject" ".*Tiger Auditing Report for.*" "mail.tiger") + "mail.misc"))) + (nnmaildir "archive" + (directory "~/Mail/archive/") + (directory-files nnheader-directory-files-safe) + (nnir-search-engine notmuch) + (nnir-notmuch-remove-prefix ,(expand-file-name "~/Mail/archive/")))) + + ;; automatically add accounts when address is not nil and not the empty + ;; string + (remove-if #'null + (mapcar (lambda (account) + (let ((account-name (nth 1 account)) + (account-address (nth 2 account))) + (when (and account-address + (stringp account-address) + (< 0 (length account-address))) + `(nnimap ,account-name + (nnimap-address ,account-address) + (nnimap-inbox "INBOX"))))) + value)))) + + ;; Set posting styles based on existing mail addresses + (setq gnus-posting-styles + (append + `((".*" + (name ,user-full-name) + (address ,user-mail-address) + (signature-file "~/.signature") + ("X-Jabber-ID" ,db/jabber-id))) + (mapcar (lambda (account) + (let ((account-name (nth 1 account)) + (account-address (nth 0 account))) + `(,(concat account-name ":") + (name ,user-full-name) + (address ,account-address) + (signature-file "~/.signature") + ("X-Jabber-ID" ,db/jabber-id)))) + value)))) + ;; XXX: This needs some functionality for local accounts (defcustom db/mail-accounts nil "Configuration for email accounts. @@ -26,12 +97,8 @@ parameters for one particular email address." (choice :tag "SMTP Stream Type" (const nil) (const starttls) (const plain) (const ssl)) (integer :tag "SMTP Service Port") - (string :tag "SMTP Login Name")))) - -(defcustom db/personal-gnus-filter-rules nil - "Default filter rules as used by Gnus for `user-mail-address’." - :group 'personal-settings - :type 'sexp) + (string :tag "SMTP Login Name"))) + :set #'db/mail-accounts--set-value) (defun db/public-key (address &optional method) "Return valid public keys for ADDRESS and given METHOD.