unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Pierre Neidhardt <mail@ambrevar.xyz>
To: notmuch@notmuchmail.org
Subject: Synchronize tags across machines without a mail server
Date: Tue, 19 Mar 2019 11:20:46 +0100	[thread overview]
Message-ID: <87ef73b1xd.fsf@bababa.i-did-not-set--mail-host-address--so-tickle-me> (raw)

[-- 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 --]

             reply	other threads:[~2019-03-19 10:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-19 10:20 Pierre Neidhardt [this message]
2019-03-19 17:15 ` Synchronize tags across machines without a mail server Ralph Seichter
2019-03-19 18:23   ` Dan Čermák
2019-03-19 18:45     ` Ralph Seichter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ef73b1xd.fsf@bababa.i-did-not-set--mail-host-address--so-tickle-me \
    --to=mail@ambrevar.xyz \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).