[PATCH 0/2] Enhancements to notmuch-hello search history
[notmuch-archives.git] / 1b / 5bd8821b4a4d00c7e0197f26993970951c058c
1 Return-Path: <amdragon@mit.edu>\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 638BC431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 10:26:50 -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 KTh14KInYz0Y for <notmuch@notmuchmail.org>;\r
16         Fri, 28 Dec 2012 10:26:49 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 53843431FBD\r
20         for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 10:26:49 -0800 (PST)\r
21 X-AuditID: 1209190f-b7f016d000000e07-1e-50dde4676cff\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 2C.80.03591.764EDD05; Fri, 28 Dec 2012 13:26:47 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBSIQk3n031994; \r
27         Fri, 28 Dec 2012 13:26:46 -0500\r
28 Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
29         [76.21.105.205]) (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBSIQf4B012711\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 28 Dec 2012 13:26:43 -0500 (EST)\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Toedj-0000sN-Jp; Fri, 28 Dec 2012 13:26:39 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v3 0/5] Use Xapian query syntax for batch-tag dump/restore\r
40 Date: Fri, 28 Dec 2012 13:26:24 -0500\r
41 Message-Id: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 X-Brightmail-Tracker:\r
44  H4sIAAAAAAAAA+NgFtrKIsWRmVeSWpSXmKPExsUixCmqrJv+5G6AwZdlAhY3WrsZLZqmO1us\r
45         nstjcf3mTGYHFo+ds+6ye9y6/5rd49mqW8weWw69Zw5gieKySUnNySxLLdK3S+DK+Hx5O0vB\r
46         QaGKPedPMzYw7ubrYuTgkBAwkTjwVLSLkRPIFJO4cG89WxcjF4eQwD5GiRs7tzJCOBsYJa7u\r
47         PwGVucgkcXTtTRYIZy6jxL/Dm5hA+tkENCS27V/OCGKLCEhL7Lw7mxXEZhZwlDjzuo0RZJ2w\r
48         gJfE7v0VICaLgKrE7PeCIBW8AvYSH95sY4O4QlGi+9kEtgmMvAsYGVYxyqbkVunmJmbmFKcm\r
49         6xYnJ+blpRbpmujlZpbopaaUbmIEh44k/w7GbweVDjEKcDAq8fCeuH03QIg1say4MvcQoyQH\r
50         k5Io7/IHQCG+pPyUyozE4oz4otKc1OJDjBIczEoivH3NQDnelMTKqtSifJiUNAeLkjjv1ZSb\r
51         /kIC6YklqdmpqQWpRTBZGQ4OJQnepsdAjYJFqempFWmZOSUIaSYOTpDhPEDDp4DU8BYXJOYW\r
52         Z6ZD5E8xKkqJ80aCJARAEhmleXC9sNh+xSgO9IowbyZIFQ8wLcB1vwIazAQ02JrnDsjgkkSE\r
53         lFQDI/+eC10ue5XFFSdYr582e+b6j+e2zYyduHHnkYh1hRJBTWJfrtk1Cx55bbwk3KzE8LoJ\r
54         02rlcwkfYqdU1867/GTuP8UUNY+8yYHbJn+vNd/OPnGXo8ey912GWWtn8Jyv/dFzbGH0oeYj\r
55         Vct3FsX49TJwbz2V0tw3z/HaJLOVz/m0/y2wPNS+64USS3FGoqEWc1FxIgAyrQ4CyAIAAA==\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: Fri, 28 Dec 2012 18:26:50 -0000\r
69 \r
70 This obsoletes\r
71 \r
72   id:1356493723-11085-1-git-send-email-amdragon@mit.edu\r
73 \r
74 This version improves the documentation comment for make_boolean_term\r
75 and hopefully simplifies parse_boolean_term (though in a somewhat\r
76 different way than David suggested).\r
77 \r
78 The diff relative to v2 follows\r
79 \r
80 diff --git a/util/string-util.c b/util/string-util.c\r
81 index db01b4b..83b4953 100644\r
82 --- a/util/string-util.c\r
83 +++ b/util/string-util.c\r
84 @@ -112,11 +112,12 @@ parse_boolean_term (void *ctx, const char *str,\r
85  \r
86      /* Implement de-quoting compatible with make_boolean_term. */\r
87      if (*pos == '"') {\r
88 -       char *out = talloc_strdup (ctx, pos + 1);\r
89 +       char *out = talloc_array (ctx, char, strlen (pos));\r
90         int closed = 0;\r
91 -       /* Find the closing quote and un-double doubled internal\r
92 -        * quotes. */\r
93 -       for (pos = *term_out = out; *pos; ) {\r
94 +       *term_out = out;\r
95 +       /* Skip the opening quote, find the closing quote, and\r
96 +        * un-double doubled internal quotes. */\r
97 +       for (++pos; *pos; ) {\r
98             if (*pos == '"') {\r
99                 ++pos;\r
100                 if (*pos != '"') {\r
101 @@ -133,12 +134,15 @@ parse_boolean_term (void *ctx, const char *str,\r
102             goto FAIL;\r
103         *out = '\0';\r
104      } else {\r
105 -       *term_out = talloc_strdup (ctx, pos);\r
106 +       const char *start = pos;\r
107         /* Check for text after the boolean term. */\r
108         while (*pos > ' ' && *pos != ')')\r
109             ++pos;\r
110         if (*pos)\r
111             goto FAIL;\r
112 +       /* No trailing text; dup the string so the caller can free\r
113 +        * it. */\r
114 +       *term_out = talloc_strdup (ctx, start);\r
115      }\r
116      return 0;\r
117  \r
118 diff --git a/util/string-util.h b/util/string-util.h\r
119 index aff2d65..43d49d0 100644\r
120 --- a/util/string-util.h\r
121 +++ b/util/string-util.h\r
122 @@ -20,7 +20,12 @@\r
123  char *strtok_len (char *s, const char *delim, size_t *len);\r
124  \r
125  /* Construct a boolean term query with the specified prefix (e.g.,\r
126 - * "id") and search term, quoting term as necessary.\r
127 + * "id") and search term, quoting term as necessary.  Specifically, if\r
128 + * term contains any non-printable ASCII characters, non-ASCII\r
129 + * characters, close parenthesis or double quotes, it will be enclosed\r
130 + * in double quotes and any internal double quotes will be doubled\r
131 + * (e.g. a"b -> "a""b").  The result will be a valid notmuch query and\r
132 + * can be parsed by parse_boolean_term.\r
133   *\r
134   * Output is into buf; it may be talloc_realloced.\r
135   * Return: 0 on success, non-zero on memory allocation failure.\r
136 \r