notmuch: Add function to sync tags

master
Pierre Neidhardt 2019-03-18 18:55:24 +01:00
parent 4997b497af
commit 100c826cd4
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,33 @@
;; TODO: Report notmuch dump/tag sync technique upstream.
(require 'seq)
(unless (boundp 'notmuch-command)
;; So that this file can be use in external scripts without require
;; notmuch.el.
(setq notmuch-command "notmuch"))
(defun notmuch-all-tags ()
(split-string
(with-output-to-string
(with-current-buffer standard-output
(call-process notmuch-command nil t
nil "search" "--output=tags" "--exclude=false" "*")))))
(defvar notmuch-unimportant-tags '("attachment" "deleted" "draft" "encrypted"
"flagged" "inbox" "passed" "replied" "sent"
"signed" "unread"))
(defvar notmuch-dump-file (expand-file-name "~/personal/mail/notmuch.dump"))
(defun notmuch-dump-important-tags (&optional file)
"Dump notmuch tag database to `notmuch-dump-file'.
Messages with only `notmuch-unimportant-tags' are ignored."
(interactive)
(setq file (or file notmuch-dump-file))
(let* ((important-tags (seq-difference (notmuch-all-tags) notmuch-unimportant-tags))
(tags-arg (cons (concat "tag:" (car important-tags))
(cl-loop for tag in (cdr important-tags)
append (list "or" (concat "tag:" tag))))))
(apply 'call-process notmuch-command nil `(:file ,file) nil
"dump" tags-arg)))
(provide 'init-notmuch-sync)

View File

@ -2,6 +2,7 @@
(require 'init-message)
(require 'patch-notmuch)
(require 'init-notmuch-sync)
;; To find files matching email:
;; notmuch search --output=files FOO
@ -41,6 +42,7 @@
notmuch-show-mode-map
notmuch-tree-mode-map))
(define-key map "s" 'helm-notmuch)))
(when (require 'org-notmuch nil 'noerror)
(dolist (map (list notmuch-show-mode-map notmuch-tree-mode-map))
(define-key map (kbd "C-c C-t") 'org-capture))