[PATCH v4 5/7] Introduce _notmuch_message_has_term()
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Sat, 9 Apr 2016 01:54:50 +0000 (22:54 +2100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:21:32 +0000 (16:21 -0700)
35/d6f98a35a36406ef9fcb072524c95c370b787a [new file with mode: 0644]

diff --git a/35/d6f98a35a36406ef9fcb072524c95c370b787a b/35/d6f98a35a36406ef9fcb072524c95c370b787a
new file mode 100644 (file)
index 0000000..a0aade2
--- /dev/null
@@ -0,0 +1,120 @@
+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 BC7EC6DE034D\r
+ for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 18:55:40 -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=[AWL=0.000]\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 WfWHNzjdNZMs for <notmuch@notmuchmail.org>;\r
+ Fri,  8 Apr 2016 18:55:33 -0700 (PDT)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 1FB396DE0350\r
+ for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 18:55:10 -0700 (PDT)\r
+Received: from fifthhorseman.net (unknown [201.140.212.132])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id 16AC310072\r
+ for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 21:55:07 -0400 (EDT)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id 5A24B204BD; Fri,  8 Apr 2016 22:54:52 -0300 (ART)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v4 5/7] Introduce _notmuch_message_has_term()\r
+Date: Fri,  8 Apr 2016 22:54:50 -0300\r
+Message-Id: <1460166892-29721-5-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.8.0.rc3\r
+In-Reply-To: <1460166892-29721-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>\r
+ <1460166892-29721-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:55:40 -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