int
notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
{
- void *local = talloc_new (ctx);
- char *query_string;
- notmuch_database_t *notmuch = NULL;
- notmuch_query_t *query = NULL;
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
+ notmuch_query_t *query;
notmuch_messages_t *messages;
notmuch_message_t *message;
- int ret = 0;
+ char *query_string;
const char *headers[] = {
- "From", "To", "Cc", "Bcc", "Date"
+ "Subject", "From", "To", "Cc", "Bcc", "Date"
};
const char *name, *value;
unsigned int i;
- notmuch = notmuch_database_open (NULL);
- if (notmuch == NULL) {
- ret = 1;
- goto DONE;
- }
+ config = notmuch_config_open (ctx, NULL, NULL);
+ if (config == NULL)
+ return 1;
+
+ notmuch = notmuch_database_open (notmuch_config_get_database_path (config));
+ if (notmuch == NULL)
+ return 1;
- query_string = query_string_from_args (local, argc, argv);
+ query_string = query_string_from_args (ctx, argc, argv);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
- ret = 1;
- goto DONE;
+ return 1;
}
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
- ret = 1;
- goto DONE;
+ return 1;
}
- for (messages = notmuch_query_search_messages (query);
+ for (messages = notmuch_query_search_messages (query, 0, -1);
notmuch_messages_has_more (messages);
notmuch_messages_advance (messages))
{
printf ("\fheader{\n");
- printf ("%s\n", _get_one_line_summary (local, message));
-
- printf ("%s\n", notmuch_message_get_header (message, "subject"));
+ printf ("%s\n", _get_one_line_summary (ctx, message));
for (i = 0; i < ARRAY_SIZE (headers); i++) {
name = headers[i];
notmuch_message_destroy (message);
}
- DONE:
- if (local)
- talloc_free (local);
-
- if (query)
- notmuch_query_destroy (query);
-
- if (notmuch)
- notmuch_database_close (notmuch);
+ notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
- return ret;
+ return 0;
}