]> git.cworth.org Git - notmuch-wiki/blob - emacstips.mdwn
Starting of a gentle walk-through the notmuch emacs setup.
[notmuch-wiki] / emacstips.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 #Tips and Tricks for using notmuch with Emacs
3
4 The main client based on notmuch is notmuch.el, which is included in the notmuch package. It is might, and allows you to configure a lot of things, however, it might not be immediately obvious how, and how the general workflow generally looks like. This first section will describe a typical workflow and setup, while the section [Advanced tips and tweaks] below, focuses on more specific questions.
5
6 ##Typical setup and workflow
7
8 notmuch requires either a MailDir or a "mh" -style maildirectory to operate on (It basically simply requires that each mail is in a file of it's own). Most people therefore use "[offlineimap](http://software.complete.org/software/projects/show/offlineimap)" or "mbsync" in order to synchronize their IMAP or pop mail server with a local mail store. offlineimap is quite useful and widely tested, it also offers a handy hook that will come in useful a bit later in our setup. So go install and configure offlineimap so you can simply run offlineimap and have an updated maildir. In the [Account xxx] section of your .offineimaprc file your can specify a "presynchook" and "postsynchook" command that will get run whenever you sync. Point postsynchook to a script that gets run on every sync and that will do the automatic tagging and updating of your notmuch database.
9
10 The script will look somewhat like this:
11
12     #/bin/sh
13     # incorporate all new mails in the database
14     notmuch new
15     #apply some automatic tags
16     notmuch tag +notmuch from:notmuch@notmuchmail.org and not tag:notmuch
17     ...more tag rules...
18
19 One advanced setup with automatic tagging has been described by James Vasile here (id: _87hbp5j9dv.fsf@hackervisions.org_). Carl Worth has described his script in this mail (id: _87r5o8stbj.fsf@yoom.home.cworth.org_). See more on message ids below.
20
21 -----
22
23 __A note on message ids__: Confused by those message ids? Get used to it because they are an importance part of the notmuch workflow. Every send message has a unique message id, just like a website has a unique url. On the notmuch mailing list people will throw around message ids and expect people to just find the right mails, as this is what notmuch makes easy. In order to find a specific message, hit 's' for search and type: "id:messageidhere". If you incorporated the notmuch mail archive, you can e.g. try to find id:87r5o8stbj.fsf@yoom.home.cworth.org. Don't have the notmuch archive back to Feb 25, 2010? Fortunately gmane (and probably others allow to search for message id in their archives as well. You'll find this message under [http://mid.gmane.org/87r5o8stbj.fsf@yoom.home.cworth.org] (incidentally, this server seems to be down right now).
24
25 -----
26
27 OK, messages are in your maildir and they have the tags you want them to have (of course you will be assigning more tags manually as you parse through your mail.). Now, on to actually using notmuch in emacs. If you added the correct bits to your .emacs file you will be able to start notmuch by typing "M-x notmuch" (or M-x notmuch-folder). If you want to start notmuch immediately when starting emacs you can also call emacs as "emacs -f notmuch" (and create a handy shortcut on your desktop for that).
28
29 notmuch (the search view) and notmuch-folder are the 2 main views that can be used to navigate through your mail.
30 [TODO: to be continued...]
31
32 ###Sending mail
33 Notmuch itself does not provide any facilities for sending mail. Fortunately, emacs comes with "message mode" which offers that functionality. This also means that there are various methods to invoke the mail sending command. One possibility is to use "CTRL-x m" which will invoke a new "message mail" window. The second possibility is to type 'm' when you are in a notmuch window. And finally, when looking at a message or thread in notmuch you can type 'r' to start a reply.
34
35 If you want to use mail address autocompletion, check out [bbdb](http://bbdb.sourceforge.net) which works nicely together with message mode.
36
37 Type your message and send it off with ctrl-c ctrl-c. By default message mode will use your /usr/sbin/sendmail command to send a mail, so make sure that works.
38 One annoying standard configuration of message mode is that it will hide the sent mail in your emacs frame stack, but it will not close it. If you type several mails in an emacs session they will accumulate and make switching between buffers more annoying. You can avoid that behavior by adding `(setq message-kill-buffer-on-exit t)` in your .emacs file which will really close the mail window after sending it.
39
40 ##Advanced tips and tweaks
41 * How to do FCC/BCC...
42
43   Any notmuch reply will automatically include your primary email
44   address in a BCC so that any messages you send will (eventually) end
45   up in your mail store as well.
46
47   But this doesn't do anything for messages that you compose that are
48   not replies. So we need to get sane message-mode FCC figured
49   out. Some investigation is still needed here.
50
51 * How to customize notmuch-folders
52
53   There's a "notmuch-folder" command available in the emacs client
54   that displays a list of "folders" and the number of messages in
55   each. Each folder is simply a named search specification. To
56   configure this mode, edit your ${HOME}/.emacs file and include text
57   something like the following:
58
59                 (setq notmuch-folders '(("inbox" . "tag:inbox")
60                                         ("unread" . "tag:inbox AND tag:unread")
61                                         ("notmuch" . "tag:inbox AND to:notmuchmail.org")))
62
63   Of course, you can have any number of folders, each configured
64   with any supported search terms (see "notmuch help search-terms").
65
66 * Viewing HTML messages with an external viewer
67
68   The emacs client can often display an HTML message inline, but it
69   sometimes fails for one reason or another, (or is perhaps inadequate
70   if you really need to see the graphical presentation of the HTML
71   message).
72
73   In this case, it can be useful to display the message in an external
74   viewer, such as a web browser. Here's a little script that Keith
75   Packard wrote, which he calls view-html:
76
77                 #!/bin/sh
78                 dir=3D`mktemp -d`
79                 trap "rm -r $dir" 0
80                 cat "$@" > "$dir"/msg
81                 if munpack -C "$dir" -t < "$dir"/msg 2>&1 | grep 'Did not find'; then
82                     sed -n '/[Hh][Tt][Mm][Ll]/,$p' "$dir"/msg > $dir/part1.html
83                     rm "$dir"/msg
84                 fi
85                 for i in "$dir"/part*; do
86                     if grep -q -i -e '<html>' -e 'text/html' "$i"; then
87                         iceweasel "$i" &
88                         sleep 3
89                         exit 0
90                     fi
91                 done
92
93   Save that script somewhere in your ${PATH}, make it executable, and
94   change the invocation of iceweasel to any other HTML viewer if
95   necessary. Then within the emacs client, press "|" to pipe the
96   current message, then type "view-html".
97
98   Keith mentions the following caveat, "Note that if iceweasel isn't
99   already running, it seems to shut down when the script exits. I
100   don't know why."