1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 #Using notmuch remotely#
5 It is hard to keep nomuch tags in sync across multiple instances of
6 notmuch, on multiple computers. Though you can do this with "notmuch
7 dump" and "notmuch restore", it is often preferable to be able to use
8 notmuch on a remote computer as if it were present on a local
11 The following guidelines show how I have accomplished this. It isn't
12 perfect, but it works pretty well, and allows me to access notmuch on
13 my home computer, using only an emacs client on my netbook or work
14 computer, a trivial shell script, a few settings in my .emacs, and
17 Note that this is all something of a hack, and future versions of
18 notmuch will likely make all of these steps much more
19 transparent. I'll note particularly which things should become
20 unneccessary with future version. At the moment though, this does
21 work, and might enable some of you to use notmuch away from your
24 ##What you will need##
25 You will need to have the following items in place:
27 1. a working notmuch on one computer (let's call that computer
28 "server"). The notmuch should be at least version 0.2.
29 2. a working notmuch emacs interface on another computer (let's call
30 that computer "client")
31 3. password-free login (public key authentication) from client to
32 server. [Here](http://www.debian-administration.org/articles/152) is a
33 good page on how to set it up.
34 4. a reasonably fast connection. (This isn't really *neccessary*, but
35 if your connection is too slow, this won't be very pleasant to use,
36 and certainly won't seem transparent.)
38 ##Write a wrapper shell script##
40 /!\ Now that notmuch (>=0.5) allows for "raw" downloading of messages, a lot
41 of the hacks in the older script, posted in 2010, are no longer necessary.
43 Now we will need to write a simple shell script that does two things:
45 1. replaces the call to the notmuch binary with a call to notmuch
47 2. caches messages when the entire raw message is downloaded. This
48 avoids the need to constantly download large attachments over and
49 over. (NB: this just checks to see if a message with the same id
50 has already been cached. If you delete an attachment on the server,
51 that could lead to an out-of-date cache. It would probably make more
52 sense in the future to concatenate a hash of the message id and a hash
55 Note that this shell script also pauses briefly after every message
56 entries. This is currently necessary so that the emacs process-filter
57 doesn't chop off messages. It's an obvious hack, and hopefully won't
58 be necessary in the furture.
61 SSH_BIN="/path/to/ssh/on/client"
63 SSH_HOST="server_name"
64 NOTMUCH_REMOTE_BIN="/path/to/notmuch/on/server"
65 CACHE="${HOME}/.notmuch-cache.d"
69 echo -n ${1} | sha1sum | awk '{print $1}'
72 check_for_file_name ()
74 [ -f "${CACHE}/${1}" ]
79 [ -d "${CACHE}" ] || mkdir -p "${CACHE}"
82 # we need to a little sanitizing of msg ids so the shell
84 printf -v ARGS "%q " "$@"
85 $SSH_BIN $USER@$SSH_HOST $NOTMUCH_REMOTE_BIN ${CMD} ${ARGS}
90 notmuch_run search $@ |
92 sleep 0.02 # Workaround a bug (missing lines) in the emacs interface
93 # NOTE: This workaround is no longer necessary as of
94 # git rev eead2382. You can just run
95 # `notmuch_run search $@'
103 if [ ${1} = "--format=raw" ]; then
104 hashed=`hash_name ${2}`
105 check_for_file_name ${hashed} ||
106 notmuch_run show --format=raw ${2} > "${CACHE}/${hashed}"
107 cat "${CACHE}/${hashed}"
114 if [ ${1} = "search" ]; then
117 elif [ ${1} = "show" ]; then
125 Save this to a file, "remote-notmuch.sh", in your path.
127 Now you can run "remote-notmuch.sh new". You can call the script
128 anything you like. I actually have $HOME/bin/notmuch linked to that
129 script, so I can transparent
130 usage. (Since I run "new" from an emacs keybinding, I've never
131 bothered with this renaming.)
133 ##Configure your emacs client##
135 The only thing you need to do is tell your emacs client to use the
136 script. Add the following to your .emacs (this is on your client
139 (setq notmuch-command "/path/to/your/remote-notmuch.sh")
142 ##A tip to speed things up##
143 If you have openssh >= 0.4, you can make use of the "ControlMaster"
144 feature. This allows you to reuse an existing connection. Therefore
145 if you keep a connection open, you won't have to authenticate every
148 Add the following to your ~/.ssh/config file:
152 ControlPath ~/.ssh/master-%r@%h:%p
154 You can also se the Host to "*", if you want to use it for all
155 connections. I usually have an interactive ssh connection to my home
156 computer open, so I don't need to do anything more. But if not, you
161 which will open up a background connection, which you can then reuse
162 for all of your notmuch commands.
165 Some things won't work perfectly, and there might be some unexpected
166 mismatches between normal usage and this sort of usage. If you're
167 using this approach and run into any problems, please feel free to
168 list them here. And, of course, if you improve on any of these
169 approaches, please do edit this page and let people know!