summaryrefslogtreecommitdiff
path: root/emacs/notmuch-config.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/notmuch-config.el')
-rw-r--r--emacs/notmuch-config.el244
1 files changed, 244 insertions, 0 deletions
diff --git a/emacs/notmuch-config.el b/emacs/notmuch-config.el
new file mode 100644
index 0000000..d916c3d
--- /dev/null
+++ b/emacs/notmuch-config.el
@@ -0,0 +1,244 @@
+;; ===================================================================
+;; 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))
+ "posteo.de")))
+ (setq smtpmail-smtp-server server
+ smtpmail-stream-type 'ssl
+ smtpmail-smtp-service 465)
+ (when (string-equal server "smtp.office365.com")
+ (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"
+ notmuch-crypto-process-mime t)
+
+(defmacro secure-or-send (&rest body)
+ `(quote (lambda ()
+ (interactive)
+ (set-smtp-server)
+ ,@(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))
+
+;; ===================================================================
+;; bbdb stuff
+;; (require 'bbdb)
+;; (bbdb-initialize)
+
+;; (setq bbdb-file "~/.bbdb"
+;; bbdb-completion-list t
+;; bbdb-complete-mail t
+;; bbdb-mail-user-agent 'message-user-agent
+;; bbdb-complete-mail-allow-cycling t
+;; bbdb-mua-pop-up nil
+;; bbdb-mua-auto-update-p t)
+
+;; (add-hook 'notmuch-message-mode-hook (lambda ()
+;; (add-to-list 'company-backends 'company-bbdb)))
+
+;; ===================================================================
+;; notmuch-hello bindings
+(setq notmuch-saved-searches '(list-of-things))
+
+(defvar notmuch-hello-tree-searches '(("u" . "tag:unread")
+ ("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-show-mode-map (kbd "R") 'notmuch-show-reply)
+;;(define-key notmuch-show-mode-map (kbd "r") 'notmuch-show-reply-sender)
+(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)))
+
+
+(define-key notmuch-hello-mode-map (kbd "q")
+ (lambda ()
+ (interactive)
+ (when (timerp offlineimap--timer)
+ (cancel-timer offlineimap--timer))
+ (notmuch-bury-or-kill-this-buffer)))
+
+(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))
+
+;; ===================================================================
+;; 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")))
+
+(defun check-and-notify-new-mail ()
+ (notmuch-hello-update t)
+ (let ((num (string-to-number (car (process-lines
+ notmuch-command "count" "tag:unread")))))
+ (when (< 0 num)
+ (message (format "New mail! (%s)" num)))))
+
+(defun offlineimap-output-filter (process string)
+ "Handle output from offlineimap process."
+ (let ((buff (process-buffer process)))
+ (when (buffer-live-p buff)
+ (with-current-buffer buff
+ (save-excursion
+ (goto-char (point-max))
+ (insert string)))
+ (let ((lines (split-string string "\n+" t)))
+ (cl-loop for line in lines do
+ (when (string-match-p "added to the database" line)
+ (check-and-notify-new-mail)))))))
+
+(defun offlineimap-sentinal (process string)
+ "Handle the termination of the offlineimap process."
+ (when (string-equal "finished\n" string)
+ (let ((buff (process-buffer process)))
+ (when (buffer-live-p buff)
+ (with-current-buffer buff
+ (save-excursion
+ (goto-char (point-max))
+ (insert (format-time-string "--- %d.%m.%y/%H:%M:%S ---\n\n\n"))))))
+ (check-and-notify-new-mail)))
+
+(defun offlineimap-run ()
+ "Run offlineimap and report on results."
+ (let ((proc (start-process "offlineimap-process"
+ "*offlineimap*"
+ "offlineimap")))
+ (set-process-filter proc 'offlineimap-output-filter)
+ (set-process-sentinel proc 'offlineimap-sentinal)))
+
+(defun notmuch-hello-offlineimap ()
+ "Widget to run offlineimap async."
+ (setq fill-column (window-width))
+ (widget-create 'push-button :help-echo "Run offlineimap"
+ :notify (lambda (&rest nope)
+ (offlineimap-run))
+ "Fetch mail")
+ (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")
+
+;; I don't actually want w3m anymore
+(setq mm-text-html-renderer 'shr)
+
+(add-hook 'message-mode-hook (lambda ()
+ (turn-on-auto-fill)
+ (flyspell-mode)
+ (company-mode)))
+
+(setq notmuch-tree-result-format '(("date" . "%12s | ")
+ ("authors" . "%-20s")
+ ((("tree" . "%s")
+ ("subject" . "%-10s"))
+ . " | %-54s")
+ ("tags" . "(%s)")))