1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
4 * Copyright © 2009 Jan Janak
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: Jan Janak <jan@ryngle.com>
22 #include "notmuch-client.h"
25 print_tags (notmuch_tags_t *tags)
29 while ((t = notmuch_tags_get (tags))) {
31 notmuch_tags_move_to_next (tags);
36 notmuch_search_tags_command (void *ctx, int argc, char *argv[])
38 notmuch_messages_t *msgs;
40 notmuch_config_t *config;
41 notmuch_database_t *db;
42 notmuch_query_t *query;
50 if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) {
54 db = notmuch_database_open (notmuch_config_get_database_path (config),
55 NOTMUCH_DATABASE_MODE_READ_ONLY);
61 if ((query_str = query_string_from_args (ctx, argc, argv)) == NULL) {
62 fprintf (stderr, "Out of memory.\n");
66 if (*query_str == '\0') {
67 fprintf (stderr, "Error: Invalid search string.\n");
71 if ((query = notmuch_query_create (db, query_str)) == NULL) {
72 fprintf (stderr, "Out of memory\n");
77 msgs = notmuch_query_search_messages (query);
78 if ((tags = notmuch_messages_collect_tags (msgs)) == NULL) goto error;
80 if ((tags = notmuch_database_get_all_tags (db)) == NULL) {
81 fprintf (stderr, "Error while getting tags from the database.\n");
88 notmuch_tags_destroy (tags);
89 if (query) notmuch_query_destroy (query);
90 notmuch_database_close (db);
94 if (tags) notmuch_tags_destroy (tags);
95 if (query) notmuch_query_destroy (query);
96 if (db) notmuch_database_close (db);