]> 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 neomutt
21
22 *Note*: This discussion was updated by a non-mutt user from talking about mutt-kz to
23 [neomutt](https://neomutt.org/). Caveat lector!
24
25
26 ## Install:
27
28 See [the neomutt install page](https://neomutt.org/distro). If
29 building from source see [build
30 instructions](https://neomutt.org/dev/build/build). Note in particular
31 the `--notmuch` configuration option.
32
33 ## Configuration:
34
35 *N.B.* From here is unmodified previous discussion about `mutt-kz`,
36 which hopefully also applies to neomutt.
37
38 Here is my `.muttrc` I use with `mutt-kz`, explanations as comments:
39
40         # notmuch
41         set nm_default_uri="notmuch:///PATH/TO/MY/Maildir" # path to the maildir
42         set virtual_spoolfile=yes                          # enable virtual folders
43         set sendmail="/PATH/TO/bin/nm_sendmail"            # enables parsing of outgoing mail
44         virtual-mailboxes \
45             "INBOX"     "notmuch://?query=tag:INBOX and NOT tag:archive"\
46             "Unread"    "notmuch://?query=tag:unread"\
47             "Starred"   "notmuch://?query=tag:*"\
48             "Sent"      "notmuch://?query=tag:sent"        # sets up queries for virtual folders
49         # notmuch bindings
50         macro index \\\\ "<vfolder-from-query>"              # looks up a hand made query
51         macro index A "<modify-labels>+archive -unread -inbox\\n"        # tag as Archived
52         macro index I "<modify-labels>-inbox -unread\\n"                 # removed from inbox
53         macro index S "<modify-labels-then-hide>-inbox -unread +junk\\n" # tag as Junk mail
54         macro index + "<modify-labels>+*\\n<sync-mailbox>"               # tag as starred
55         macro index - "<modify-labels>-*\\n<sync-mailbox>"               # tag as unstarred
56         # sidebar
57         set sidebar_width   = 20
58         set sidebar_visible = yes               # set to "no" to disable sidebar view at startup
59         color sidebar_new yellow default
60         # sidebar bindings
61         bind index <left> sidebar-prev          # got to previous folder in sidebar
62         bind index <right> sidebar-next         # got to next folder in sidebar
63         bind index <space> sidebar-open         # open selected folder from sidebar
64         # sidebar toggle
65         macro index ,@) "<enter-command> set sidebar_visible=no; macro index ~ ,@( 'Toggle sidebar'<Enter>"
66         macro index ,@( "<enter-command> set sidebar_visible=yes; macro index ~ ,@) 'Toggle sidebar'<Enter>"
67         macro index ~ ,@( 'Toggle sidebar'      # toggle the sidebar
68
69 There is no major difference with the standard mutt. Just a new concept (and URL) the
70 virtual folder, that is addressed as `notmuch://`, a few new settings and commands.
71
72 ## Using:
73
74 when you open `mutt` you get the INBOX opened. There you can crawl through your
75 mails, and tag them as appropriate, either manually using the " ` " command, or using
76 the bindings defined in configuration (such as A/I/S/+/-).
77
78 ## Mail tagging on sending
79
80 You may have noticed in `neomutts`'s configuration that I set the `sendmail` variable
81 of mutt to a `nm_sendmail` script. This is for tagging outgoing mail each time I send
82 a mail. Here is the content of the script (which may be used directly in mutt's
83 variable, I did not try).
84
85 Source of `nm_sendmail`:
86
87         #!/bin/bash
88         tee >(notmuch insert --folder=Sent +sent) | sendmail $*
89
90 ## Mail filtering/tagging
91
92 For mail tagging on arrival, I prefer to use a simple procmail delivery along with
93 `notmuch insert`.
94
95 Of course, you could use formail or maildrop, instead of procmail, but it is flexible
96 enough for my needs, and here is an example of configuration that can be useful:
97
98         PATH=/bin:/usr/bin:/usr/local/bin
99
100         # ensure each mail is unique
101         :0 Wh: msgid.lock
102         | formail -D 8192 msgid.cache
103
104         # update addressbook with current mail
105         :0 Wh
106         | /usr/local/bin/notmuch_abook update
107
108         NOINBOX="-inbox"
109         TAGS=""
110
111         # manage dynamic tagging, using the ' + ' token in mail addresses
112         # e.g.: user+TAG@fqdn.tld will generate the tag TAG
113         :0:notmuch.lock
114         * ^TO\/user\+[a-z0-9]+@fqdn\.tld
115         * MATCH ?? ^user\+\/[a-z0-9]+
116         {
117         TAGS="+${MATCH}"
118         }
119
120         # match all mails from mailing-lists, don't let them go to inbox, but tag them with ml
121         :0:notmuch.lock
122         * ^List-[Ii][dD]:.*
123         {
124         TAGS="${TAGS} +ml -inbox"
125         }
126
127         # tag all mails coming from mutt-kz mailing list
128         :0:notmuch.lock
129         * .*mutt-kz\.lists\.fedoraproject\.org.*
130         | notmuch insert $TAGS +mutt +notmuch
131
132         # tag all mails coming from notmuch mailing list
133         :0:notmuch.lock
134         * .*notmuch\.notmuchmail\.org.*
135         | notmuch insert $TAGS +notmuch
136
137         # Mark all spams as junk mail
138         :0:notmuch.lock
139         * ^X-Spam-Status: Yes
140         | notmuch insert +junk
141
142         :0:notmuch.lock
143         * ^Subject: .*SPAM.*
144         | notmuch insert +junk
145
146         ### All unmatched mails
147         :0:notmuch.lock
148         * .*
149         | notmuch insert $TAGS
150
151 there's a line that updates the addressbook with addresses of current mail, and you'll
152 be able to read more about it on the [[vimtips]] page.
153