1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Approaches to initial tagging of messages
4 This page collects scripts and strategies for organizing mail using
5 notmuch and doing automated initial tagging.
7 The `[new]` config section allows you to control which tags new messages
8 receive. By default, `notmuch config` will use the tags *inbox* and *unread*.
10 If `maildir.synchronize_flags` is true (which is the default), Maildir flags
11 have precedence over the initial tags. Thus an already read mail gets its
12 initial *unread* tag correctly removed.
14 ## The *new* tag approach
16 Here's another very general and ad-hoc approach to initial message tagging,
17 which sets all new messages to get the *new* tag:
22 After running `notmuch new`, all new messages will be marked *new*.
23 You can then do various tag post-processing by just acting on messages
24 with that tag. For instance, a post-processing script might do the
27 # immediately archive all messages from "me"
28 notmuch tag -new -- tag:new and from:me@example.com
30 # delete all messages from a spammer:
31 notmuch tag +deleted -- tag:new and from:spam@spam.com
33 # tag all message from notmuch mailing list
34 notmuch tag +notmuch -- tag:new and to:notmuch@notmuchmail.org
36 # finally, retag all "new" messages "inbox" and "unread"
37 notmuch tag +inbox +unread -new -- tag:new
39 Note that the command above will mark a new but already-read mail as unread.
41 Since the post-processing is only acting on a few messages, it is
42 generally extremely fast.
44 You can use the `post-new` hook, which is automatically run after `notmuch new`,
45 to do post-processing. See `man notmuch-hooks` for details on hooks.
47 ## Tagging based on content
49 Since notmuch currently does not index arbitrary headers, it can be
50 useful to tag based on content. Here is a snippet that would fit with
51 the 'new' tag approach discussed above.
53 for mid in $(notmuch search --output=messages tag:new); do
54 if notmuch show --format=raw "$mid" 2>/dev/null | awk '!NF{exit 1} /^X-Spam_bar: \+\+\+\+\+\+\+\+/ {exit 0}'; then
55 notmuch tag +spam "$mid"
62 * [Carl Worth's approach to tagging](https://notmuchmail.org/pipermail/notmuch/2010/001691.html). It
63 is email id:87r5o8stbj.fsf@yoom.home.cworth.org in the notmuch
64 mailing list archives.
67 * [One user's setup](https://notmuchmail.org/pipermail/notmuch/2010/001690.html)
68 (id:87hbp5j9dv.fsf@hackervisions.org), which includes using the
69 inbox tag as a "new mail" flag.
71 * [Another user's setup](https://notmuchmail.org/pipermail/notmuch/2011/003976.html)
72 (id:"87tyfu3k5a.fsf@gmail.com"), which uses a dedicated tag for
73 marking new mail, which is then sorted with a python script using
74 Bogofilter for spam detection. This is generally a great deal
75 faster than a shell-scripted approach. This approach introduces a
76 workflow built around a "watch" tag. Here, the user is only
77 presented with threads as they are started. At this point the user
78 can choose to watch the thread, in which case future messages will
79 be tagged with "inbox", or ignore it. This provides an excellent
80 means for dealing with a large flux of messages with a low
83 * [afew](https://github.com/teythoon/afew) is an initial tagging
84 solution that should work out of the box for most basic tagging
85 needs (mailinglist handling, killed thread handling, autoarchiving
86 of sent mails) and has some fancy features (e.g. mail classification
87 using bayesian filters).
89 * [p6-notmuch-filter](https://github.com/goneri/p6-notmuch-filter) a initial
90 tagging script that read its configuration from a JSON file. The script is
91 written in Perl6 and depends on the Email::Notmuch binding.
93 * [gmailieer](https://github.com/gauteh/gmailieer) Fast email-fetching and two-way tag synchronization between notmuch and GMail.
95 ## Notmuch MDA -- `notmuch-insert`
97 The [[notmuch insert command|manpages/notmuch-insert-1]] is a tool for
98 delivering emails to maildir, indexing them to the Notmuch database, and tagging