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