[PATCH 4/6] cli: add --output=files option to notmuch count
authorJani Nikula <jani@nikula.org>
Mon, 13 May 2013 18:26:59 +0000 (21:26 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:54:44 +0000 (09:54 -0800)
4d/6048ae21267a06f6735142fa6674905852efaf [new file with mode: 0644]

diff --git a/4d/6048ae21267a06f6735142fa6674905852efaf b/4d/6048ae21267a06f6735142fa6674905852efaf
new file mode 100644 (file)
index 0000000..ef54653
--- /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 6A19C431FBF\r
+       for <notmuch@notmuchmail.org>; Mon, 13 May 2013 11:27:28 -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 c7GXAn6D5jii for <notmuch@notmuchmail.org>;\r
+       Mon, 13 May 2013 11:27:22 -0700 (PDT)\r
+Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com\r
+       [209.85.217.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id EFDF4431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 13 May 2013 11:27:15 -0700 (PDT)\r
+Received: by mail-lb0-f169.google.com with SMTP id 10so1941441lbf.14\r
+       for <notmuch@notmuchmail.org>; Mon, 13 May 2013 11:27:14 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=x-received:from:to:subject:date:message-id:x-mailer:in-reply-to\r
+       :references:in-reply-to:references:x-gm-message-state;\r
+       bh=NG/O/Rbm6Yp8iPwA78WqtYtjhP1aDjP101L2NBI3HMg=;\r
+       b=C04OkV64bb/3SpQl6dDoJWfhl+JPMbF1yB9/n83sowungp8tMUqK5OEqjbBh9F07El\r
+       KKeKb9P2dGHziFcPqC7q5ggJExpUMb4y8taJSQUd1+q/gCVH/EXlVzeR/EIJtvxkAPpG\r
+       QNwXJXBP0MqNq5gABMWXnC7rsCBgtaNAbnCIfKS4zWDtnOx4XO+huHcSrAjlHum3umUs\r
+       4FSnfK1N4EdmcnOV9ILZI89gQJ5GwnMuWIjqhYNhdlpTLzpKFp2u9WXID1Hj+dWvU2Yx\r
+       eCy06MErGGKBTTJcSr/LCTUQLOFqb+7IUbkRi1FZetMUtg4KapWwh/VVVrqvlE3Jc1oN\r
+       9N/Q==\r
+X-Received: by 10.152.87.116 with SMTP id w20mr13902219laz.0.1368469634428;\r
+       Mon, 13 May 2013 11:27:14 -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 u6sm5927846lbe.4.2013.05.13.11.27.12\r
+       for <notmuch@notmuchmail.org>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Mon, 13 May 2013 11:27:13 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/6] cli: add --output=files option to notmuch count\r
+Date: Mon, 13 May 2013 21:26:59 +0300\r
+Message-Id:\r
+ <a2cd6f387b0c895a285f68b427ebea75fa0cedf2.1368467532.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1368467532.git.jani@nikula.org>\r
+References: <cover.1368467532.git.jani@nikula.org>\r
+In-Reply-To: <cover.1368467532.git.jani@nikula.org>\r
+References: <cover.1368467532.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQlTDNHStAUyA2SnyGCgF5VU9JRfV3BQv9ObxD0OZ9IXfT7adJS+lh2H9bhSm+hbjtY1THjx\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: Mon, 13 May 2013 18:27:28 -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