Synchronize tags across machines without a mail server

Subject: Synchronize tags across machines without a mail server

Date: Tue, 19 Mar 2019 11:20:46 +0100

To: notmuch@notmuchmail.org

Cc:

From: Pierre Neidhardt


Hi,

I know this has been asked a couple of times, and it seems that the
current solutions are:

- nmbug
  (http://notmuch.198994.n3.nabble.com/multiple-machine-tagging-td831812.html#a4031973
  http://notmuch.198994.n3.nabble.com/PATCH-v4-nmbug-Add-an-init-command-td4032972.html)
  It seems that "nmbug init" has not been merged yet.  Using the patch
  above I wasn't able to add an "upstream".  Am I missing the obvious?

- muchsync (http://www.muchsync.org/): Requires our own mail server if I
  understand correctly.


What I want is sync the `notmuch dump' of non-automatic tags across my
systems, considering I don't run my own webserver.

So far, I came up with the following:

--8<---------------cut here---------------start------------->8---
(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)))
--8<---------------cut here---------------end--------------->8---

This will save all non-trivial / non-automated tags.  I can call
`notmuch-dump-important-tags' manually from Emacs or automatically
(e.g. mcron job or similar sync script) with

	emacs --quick --batch --load=$HOME/.emacs.d/lisp/init-notmuch-sync.el \
				-f notmuch-dump-important-tags

Thoughts?

-- 
Pierre Neidhardt
https://ambrevar.xyz/
signature.asc (application/pgp-signature)
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: