--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 638BC431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 10:26:50 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id KTh14KInYz0Y for <notmuch@notmuchmail.org>;\r
+ Fri, 28 Dec 2012 10:26:49 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+ [18.9.25.15])\r
+ by olra.theworths.org (Postfix) with ESMTP id 53843431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 10:26:49 -0800 (PST)\r
+X-AuditID: 1209190f-b7f016d000000e07-1e-50dde4676cff\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 2C.80.03591.764EDD05; Fri, 28 Dec 2012 13:26:47 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBSIQk3n031994; \r
+ Fri, 28 Dec 2012 13:26:46 -0500\r
+Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
+ [76.21.105.205]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBSIQf4B012711\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Fri, 28 Dec 2012 13:26:43 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Toedj-0000sN-Jp; Fri, 28 Dec 2012 13:26:39 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 0/5] Use Xapian query syntax for batch-tag dump/restore\r
+Date: Fri, 28 Dec 2012 13:26:24 -0500\r
+Message-Id: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrKIsWRmVeSWpSXmKPExsUixCmqrJv+5G6AwZdlAhY3WrsZLZqmO1us\r
+ nstjcf3mTGYHFo+ds+6ye9y6/5rd49mqW8weWw69Zw5gieKySUnNySxLLdK3S+DK+Hx5O0vB\r
+ QaGKPedPMzYw7ubrYuTgkBAwkTjwVLSLkRPIFJO4cG89WxcjF4eQwD5GiRs7tzJCOBsYJa7u\r
+ PwGVucgkcXTtTRYIZy6jxL/Dm5hA+tkENCS27V/OCGKLCEhL7Lw7mxXEZhZwlDjzuo0RZJ2w\r
+ gJfE7v0VICaLgKrE7PeCIBW8AvYSH95sY4O4QlGi+9kEtgmMvAsYGVYxyqbkVunmJmbmFKcm\r
+ 6xYnJ+blpRbpmujlZpbopaaUbmIEh44k/w7GbweVDjEKcDAq8fCeuH03QIg1say4MvcQoyQH\r
+ k5Io7/IHQCG+pPyUyozE4oz4otKc1OJDjBIczEoivH3NQDnelMTKqtSifJiUNAeLkjjv1ZSb\r
+ /kIC6YklqdmpqQWpRTBZGQ4OJQnepsdAjYJFqempFWmZOSUIaSYOTpDhPEDDp4DU8BYXJOYW\r
+ Z6ZD5E8xKkqJ80aCJARAEhmleXC9sNh+xSgO9IowbyZIFQ8wLcB1vwIazAQ02JrnDsjgkkSE\r
+ lFQDI/+eC10ue5XFFSdYr582e+b6j+e2zYyduHHnkYh1hRJBTWJfrtk1Cx55bbwk3KzE8LoJ\r
+ 02rlcwkfYqdU1867/GTuP8UUNY+8yYHbJn+vNd/OPnGXo8ey912GWWtn8Jyv/dFzbGH0oeYj\r
+ Vct3FsX49TJwbz2V0tw3z/HaJLOVz/m0/y2wPNS+64USS3FGoqEWc1FxIgAyrQ4CyAIAAA==\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 28 Dec 2012 18:26:50 -0000\r
+\r
+This obsoletes\r
+\r
+ id:1356493723-11085-1-git-send-email-amdragon@mit.edu\r
+\r
+This version improves the documentation comment for make_boolean_term\r
+and hopefully simplifies parse_boolean_term (though in a somewhat\r
+different way than David suggested).\r
+\r
+The diff relative to v2 follows\r
+\r
+diff --git a/util/string-util.c b/util/string-util.c\r
+index db01b4b..83b4953 100644\r
+--- a/util/string-util.c\r
++++ b/util/string-util.c\r
+@@ -112,11 +112,12 @@ parse_boolean_term (void *ctx, const char *str,\r
+ \r
+ /* Implement de-quoting compatible with make_boolean_term. */\r
+ if (*pos == '"') {\r
+- char *out = talloc_strdup (ctx, pos + 1);\r
++ char *out = talloc_array (ctx, char, strlen (pos));\r
+ int closed = 0;\r
+- /* Find the closing quote and un-double doubled internal\r
+- * quotes. */\r
+- for (pos = *term_out = out; *pos; ) {\r
++ *term_out = out;\r
++ /* Skip the opening quote, find the closing quote, and\r
++ * un-double doubled internal quotes. */\r
++ for (++pos; *pos; ) {\r
+ if (*pos == '"') {\r
+ ++pos;\r
+ if (*pos != '"') {\r
+@@ -133,12 +134,15 @@ parse_boolean_term (void *ctx, const char *str,\r
+ goto FAIL;\r
+ *out = '\0';\r
+ } else {\r
+- *term_out = talloc_strdup (ctx, pos);\r
++ const char *start = pos;\r
+ /* Check for text after the boolean term. */\r
+ while (*pos > ' ' && *pos != ')')\r
+ ++pos;\r
+ if (*pos)\r
+ goto FAIL;\r
++ /* No trailing text; dup the string so the caller can free\r
++ * it. */\r
++ *term_out = talloc_strdup (ctx, start);\r
+ }\r
+ return 0;\r
+ \r
+diff --git a/util/string-util.h b/util/string-util.h\r
+index aff2d65..43d49d0 100644\r
+--- a/util/string-util.h\r
++++ b/util/string-util.h\r
+@@ -20,7 +20,12 @@\r
+ char *strtok_len (char *s, const char *delim, size_t *len);\r
+ \r
+ /* Construct a boolean term query with the specified prefix (e.g.,\r
+- * "id") and search term, quoting term as necessary.\r
++ * "id") and search term, quoting term as necessary. Specifically, if\r
++ * term contains any non-printable ASCII characters, non-ASCII\r
++ * characters, close parenthesis or double quotes, it will be enclosed\r
++ * in double quotes and any internal double quotes will be doubled\r
++ * (e.g. a"b -> "a""b"). The result will be a valid notmuch query and\r
++ * can be parsed by parse_boolean_term.\r
+ *\r
+ * Output is into buf; it may be talloc_realloced.\r
+ * Return: 0 on success, non-zero on memory allocation failure.\r
+\r