Notmuch logo

Frequently Asked Questions

See also Less Frequently Asked Questions.

  1. Frequently Asked Questions
    1. How come this query matches mails in folder:2013? notmuch search --output=files folder:inbox
    2. How come my query does not list all the emails on the file system?
    3. Shouldn't notmuch support inline PGP?
    4. How do I delete messages
    5. How do I configure the citation line when replying in Emacs?
    6. What are sexp queries?
    7. How do I search for messages that have no tags?
    8. How do I search for punctuation, specific special characters, or regexp?
    9. How do I search for folders or paths with spaces?
    10. How do I search for the List-Id: header?
    11. Can I use notmuch with grsec?
    12. Can I tag threads?
    13. How can I extract a git patchset for an email thread?

How come this query matches mails in folder:2013? notmuch search --output=files folder:inbox

You have duplicates of a message (or messages) in both folders.

Notmuch searches are message based. Multiple files may be associated with the same message (i.e. the files have identical Message-ID). A folder: search will match the folder of any of the files. The --output=files option outputs all the files of all matching messages.

How come my query does not list all the emails on the file system?

You may have emails that have some of the exclude tags

Notmuch can be configured to exclude some tags while searching. You can list excluded tags with

$ notmuch config get search.exclude_tags
deleted

To verify this is the reason of the discrepancy, add the excluded tags explicitly to your query. If the problematic query is

$ notmuch search --output=files -- folder:inbox

Try

$ notmuch search --output=files -- folder:inbox tag:deleted

You can also temporarily turn of the excluded tags feature with --exclude.

$ notmuch search --output=files --exclude=false -- folder:inbox

Shouldn't notmuch support inline PGP?

Why it might not be a good idea

How do I delete messages

See excluding.

How do I configure the citation line when replying in Emacs?

    (setq message-citation-line-format "On %a, %d %b %Y, %f wrote:")
    (setq message-citation-line-function 'message-insert-formatted-citation-line)

See help for message-citation-line-format for details.

What are sexp queries?

For the syntax of sexp queries, see the manual page.

To see if your version of notmuch supports them, run

    $ notmuch config get built_with.sexp_queries

How do I search for messages that have no tags?

To do this directly, you need a recent notmuch compiled with sexp queries (see above). You can then run

    $ notmuch search --query=sexp --output=messages '(not (tag *))'

The same style of query should work for any prefix, even user defined prefixes like List (see below).

Otherwise, it's possible to accomplish this using two searches in shell. First, you need to query all tags in the database, and transform the result into a query that matches messages that have none of those tags:

    $ notmuch search --output=tags \* | sed 's/^/not tag:/;2~1s/^/and /'

Next, use that to query the messages:

    $ notmuch search $(notmuch search --output=tags \* | \
            sed 's/^/not tag:/;2~1s/^/and /')

How do I search for punctuation, specific special characters, or regexp?

Please see the notmuch-search-terms manual page first.

The main thing to understand is that Xapian, and therefore Notmuch, searches are closer to natural language searches than regular expression searches. Punctuation is mostly ignored.

The boolean prefix searches (see Boolean and Probabilistic Prefixes in the man page), such as tag: or path: searches, need an exact match.

For specific fields it is possible to use regex searches (although these are often noticeably slower than native Xapian queries). The limited set of fields is a quirk of implementation which requires a Xapian "value slot" in the database schema. Adding regex support for more fields to would require of adding more value slots to the schema. The performance impact of that needs to be experimentally evaluated, and assuming it is not too bad, some database upgrade code would need to be written.

How do I search for folders or paths with spaces?

The spaces in the names must be escaped. For example if you use bash or zsh, you can search for messages with tag foo in folder INBOX/folder with spaces with this query:

    $ notmuch search tag:foo 'folder:"INBOX/folder with spaces"'

How do I search for the List-Id: header?

See index.header.<prefix> in notmuch-config(1) for details. TLD;R:

notmuch config set index.header.List List-Id

Can I use notmuch with grsec?

Sure! It works out of the box. If you have TPE enabled (trusted path execution), make sure the user is executing the script belongs to the kernel.grsecurity.tpe_gid (in debian this is grsec-tpe). This is required in order to run the pre-new and post-new hooks.

Can I tag threads?

No. Tagging is message based.

It is possible, however, to make tags propagate to all messages in a thread using a little bit of scripting in the post-new hook. For example, to add the muted tag to all messages in threads that have at least one message with the muted tag:

    THREAD_TAGS="muted"
    for tag in "$THREAD_TAGS"; do
            notmuch tag +$tag thread:{tag:$tag}
    done

You can add other tags to THREAD_TAGS as needed. Note that this is one way only; you need to explicitly remove the tag from all the messages in a thread to stop it from propagating again. See notmuch-search-terms for discussion of thread:{} queries.

How can I extract a git patchset for an email thread?

See notmuch-extract-patch. See also notmuch-extract-patch in mailscripts.