From: Jani Nikula Date: Sat, 17 Aug 2013 12:11:29 +0000 (+0300) Subject: [PATCH v3 4/8] cli: add --output=files option to notmuch count X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9441e8b932aeb458da787c3aa4a3981700ee30ab;p=notmuch-archives.git [PATCH v3 4/8] cli: add --output=files option to notmuch count --- diff --git a/03/2c2506e0670ad2fd3906a0945df0f93b89c9d6 b/03/2c2506e0670ad2fd3906a0945df0f93b89c9d6 new file mode 100644 index 000000000..589fb088e --- /dev/null +++ b/03/2c2506e0670ad2fd3906a0945df0f93b89c9d6 @@ -0,0 +1,148 @@ +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 49B4C42116E + for ; Sat, 17 Aug 2013 05:12: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 Lnpr710Vnusl for ; + Sat, 17 Aug 2013 05:12:01 -0700 (PDT) +Received: from mail-bk0-f49.google.com (mail-bk0-f49.google.com + [209.85.214.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B297A421164 + for ; Sat, 17 Aug 2013 05:11:44 -0700 (PDT) +Received: by mail-bk0-f49.google.com with SMTP id r7so910343bkg.22 + for ; Sat, 17 Aug 2013 05:11:43 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=NG/O/Rbm6Yp8iPwA78WqtYtjhP1aDjP101L2NBI3HMg=; + b=Slu5qFu9Yb0gHbPMERFEATr+ex6RHHIjc/fNOoxEw4DfN6a5TPQYImS92BpmtWB3IA + HUFdGquksv7NPs4U9vdFayth0QCaDNe/kQN38AOj3QaTONzSBVdwWG88hCga27ER21bs + ENOdnsrmjzsKWep9cPW4rXjkb/W66ZO54uGVTpwuBMpR45UeToiWFZRa+6M6hS+NDDmv + cdHPj4c/Vptr50MWGGUorT7opmvEuENq4yVLam3VncopKnNzX0o3dWw1aaHzem0YpJpT + i6+MOBREwRzl8vXZsYVsagJN5QvXyY/YqRLIEupKwA9+5X8+st9ktP/JrnYXc3lmYlGD + TbMw== +X-Gm-Message-State: + ALoCoQkVn+TxksUWrcy8joWdWxa7LdBtPRLuRW178nyZQelD9ZigHF9R+ychhjRplMBzIrcBKPUu +X-Received: by 10.204.225.12 with SMTP id iq12mr1652252bkb.4.1376741503399; + Sat, 17 Aug 2013 05:11:43 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id ku9sm251156bkb.1.1969.12.31.16.00.00 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 17 Aug 2013 05:11:42 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v3 4/8] cli: add --output=files option to notmuch count +Date: Sat, 17 Aug 2013 15:11:29 +0300 +Message-Id: + +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: +References: +In-Reply-To: +References: +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: Sat, 17 Aug 2013 12:12: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 +