--- /dev/null
+Return-Path: <dkg@fifthhorseman.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 8CF656DE0352\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Apr 2016 18:02:54 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id sDTmN_8vcF_I for <notmuch@notmuchmail.org>;\r
+ Fri, 8 Apr 2016 18:02:46 -0700 (PDT)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id C5C906DE02C6\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Apr 2016 18:02:38 -0700 (PDT)\r
+Received: from fifthhorseman.net (unknown [201.140.212.132])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id AE52510085\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Apr 2016 21:02:36 -0400 (EDT)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id 06C0A200A9; Fri, 8 Apr 2016 22:02:35 -0300 (ART)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v3 5/7] Introduce _notmuch_message_has_term()\r
+Date: Fri, 8 Apr 2016 22:02:32 -0300\r
+Message-Id: <1460163754-22994-5-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.8.0.rc3\r
+In-Reply-To: <1460163754-22994-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>\r
+ <1460163754-22994-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 09 Apr 2016 01:02:54 -0000\r
+\r
+It can be useful to easily tell if a given message has a given term\r
+associated with it.\r
+---\r
+ lib/message.cc | 35 +++++++++++++++++++++++++++++++++++\r
+ lib/notmuch-private.h | 6 ++++++\r
+ 2 files changed, 41 insertions(+)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 435b78a..2399ab3 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -1217,6 +1217,41 @@ _notmuch_message_remove_term (notmuch_message_t *message,\r
+ return NOTMUCH_PRIVATE_STATUS_SUCCESS;\r
+ }\r
+ \r
++notmuch_private_status_t\r
++_notmuch_message_has_term (notmuch_message_t *message,\r
++ const char *prefix_name,\r
++ const char *value,\r
++ notmuch_bool_t *result)\r
++{\r
++ char *term;\r
++ notmuch_bool_t out = FALSE;\r
++ notmuch_private_status_t status = NOTMUCH_PRIVATE_STATUS_SUCCESS;\r
++\r
++ if (value == NULL)\r
++ return NOTMUCH_PRIVATE_STATUS_NULL_POINTER;\r
++\r
++ term = talloc_asprintf (message, "%s%s",\r
++ _find_prefix (prefix_name), value);\r
++\r
++ if (strlen (term) > NOTMUCH_TERM_MAX)\r
++ return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG;\r
++\r
++ try {\r
++ /* Look for the exact term */\r
++ Xapian::TermIterator i = message->doc.termlist_begin ();\r
++ i.skip_to (term);\r
++ if (i != message->doc.termlist_end () &&\r
++ !strcmp ((*i).c_str (), term))\r
++ out = TRUE;\r
++ } catch (Xapian::Error &error) {\r
++ status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;\r
++ }\r
++ talloc_free (term);\r
++\r
++ *result = out;\r
++ return status;\r
++}\r
++\r
+ notmuch_status_t\r
+ notmuch_message_add_tag (notmuch_message_t *message, const char *tag)\r
+ {\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index d95bf31..9280797 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -280,6 +280,12 @@ _notmuch_message_remove_term (notmuch_message_t *message,\r
+ const char *value);\r
+ \r
+ notmuch_private_status_t\r
++_notmuch_message_has_term (notmuch_message_t *message,\r
++ const char *prefix_name,\r
++ const char *value,\r
++ notmuch_bool_t *result);\r
++\r
++notmuch_private_status_t\r
+ _notmuch_message_gen_terms (notmuch_message_t *message,\r
+ const char *prefix_name,\r
+ const char *text);\r
+-- \r
+2.8.0.rc3\r
+\r