]> git.notmuchmail.org Git - notmuch-wiki/blob - excluding.mdwn
News for release 0.38.3
[notmuch-wiki] / excluding.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Message exclusion and deletion
3
4 An important principle of notmuch is that it does not modify your mail
5 (with the one exception of
6 [[maildir flag syncing|howto/#sync_maildir_flags]]).  A question that
7 frequently comes up, though, is how users can delete messages.  While
8 notmuch does not support, nor ever will, the deleting of messages,
9 notmuch has a couple of nice features that allow users to handle
10 excluding unwanted messages in a sensible way.
11
12 ## <span id="exclude">**message exclusion**</span>
13
14 Notmuch has the ability to exclude message with certain tags from
15 search results.  A common usage is to exclude "deleted" or "spam"
16 messages so that they don't clutter your search results.  To enable
17 excludes, use the config utility:
18
19         $ notmuch config set search.exclude_tags deleted spam
20
21 This will cause messages with the "deleted" or "spam" tags to be
22 excluded from search results.
23
24 It is still possible to find messages with excluded tags, though, by
25 manually including the excluded tag in your search:
26
27         $ notmuch search from:foo and tag:spam
28
29 This will find messages from "foo" with the tag "spam", even though
30 "spam" is an excluded tag.
31
32 ## <span id="files">**message files**</span>
33
34 Notmuch makes it very easy to access the underlying mail files
35 associated with specific search terms using the "file" output format
36 of notmuch search.  To find all message files associated with the tag
37 "foo" run:
38
39         $ notmuch search --output=files tag:foo
40
41 This will output the paths to all message files with "tag:foo", one
42 per line.
43
44 This is useful in a number of different ways.  For instance, it could
45 be used to train a spam filter:
46
47         $ notmuch search --output=files tag:spam | sa-learn -f -
48
49 It can also be used to purge mail files from disk:
50
51         $ notmuch search --format=text0 --output=files tag:deleted | xargs -0 --no-run-if-empty rm
52
53 Make sure you run "notmuch new" after the last command so the database
54 becomes aware that the files have been removed and can remove the
55 corresponding entries from the index.
56
57 ## <span id="recipe">**putting it all together**</span>
58
59 So if you want to add message deletion to your work flow, here's a
60 procedure:
61
62 * Add exclusion for messages with the "deleted" tag:
63
64         $ notmuch config set search.exclude_tags deleted
65
66 * In emacs MUA use keybinding `k d` to add a "deleted" tag to messages
67   that you want to delete.
68
69 * And, finally, if you _really_ want the messages purged from disk,
70   you can delete them manually with:
71
72        $ notmuch search --output=files tag:deleted | xargs -l rm
73
74 ## <span id="exclude">**killing threads**</span>
75
76 In a [hook](https://notmuchmail.org/doc/latest/man5/notmuch-hooks.html)
77
78     notmuch tag +muted $(notmuch search --output=threads tag:muted)
79
80 New messages in the thread get the muted tag.  Make muted an excluded tag (see
81 above).  To kill a thread, tag it with muted, run notmuch new.