From: Jani Nikula Date: Sun, 9 Jun 2013 11:03:10 +0000 (+0300) Subject: [PATCH v2 4/7] cli: add --output=files option to notmuch count X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ad1124ac97e8e62ae1a18250910e93bb9f3045b6;p=notmuch-archives.git [PATCH v2 4/7] cli: add --output=files option to notmuch count --- diff --git a/9e/467a365afee3d3d78c3c93da78721669800b50 b/9e/467a365afee3d3d78c3c93da78721669800b50 new file mode 100644 index 000000000..87121cdff --- /dev/null +++ b/9e/467a365afee3d3d78c3c93da78721669800b50 @@ -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 2D3EB431FC2 + for ; Sun, 9 Jun 2013 04:04:06 -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 ABvp6MUG4+VX for ; + Sun, 9 Jun 2013 04:04:00 -0700 (PDT) +Received: from mail-la0-f43.google.com (mail-la0-f43.google.com + [209.85.215.43]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8E497431FD8 + for ; Sun, 9 Jun 2013 04:03:36 -0700 (PDT) +Received: by mail-la0-f43.google.com with SMTP id gw10so4950503lab.30 + for ; Sun, 09 Jun 2013 04:03:34 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references + :in-reply-to:references:x-gm-message-state; + bh=NG/O/Rbm6Yp8iPwA78WqtYtjhP1aDjP101L2NBI3HMg=; + b=E6EeFt0pC3z3QX39/xdp47mQXTnyjRUiqhdN6NejYDJ/KkB0bDHVu0uwvTWlY2zobd + 59RQDvAOnK/us3hjAf6NwlL0LtUQgEG6EUPqs1Ui/C70DmQpsKUCVxCZ5WGLo9OuouMg + RgcvkbB9H+t1HqfOxN9b5ngOsE9HUzr2BiqoJi2+8C4KSAj9Sy6zlj3YcB37CXbOPuMC + mdU78LrkszxFQm3AJfEYRhcwSkXMtT3j4CBiUBnt7YntWfEeLa7LF43uLYCbgi9/l4Qe + hoPHKxT+AGXw5EOupHFE9ayV/C6N0XtqROuxQHYSOCvofW07j1feD3+wmEJ5n4H5RX7q + mbAA== +X-Received: by 10.152.4.163 with SMTP id l3mr2827193lal.60.1370775814906; + Sun, 09 Jun 2013 04:03:34 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi. + [88.195.118.211]) + by mx.google.com with ESMTPSA id x8sm2523500lae.10.2013.06.09.04.03.33 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 09 Jun 2013 04:03:34 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 4/7] cli: add --output=files option to notmuch count +Date: Sun, 9 Jun 2013 14:03:10 +0300 +Message-Id: + <766fbdc385e9d1b6145261d65cb697d4c6e378c1.1370775663.git.jani@nikula.org> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-Gm-Message-State: + ALoCoQl0A/x+A9fqWKFdlIrNt3Qt+TZt29eyBjidRqPmLAgwjEQAuWdFcn757GZi5iGvccP/nWvT +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: Sun, 09 Jun 2013 11:04:06 -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 +