1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-client.h"
24 notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
26 notmuch_config_t *config;
27 notmuch_database_t *notmuch;
28 notmuch_query_t *query;
30 notmuch_messages_t *messages;
31 notmuch_message_t *message;
34 config = notmuch_config_open (ctx, NULL, NULL);
38 notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
39 NOTMUCH_DATABASE_MODE_READ_ONLY);
43 query = notmuch_query_create (notmuch, "");
45 fprintf (stderr, "Out of memory\n");
48 notmuch_query_set_sort (query, NOTMUCH_SORT_MESSAGE_ID);
51 output = fopen (argv[0], "w");
53 fprintf (stderr, "Error opening %s for writing: %s\n",
54 argv[0], strerror (errno));
61 for (messages = notmuch_query_search_messages (query, 0, -1);
62 notmuch_messages_has_more (messages);
63 notmuch_messages_advance (messages))
66 message = notmuch_messages_get (messages);
69 "%s (", notmuch_message_get_message_id (message));
71 for (tags = notmuch_message_get_tags (message);
72 notmuch_tags_has_more (tags);
73 notmuch_tags_advance (tags))
76 fprintf (output, " ");
78 fprintf (output, "%s", notmuch_tags_get (tags));
83 fprintf (output, ")\n");
85 notmuch_message_destroy (message);
91 notmuch_query_destroy (query);
92 notmuch_database_close (notmuch);