notmuch: Poll new mails asynchronously and fix GPG decrypt issue.

master
Pierre Neidhardt 2020-04-03 11:12:18 +02:00
parent 939e72127c
commit 96084932aa
1 changed files with 28 additions and 8 deletions

View File

@ -84,19 +84,39 @@
" ")))
(notmuch-search (format "%s %s" address merged-addresses)))))
;; (advice-add 'debbugs-gnu-select-report :override #'debbugs-notmuch-select-report)
(defun ambrevar/notmuch-poll-async ()
"Like `notmuch-poll' but asynchronous."
(notmuch-start-notmuch
"notmuch-new"
nil
(lambda (_proc change)
(with-current-buffer (find-if (lambda (b)
(with-current-buffer b
(eq major-mode 'notmuch-search-mode)))
(buffer-list))
(notmuch-refresh-this-buffer))
(message "notmuch-new: %s" change))
"new"))
;; TODO: This is a bit brittle since it only works if ~/.authinfo.gpg exists.
;; TODO: This is a bit brittle since it only works if the given gpg file exists.
;; Is there a way to unlock gpg manually without a file?
(defun ambrevar/gpg-unlock ()
"Unlock GPG."
(defun ambrevar/notmuch-poll-after-gpg-unlock ()
"Unlock GPG and get Notmuch mail."
;; The gpg unlock needs to be asynchronous for EXWM, or else pinentry-emacs
;; will be blocked.
(let ((sentinel (lambda (_process _args)
(notmuch-poll)
(notmuch-refresh-this-buffer))))
(ambrevar/notmuch-poll-async))))
(make-process :name "gpg" :buffer nil
:command (list "gpg" "--decrypt" (expand-file-name "~/.authinfo.gpg"))
:command (list "gpg" "--decrypt"
(expand-file-name
(or (find-if (lambda (agenda) (string-suffix-p ".gpg" agenda))
org-agenda-files)
(error "No .gpg file in `org-agenda-files'."))))
:sentinel sentinel)))
(advice-add 'notmuch-poll-and-refresh-this-buffer :override #'ambrevar/gpg-unlock)
(advice-add 'notmuch-poll-and-refresh-this-buffer
:override #'ambrevar/notmuch-poll-after-gpg-unlock)
;; (advice-add 'debbugs-gnu-select-report :override #'debbugs-notmuch-select-report)
(provide 'init-notmuch)