--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\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 5186D431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 14:34:21 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 rnQ+3MEYycJ8 for <notmuch@notmuchmail.org>;\r
+ Sat, 24 Nov 2012 14:34:21 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id CD668431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 14:34:20 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 44C7F10010B;\r
+ Sun, 25 Nov 2012 00:34:19 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: markwalters1009 <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 1/7] cli: allow query to come from stdin\r
+In-Reply-To: <1353763256-32336-2-git-send-email-markwalters1009@gmail.com>\r
+References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\r
+ <1353763256-32336-2-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.14+84~g8a199bf (http://notmuchmail.org) Emacs/24.2.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sun, 25 Nov 2012 00:34:19 +0200\r
+Message-ID: <m238zyk4us.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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, 24 Nov 2012 22:34:21 -0000\r
+\r
+On Sat, Nov 24 2012, markwalters1009 wrote:\r
+\r
+> From: Mark Walters <markwalters1009@gmail.com>\r
+>\r
+> After this series there will be times when a caller will want to pass\r
+> a very large query string to notmuch (eg a list of 10,000 message-ids)\r
+> and this can exceed the size of ARG_MAX. Hence allow notmuch to take\r
+> the query from stdin (if the query is -).\r
+\r
+\r
+> ---\r
+> query-string.c | 41 +++++++++++++++++++++++++++++++++++++++++\r
+> 1 files changed, 41 insertions(+), 0 deletions(-)\r
+>\r
+> diff --git a/query-string.c b/query-string.c\r
+> index 6536512..b1fbdeb 100644\r
+> --- a/query-string.c\r
+> +++ b/query-string.c\r
+> @@ -20,6 +20,44 @@\r
+> \r
+> #include "notmuch-client.h"\r
+> \r
+> +/* Read a single query string from STDIN, using\r
+> + * 'ctx' as the talloc owner for all allocations.\r
+> + *\r
+> + * This function returns NULL in case of insufficient memory or read\r
+> + * errors.\r
+> + */\r
+> +static char *\r
+> +query_string_from_stdin (void *ctx)\r
+\r
+Austin provided pretty nice alternative implementation of \r
+query_string_from_stdin() in his reply so I decline to\r
+comment minor formatting issue below :D\r
+\r
+> +{\r
+> + char *query_string;\r
+> + char buf[4096];\r
+> + ssize_t remain;\r
+> +\r
+> + query_string = talloc_strdup (ctx, "");\r
+> + if (query_string == NULL)\r
+> + return NULL;\r
+> +\r
+> + for (;;) {\r
+> + remain = read (STDIN_FILENO, buf, sizeof(buf) - 1);\r
+> + if (remain == 0)\r
+> + break;\r
+> + if (remain < 0) {\r
+> + if (errno == EINTR)\r
+> + continue;\r
+> + fprintf (stderr, "Error: reading from standard input: %s\n",\r
+> + strerror (errno));\r
+> + return NULL;\r
+> + }\r
+> +\r
+> + buf[remain] = '\0';\r
+> + query_string = talloc_strdup_append (query_string, buf);\r
+> + if (query_string == NULL)\r
+> + return NULL;\r
+> + }\r
+> +\r
+> + return query_string;\r
+> +}\r
+> +\r
+> /* Construct a single query string from the passed arguments, using\r
+> * 'ctx' as the talloc owner for all allocations.\r
+> *\r
+> @@ -35,6 +73,9 @@ query_string_from_args (void *ctx, int argc, char *argv[])\r
+> char *query_string;\r
+> int i;\r
+> \r
+> + if ((argc == 1) && (strcmp ("-", argv[0]) == 0))\r
+\r
+the argument order in strcmp() is not consistent with all the \r
+other uses of strcmp () in the codebase.\r
+\r
+> + return query_string_from_stdin (ctx);\r
+> +\r
+> query_string = talloc_strdup (ctx, "");\r
+> if (query_string == NULL)\r
+> return NULL;\r
+> -- \r
+> 1.7.9.1\r
+\r
+Tomi\r