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 53235431FBF
\r
6 for <notmuch@notmuchmail.org>; Sun, 23 Dec 2012 17:40:14 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 KrKXEzMdKkt9 for <notmuch@notmuchmail.org>;
\r
16 Sun, 23 Dec 2012 17:40:12 -0800 (PST)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 919E0431FCB
\r
21 for <notmuch@notmuchmail.org>; Sun, 23 Dec 2012 17:40:02 -0800 (PST)
\r
22 Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([156.34.82.78] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>) id 1Tmx1K-0008Kj-SZ
\r
27 for notmuch@notmuchmail.org; Sun, 23 Dec 2012 21:40:01 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>) id 1Tmx1F-0002nD-C6
\r
30 for notmuch@notmuchmail.org; Sun, 23 Dec 2012 21:39:53 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: v9 of batch tagging
\r
34 Date: Sun, 23 Dec 2012 21:39:26 -0400
\r
35 Message-Id: <1356313183-9266-1-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Mon, 24 Dec 2012 01:40:14 -0000
\r
54 id:1356095307-22895-1-git-send-email-david@tethera.net
\r
56 The main changes since v8 are the rebasing against the notmuch-restore
\r
57 fixes in master, and the rewrite of the query (pre)-processing
\r
58 unhex_and_quote. This incorporates the changes of
\r
60 id:1356231570-28232-1-git-send-email-david@tethera.net
\r
62 and now handles '()' (cf. id:87a9t5p4dz.fsf@qmul.ac.uk)
\r
67 | Finally, I don't know if a query can contain a : without being a
\r
68 | prefix query. If it can that could end up being misquoted.
\r
71 This is pretty easy to work around by encoding that :. I think unless
\r
72 it is a problem in practice I prefer not to keep an explicity list of
\r
73 prefixes here; recognizing prefixes should really be a service from
\r
76 I dropped two patches (strnspn and hex_invariant), but picked up a new
\r
77 strtok variation. Probably the name strtok_len2 could be improved
\r
78 (and I see there is a typo in the patch subject).
\r
80 [Patch v9 05/17] util/string-util: add a new string tokenized
\r
82 Finally I added a test for the new parenthesis handling.
\r
84 [Patch v9 17/17] test/tagging: add test for handling of parens
\r
86 Fixup wise, the tests needed to be adjusted a bit for () being delimiters,
\r
87 and the man page as well.
\r
89 I added the fclose in id:87wqw9hf9a.fsf@oiva.home.nikula.org
\r
91 And I modified the return value per id:87zk15hi7f.fsf@oiva.home.nikula.org
\r
93 Here is the interdiff for unhex_and_quote:
\r
95 commit 67c6aee87db5c7da25529e1c0feb64e422abb4b7
\r
96 Author: David Bremner <bremner@unb.ca>
\r
97 Date: Sat Dec 22 22:49:02 2012 -0400
\r
99 simplify unhex_and_quote, support parens
\r
101 the overgeneral definition of a prefix can be replaced by lower case
\r
102 alphabetic, and still work fine with current notmuch query syntax.
\r
104 use () as delimiters in unhex_and_quote, preserve delimiters
\r
106 diff --git a/tag-util.c b/tag-util.c
\r
107 index 6f62fe6..91f3603 100644
\r
110 @@ -56,6 +56,21 @@ illegal_tag (const char *tag, notmuch_bool_t remove)
\r
114 +/* Factor out the boilerplate to append a token to the query string.
\r
115 + * For use in unhex_and_quote */
\r
117 +static tag_parse_status_t
\r
118 +append_tok (const char *tok, size_t tok_len,
\r
119 + const char *line_for_error, char **query_string)
\r
122 + *query_string = talloc_strndup_append_buffer (*query_string, tok, tok_len);
\r
123 + if (*query_string == NULL)
\r
124 + return line_error (TAG_PARSE_OUT_OF_MEMORY, line_for_error, "aborting");
\r
126 + return TAG_PARSE_SUCCESS;
\r
129 /* Input is a hex encoded string, presumed to be a query for Xapian.
\r
131 * Space delimited tokens are decoded and quoted, with '*' and prefixes
\r
132 @@ -67,45 +82,41 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,
\r
134 char *tok = encoded;
\r
135 size_t tok_len = 0;
\r
136 + size_t delim_len = 0;
\r
138 size_t buf_len = 0;
\r
139 tag_parse_status_t ret = TAG_PARSE_SUCCESS;
\r
141 *query_string = talloc_strdup (ctx, "");
\r
143 - while ((tok = strtok_len (tok + tok_len, " ", &tok_len)) != NULL) {
\r
144 + while ((tok = strtok_len2 (tok + tok_len + delim_len, " ()",
\r
145 + &tok_len, &delim_len)) != NULL) {
\r
148 char delim = *(tok + tok_len);
\r
150 - *(tok + tok_len++) = '\0';
\r
151 + *(tok + tok_len) = '\0';
\r
153 - prefix_len = hex_invariant (tok, tok_len);
\r
154 + /* The following matches a superset of prefixes currently
\r
155 + * used by notmuch */
\r
156 + prefix_len = strspn (tok, "abcdefghijklmnopqrstuvwxyz");
\r
158 - if ((strcmp (tok, "*") == 0) || prefix_len >= tok_len - 1) {
\r
159 + if ((strcmp (tok, "*") == 0) || prefix_len == tok_len) {
\r
161 /* pass some things through without quoting or decoding.
\r
162 * Note for '*' this is mandatory.
\r
165 - if (! (*query_string = talloc_asprintf_append_buffer (
\r
166 - *query_string, "%s%c", tok, delim))) {
\r
168 - ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
169 - line_for_error, "aborting");
\r
172 + ret = append_tok (tok, tok_len, line_for_error, query_string);
\r
173 + if (ret) goto DONE;
\r
176 /* potential prefix: one for ':', then something after */
\r
177 - if ((tok_len - prefix_len > 2) && *(tok + prefix_len) == ':') {
\r
178 - if (! (*query_string = talloc_strndup_append (*query_string,
\r
180 - prefix_len + 1))) {
\r
181 - ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
182 - line_for_error, "aborting");
\r
185 + if ((tok_len - prefix_len >= 2) && *(tok + prefix_len) == ':') {
\r
186 + ret = append_tok (tok, prefix_len + 1,
\r
187 + line_for_error, query_string);
\r
188 + if (ret) goto DONE;
\r
190 tok += prefix_len + 1;
\r
191 tok_len -= prefix_len + 1;
\r
193 @@ -122,13 +133,15 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,
\r
197 - if (! (*query_string = talloc_asprintf_append_buffer (
\r
198 - *query_string, "%s%c", buf, delim))) {
\r
199 - ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
200 - line_for_error, "aborting");
\r
203 + ret = append_tok (buf, buf_len, line_for_error, query_string);
\r
204 + if (ret) goto DONE;
\r
206 + /* restore the string */
\r
207 + *(tok + tok_len) = delim;
\r
209 + /* copy any delimiters */
\r
210 + ret = append_tok (tok + tok_len, delim_len, line_for_error, query_string);
\r
211 + if (ret) goto DONE;
\r