Re: [PATCH v3] nmbug: Translate to Python
[notmuch-archives.git] / 5f / 3297e87b2caca09e4387987a6c77453c69199a
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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
26         23:01:46 -0000\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
37 Precedence: list\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
48 \r
49 From: Jani Nikula <jani@nikula.org>\r
50 \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
53 \r
54 path:foo matches all message files in foo (but not in foo/new or\r
55 foo/cur).\r
56 \r
57 path:foo/new matches all message files in foo/new.\r
58 \r
59 path:"" matches all message files in the top level maildir.\r
60 \r
61 path:foo/** matches all message files in foo and recursively in all\r
62 subdirectories of foo.\r
63 \r
64 path:** matches all message files recursively, i.e. all messages.\r
65 ---\r
66  lib/database.cc |  7 ++++---\r
67  lib/message.cc  | 52 +++++++++++++++++++++++++++++++++++++++++++++-------\r
68  2 files changed, 49 insertions(+), 10 deletions(-)\r
69 \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
82   *\r
83   * The data portion of a mail document is empty.\r
84   *\r
85 @@ -208,7 +208,8 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
86      { "thread",                        "G" },\r
87      { "tag",                   "K" },\r
88      { "is",                    "K" },\r
89 -    { "id",                    "Q" }\r
90 +    { "id",                    "Q" },\r
91 +    { "path",                  "P" },\r
92  };\r
93  \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
100      }\r
101  }\r
102  \r
103 +#define RECURSIVE_SUFFIX "/**"\r
104 +\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
109 +{\r
110 +    /* Add exact "path:" term. */\r
111 +    _notmuch_message_add_term (message, "path", directory);\r
112 +\r
113 +    if (strlen (directory)) {\r
114 +       char *path, *p;\r
115 +\r
116 +       path = talloc_asprintf (NULL, "%s%s", directory, RECURSIVE_SUFFIX);\r
117 +       if (! path)\r
118 +           return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
119 +\r
120 +       /* Add recursive "path:" terms for directory and all parents. */\r
121 +       for (p = path + strlen (path) - 1; p > path; p--) {\r
122 +           if (*p == '/') {\r
123 +               strcpy (p, RECURSIVE_SUFFIX);\r
124 +               _notmuch_message_add_term (message, "path", path);\r
125 +           }\r
126 +       }\r
127 +\r
128 +       talloc_free (path);\r
129 +    }\r
130 +\r
131 +    /* Recursive all-matching path:** for consistency. */\r
132 +    _notmuch_message_add_term (message, "path", "**");\r
133 +\r
134 +    return NOTMUCH_STATUS_SUCCESS;\r
135 +}\r
136 +\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
141                                                           directory_id);\r
142         if (strlen (directory))\r
143             _notmuch_message_gen_terms (message, "folder", directory);\r
144 +\r
145 +       _notmuch_message_add_path_terms (message, directory);\r
146      }\r
147  \r
148      return status;\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
152  \r
153 +    _notmuch_message_add_path_terms (message, directory);\r
154 +\r
155      talloc_free (local);\r
156  \r
157      return NOTMUCH_STATUS_SUCCESS;\r
158 @@ -618,18 +656,18 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
159      if (status)\r
160         return status;\r
161  \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
167  \r
168 -    /* 1. removing all "folder:" terms */\r
169 +    /* Remove all "folder:" terms. */\r
170      _notmuch_message_remove_terms (message, folder_prefix);\r
171  \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
175  \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
179 +\r
180 +    /* Add back terms for all remaining filenames of the message. */\r
181      status = _notmuch_message_add_directory_terms (local, message);\r
182  \r
183      talloc_free (local);\r
184 -- \r
185 1.8.5.3\r
186 \r