From c22a899ca817798b30ae541081be1e0f5d4570c0 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Mon, 13 May 2013 21:26:59 +0300 Subject: [PATCH] [PATCH 4/6] cli: add --output=files option to notmuch count --- 4d/6048ae21267a06f6735142fa6674905852efaf | 149 ++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 4d/6048ae21267a06f6735142fa6674905852efaf diff --git a/4d/6048ae21267a06f6735142fa6674905852efaf b/4d/6048ae21267a06f6735142fa6674905852efaf new file mode 100644 index 000000000..ef546532e --- /dev/null +++ b/4d/6048ae21267a06f6735142fa6674905852efaf @@ -0,0 +1,149 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 6A19C431FBF + for ; Mon, 13 May 2013 11:27:28 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id c7GXAn6D5jii for ; + Mon, 13 May 2013 11:27:22 -0700 (PDT) +Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com + [209.85.217.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id EFDF4431FB6 + for ; Mon, 13 May 2013 11:27:15 -0700 (PDT) +Received: by mail-lb0-f169.google.com with SMTP id 10so1941441lbf.14 + for ; Mon, 13 May 2013 11:27:14 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-received:from:to:subject:date:message-id:x-mailer:in-reply-to + :references:in-reply-to:references:x-gm-message-state; + bh=NG/O/Rbm6Yp8iPwA78WqtYtjhP1aDjP101L2NBI3HMg=; + b=C04OkV64bb/3SpQl6dDoJWfhl+JPMbF1yB9/n83sowungp8tMUqK5OEqjbBh9F07El + KKeKb9P2dGHziFcPqC7q5ggJExpUMb4y8taJSQUd1+q/gCVH/EXlVzeR/EIJtvxkAPpG + QNwXJXBP0MqNq5gABMWXnC7rsCBgtaNAbnCIfKS4zWDtnOx4XO+huHcSrAjlHum3umUs + 4FSnfK1N4EdmcnOV9ILZI89gQJ5GwnMuWIjqhYNhdlpTLzpKFp2u9WXID1Hj+dWvU2Yx + eCy06MErGGKBTTJcSr/LCTUQLOFqb+7IUbkRi1FZetMUtg4KapWwh/VVVrqvlE3Jc1oN + 9N/Q== +X-Received: by 10.152.87.116 with SMTP id w20mr13902219laz.0.1368469634428; + Mon, 13 May 2013 11:27:14 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi. + [88.195.118.211]) + by mx.google.com with ESMTPSA id u6sm5927846lbe.4.2013.05.13.11.27.12 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 13 May 2013 11:27:13 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 4/6] cli: add --output=files option to notmuch count +Date: Mon, 13 May 2013 21:26:59 +0300 +Message-Id: + +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-Gm-Message-State: + ALoCoQlTDNHStAUyA2SnyGCgF5VU9JRfV3BQv9ObxD0OZ9IXfT7adJS+lh2H9bhSm+hbjtY1THjx +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 13 May 2013 18:27:28 -0000 + +Add support for querying the total number of files associated with the +messages matching the search. This is mostly useful with an +id: query for a single message. +--- + notmuch-count.c | 37 +++++++++++++++++++++++++++++++++++++ + 1 file changed, 37 insertions(+) + +diff --git a/notmuch-count.c b/notmuch-count.c +index 8772cff..01e4e30 100644 +--- a/notmuch-count.c ++++ b/notmuch-count.c +@@ -24,6 +24,7 @@ + enum { + OUTPUT_THREADS, + OUTPUT_MESSAGES, ++ OUTPUT_FILES, + }; + + /* The following is to allow future options to be added more easily */ +@@ -32,6 +33,38 @@ enum { + EXCLUDE_FALSE, + }; + ++static unsigned int ++count_files (notmuch_query_t *query) ++{ ++ notmuch_messages_t *messages; ++ notmuch_message_t *message; ++ notmuch_filenames_t *filenames; ++ unsigned int count = 0; ++ ++ messages = notmuch_query_search_messages (query); ++ if (messages == NULL) ++ return 0; ++ ++ for (; ++ notmuch_messages_valid (messages); ++ notmuch_messages_move_to_next (messages)) { ++ message = notmuch_messages_get (messages); ++ filenames = notmuch_message_get_filenames (message); ++ ++ for (; ++ notmuch_filenames_valid (filenames); ++ notmuch_filenames_move_to_next (filenames)) ++ count++; ++ ++ notmuch_filenames_destroy (filenames); ++ notmuch_message_destroy (message); ++ } ++ ++ notmuch_messages_destroy (messages); ++ ++ return count; ++} ++ + static int + print_count (notmuch_database_t *notmuch, const char *query_str, + const char **exclude_tags, size_t exclude_tags_length, int output) +@@ -55,6 +88,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str, + case OUTPUT_THREADS: + printf ("%u\n", notmuch_query_count_threads (query)); + break; ++ case OUTPUT_FILES: ++ printf ("%u\n", count_files (query)); ++ break; + } + + notmuch_query_destroy (query); +@@ -102,6 +138,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) + { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', + (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS }, + { "messages", OUTPUT_MESSAGES }, ++ { "files", OUTPUT_FILES }, + { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', + (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, +-- +1.7.10.4 + -- 2.26.2