unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Synchronize tags across machines without a mail server
@ 2019-03-19 10:20 Pierre Neidhardt
  2019-03-19 17:15 ` Ralph Seichter
  0 siblings, 1 reply; 4+ messages in thread
From: Pierre Neidhardt @ 2019-03-19 10:20 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 2529 bytes --]

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/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-19 18:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 10:20 Synchronize tags across machines without a mail server Pierre Neidhardt
2019-03-19 17:15 ` Ralph Seichter
2019-03-19 18:23   ` Dan Čermák
2019-03-19 18:45     ` Ralph Seichter

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).