1 Return-Path: <m.walters@qmul.ac.uk>
\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 91F60431FAF
\r
6 for <notmuch@notmuchmail.org>; Tue, 8 Oct 2013 09:39:04 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5
\r
12 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,
\r
13 NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id Y7H6Qb12vx3K for <notmuch@notmuchmail.org>;
\r
17 Tue, 8 Oct 2013 09:38:57 -0700 (PDT)
\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 16D53431FAE
\r
22 for <notmuch@notmuchmail.org>; Tue, 8 Oct 2013 09:38:57 -0700 (PDT)
\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])
\r
24 by mail2.qmul.ac.uk with esmtp (Exim 4.71)
\r
25 (envelope-from <m.walters@qmul.ac.uk>)
\r
26 id 1VTaJ5-0001py-U6; Tue, 08 Oct 2013 17:38:53 +0100
\r
27 Received: from 188.28.146.25.threembb.co.uk ([188.28.146.25] helo=localhost)
\r
28 by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)
\r
29 (envelope-from <m.walters@qmul.ac.uk>)
\r
30 id 1VTaIu-0008EX-T7; Tue, 08 Oct 2013 17:38:47 +0100
\r
31 From: Mark Walters <markwalters1009@gmail.com>
\r
32 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
33 Subject: Re: [PATCH 08/11] search: Add stable queries to thread search results
\r
34 In-Reply-To: <1381185201-25197-9-git-send-email-amdragon@mit.edu>
\r
35 References: <1381185201-25197-1-git-send-email-amdragon@mit.edu>
\r
36 <1381185201-25197-9-git-send-email-amdragon@mit.edu>
\r
37 User-Agent: Notmuch/0.15.2+334~gafd5c6a (http://notmuchmail.org) Emacs/23.4.1
\r
38 (x86_64-pc-linux-gnu)
\r
39 Date: Tue, 08 Oct 2013 17:37:29 +0100
\r
40 Message-ID: <87wqlnafcm.fsf@qmul.ac.uk>
\r
42 Content-Type: text/plain; charset=utf-8
\r
43 Content-Transfer-Encoding: quoted-printable
\r
44 X-Sender-Host-Address: 188.28.146.25
\r
45 X-QM-SPAM-Info: Sender has good ham record. :)
\r
46 X-QM-Body-MD5: 68a047edf5c877238a745409d245a3ed (of first 20000 bytes)
\r
47 X-SpamAssassin-Score: 0.0
\r
48 X-SpamAssassin-SpamBar: /
\r
49 X-SpamAssassin-Report: The QM spam filters have analysed this message to
\r
51 spam. We require at least 5.0 points to mark a message as spam.
\r
52 This message scored 0.0 points. Summary of the scoring:
\r
53 * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
\r
54 provider * (markwalters1009[at]gmail.com)
\r
55 X-QM-Scan-Virus: ClamAV says the message is clean
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\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: Tue, 08 Oct 2013 16:39:04 -0000
\r
71 On Mon, 07 Oct 2013, Austin Clements <amdragon@MIT.EDU> wrote:
\r
72 > These queries will match exactly the set of messages currently in the
\r
73 > thread, even if more messages later arrive. Two queries are provided:
\r
74 > one for matched messages and one for unmatched messages.
\r
76 > This can be used to fix race conditions with tagging threads from
\r
77 > search results. While tagging based on a thread: query can affect
\r
78 > messages that arrived after the search, tagging based on stable
\r
79 > queries affects only the messages the user was shown in the search UI.
\r
81 > Since we want clients to be able to depend on the presence of these
\r
82 > queries, this ushers in schema version 2.
\r
84 > devel/schemata | 22 +++++++++++++++++--
\r
85 > notmuch-client.h | 2 +-
\r
86 > notmuch-search.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++=
\r
89 > test/missing-headers | 6 ++++--
\r
90 > test/sexp | 4 ++--
\r
91 > 6 files changed, 89 insertions(+), 7 deletions(-)
\r
93 > diff --git a/devel/schemata b/devel/schemata
\r
94 > index cdd0e43..41dc4a6 100644
\r
95 > --- a/devel/schemata
\r
96 > +++ b/devel/schemata
\r
97 > @@ -14,7 +14,17 @@ are interleaved. Keys are printed as keywords (symbols=
\r
99 > colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as
\r
100 > nil, true as t and false as nil.
\r
102 > -This is version 1 of the structured output format.
\r
103 > +This is version 2 of the structured output format.
\r
109 > +- First versioned schema release.
\r
110 > +- Added part.content-length and part.content-transfer-encoding fields.
\r
113 > +- Added the thread_summary.query field.
\r
115 > Common non-terminals
\r
116 > --------------------
\r
117 > @@ -145,7 +155,15 @@ thread_summary =3D {
\r
118 > authors: string, # comma-separated names with | between
\r
119 > # matched and unmatched
\r
121 > - tags: [string*]
\r
122 > + tags: [string*],
\r
124 > + # Two stable query strings identifying exactly the matched and
\r
125 > + # unmatched messages currently in this thread. The messages
\r
126 > + # matched by these queries will not change even if more messages
\r
127 > + # arrive in the thread. If there are no matched or unmatched
\r
128 > + # messages, the corresponding query will be null (there is no
\r
129 > + # query that matches nothing). (Added in schema version 2.)
\r
130 > + query: [string|null, string|null],
\r
133 > notmuch reply schema
\r
134 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
135 > index 8d986f4..1b14910 100644
\r
136 > --- a/notmuch-client.h
\r
137 > +++ b/notmuch-client.h
\r
138 > @@ -138,7 +138,7 @@ chomp_newline (char *str)
\r
139 > * this. New (required) map fields can be added without increasing
\r
142 > -#define NOTMUCH_FORMAT_CUR 1
\r
143 > +#define NOTMUCH_FORMAT_CUR 2
\r
144 > /* The minimum supported structured output format version. Requests
\r
145 > * for format versions below this will return an error. */
\r
146 > #define NOTMUCH_FORMAT_MIN 1
\r
147 > diff --git a/notmuch-search.c b/notmuch-search.c
\r
148 > index d9d39ec..1d14651 100644
\r
149 > --- a/notmuch-search.c
\r
150 > +++ b/notmuch-search.c
\r
151 > @@ -20,6 +20,7 @@
\r
153 > #include "notmuch-client.h"
\r
154 > #include "sprinter.h"
\r
155 > +#include "string-util.h"
\r
159 > @@ -46,6 +47,46 @@ sanitize_string (const void *ctx, const char *str)
\r
163 > +/* Return two stable query strings that identify exactly the matched
\r
164 > + * and unmatched messages currently in thread. If there are no
\r
165 > + * matched or unmatched messages, the returned buffers will be
\r
168 > +get_thread_query (notmuch_thread_t *thread,
\r
169 > + char **matched_out, char **unmached_out)
\r
171 > + notmuch_messages_t *messages;
\r
172 > + char *escaped =3D NULL;
\r
173 > + size_t escaped_len =3D 0;
\r
175 > + *matched_out =3D *unmached_out =3D NULL;
\r
177 A missing t in unmatched? (and once below where it is used)
\r
180 > + for (messages =3D notmuch_thread_get_messages (thread);
\r
181 > + notmuch_messages_valid (messages);
\r
182 > + notmuch_messages_move_to_next (messages))
\r
184 > + notmuch_message_t *message =3D notmuch_messages_get (messages);
\r
185 > + const char *mid =3D notmuch_message_get_message_id (message);
\r
186 > + /* Determine which query buffer to extend */
\r
187 > + char **buf =3D notmuch_message_get_flag (
\r
188 > + message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmached_out;
\r
189 > + /* Allocate the query buffer is this is the first message */
\r
190 > + if (!*buf && (*buf =3D talloc_strdup (thread, "")) =3D=3D NULL)
\r
192 > + /* Add this message's id: query. Since "id" is an exclusive
\r
193 > + * prefix, it is implicitly 'or'd together, so we only need to
\r
194 > + * join queries with a space. */
\r
195 > + if (make_boolean_term (thread, "id", mid, &escaped, &escaped_len) < 0)
\r
197 > + *buf =3D talloc_asprintf_append_buffer (
\r
198 > + *buf, "%s%s", **buf ? " " : "", escaped);
\r
202 > + talloc_free (escaped);
\r
207 > do_search_threads (sprinter_t *format,
\r
208 > notmuch_query_t *query,
\r
209 > @@ -131,6 +172,25 @@ do_search_threads (sprinter_t *format,
\r
210 > format->string (format, authors);
\r
211 > format->map_key (format, "subject");
\r
212 > format->string (format, subject);
\r
213 > + if (notmuch_format_version >=3D 2) {
\r
214 > + char *matched_query, *unmatched_query;
\r
215 > + if (get_thread_query (thread, &matched_query,
\r
216 > + &unmatched_query) < 0) {
\r
217 > + fprintf (stderr, "Out of memory\n");
\r
220 > + format->map_key (format, "query");
\r
221 > + format->begin_list (format);
\r
222 > + if (matched_query)
\r
223 > + format->string (format, matched_query);
\r
225 > + format->null (format);
\r
226 > + if (unmatched_query)
\r
227 > + format->string (format, unmatched_query);
\r
229 > + format->null (format);
\r
230 > + format->end (format);
\r
234 > talloc_free (ctx_quote);
\r
235 > diff --git a/test/json b/test/json
\r
236 > index b87b7f6..e07a290 100755
\r
239 > @@ -26,6 +26,7 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
\r
241 > \"authors\": \"Notmuch Test Suite\",
\r
242 > \"subject\": \"json-search-subject\",
\r
243 > + \"query\": [\"id:$gen_msg_id\", null],
\r
244 > \"tags\": [\"inbox\",
\r
247 > @@ -59,6 +60,7 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
\r
249 > \"authors\": \"Notmuch Test Suite\",
\r
250 > \"subject\": \"json-search-utf8-body-s=C3=BCbj=C3=A9ct\",
\r
251 > + \"query\": [\"id:$gen_msg_id\", null],
\r
252 > \"tags\": [\"inbox\",
\r
255 > diff --git a/test/missing-headers b/test/missing-headers
\r
256 > index f14b878..43e861b 100755
\r
257 > --- a/test/missing-headers
\r
258 > +++ b/test/missing-headers
\r
259 > @@ -43,7 +43,8 @@ test_expect_equal_json "$output" '
\r
262 > "timestamp": 978709437,
\r
265 > + "query": ["id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01=
\r
269 > "authors": "Notmuch Test Suite",
\r
270 > @@ -56,7 +57,8 @@ test_expect_equal_json "$output" '
\r
276 > + "query": ["id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401=
\r
281 > diff --git a/test/sexp b/test/sexp
\r
282 > index 492a82f..be815e1 100755
\r
285 > @@ -19,7 +19,7 @@ test_expect_equal "$output" "((((:id \"${gen_msg_id}\" =
\r
286 :match t :excluded nil :f
\r
287 > test_begin_subtest "Search message: sexp"
\r
288 > add_message "[subject]=3D\"sexp-search-subject\"" "[date]=3D\"Sat, 01 Ja=
\r
289 n 2000 12:00:00 -0000\"" "[body]=3D\"sexp-search-message\""
\r
290 > output=3D$(notmuch search --format=3Dsexp "sexp-search-message" | notmuc=
\r
292 > -test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 9=
\r
293 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu=
\r
294 ch Test Suite\" :subject \"sexp-search-subject\" :tags (\"inbox\" \"unread\=
\r
296 > +test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 9=
\r
297 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu=
\r
298 ch Test Suite\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\"=
\r
299 nil) :tags (\"inbox\" \"unread\")))"
\r
301 > test_begin_subtest "Show message: sexp, utf-8"
\r
302 > add_message "[subject]=3D\"sexp-show-utf8-body-s=C3=BCbj=C3=A9ct\"" "[da=
\r
303 te]=3D\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=3D\"js=C3=B6n-show-m=C3=
\r
305 > @@ -44,7 +44,7 @@ test_expect_equal "$output" "((((:id \"$id\" :match t :=
\r
306 excluded nil :filename \"
\r
307 > test_begin_subtest "Search message: sexp, utf-8"
\r
308 > add_message "[subject]=3D\"sexp-search-utf8-body-s=C3=BCbj=C3=A9ct\"" "[=
\r
309 date]=3D\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=3D\"js=C3=B6n-search-m=
\r
311 > output=3D$(notmuch search --format=3Dsexp "js=C3=B6n-search-m=C3=A9ssage=
\r
312 " | notmuch_search_sanitize)
\r
313 > -test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 9=
\r
314 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu=
\r
315 ch Test Suite\" :subject \"sexp-search-utf8-body-s=C3=BCbj=C3=A9ct\" :tags =
\r
316 (\"inbox\" \"unread\")))"
\r
317 > +test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 9=
\r
318 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu=
\r
319 ch Test Suite\" :subject \"sexp-search-utf8-body-s=C3=BCbj=C3=A9ct\" :query=
\r
320 (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
\r
322 Would it be worth adding an explicit test when unmatched is non-nil?
\r
334 > _______________________________________________
\r
335 > notmuch mailing list
\r
336 > notmuch@notmuchmail.org
\r
337 > http://notmuchmail.org/mailman/listinfo/notmuch
\r