[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 03 / 477e9d3fe192dd652460d557e2b0186421e511
1 Return-Path: <morgan.veyret@gmail.com>\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 arlo.cworth.org (Postfix) with ESMTP id B7FF46DE02B1\r
6  for <notmuch@notmuchmail.org>; Mon,  8 Jun 2015 11:41:42 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.729\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.729 tagged_above=-999 required=5 tests=[AWL=0.090,\r
12   DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001,\r
13  HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
14  RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id 7qZtRctZlEjo for <notmuch@notmuchmail.org>;\r
18  Mon,  8 Jun 2015 11:41:40 -0700 (PDT)\r
19 Received: from mail-yk0-f177.google.com (mail-yk0-f177.google.com\r
20  [209.85.160.177])\r
21  by arlo.cworth.org (Postfix) with ESMTPS id 5B1236DE02D2\r
22  for <notmuch@notmuchmail.org>; Mon,  8 Jun 2015 11:41:40 -0700 (PDT)\r
23 Received: by ykfl8 with SMTP id l8so56277649ykf.1\r
24  for <notmuch@notmuchmail.org>; Mon, 08 Jun 2015 11:41:38 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26  h=mime-version:in-reply-to:references:date:message-id:subject:from:to\r
27  :content-type; bh=hLsFt/ZtgTpTp2w8HaK0QiawoCwdSLoFDHjTc8BHBEk=;\r
28  b=wb9BRcHF0D69Gy3nVTfTWuqDnwldGVmcgBVwBCICUwUP9eJi8K3GUlZHhABgvOeKJC\r
29  ehH95WomIq6qS72QedC/9oyA+PNIlU5rRJvVVzGSKOvgCql304pnVpLLlWsTmE/pWZc3\r
30  hJK+5XWR9xyg24us/VjD2OerVxxn7gSmTeKcUb5KFY7L9xiCA5tFbZW5Di5m8QLQKGxP\r
31  qbtoM4IdDFqZyptcJTE5XxYZxWPvqMZdZ1H9mWovmgxFELdTmBJUwntmH4ufN4DkCMwH\r
32  78G23doK5jWempK3Nup1LvGFbljDLAXKanhSnPvBcoPCJCnCYbKL0Z9XfmRuGHAoZSe6\r
33  xcBg==\r
34 MIME-Version: 1.0\r
35 X-Received: by 10.13.218.71 with SMTP id c68mr17715709ywe.126.1433788897355;\r
36  Mon, 08 Jun 2015 11:41:37 -0700 (PDT)\r
37 Received: by 10.129.123.197 with HTTP; Mon, 8 Jun 2015 11:41:37 -0700 (PDT)\r
38 In-Reply-To: <871thmivpt.fsf@maritornes.cs.unb.ca>\r
39 References:\r
40  <CACMMjMLecmXopb8AATjE3UuCnNLOO+5Nmev5X8K-UostDEUdrQ@mail.gmail.com>\r
41  <871thmivpt.fsf@maritornes.cs.unb.ca>\r
42 Date: Mon, 8 Jun 2015 20:41:37 +0200\r
43 Message-ID:\r
44  <CACMMjM+twCQ9MjB6H51eVW-izekpStNT5+u75LUu9rduG1CWEQ@mail.gmail.com>\r
45 Subject: Re: BUG: maildir flags sync with database relative path results in\r
46  corrupted filename\r
47 From: Morgan Veyret <morgan.veyret@gmail.com>\r
48 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
49 Content-Type: multipart/alternative; boundary=94eb2c081926e8ee74051805fde2\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.18\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54  <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Mon, 08 Jun 2015 18:41:42 -0000\r
63 \r
64 --94eb2c081926e8ee74051805fde2\r
65 Content-Type: text/plain; charset=UTF-8\r
66 \r
67 It does the job, now opening the database with a relative path raise\r
68 a NotmuchError.\r
69 \r
70 \r
71 \r
72 On Mon, Jun 8, 2015 at 8:02 AM, David Bremner <david@tethera.net> wrote:\r
73 \r
74 > Morgan Veyret <morgan.veyret@gmail.com> writes:\r
75 >\r
76 > >\r
77 > > As I understand it's expected that the database path should be absolute\r
78 > but\r
79 > > corrupting the database when the path is relative sounds dangerous.\r
80 >\r
81 > Thanks for the report.  I can see how this could happen, since the\r
82 > internal functions _notmuch_message_add_file_name and\r
83 > _notmuch_database_relative_path classify message filenames into absolute\r
84 > paths starting with the database path and paths relative to the database\r
85 > root.\r
86 >\r
87 > The obvious solution is to reject non-absolute paths in\r
88 > notmuch_database_open_verbose. A slightly friendlier approach would be\r
89 > to canonicalize the path, but this might have unforseen consequences for\r
90 > clients relying on the database path being exactly what they pass in.\r
91 >\r
92 > Can you see if the attached patch "fixes" it for you? You'll have to\r
93 > rebuild notmuch from source. The patch should apply to 0.20 or later.\r
94 >\r
95 >\r
96 > diff --git a/lib/database.cc b/lib/database.cc\r
97 > index 78a24f7..2a5b82a 100644\r
98 > --- a/lib/database.cc\r
99 > +++ b/lib/database.cc\r
100 > @@ -847,6 +847,12 @@ notmuch_database_open_verbose (const char *path,\r
101 >         goto DONE;\r
102 >      }\r
103 >\r
104 > +    if (path[0] != '/') {\r
105 > +       message = strdup ("Error: Database path must be absolute.\n");\r
106 > +       status = NOTMUCH_STATUS_FILE_ERROR;\r
107 > +       goto DONE;\r
108 > +    }\r
109 > +\r
110 >      if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path,\r
111 > ".notmuch"))) {\r
112 >         message = strdup ("Out of memory\n");\r
113 >         status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
114 >\r
115 >\r
116 \r
117 --94eb2c081926e8ee74051805fde2\r
118 Content-Type: text/html; charset=UTF-8\r
119 Content-Transfer-Encoding: quoted-printable\r
120 \r
121 <div dir=3D"ltr"><div>It does the job, now opening the database with a rela=\r
122 tive path raise<br></div>a NotmuchError.<br><br><br></div><div class=3D"gma=\r
123 il_extra"><br><div class=3D"gmail_quote">On Mon, Jun 8, 2015 at 8:02 AM, Da=\r
124 vid Bremner <span dir=3D"ltr">&lt;<a href=3D"mailto:david@tethera.net" targ=\r
125 et=3D"_blank">david@tethera.net</a>&gt;</span> wrote:<br><blockquote class=\r
126 =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=\r
127 ing-left:1ex"><span class=3D"">Morgan Veyret &lt;<a href=3D"mailto:morgan.v=\r
128 eyret@gmail.com">morgan.veyret@gmail.com</a>&gt; writes:<br>\r
129 <br>\r
130 &gt;<br>\r
131 &gt; As I understand it&#39;s expected that the database path should be abs=\r
132 olute but<br>\r
133 &gt; corrupting the database when the path is relative sounds dangerous.<br=\r
134 >\r
135 <br>\r
136 </span>Thanks for the report.=C2=A0 I can see how this could happen, since =\r
137 the<br>\r
138 internal functions _notmuch_message_add_file_name and<br>\r
139 _notmuch_database_relative_path classify message filenames into absolute<br=\r
140 >\r
141 paths starting with the database path and paths relative to the database<br=\r
142 >\r
143 root.<br>\r
144 <br>\r
145 The obvious solution is to reject non-absolute paths in<br>\r
146 notmuch_database_open_verbose. A slightly friendlier approach would be<br>\r
147 to canonicalize the path, but this might have unforseen consequences for<br=\r
148 >\r
149 clients relying on the database path being exactly what they pass in.<br>\r
150 <br>\r
151 Can you see if the attached patch &quot;fixes&quot; it for you? You&#39;ll =\r
152 have to<br>\r
153 rebuild notmuch from source. The patch should apply to 0.20 or later.<br>\r
154 <br>\r
155 <br>diff --git a/lib/database.cc b/lib/database.cc<br>\r
156 index 78a24f7..2a5b82a 100644<br>\r
157 --- a/lib/database.cc<br>\r
158 +++ b/lib/database.cc<br>\r
159 @@ -847,6 +847,12 @@ notmuch_database_open_verbose (const char *path,<br>\r
160 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto DONE;<br>\r
161 =C2=A0 =C2=A0 =C2=A0}<br>\r
162 <br>\r
163 +=C2=A0 =C2=A0 if (path[0] !=3D &#39;/&#39;) {<br>\r
164 +=C2=A0 =C2=A0 =C2=A0 =C2=A0message =3D strdup (&quot;Error: Database path =\r
165 must be absolute.\n&quot;);<br>\r
166 +=C2=A0 =C2=A0 =C2=A0 =C2=A0status =3D NOTMUCH_STATUS_FILE_ERROR;<br>\r
167 +=C2=A0 =C2=A0 =C2=A0 =C2=A0goto DONE;<br>\r
168 +=C2=A0 =C2=A0 }<br>\r
169 +<br>\r
170 =C2=A0 =C2=A0 =C2=A0if (! (notmuch_path =3D talloc_asprintf (local, &quot;%=\r
171 s/%s&quot;, path, &quot;.notmuch&quot;))) {<br>\r
172 =C2=A0 =C2=A0 =C2=A0 =C2=A0 message =3D strdup (&quot;Out of memory\n&quot;=\r
173 );<br>\r
174 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D NOTMUCH_STATUS_OUT_OF_MEMORY;<br>\r
175 <br></blockquote></div><br></div>\r
176 \r
177 --94eb2c081926e8ee74051805fde2--\r