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