                           'words))
 
 (setq gnus-select-method '(nnnil "")
+      ;; XXX: this should be set by the customize interface of
+      ;; `db/mail-accounts’
       gnus-secondary-select-methods
-      `((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-plain-stream)
-              ;; (nntp-open-connection-function nntp-open-tls-stream)
-              ;; (nntp-port-number 563)
-              (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/")))))
+      (append
+       `((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-plain-stream)
+               ;; (nntp-open-connection-function nntp-open-tls-stream)
+               ;; (nntp-port-number 563)
+               (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")))))
+                          db/mail-accounts))))
 
 ;; General Configuration
 

                        (mail-fetch-field "From"))
                      user-mail-address))
         (address (cadr (mail-extract-address-components from)))
         ;; db/smtp-accounts set in db-private
         (account (assoc address db/smtp-accounts)))
    (message "Using address: %s" address)
    (if account
        (progn
          (message "Sending with account for %s" address)
          (cl-destructuring-bind (smtpmail-smtp-server
                                  smtpmail-stream-type
                                  smtpmail-smtp-service
                                  smtpmail-smtp-user)
              (cdr account)
            (apply orig-fun args)))
      (progn
        (message "Sending with default account settings")

      smtpmail-smtp-service 587
      starttls-use-gnutls t
      starttls-extra-arguments '("--strict-tofu")
      smtpmail-smtp-server (nth 3 (car db/mail-accounts))
      smtpmail-smtp-user (nth 6 (car db/mail-accounts)))

(defun db/set-smtp-server-from-header (orig-fun &rest args)
  "Choose smtp-settings dynamically, based on the From: header
