[PATCH v2 4/7] cli: add --output=files option to notmuch count
authorJani Nikula <jani@nikula.org>
Sun, 9 Jun 2013 11:03:10 +0000 (14:03 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:55:29 +0000 (09:55 -0800)
9e/467a365afee3d3d78c3c93da78721669800b50 [new file with mode: 0644]

diff --git a/9e/467a365afee3d3d78c3c93da78721669800b50 b/9e/467a365afee3d3d78c3c93da78721669800b50
new file mode 100644 (file)
index 0000000..87121cd
--- /dev/null
@@ -0,0 +1,149 @@
+Return-Path: <jani@nikula.org>\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 2D3EB431FC2\r
+       for <notmuch@notmuchmail.org>; Sun,  9 Jun 2013 04:04:06 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 ABvp6MUG4+VX for <notmuch@notmuchmail.org>;\r
+       Sun,  9 Jun 2013 04:04:00 -0700 (PDT)\r
+Received: from mail-la0-f43.google.com (mail-la0-f43.google.com\r
+       [209.85.215.43]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 8E497431FD8\r
+       for <notmuch@notmuchmail.org>; Sun,  9 Jun 2013 04:03:36 -0700 (PDT)\r
+Received: by mail-la0-f43.google.com with SMTP id gw10so4950503lab.30\r
+       for <notmuch@notmuchmail.org>; Sun, 09 Jun 2013 04:03:34 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
+       :in-reply-to:references:x-gm-message-state;\r
+       bh=NG/O/Rbm6Yp8iPwA78WqtYtjhP1aDjP101L2NBI3HMg=;\r
+       b=E6EeFt0pC3z3QX39/xdp47mQXTnyjRUiqhdN6NejYDJ/KkB0bDHVu0uwvTWlY2zobd\r
+       59RQDvAOnK/us3hjAf6NwlL0LtUQgEG6EUPqs1Ui/C70DmQpsKUCVxCZ5WGLo9OuouMg\r
+       RgcvkbB9H+t1HqfOxN9b5ngOsE9HUzr2BiqoJi2+8C4KSAj9Sy6zlj3YcB37CXbOPuMC\r
+       mdU78LrkszxFQm3AJfEYRhcwSkXMtT3j4CBiUBnt7YntWfEeLa7LF43uLYCbgi9/l4Qe\r
+       hoPHKxT+AGXw5EOupHFE9ayV/C6N0XtqROuxQHYSOCvofW07j1feD3+wmEJ5n4H5RX7q\r
+       mbAA==\r
+X-Received: by 10.152.4.163 with SMTP id l3mr2827193lal.60.1370775814906;\r
+       Sun, 09 Jun 2013 04:03:34 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi.\r
+       [88.195.118.211])\r
+       by mx.google.com with ESMTPSA id x8sm2523500lae.10.2013.06.09.04.03.33\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 09 Jun 2013 04:03:34 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 4/7] cli: add --output=files option to notmuch count\r
+Date: Sun,  9 Jun 2013 14:03:10 +0300\r
+Message-Id:\r
+ <766fbdc385e9d1b6145261d65cb697d4c6e378c1.1370775663.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1370775663.git.jani@nikula.org>\r
+References: <cover.1370775663.git.jani@nikula.org>\r
+In-Reply-To: <cover.1370775663.git.jani@nikula.org>\r
+References: <cover.1370775663.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQl0A/x+A9fqWKFdlIrNt3Qt+TZt29eyBjidRqPmLAgwjEQAuWdFcn757GZi5iGvccP/nWvT\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: Sun, 09 Jun 2013 11:04:06 -0000\r
+\r
+Add support for querying the total number of files associated with the\r
+messages matching the search. This is mostly useful with an\r
+id:<message-id> query for a single message.\r
+---\r
+ notmuch-count.c |   37 +++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 37 insertions(+)\r
+\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index 8772cff..01e4e30 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -24,6 +24,7 @@\r
+ enum {\r
+     OUTPUT_THREADS,\r
+     OUTPUT_MESSAGES,\r
++    OUTPUT_FILES,\r
+ };\r
\r
+ /* The following is to allow future options to be added more easily */\r
+@@ -32,6 +33,38 @@ enum {\r
+     EXCLUDE_FALSE,\r
+ };\r
\r
++static unsigned int\r
++count_files (notmuch_query_t *query)\r
++{\r
++    notmuch_messages_t *messages;\r
++    notmuch_message_t *message;\r
++    notmuch_filenames_t *filenames;\r
++    unsigned int count = 0;\r
++\r
++    messages = notmuch_query_search_messages (query);\r
++    if (messages == NULL)\r
++      return 0;\r
++\r
++    for (;\r
++       notmuch_messages_valid (messages);\r
++       notmuch_messages_move_to_next (messages)) {\r
++      message = notmuch_messages_get (messages);\r
++      filenames = notmuch_message_get_filenames (message);\r
++\r
++      for (;\r
++           notmuch_filenames_valid (filenames);\r
++           notmuch_filenames_move_to_next (filenames))\r
++          count++;\r
++\r
++      notmuch_filenames_destroy (filenames);\r
++      notmuch_message_destroy (message);\r
++    }\r
++\r
++    notmuch_messages_destroy (messages);\r
++\r
++    return count;\r
++}\r
++\r
+ static int\r
+ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+            const char **exclude_tags, size_t exclude_tags_length, int output)\r
+@@ -55,6 +88,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+     case OUTPUT_THREADS:\r
+       printf ("%u\n", notmuch_query_count_threads (query));\r
+       break;\r
++    case OUTPUT_FILES:\r
++      printf ("%u\n", count_files (query));\r
++      break;\r
+     }\r
\r
+     notmuch_query_destroy (query);\r
+@@ -102,6 +138,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+       { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',\r
+         (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },\r
+                                 { "messages", OUTPUT_MESSAGES },\r
++                                { "files", OUTPUT_FILES },\r
+                                 { 0, 0 } } },\r
+       { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
+         (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+-- \r
+1.7.10.4\r
+\r