Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 91F60431FAF for ; Tue, 8 Oct 2013 09:39:04 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y7H6Qb12vx3K for ; Tue, 8 Oct 2013 09:38:57 -0700 (PDT) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 16D53431FAE for ; Tue, 8 Oct 2013 09:38:57 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1VTaJ5-0001py-U6; Tue, 08 Oct 2013 17:38:53 +0100 Received: from 188.28.146.25.threembb.co.uk ([188.28.146.25] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) (envelope-from ) id 1VTaIu-0008EX-T7; Tue, 08 Oct 2013 17:38:47 +0100 From: Mark Walters To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH 08/11] search: Add stable queries to thread search results In-Reply-To: <1381185201-25197-9-git-send-email-amdragon@mit.edu> References: <1381185201-25197-1-git-send-email-amdragon@mit.edu> <1381185201-25197-9-git-send-email-amdragon@mit.edu> User-Agent: Notmuch/0.15.2+334~gafd5c6a (http://notmuchmail.org) Emacs/23.4.1 (x86_64-pc-linux-gnu) Date: Tue, 08 Oct 2013 17:37:29 +0100 Message-ID: <87wqlnafcm.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Sender-Host-Address: 188.28.146.25 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 68a047edf5c877238a745409d245a3ed (of first 20000 bytes) X-SpamAssassin-Score: 0.0 X-SpamAssassin-SpamBar: / X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored 0.0 points. Summary of the scoring: * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) X-QM-Scan-Virus: ClamAV says the message is clean X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Oct 2013 16:39:04 -0000 On Mon, 07 Oct 2013, Austin Clements wrote: > These queries will match exactly the set of messages currently in the > thread, even if more messages later arrive. Two queries are provided: > one for matched messages and one for unmatched messages. > > This can be used to fix race conditions with tagging threads from > search results. While tagging based on a thread: query can affect > messages that arrived after the search, tagging based on stable > queries affects only the messages the user was shown in the search UI. > > Since we want clients to be able to depend on the presence of these > queries, this ushers in schema version 2. > --- > devel/schemata | 22 +++++++++++++++++-- > notmuch-client.h | 2 +- > notmuch-search.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > test/json | 2 ++ > test/missing-headers | 6 ++++-- > test/sexp | 4 ++-- > 6 files changed, 89 insertions(+), 7 deletions(-) > > diff --git a/devel/schemata b/devel/schemata > index cdd0e43..41dc4a6 100644 > --- a/devel/schemata > +++ b/devel/schemata > @@ -14,7 +14,17 @@ are interleaved. Keys are printed as keywords (symbols= preceded by a > colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as > nil, true as t and false as nil. >=20=20 > -This is version 1 of the structured output format. > +This is version 2 of the structured output format. > + > +Version history > +--------------- > + > +v1 > +- First versioned schema release. > +- Added part.content-length and part.content-transfer-encoding fields. > + > +v2 > +- Added the thread_summary.query field. >=20=20 > Common non-terminals > -------------------- > @@ -145,7 +155,15 @@ thread_summary =3D { > authors: string, # comma-separated names with | between > # matched and unmatched > subject: string, > - tags: [string*] > + tags: [string*], > + > + # Two stable query strings identifying exactly the matched and > + # unmatched messages currently in this thread. The messages > + # matched by these queries will not change even if more messages > + # arrive in the thread. If there are no matched or unmatched > + # messages, the corresponding query will be null (there is no > + # query that matches nothing). (Added in schema version 2.) > + query: [string|null, string|null], > } >=20=20 > notmuch reply schema > diff --git a/notmuch-client.h b/notmuch-client.h > index 8d986f4..1b14910 100644 > --- a/notmuch-client.h > +++ b/notmuch-client.h > @@ -138,7 +138,7 @@ chomp_newline (char *str) > * this. New (required) map fields can be added without increasing > * this. > */ > -#define NOTMUCH_FORMAT_CUR 1 > +#define NOTMUCH_FORMAT_CUR 2 > /* The minimum supported structured output format version. Requests > * for format versions below this will return an error. */ > #define NOTMUCH_FORMAT_MIN 1 > diff --git a/notmuch-search.c b/notmuch-search.c > index d9d39ec..1d14651 100644 > --- a/notmuch-search.c > +++ b/notmuch-search.c > @@ -20,6 +20,7 @@ >=20=20 > #include "notmuch-client.h" > #include "sprinter.h" > +#include "string-util.h" >=20=20 > typedef enum { > OUTPUT_SUMMARY, > @@ -46,6 +47,46 @@ sanitize_string (const void *ctx, const char *str) > return out; > } >=20=20 > +/* Return two stable query strings that identify exactly the matched > + * and unmatched messages currently in thread. If there are no > + * matched or unmatched messages, the returned buffers will be > + * NULL. */ > +static int > +get_thread_query (notmuch_thread_t *thread, > + char **matched_out, char **unmached_out) > +{ > + notmuch_messages_t *messages; > + char *escaped =3D NULL; > + size_t escaped_len =3D 0; > + > + *matched_out =3D *unmached_out =3D NULL; A missing t in unmatched? (and once below where it is used) > + > + for (messages =3D notmuch_thread_get_messages (thread); > + notmuch_messages_valid (messages); > + notmuch_messages_move_to_next (messages)) > + { > + notmuch_message_t *message =3D notmuch_messages_get (messages); > + const char *mid =3D notmuch_message_get_message_id (message); > + /* Determine which query buffer to extend */ > + char **buf =3D notmuch_message_get_flag ( > + message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmached_out; > + /* Allocate the query buffer is this is the first message */ > + if (!*buf && (*buf =3D talloc_strdup (thread, "")) =3D=3D NULL) > + return -1; > + /* Add this message's id: query. Since "id" is an exclusive > + * prefix, it is implicitly 'or'd together, so we only need to > + * join queries with a space. */ > + if (make_boolean_term (thread, "id", mid, &escaped, &escaped_len) < 0) > + return -1; > + *buf =3D talloc_asprintf_append_buffer ( > + *buf, "%s%s", **buf ? " " : "", escaped); > + if (!*buf) > + return -1; > + } > + talloc_free (escaped); > + return 0; > +} > + > static int > do_search_threads (sprinter_t *format, > notmuch_query_t *query, > @@ -131,6 +172,25 @@ do_search_threads (sprinter_t *format, > format->string (format, authors); > format->map_key (format, "subject"); > format->string (format, subject); > + if (notmuch_format_version >=3D 2) { > + char *matched_query, *unmatched_query; > + if (get_thread_query (thread, &matched_query, > + &unmatched_query) < 0) { > + fprintf (stderr, "Out of memory\n"); > + return 1; > + } > + format->map_key (format, "query"); > + format->begin_list (format); > + if (matched_query) > + format->string (format, matched_query); > + else > + format->null (format); > + if (unmatched_query) > + format->string (format, unmatched_query); > + else > + format->null (format); > + format->end (format); > + } > } >=20=20 > talloc_free (ctx_quote); > diff --git a/test/json b/test/json > index b87b7f6..e07a290 100755 > --- a/test/json > +++ b/test/json > @@ -26,6 +26,7 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\", > \"total\": 1, > \"authors\": \"Notmuch Test Suite\", > \"subject\": \"json-search-subject\", > + \"query\": [\"id:$gen_msg_id\", null], > \"tags\": [\"inbox\", > \"unread\"]}]" >=20=20 > @@ -59,6 +60,7 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\", > \"total\": 1, > \"authors\": \"Notmuch Test Suite\", > \"subject\": \"json-search-utf8-body-s=C3=BCbj=C3=A9ct\", > + \"query\": [\"id:$gen_msg_id\", null], > \"tags\": [\"inbox\", > \"unread\"]}]" >=20=20 > diff --git a/test/missing-headers b/test/missing-headers > index f14b878..43e861b 100755 > --- a/test/missing-headers > +++ b/test/missing-headers > @@ -43,7 +43,8 @@ test_expect_equal_json "$output" ' > ], > "thread": "XXX", > "timestamp": 978709437, > - "total": 1 > + "total": 1, > + "query": ["id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01= 161", null] > }, > { > "authors": "Notmuch Test Suite", > @@ -56,7 +57,8 @@ test_expect_equal_json "$output" ' > ], > "thread": "XXX", > "timestamp": 0, > - "total": 1 > + "total": 1, > + "query": ["id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401= 334", null] > } > ]' >=20=20 > diff --git a/test/sexp b/test/sexp > index 492a82f..be815e1 100755 > --- a/test/sexp > +++ b/test/sexp > @@ -19,7 +19,7 @@ test_expect_equal "$output" "((((:id \"${gen_msg_id}\" = :match t :excluded nil :f > test_begin_subtest "Search message: sexp" > add_message "[subject]=3D\"sexp-search-subject\"" "[date]=3D\"Sat, 01 Ja= n 2000 12:00:00 -0000\"" "[body]=3D\"sexp-search-message\"" > output=3D$(notmuch search --format=3Dsexp "sexp-search-message" | notmuc= h_search_sanitize) > -test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 9= 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu= ch Test Suite\" :subject \"sexp-search-subject\" :tags (\"inbox\" \"unread\= ")))" > +test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 9= 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu= ch Test Suite\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\"= nil) :tags (\"inbox\" \"unread\")))" >=20=20 > test_begin_subtest "Show message: sexp, utf-8" > add_message "[subject]=3D\"sexp-show-utf8-body-s=C3=BCbj=C3=A9ct\"" "[da= te]=3D\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=3D\"js=C3=B6n-show-m=C3= =A9ssage\"" > @@ -44,7 +44,7 @@ test_expect_equal "$output" "((((:id \"$id\" :match t := excluded nil :filename \" > test_begin_subtest "Search message: sexp, utf-8" > add_message "[subject]=3D\"sexp-search-utf8-body-s=C3=BCbj=C3=A9ct\"" "[= date]=3D\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=3D\"js=C3=B6n-search-m= =C3=A9ssage\"" > output=3D$(notmuch search --format=3Dsexp "js=C3=B6n-search-m=C3=A9ssage= " | notmuch_search_sanitize) > -test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 9= 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu= ch Test Suite\" :subject \"sexp-search-utf8-body-s=C3=BCbj=C3=A9ct\" :tags = (\"inbox\" \"unread\")))" > +test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 9= 46728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmu= ch Test Suite\" :subject \"sexp-search-utf8-body-s=C3=BCbj=C3=A9ct\" :query= (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))" Would it be worth adding an explicit test when unmatched is non-nil? Best wishes=20 Mark >=20=20 > test_done > --=20 > 1.8.4.rc3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch