[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / b7 / 1362bb929aeaf504b7e4c1ebfca0ba711e37c6
1 Return-Path: <jani@nikula.org>\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 1BB97429E2F\r
6         for <notmuch@notmuchmail.org>; Sun, 12 Jan 2014 07:54:06 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 QGlgr1SUVk4n for <notmuch@notmuchmail.org>;\r
16         Sun, 12 Jan 2014 07:53:57 -0800 (PST)\r
17 Received: from mail-ea0-f175.google.com (mail-ea0-f175.google.com\r
18         [209.85.215.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 6A1C9431FAE\r
21         for <notmuch@notmuchmail.org>; Sun, 12 Jan 2014 07:53:57 -0800 (PST)\r
22 Received: by mail-ea0-f175.google.com with SMTP id z10so2882467ead.34\r
23         for <notmuch@notmuchmail.org>; Sun, 12 Jan 2014 07:53:56 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:subject:in-reply-to:references\r
27         :user-agent:date:message-id:mime-version:content-type;\r
28         bh=YnE7KdWNVED3swQpS8Ul+Iiya3B3J3Dp6JDMonkPnIQ=;\r
29         b=ADvLS+BS9dfinVRg5YeYNEtjQ7htPn13HULAM7OLOfXlGHMOEaRRW4ZTlDjLp0T/90\r
30         YVS2scSsQ1gZkF5pveYA51+OCgiYnlf1mnk6dD7kKldO07cHUobyrPZhz/foEw7Cw1gY\r
31         LNtRRA1r1hUbNF+hQxZQ6huyttlRjzRfhA4jIte2I6mpQPq/LPlFAAIpWBZslDGQXwLC\r
32         Zh4jJ/5whIjqGa82Pc2IhPvocIYCrLOo0CBm73iMLTZ9qjpwlBujbtofS0ylcJ7c+sTW\r
33         SoXWAMoaJpz8mEpLJnYTA5IjPOY8a3WIH3SURS4TxYbK7qfTEvTEP7Bb/lisf2/1sqxK\r
34         PxGw==\r
35 X-Gm-Message-State:\r
36  ALoCoQk1dRvLh2HL/DfAgka3XjrFP2bPXn00uApuAHO/6JGVE5TnsvFWBXrARvsBQvOUK/sgfe8y\r
37 X-Received: by 10.14.211.195 with SMTP id w43mr9925838eeo.100.1389542036266;\r
38         Sun, 12 Jan 2014 07:53:56 -0800 (PST)\r
39 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
40         [88.195.111.91])\r
41         by mx.google.com with ESMTPSA id v7sm32012840eel.2.2014.01.12.07.53.54\r
42         for <multiple recipients>\r
43         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
44         Sun, 12 Jan 2014 07:53:55 -0800 (PST)\r
45 From: Jani Nikula <jani@nikula.org>\r
46 To: Peter Zijlstra <peterz@infradead.org>, notmuch@notmuchmail.org\r
47 Subject: Re: [PATCH] notmuch: Add "maildir:" search option\r
48 In-Reply-To: <20131112155637.GA16796@laptop.programming.kicks-ass.net>\r
49 References: <20131112155637.GA16796@laptop.programming.kicks-ass.net>\r
50 User-Agent: Notmuch/0.17~rc2+18~g39a67a6 (http://notmuchmail.org) Emacs/24.3.1\r
51         (x86_64-pc-linux-gnu)\r
52 Date: Sun, 12 Jan 2014 17:53:52 +0200\r
53 Message-ID: <8761ppurfz.fsf@nikula.org>\r
54 MIME-Version: 1.0\r
55 Content-Type: text/plain\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Sun, 12 Jan 2014 15:54:06 -0000\r
69 \r
70 On Tue, 12 Nov 2013, Peter Zijlstra <peterz@infradead.org> wrote:\r
71 > Subject: notmuch: Add "maildir:" search option\r
72 >\r
73 > The current "folder:" search terms are near useless when you have\r
74 > recursive folders, introduce a boolean "maildir:" search term to\r
75 > exactly match the maildir folder.\r
76 \r
77 Hi Peter -\r
78 \r
79 Per some discussion on IRC about the usefulness of the current "folder:"\r
80 prefix, I went ahead and sent patches to make "folder:" a boolean prefix\r
81 [1]. It's not the same as your "maildir:" implementation, but I believe\r
82 you could use it to achieve the things you want with that. In\r
83 particular, my proposed "folder:" prefix is the literal path from\r
84 maildir root, and does not make any assumptions about maildir - i.e. it\r
85 requires the final cur/new too. (That can be useful for some mutt users\r
86 who need the cur/new distinction.)\r
87 \r
88 I am not opposed to adding another prefix like "maildir:" that does make\r
89 assumptions on the mail storage and transformations on the path, but I\r
90 do think it would be less important with the boolean "folder:" in place.\r
91 \r
92 BR,\r
93 Jani.\r
94 \r
95 \r
96 [1] id:cover.1389304779.git.jani@nikula.org\r
97 \r
98 \r
99 \r
100 >\r
101 > Given a Maildir++ layout like:\r
102 >\r
103 >       ~/Maildir/\r
104 >       ~/Maildir/cur\r
105 >       ~/Maildir/new\r
106 >       ~/Maildir/tmp\r
107 >       ~/Maildir/.Sent\r
108 >       ~/Maildir/.Sent/cur\r
109 >       ~/Maildir/.Sent/new\r
110 >       ~/Maildir/.Sent/tmp\r
111 >       ~/Maildir/.INBOX.LKML\r
112 >       ~/Maildir/.INBOX.LKML/cur\r
113 >       ~/Maildir/.INBOX.LKML/new\r
114 >       ~/Maildir/.INBOX.LKML/tmp\r
115 >       ~/Maildir/.INBOX.LKML.netdev\r
116 >       ~/Maildir/.INBOX.LKML.netdev/cur\r
117 >       ~/Maildir/.INBOX.LKML.netdev/new\r
118 >       ~/Maildir/.INBOX.LKML.netdev/tmp\r
119 >       ~/Maildir/.INBOX.LKML.arch\r
120 >       ~/Maildir/.INBOX.LKML.arch/cur\r
121 >       ~/Maildir/.INBOX.LKML.arch/new\r
122 >       ~/Maildir/.INBOX.LKML.arch/tmp\r
123 >\r
124 > This patch generates the following search index:\r
125 >\r
126 >       $ delve -a Maildir/.notmuch/xapian/ | ~/s XMAILDIR\r
127 >       XMAILDIR:INBOX\r
128 >       XMAILDIR:INBOX/LKML\r
129 >       XMAILDIR:INBOX/LKML/arch\r
130 >       XMAILDIR:INBOX/LKML/netdev\r
131 >       XMAILDIR:Sent\r
132 >\r
133 > Which allows one (me!!1) to pose queries like:\r
134 >\r
135 >       maildir:INBOX and not tag:list\r
136 >\r
137 > to more easily find offlist mail (from people like my family who don't\r
138 > actually send their stuff over LKML :-).\r
139 >\r
140 > Signed-off-by: Peter Zijlstra <peterz@infradead.org>\r
141 > ---\r
142 >\r
143 > XXX: now I need to go figure out how to do searches like:\r
144 >\r
145 >   subject:PATCH/0\r
146 >\r
147 > which would mandate that PATCH is the first word occurring in the\r
148 > subject. I think the position index holds enough information but I\r
149 > need to look into that and obviously the query parser needs work for\r
150 > this.\r
151 >\r
152 >\r
153 >  lib/database.cc |  7 ++++---\r
154 >  lib/message.cc  | 40 ++++++++++++++++++++++++++++++++++++++++\r
155 >  2 files changed, 44 insertions(+), 3 deletions(-)\r
156 >\r
157 > diff --git a/lib/database.cc b/lib/database.cc\r
158 > index a021bf17253c..53aeaa68954d 100644\r
159 > --- a/lib/database.cc\r
160 > +++ b/lib/database.cc\r
161 > @@ -208,15 +208,16 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
162 >      { "thread",                      "G" },\r
163 >      { "tag",                 "K" },\r
164 >      { "is",                  "K" },\r
165 > -    { "id",                  "Q" }\r
166 > +    { "id",                  "Q" },\r
167 > +    { "maildir",             "XMAILDIR:" },\r
168 >  };\r
169 >  \r
170 >  static prefix_t PROBABILISTIC_PREFIX[]= {\r
171 >      { "from",                        "XFROM" },\r
172 >      { "to",                  "XTO" },\r
173 >      { "attachment",          "XATTACHMENT" },\r
174 > -    { "subject",             "XSUBJECT"},\r
175 > -    { "folder",                      "XFOLDER"}\r
176 > +    { "subject",             "XSUBJECT" },\r
177 > +    { "folder",                      "XFOLDER" },\r
178 >  };\r
179 >  \r
180 >  const char *\r
181 > diff --git a/lib/message.cc b/lib/message.cc\r
182 > index 1b4637950f8e..45a727a6208f 100644\r
183 > --- a/lib/message.cc\r
184 > +++ b/lib/message.cc\r
185 > @@ -22,6 +22,7 @@\r
186 >  #include "database-private.h"\r
187 >  \r
188 >  #include <stdint.h>\r
189 > +#include <string.h>\r
190 >  \r
191 >  #include <gmime/gmime.h>\r
192 >  \r
193 > @@ -485,6 +486,8 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
194 >      notmuch_status_t status;\r
195 >      void *local = talloc_new (message);\r
196 >      char *direntry;\r
197 > +    char *maildir;\r
198 > +    int i;\r
199 >  \r
200 >      if (filename == NULL)\r
201 >       INTERNAL_ERROR ("Message filename cannot be NULL.");\r
202 > @@ -507,6 +510,43 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
203 >      /* New terms allow user to search with folder: specification. */\r
204 >      _notmuch_message_gen_terms (message, "folder", directory);\r
205 >  \r
206 > +    /* Convert the directory into a maildir path */\r
207 > +    maildir = talloc_strdup(local, directory);\r
208 > +\r
209 > +    /* Strip the maildir "cur", "new" directory entries. */\r
210 > +    i = strlen(maildir);\r
211 > +    if (strncmp(maildir + i - 3, "cur", 3) == 0 ||\r
212 > +     strncmp(maildir + i - 3, "new", 3) == 0) {\r
213 > +         maildir[i - 3] = '\0';\r
214 > +         i -= 3;\r
215 > +    }\r
216 > +\r
217 > +    /* Strip trailing '/' */\r
218 > +    while (maildir[i-1] == '/') {\r
219 > +         maildir[i-1] = '\0';\r
220 > +         i--;\r
221 > +    }\r
222 > +\r
223 > +    /* Strip leading '/' */\r
224 > +    while (maildir[0] == '/')\r
225 > +         maildir++;\r
226 > +\r
227 > +    /* Strip leading '.' */\r
228 > +    while (maildir[0] == '.')\r
229 > +         maildir++;\r
230 > +\r
231 > +    /* Replace all remaining '.' with '/' */\r
232 > +    for (i = 0; maildir[i]; i++) {\r
233 > +         if (maildir[i] == '.')\r
234 > +                 maildir[i] = '/';\r
235 > +    }\r
236 > +\r
237 > +    /* If there's no string left, we're the "INBOX" */\r
238 > +    if (maildir[0] == '\0')\r
239 > +         maildir = talloc_strdup(local, "INBOX");\r
240 > +\r
241 > +    _notmuch_message_add_term (message, "maildir", maildir);\r
242 > +\r
243 >      talloc_free (local);\r
244 >  \r
245 >      return NOTMUCH_STATUS_SUCCESS;\r
246 > _______________________________________________\r
247 > notmuch mailing list\r
248 > notmuch@notmuchmail.org\r
249 > http://notmuchmail.org/mailman/listinfo/notmuch\r