1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
4 * Copyright © 2009 Keith Packard
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see http://www.gnu.org/licenses/ .
19 * Author: Keith Packard <keithp@keithp.com>
22 #include "notmuch-client.h"
25 notmuch_count_command (void *ctx, int argc, char *argv[])
27 notmuch_config_t *config;
28 notmuch_database_t *notmuch;
29 notmuch_query_t *query;
32 notmuch_bool_t output_messages = TRUE;
34 argc--; argv++; /* skip subcommand argument */
36 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
37 if (strcmp (argv[i], "--") == 0) {
41 if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
42 const char *opt = argv[i] + sizeof ("--output=") - 1;
43 if (strcmp (opt, "threads") == 0) {
44 output_messages = FALSE;
45 } else if (strcmp (opt, "messages") == 0) {
46 output_messages = TRUE;
48 fprintf (stderr, "Invalid value for --output: %s\n", opt);
52 fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
60 config = notmuch_config_open (ctx, NULL, NULL);
64 notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
65 NOTMUCH_DATABASE_MODE_READ_ONLY);
69 query_str = query_string_from_args (ctx, argc, argv);
70 if (query_str == NULL) {
71 fprintf (stderr, "Out of memory.\n");
75 if (*query_str == '\0') {
76 query_str = talloc_strdup (ctx, "");
79 query = notmuch_query_create (notmuch, query_str);
81 fprintf (stderr, "Out of memory\n");
86 printf ("%u\n", notmuch_query_count_messages (query));
88 printf ("%u\n", notmuch_query_count_threads (query));
90 notmuch_query_destroy (query);
91 notmuch_database_close (notmuch);