From 8630c8b1deebd8ea97a339a42b694c83b98fad3c Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 6 Aug 2016 22:52:39 +0900 Subject: [PATCH] [PATCH 9/9] add has: query prefix to search for specific properties --- 21/6fb6ffa3cb7adb94ca1611be550fd4c5a7f4c7 | 140 ++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 21/6fb6ffa3cb7adb94ca1611be550fd4c5a7f4c7 diff --git a/21/6fb6ffa3cb7adb94ca1611be550fd4c5a7f4c7 b/21/6fb6ffa3cb7adb94ca1611be550fd4c5a7f4c7 new file mode 100644 index 000000000..f0ae4e3e2 --- /dev/null +++ b/21/6fb6ffa3cb7adb94ca1611be550fd4c5a7f4c7 @@ -0,0 +1,140 @@ +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 97D7A6DE0942 + for ; Sat, 6 Aug 2016 06:55:29 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.653 +X-Spam-Level: +X-Spam-Status: No, score=0.653 tagged_above=-999 required=5 tests=[AWL=-0.661, + HEADER_FROM_DIFFERENT_DOMAINS=0.001, URI_HEX=1.313] 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 WJLNhI21bKl0 for ; + Sat, 6 Aug 2016 06:55:21 -0700 (PDT) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id 197726DE0930 + for ; Sat, 6 Aug 2016 06:53:21 -0700 (PDT) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) + (envelope-from ) + id 1bW22h-0007Ey-If; Sat, 06 Aug 2016 09:53:35 -0400 +Received: (nullmailer pid 4141 invoked by uid 1000); + Sat, 06 Aug 2016 13:52:44 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Cc: Daniel Kahn Gillmor +Subject: [PATCH 9/9] add has: query prefix to search for specific properties +Date: Sat, 6 Aug 2016 22:52:39 +0900 +Message-Id: <1470491559-3946-10-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.8.1 +In-Reply-To: <1470491559-3946-1-git-send-email-david@tethera.net> +References: <1470491559-3946-1-git-send-email-david@tethera.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, 06 Aug 2016 13:55:29 -0000 + +From: Daniel Kahn Gillmor + +We want to be able to query the properties directly, like: + + notmuch count has:foo=bar + +which should return a count of messages where the property with key +"foo" has value equal to "bar". +--- + doc/man7/notmuch-search-terms.rst | 9 ++++++++- + lib/database.cc | 4 ++++ + test/T610-message-property.sh | 11 +++++++++++ + 3 files changed, 23 insertions(+), 1 deletion(-) + +diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst +index 075f88c..86d02ee 100644 +--- a/doc/man7/notmuch-search-terms.rst ++++ b/doc/man7/notmuch-search-terms.rst +@@ -58,6 +58,8 @@ indicate user-supplied values): + + - query: + ++- has:= ++ + The **from:** prefix is used to match the name or address of the sender + of an email message. + +@@ -139,6 +141,11 @@ queries added with **notmuch-config(1)**. Named queries are only + available if notmuch is built with **Xapian Field Processors** (see + below). + ++The **has:** prefix searches for messages with a particular ++= property pair. Properties are used internally by notmuch ++(and extensions) to add metadata to messages. A given key can be ++present on a given message with several different values. ++ + Operators + --------- + +@@ -217,7 +224,7 @@ exact matches like "tag:inbox" or **probabilistic**, supporting a more flexible + + + Boolean +- **tag:**, **id:**, **thread:**, **folder:**, **path:** ++ **tag:**, **id:**, **thread:**, **folder:**, **path:**, **has** + Probabilistic + **from:**, **to:**, **subject:**, **attachment:**, **mimetype:** + +diff --git a/lib/database.cc b/lib/database.cc +index 3a741f0..3bdbd07 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -97,6 +97,9 @@ typedef struct { + * STRING is the name of a file within that + * directory for this mail message. + * ++ * has: Has a property with key=value ++ * FIXME: if no = is present, should match on any value ++ * + * A mail document also has four values: + * + * TIMESTAMP: The time_t value corresponding to the message's +@@ -260,6 +263,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { + { "is", "K" }, + { "id", "Q" }, + { "path", "P" }, ++ { "has", "XPROPERTY" }, + /* + * Without the ":", since this is a multi-letter prefix, Xapian + * will add a colon itself if the first letter of the path is +diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh +index c92b99b..ee7910b 100755 +--- a/test/T610-message-property.sh ++++ b/test/T610-message-property.sh +@@ -237,4 +237,15 @@ notmuch restore < BEFORE2 + notmuch dump | grep '^#=' > OUTPUT + test_expect_equal_file PROPERTIES OUTPUT + ++test_begin_subtest "test 'has:' queries: empty" ++notmuch search has:testkey1=charles > OUTPUT ++test_expect_equal_file /dev/null OUTPUT ++ ++test_begin_subtest "test 'has:' queries: single message" ++notmuch search --output=messages has:testkey1=alice > OUTPUT ++cat <EXPECTED ++id:4EFC743A.3060609@april.org ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ + test_done +-- +2.8.1 + -- 2.26.2