]> git.cworth.org Git - notmuch-wiki/blob - initial_tagging.mdwn
replace most wikilinks to manpages with external links to docs
[notmuch-wiki] / initial_tagging.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Approaches to initial tagging of messages
3
4 This page collects scripts and strategies for organizing mail using
5 notmuch and doing automated initial tagging.
6
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*.
9
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.
13
14 ## The *new* tag approach
15
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:
18
19     [new]
20     tags=new;
21
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
25 following:
26
27     # immediately archive all messages from "me"
28     notmuch tag -new -- tag:new and from:me@example.com
29
30     # delete all messages from a spammer:
31     notmuch tag +deleted -- tag:new and from:spam@spam.com
32
33     # tag all message from notmuch mailing list
34     notmuch tag +notmuch -- tag:new and to:notmuch@notmuchmail.org
35
36     # finally, retag all "new" messages "inbox" and "unread"
37     notmuch tag +inbox +unread -new -- tag:new
38
39 Note that the command above will mark a new but already-read mail as unread.
40
41 Since the post-processing is only acting on a few messages, it is
42 generally extremely fast.
43
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.
46
47 ## Tagging based on content
48
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.
52
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"
56         fi
57     done
58
59
60 ## Other solutions
61
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.
65
66
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.
70
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
81   signal-to-noise.
82
83 * [afew](https://github.com/afewmail/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).
87 * [p6-notmuch-filter](https://github.com/goneri/p6-notmuch-filter) a initial
88   tagging script that read its configuration from a JSON file. The script is
89   written in Perl6 and depends on the Email::Notmuch binding.
90
91 * [lieer](https://github.com/gauteh/lieer) Fast email-fetching and two-way tag synchronization between notmuch and GMail.
92
93 ## Notmuch MDA -- `notmuch-insert`
94
95 The [notmuch insert command](https://notmuchmail.org/doc/latest/man1/notmuch-insert.html) is a tool for
96 delivering emails to maildir, indexing them to the Notmuch database, and tagging
97 them as desired.