在 notmuch 中搜索自定义 header 值

search for custom header value in notmuch

是否可以使用 notmuch 搜索包含特定自定义 header 值的电子邮件?

我知道可以搜索像

这样的标准 header
notmuch search from:alice subject:hello to:bob@example.com

但是有没有办法搜索这样的东西?

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

这在 Notmuch 中目前是不可能的。

根据您的用例,您或许可以执行 notmuch search --output=files <search terms> 查询,然后 grep 匹配文件以获得您需要的确切内容。通过仔细选择搜索词,这应该比 greping 遍历邮件存储中的所有内容更快。

这是可能的,因为 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.

如手册中所述,它存储在数据库中 - 类似于自定义查询。您必须为每个要搜索的 header 设置它。

所以在你的问题中提到的情况:

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

您可能需要重新索引数据库 notmuch reindex '*'

最后运行搜索

notmuch search AcceptLanguage:en-US AND XSpamFlag:NO