;; =================================================================== ;; Generic mail stuff (setq user-full-name "tslil clingman" user-mail-address "email" mail-signature-file "~/.signature") (setq notmuch-fcc-dirs '(("email" . "folder"))) ;; =================================================================== ;; SMTP server configuration (setq message-send-mail-function 'smtpmail-send-it send-mail-function 'smtpmail-send-it mail-user-agent 'message-user-agent smtpmail-auth-credentials "~/.authinfo.gpg" smtpmail-smtp-server "server" smtpmail-smtp-service 465 smtpmail-stream-type 'ssl) (defconst smtp-from-server-alist '(("account" . "server"))) (defun set-smtp-server () (let ((server (or (cdr (assoc (save-restriction (message-narrow-to-headers) (message-fetch-field "from")) smtp-from-server-alist)) "server"))) (setq smtpmail-smtp-server server smtpmail-stream-type 'ssl smtpmail-smtp-service 465) (when (string-equal server "other server") (setq smtpmail-stream-type 'starttls smtpmail-smtp-service 587)) (message "SMTP server changed to %s" server))) ;; =================================================================== ;; Crypto and related (setq gnutls-min-prime-bits 2048 mm-verify-option 'always mm-decrypt-option 'always mml-secure-method "pgpmime" mml-default-sign-method "pgpmime" mml-secure-openpgp-sign-with-sender nil mml-secure-openpgp-signers '("me@server.tld") notmuch-crypto-process-mime t) (defmacro secure-or-send (&rest body) `(quote (lambda (arg) (interactive "P") (set-smtp-server) (unless arg ,@(mapcar #'list body)) (notmuch-mua-send-and-exit)))) (define-key notmuch-message-mode-map (kbd "C-c C-S-c") 'message-send-and-exit) (define-key notmuch-message-mode-map (kbd "C-c C-c") (secure-or-send mml-secure-sign)) (define-key notmuch-message-mode-map (kbd "C-c M-c") (secure-or-send mml-secure-encrypt)) ;; =================================================================== ;; notmuch-hello bindings (setq notmuch-saved-searches '((:name "flagged" :query "tag:flagged") (:name "sent" :query "tag:sent") (:name "drafts" :query "tag:draft"))) (defvar notmuch-hello-tree-searches '(("u" . "tag:unread") ("d" . "tag:drafts") ("s" . "tag:sent") ("f" . "tag:flagged") ("i" . "tag:inbox") ("*" . "*")) "List of (key . query) pairs to bind in notmuch-hello.") (defvar notmuch-tag-keys '(("d" . '("+deleted")) ("u" . '("-deleted")) ("t" . nil)) "List of (key . '(tags list)) pairs to bind in tree and search modes.") (defmacro make-binds (mode-map binds argfunc &rest body) "Create keybindings in `mode-map' using a list of (keystr . arg) pairs in `binds' of the form ( ... (argfunc arg) body)." `(progn ,@(mapcar (lambda (pair) `(define-key ,mode-map (kbd ,(car pair)) (lambda () (interactive) (,argfunc ,(cdr pair)) ,@body))) (eval binds)))) (define-key notmuch-hello-mode-map (kbd "q") (lambda () (interactive) (when (timerp offlineimap--timer) (cancel-timer offlineimap--timer)) (notmuch-bury-or-kill-this-buffer))) (define-key notmuch-search-mode-map (kbd "R") 'notmuch-search-reply-to-thread) (define-key notmuch-search-mode-map (kbd "r") 'notmuch-search-reply-to-thread-sender) (define-key notmuch-tree-mode-map (kbd "R") (lambda () (interactive) (notmuch-tree-close-message-window) (notmuch-show-reply))) (define-key notmuch-tree-mode-map (kbd "r") (lambda () (interactive) (notmuch-tree-close-message-window) (notmuch-show-reply-sender))) (make-binds notmuch-hello-mode-map notmuch-hello-tree-searches notmuch-tree) (make-binds notmuch-show-mode-map notmuch-tag-keys notmuch-show-tag (notmuch-show-next-message)) (make-binds notmuch-tree-mode-map notmuch-tag-keys notmuch-tree-tag (notmuch-tree-next-message)) ;; =================================================================== ;; I want signatures before quoted text (defun notmuch-signature-before-body (query-string &optional prompt-for-sender reply-all) (save-excursion (message-goto-body) (newline) (message-goto-signature) (when (re-search-backward message-signature-separator nil t) (if message-signature-insert-empty-line (forward-line -1)) (delete-region (point) (point-max)) (message-goto-body) (mail-signature t)))) (advice-add 'notmuch-mua-new-reply :after #'notmuch-signature-before-body) ;; =================================================================== ;; notmuch-hello widgets and offlineimap integration (defun notmuch-hello-header-new () (setq fill-column (window-width)) (let ((widget-link-prefix "") (widget-link-suffix "") (unread (string-to-number (car (process-lines notmuch-command "count" "tag:unread")))) (total (string-to-number (car (process-lines notmuch-command "count"))))) (widget-insert "You have ") (widget-create 'link :notify (lambda (&rest nope) (notmuch-hello-update)) :help-echo "Update notmuch view" (notmuch-hello-nice-number total)) (widget-insert " emails,") (center-line) (widget-insert "\n") (widget-create 'link :notify (lambda (&rest nope) (notmuch-tree "tag:unread")) :help-echo "View unread emails" (notmuch-hello-nice-number unread)) (widget-insert (format " of which %s unread." (if (= 1 unread) "is" "are"))) (center-line) (widget-insert "\n"))) (setq notmuch-hello-sections '(notmuch-hello-header-new ;; notmuch-hello-offlineimap notmuch-hello-insert-saved-searches notmuch-hello-insert-search notmuch-hello-insert-alltags)) (add-hook 'notmuch-hello-refresh-hook (lambda () (goto-char (point-min)) (search-forward "You have" nil t) (forward-word))) (defvar offlineimap--timer nil "Timer for running offlineimap.") (defvar offlineimap-use-timer nil "Whether to use a timer for running offlineimap (t) or manual (nil).") (add-hook 'notmuch-hello-mode-hook (lambda () (when offlineimap-use-timer (when (timerp offlineimap--timer) (cancel-timer offlineimap--timer)) (setq offlineimap--timer (run-with-timer 0 300 'offlineimap-run))))) ;; =================================================================== ;; Message displaying and so on (add-to-list 'mm-discouraged-alternatives "text/html") (add-to-list 'mm-discouraged-alternatives "text/richtext") (use-package w3m :ensure t :defer t) (setq mm-text-html-renderer 'w3m) (add-hook 'message-mode-hook (lambda () (turn-on-auto-fill) (spell-fu-mode 1) (company-mode))) (setq notmuch-tree-result-format '(("date" . "%12s | ") ("authors" . "%-20s") ((("tree" . "%s") ("subject" . "%-10s")) . " | %-54s") ("tags" . "(%s)")))