Re: [PATCH v2 1/7] cli: allow query to come from stdin
authorMark Walters <markwalters1009@gmail.com>
Sat, 24 Nov 2012 13:24:33 +0000 (13:24 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:50 +0000 (09:50 -0800)
a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a [new file with mode: 0644]

diff --git a/a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a b/a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a
new file mode 100644 (file)
index 0000000..9099c55
--- /dev/null
@@ -0,0 +1,159 @@
+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 0DD9D431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:24:41 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.401\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.401 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       FREEMAIL_REPLY=2.499, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3]\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 nj46y3h3PQo2 for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Nov 2012 05:24:40 -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 31EC5431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:24:40 -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 1TcFii-0001xt-U8; Sat, 24 Nov 2012 13:24:35 +0000\r
+Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] 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 1TcFii-0007Ms-JS; Sat, 24 Nov 2012 13:24:32 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: 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+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sat, 24 Nov 2012 13:24:33 +0000\r
+Message-ID: <87mwy7jfqm.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 93.97.24.31\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 9fbe8b4722f780f6d807d328c7aee5c2 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.2\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 -1.2 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
+       *  1.0 FREEMAIL_REPLY From and body contain different freemails\r
+       *  0.1 AWL AWL: From: address is in the auto white-list\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, 24 Nov 2012 13:24:41 -0000\r
+\r
+\r
+I should have said the code for reading from stdin was \r
+stolen from Peter's patch for notmuch-insert\r
+id:1343223767-9812-4-git-send-email-novalazy@gmail.com\r
+(errors are of course mine)\r
+\r
+My apologies for not mentioning this in the commit message.\r
+\r
+Mark\r
+\r
+\r
+\r
+On Sat, 24 Nov 2012, markwalters1009 <markwalters1009@gmail.com> wrote:\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
+>  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
+> +    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
+> +    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