]> git.notmuchmail.org Git - notmuch-wiki/blob - mutttips.mdwn
News for release 0.38.3
[notmuch-wiki] / mutttips.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2
3 Notmuch is a great mail indexing tool that can also be used *in conjunction*
4 with existing Mail User Agents (MUA) instead of replacing them. The advantage of
5 such mixed solutions is that users can benefit from notmuch features (such as
6 full-text search and thread reconstruction) without *having to* change MUA.
7
8 A popular geek MUA is [the Mutt e-mail client](http://www.mutt.org); integrating
9 notmuch with Mutt is not seamless, but fairly straightforward. There are two
10 principal possibilities, either using a patched mutt that handles internally
11 notmuch, or use a sets of scripts/handler within mutt to achieve something close.
12
13 [[!toc levels=2]]
14
15 # Using Notmuch with the good old mutt
16
17 There's a page about the [[notmuch-mutt]] scripts that are distributed along
18 with notmuch, in its contrib directory.
19
20 # Using Notmuch with mutt-kz
21
22 Here is a tip about how to set up [mutt-kz](https://github.com/karelzak/mutt-kz), a fork
23 of the mutt MUA with support of notmuch integrated.
24
25 ## Install:
26
27 You'll need to first have notmuch installed and the notmuch library available to 
28 configure. Otherwise, it is a good old autoconf setup, so here it goes:
29
30         git clone https://github.com/karelzak/mutt-kz.git
31         cd mutt-kz
32         ./configure && make && make install
33
34 ## Configuration:
35
36 Here is my `.muttrc` I use with `mutt-kz`, explanations as comments:
37
38         # notmuch
39         set nm_default_uri="notmuch:///PATH/TO/MY/Maildir" # path to the maildir
40         set virtual_spoolfile=yes                          # enable virtual folders
41         set sendmail="/PATH/TO/bin/nm_sendmail"            # enables parsing of outgoing mail
42         virtual-mailboxes \
43             "INBOX"     "notmuch://?query=tag:INBOX and NOT tag:archive"\
44             "Unread"    "notmuch://?query=tag:unread"\
45             "Starred"   "notmuch://?query=tag:*"\
46             "Sent"      "notmuch://?query=tag:sent"        # sets up queries for virtual folders
47         # notmuch bindings
48         macro index \\\\ "<vfolder-from-query>"              # looks up a hand made query
49         macro index A "<modify-labels>+archive -unread -inbox\\n"        # tag as Archived
50         macro index I "<modify-labels>-inbox -unread\\n"                 # removed from inbox
51         macro index S "<modify-labels-then-hide>-inbox -unread +junk\\n" # tag as Junk mail
52         macro index + "<modify-labels>+*\\n<sync-mailbox>"               # tag as starred
53         macro index - "<modify-labels>-*\\n<sync-mailbox>"               # tag as unstarred
54         # sidebar
55         set sidebar_width   = 20
56         set sidebar_visible = yes               # set to "no" to disable sidebar view at startup
57         color sidebar_new yellow default
58         # sidebar bindings
59         bind index <left> sidebar-prev          # got to previous folder in sidebar
60         bind index <right> sidebar-next         # got to next folder in sidebar
61         bind index <space> sidebar-open         # open selected folder from sidebar
62         # sidebar toggle
63         macro index ,@) "<enter-command> set sidebar_visible=no; macro index ~ ,@( 'Toggle sidebar'<Enter>"
64         macro index ,@( "<enter-command> set sidebar_visible=yes; macro index ~ ,@) 'Toggle sidebar'<Enter>"
65         macro index ~ ,@( 'Toggle sidebar'      # toggle the sidebar
66
67 There is no major difference with the standard mutt. Just a new concept (and URL) the
68 virtual folder, that is addressed as `notmuch://`, a few new settings and commands.
69
70 ## Using:
71
72 when you open `mutt` you get the INBOX opened. There you can crawl through your
73 mails, and tag them as appropriate, either manually using the " ` " command, or using
74 the bindings defined in configuration (such as A/I/S/+/-).
75
76 ## Mail tagging on sending
77
78 You may have noticed in `mutt-kz`'s configuration that I set the `sendmail` variable
79 of mutt to a `nm_sendmail` script. This is for tagging outgoing mail each time I send
80 a mail. Here is the content of the script (which may be used directly in mutt's 
81 variable, I did not try). 
82
83 Source of `nm_sendmail`:
84
85         #!/bin/bash
86         tee >(notmuch-deliver -t sent -f Sent) | sendmail $*
87
88 ## Mail filtering/tagging
89
90 For mail tagging on arrival, I prefer to use a simple procmail delivery along with 
91 notmuch-delivery (which can be compiled in the `contrib/` directory of notmuch's sources).
92
93 Of course, you could use formail or maildrop, instead of procmail, but it is flexible
94 enough for my needs, and here is an example of configuration that can be useful:
95
96         PATH=/bin:/usr/bin:/usr/local/bin
97
98         # ensure each mail is unique
99         :0 Wh: msgid.lock
100         | formail -D 8192 msgid.cache
101
102         # update addressbook with current mail
103         :0 Wh
104         | /usr/local/bin/notmuch_abook update
105
106         NOINBOX="-r inbox"
107         TAGS=""
108
109         # manage dynamic tagging, using the ' + ' token in mail addresses
110         # e.g.: user+TAG@fqdn.tld will generate the tag TAG
111         :0:notmuch.lock
112         * ^TO\/user\+[a-z0-9]+@fqdn\.tld
113         * MATCH ?? ^user\+\/[a-z0-9]+
114         {
115         TAGS="-t ${MATCH}"
116         }
117
118         # match all mails from mailing-lists, don't let them go to inbox, but tag them with ml
119         :0:notmuch.lock
120         * ^List-[Ii][dD]:.*
121         {
122         TAGS="${TAGS} -t ml -r inbox"
123         }
124
125         # tag all mails coming from mutt-kz mailing list
126         :0:notmuch.lock
127         * .*mutt-kz\.lists\.fedoraproject\.org.*
128         | notmuch-deliver $TAGS -t mutt -t notmuch
129
130         # tag all mails coming from notmuch mailing list
131         :0:notmuch.lock
132         * .*notmuch\.notmuchmail\.org.*
133         | notmuch-deliver $TAGS -t notmuch
134
135         # Mark all spams as junk mail
136         :0:notmuch.lock
137         * ^X-Spam-Status: Yes
138         | notmuch-deliver -t junk
139
140         :0:notmuch.lock
141         * ^Subject: .*SPAM.*
142         | notmuch-deliver -t junk
143
144         ### All unmatched mails
145         :0:notmuch.lock
146         * .*
147         | notmuch-deliver -v $TAGS 
148
149 there's a line that updates the addressbook with addresses of current mail, and you'll
150 be able to read more about it on the [[vimtips]] page.
151