mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 03:48:10 +01:00
cli: add --output=files option to notmuch count
Add support for querying the total number of files associated with the messages matching the search. This is mostly useful with an id:<message-id> query for a single message.
This commit is contained in:
parent
cbc1b143db
commit
431571242c
1 changed files with 37 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
||||||
enum {
|
enum {
|
||||||
OUTPUT_THREADS,
|
OUTPUT_THREADS,
|
||||||
OUTPUT_MESSAGES,
|
OUTPUT_MESSAGES,
|
||||||
|
OUTPUT_FILES,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The following is to allow future options to be added more easily */
|
/* The following is to allow future options to be added more easily */
|
||||||
|
@ -32,6 +33,38 @@ enum {
|
||||||
EXCLUDE_FALSE,
|
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
|
static int
|
||||||
print_count (notmuch_database_t *notmuch, const char *query_str,
|
print_count (notmuch_database_t *notmuch, const char *query_str,
|
||||||
const char **exclude_tags, size_t exclude_tags_length, int output)
|
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:
|
case OUTPUT_THREADS:
|
||||||
printf ("%u\n", notmuch_query_count_threads (query));
|
printf ("%u\n", notmuch_query_count_threads (query));
|
||||||
break;
|
break;
|
||||||
|
case OUTPUT_FILES:
|
||||||
|
printf ("%u\n", count_files (query));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch_query_destroy (query);
|
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_OPT_KEYWORD, &output, "output", 'o',
|
||||||
(notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
|
(notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
|
||||||
{ "messages", OUTPUT_MESSAGES },
|
{ "messages", OUTPUT_MESSAGES },
|
||||||
|
{ "files", OUTPUT_FILES },
|
||||||
{ 0, 0 } } },
|
{ 0, 0 } } },
|
||||||
{ NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
|
{ NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
|
||||||
(notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
|
(notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
|
||||||
|
|
Loading…
Reference in a new issue