[PATCH v2 1/7] cli: allow query to come from stdin
authormarkwalters1009 <markwalters1009@gmail.com>
Sat, 24 Nov 2012 13:20:50 +0000 (13:20 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:49 +0000 (09:50 -0800)
bf/4f3bf0a9e6a68ab544e3c51e93f3a1868e6d5e [new file with mode: 0644]

diff --git a/bf/4f3bf0a9e6a68ab544e3c51e93f3a1868e6d5e b/bf/4f3bf0a9e6a68ab544e3c51e93f3a1868e6d5e
new file mode 100644 (file)
index 0000000..014f736
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <markwalters1009@gmail.com>\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 83905431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:21:12 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       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 Ze9zCkWgspL2 for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Nov 2012 05:21:10 -0800 (PST)\r
+Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 822C5431FC0   for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:21:05 -0800\r
+ (PST)\r
+Received: by mail-wg0-f45.google.com with SMTP id dq11so3973532wgb.2\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:21:03 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=FCVh/gxBXG1O6Lt2mYXnoXzaGl1oLD6pAd/1YfJkoYQ=;\r
+       b=P3zP59r3xa6mMS8lmvIgf0p3w9QvSstl9xWYH+x+cQS2TA0tAClDAW35vOvgGp0Ss2\r
+       Ybv6gtR26rT6LN1iLFPyBmb0WjDftRAL3Vlv9Ci4q4yhqoVgM6/b+Zug86tJY9qTlvdf\r
+       G7WTUafRTZGpiScp8JtyOXRHjrJmH3dD6yQZveEMo4QqcQdrwZD39My6VVbkeAZlM0RK\r
+       rbBOqIEw5/AaVJiQbrWK0fB9l7x/cEuuJHRyyzbgId7YAgpiTiBVIHM2O1pRtb8jQVsM\r
+       LAq0MsjZBCgApGg6sCiohiT+KOHzb3Ge5W+2uEeyNi4QAVg67ooc75o1rGLXAeqAq9Br\r
+       YNzw==\r
+Received: by 10.180.86.7 with SMTP id l7mr10271711wiz.5.1353763262987;\r
+       Sat, 24 Nov 2012 05:21:02 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id gz3sm12685328wib.2.2012.11.24.05.21.01\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 24 Nov 2012 05:21:02 -0800 (PST)\r
+From: markwalters1009 <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 1/7] cli: allow query to come from stdin\r
+Date: Sat, 24 Nov 2012 13:20:50 +0000\r
+Message-Id: <1353763256-32336-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\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:21:13 -0000\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
+ 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
+\r