--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 7C826431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Dec 2012 08:51:02 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 kZ6ZGevh3uL8 for <notmuch@notmuchmail.org>;\r
+ Sat, 29 Dec 2012 08:50:58 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2A211431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Dec 2012 08:50:58 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1TozcY-0000bk-68; Sat, 29 Dec 2012 16:50:52 +0000\r
+Received: from 94.197.9.104.threembb.co.uk ([94.197.9.104] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1TozcW-0000mF-TG; Sat, 29 Dec 2012 16:50:49 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 2/5] util: Function to parse boolean term queries\r
+In-Reply-To: <1356719189-2837-3-git-send-email-amdragon@mit.edu>\r
+References: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
+ <1356719189-2837-3-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.14+236~g1d0044f (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sat, 29 Dec 2012 16:50:51 +0000\r
+Message-ID: <87y5ggssyc.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.197.9.104\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: df4242471a0c8f99ee5abc9849039f5f (of first 20000 bytes)\r
+X-SpamAssassin-Score: -2.3\r
+X-SpamAssassin-SpamBar: --\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -2.3 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Sat, 29 Dec 2012 16:51:02 -0000\r
+\r
+\r
+On Fri, 28 Dec 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> This parses the subset of Xapian's boolean term quoting rules that are\r
+> used by make_boolean_term. This is provided as a generic string\r
+> utility, but will be used shortly in notmuch restore to parse and\r
+> optimize for ID queries.\r
+> ---\r
+> util/string-util.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+> util/string-util.h | 11 +++++++++++\r
+> 2 files changed, 66 insertions(+)\r
+>\r
+> diff --git a/util/string-util.c b/util/string-util.c\r
+> index e4bea21..83b4953 100644\r
+> --- a/util/string-util.c\r
+> +++ b/util/string-util.c\r
+> @@ -96,3 +96,58 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,\r
+> \r
+> return 0;\r
+> }\r
+> +\r
+> +int\r
+> +parse_boolean_term (void *ctx, const char *str,\r
+> + char **prefix_out, char **term_out)\r
+> +{\r
+> + *prefix_out = *term_out = NULL;\r
+> +\r
+> + /* Parse prefix */\r
+> + const char *pos = strchr (str, ':');\r
+> + if (! pos)\r
+> + goto FAIL;\r
+> + *prefix_out = talloc_strndup (ctx, str, pos - str);\r
+> + ++pos;\r
+> +\r
+> + /* Implement de-quoting compatible with make_boolean_term. */\r
+> + if (*pos == '"') {\r
+> + char *out = talloc_array (ctx, char, strlen (pos));\r
+> + int closed = 0;\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
+> + /* Found the closing quote. */\r
+> + closed = 1;\r
+> + break;\r
+> + }\r
+> + }\r
+> + *out++ = *pos++;\r
+> + }\r
+> + /* Did the term terminate without a closing quote or is there\r
+> + * trailing text after the closing quote? */\r
+> + if (!closed || *pos)\r
+> + goto FAIL;\r
+> + *out = '\0';\r
+> + } else {\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
+This looks like it will fail if a line contains trailing white space\r
+(and that seemed to be the case from my experiment). Is that wanted?\r
+\r
+If yes we may want to make the error message clearer as I got an error\r
+of the form\r
+Warning: cannot parse query: id:message-id@example.com \r
+and the fact that line contained trailing spaces was not clear.\r
+\r
+> +\r
+> + FAIL:\r
+> + talloc_free (*prefix_out);\r
+> + talloc_free (*term_out);\r
+> + return 1;\r
+> +}\r
+> diff --git a/util/string-util.h b/util/string-util.h\r
+> index b8844a3..43d49d0 100644\r
+> --- a/util/string-util.h\r
+> +++ b/util/string-util.h\r
+> @@ -33,4 +33,15 @@ char *strtok_len (char *s, const char *delim, size_t *len);\r
+> int make_boolean_term (void *talloc_ctx, const char *prefix, const char *term,\r
+> char **buf, size_t *len);\r
+> \r
+> +/* Parse a boolean term query produced by make_boolean_term, returning\r
+> + * the prefix in *prefix_out and the term in *term_out. *prefix_out\r
+> + * and *term_out will be talloc'd with context ctx.\r
+> + *\r
+> + * Return: 0 on success, non-zero on parse error (including trailing\r
+> + * data in str).\r
+> + */\r
+\r
+I think it would be worth detailing what requirements a boolean term\r
+here should meet to be parsed. In particular, since make_boolean_term\r
+is more restrictive than Xapian we should say whether this is like\r
+make_boolean_term, like Xapian or somewhere in between.\r
+\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+> +int\r
+> +parse_boolean_term (void *ctx, const char *str,\r
+> + char **prefix_out, char **term_out);\r
+> +\r
+> #endif\r
+> -- \r
+> 1.7.10.4\r