Search code examples
emailsearch-engine

search for custom header value in notmuch


Is it possible to search for emails containing a specific custom header value using notmuch?

I know it's possible to search for standard headers like

notmuch search from:alice subject:hello to:bob@example.com

but is there a way to search for something like this?

notmuch search Accept-Language:en-US X-Spam-Flag:NO

Solution

  • It's possible since notmuch 0.29 - see man pages for notmuch-config(1)

       index.header.<prefix> [STORED IN DATABASE]
              Define  the  query  prefix <prefix>, based on a mail header. For
              example index.header.List=List-Id will add a probabilistic  pre‐
              fix  List:  that  searches the List-Id field.  User defined pre‐
              fixes must not start with 'a'...'z'; in particular adding a pre‐
              fix  with same name as a predefined prefix is not supported. See
              notmuch-search-terms(7) for a list of existing prefixes, and  an
              explanation of probabilistic prefixes.
    

    As mentioned in the manual it's stored in the database - similar to custom queries. You have to set it for every header you want to search.

    So in the case mentioned in Your question:

    notmuch config set index.header.AcceptLanguage Accept-Language
    notmuch config set index.header.XSpamFlag X-Spam-Flag
    

    It's possible you would need to reindex your database notmuch reindex '*'

    and finally runing the search

    notmuch search AcceptLanguage:en-US AND XSpamFlag:NO