1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 83798431FBF
\r
6 for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 16:02:27 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id NwgXMjS0Um2h for <notmuch@notmuchmail.org>;
\r
16 Tue, 11 Mar 2014 16:02:25 -0700 (PDT)
\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])
\r
18 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 4D8B0429E2E
\r
21 for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 16:02:11 -0700 (PDT)
\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)
\r
23 (envelope-from <bremner@tethera.net>)
\r
24 id 1WNVgY-0001v5-LN; Tue, 11 Mar 2014 20:02:10 -0300
\r
25 Received: (nullmailer pid 25849 invoked by uid 1000); Tue, 11 Mar 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [Patch v6 05/14] lib: add support for path: prefix searches
\r
30 Date: Tue, 11 Mar 2014 20:01:31 -0300
\r
31 Message-Id: <1394578900-25618-6-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.8.5.3
\r
33 In-Reply-To: <1394578900-25618-1-git-send-email-david@tethera.net>
\r
34 References: <1394578900-25618-1-git-send-email-david@tethera.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.13
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Tue, 11 Mar 2014 23:02:27 -0000
\r
49 From: Jani Nikula <jani@nikula.org>
\r
51 The path: prefix is a literal boolean prefix matching the paths,
\r
52 relative from the maildir root, of the message files.
\r
54 path:foo matches all message files in foo (but not in foo/new or
\r
57 path:foo/new matches all message files in foo/new.
\r
59 path:"" matches all message files in the top level maildir.
\r
61 path:foo/** matches all message files in foo and recursively in all
\r
62 subdirectories of foo.
\r
64 path:** matches all message files recursively, i.e. all messages.
\r
66 lib/database.cc | 7 ++++---
\r
67 lib/message.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
\r
68 2 files changed, 49 insertions(+), 10 deletions(-)
\r
70 diff --git a/lib/database.cc b/lib/database.cc
\r
71 index f395061..93cc7f5 100644
\r
72 --- a/lib/database.cc
\r
73 +++ b/lib/database.cc
\r
74 @@ -100,8 +100,8 @@ typedef struct {
\r
75 * In addition, terms from the content of the message are added with
\r
76 * "from", "to", "attachment", and "subject" prefixes for use by the
\r
77 * user in searching. Similarly, terms from the path of the mail
\r
78 - * message are added with a "folder" prefix. But the database doesn't
\r
79 - * really care itself about any of these.
\r
80 + * message are added with "folder" and "path" prefixes. But the
\r
81 + * database doesn't really care itself about any of these.
\r
83 * The data portion of a mail document is empty.
\r
85 @@ -208,7 +208,8 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
\r
94 static prefix_t PROBABILISTIC_PREFIX[]= {
\r
95 diff --git a/lib/message.cc b/lib/message.cc
\r
96 index 7aff4ae..21abe8e 100644
\r
97 --- a/lib/message.cc
\r
98 +++ b/lib/message.cc
\r
99 @@ -504,6 +504,40 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
\r
103 +#define RECURSIVE_SUFFIX "/**"
\r
105 +/* Add "path:" terms for directory. */
\r
106 +static notmuch_status_t
\r
107 +_notmuch_message_add_path_terms (notmuch_message_t *message,
\r
108 + const char *directory)
\r
110 + /* Add exact "path:" term. */
\r
111 + _notmuch_message_add_term (message, "path", directory);
\r
113 + if (strlen (directory)) {
\r
116 + path = talloc_asprintf (NULL, "%s%s", directory, RECURSIVE_SUFFIX);
\r
118 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
120 + /* Add recursive "path:" terms for directory and all parents. */
\r
121 + for (p = path + strlen (path) - 1; p > path; p--) {
\r
123 + strcpy (p, RECURSIVE_SUFFIX);
\r
124 + _notmuch_message_add_term (message, "path", path);
\r
128 + talloc_free (path);
\r
131 + /* Recursive all-matching path:** for consistency. */
\r
132 + _notmuch_message_add_term (message, "path", "**");
\r
134 + return NOTMUCH_STATUS_SUCCESS;
\r
137 /* Add directory based terms for all filenames of the message. */
\r
138 static notmuch_status_t
\r
139 _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
\r
140 @@ -538,6 +572,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
\r
142 if (strlen (directory))
\r
143 _notmuch_message_gen_terms (message, "folder", directory);
\r
145 + _notmuch_message_add_path_terms (message, directory);
\r
149 @@ -577,6 +613,8 @@ _notmuch_message_add_filename (notmuch_message_t *message,
\r
150 /* New terms allow user to search with folder: specification. */
\r
151 _notmuch_message_gen_terms (message, "folder", directory);
\r
153 + _notmuch_message_add_path_terms (message, directory);
\r
155 talloc_free (local);
\r
157 return NOTMUCH_STATUS_SUCCESS;
\r
158 @@ -618,18 +656,18 @@ _notmuch_message_remove_filename (notmuch_message_t *message,
\r
162 - /* Re-synchronize "folder:" terms for this message. This requires:
\r
163 - * 1. removing all "folder:" terms
\r
164 - * 2. removing all "folder:" stemmed terms
\r
165 - * 3. adding back terms for all remaining filenames of the message. */
\r
166 + /* Re-synchronize "folder:" and "path:" terms for this message. */
\r
168 - /* 1. removing all "folder:" terms */
\r
169 + /* Remove all "folder:" terms. */
\r
170 _notmuch_message_remove_terms (message, folder_prefix);
\r
172 - /* 2. removing all "folder:" stemmed terms */
\r
173 + /* Remove all "folder:" stemmed terms. */
\r
174 _notmuch_message_remove_terms (message, zfolder_prefix);
\r
176 - /* 3. adding back terms for all remaining filenames of the message. */
\r
177 + /* Remove all "path:" terms. */
\r
178 + _notmuch_message_remove_terms (message, _find_prefix ("path"));
\r
180 + /* Add back terms for all remaining filenames of the message. */
\r
181 status = _notmuch_message_add_directory_terms (local, message);
\r
183 talloc_free (local);
\r