int
notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
{
- FILE *output = NULL;
- notmuch_database_t *notmuch = NULL;
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
notmuch_query_t *query;
+ FILE *output;
notmuch_messages_t *messages;
notmuch_message_t *message;
notmuch_tags_t *tags;
- int ret = 0;
+
+ 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 = notmuch_query_create (notmuch, "");
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ return 1;
+ }
+ notmuch_query_set_sort (query, NOTMUCH_SORT_MESSAGE_ID);
if (argc) {
output = fopen (argv[0], "w");
if (output == NULL) {
fprintf (stderr, "Error opening %s for writing: %s\n",
argv[0], strerror (errno));
- ret = 1;
- goto DONE;
+ return 1;
}
} else {
output = stdout;
}
- notmuch = notmuch_database_open (NULL);
- if (notmuch == NULL) {
- ret = 1;
- goto DONE;
- }
-
- query = notmuch_query_create (notmuch, "");
- if (query == NULL) {
- fprintf (stderr, "Out of memory\n");
- ret = 1;
- goto DONE;
- }
-
- notmuch_query_set_sort (query, NOTMUCH_SORT_MESSAGE_ID);
-
for (messages = notmuch_query_search_messages (query);
notmuch_messages_has_more (messages);
notmuch_messages_advance (messages))
notmuch_message_destroy (message);
}
- notmuch_query_destroy (query);
-
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
- if (output && output != stdout)
+ if (output != stdout)
fclose (output);
- return ret;
+ notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
+
+ return 0;
}
int
notmuch_reply_command (void *ctx, int argc, char *argv[])
{
- void *local = talloc_new (ctx);
- notmuch_query_t *query = NULL;
- notmuch_database_t *notmuch = NULL;
- GMimeMessage *reply = NULL;
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
+ notmuch_query_t *query;
+ GMimeMessage *reply;
char *query_string;
notmuch_messages_t *messages;
notmuch_message_t *message;
};
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);
reply = g_mime_message_new (1);
if (reply == NULL) {
fprintf (stderr, "Out of memory\n");
- ret = 1;
- goto DONE;
+ return 1;
}
/* XXX: We need a configured email address (or addresses) for
notmuch_message_destroy (message);
}
- DONE:
- if (local)
- talloc_free (local);
-
- if (query)
- notmuch_query_destroy (query);
-
- if (notmuch)
- notmuch_database_close (notmuch);
-
- if (reply)
- g_object_unref (G_OBJECT (reply));
+ notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
return ret;
}
int
notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
{
- FILE *input = NULL;
- notmuch_database_t *notmuch = NULL;
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
+ FILE *input;
char *line = NULL;
size_t line_size;
ssize_t line_len;
regex_t regex;
int rerr;
- int ret = 0;
+
+ 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;
if (argc) {
input = fopen (argv[0], "r");
if (input == NULL) {
fprintf (stderr, "Error opening %s for reading: %s\n",
argv[0], strerror (errno));
- ret = 1;
- goto DONE;
+ return 1;
}
} else {
printf ("No filename given. Reading dump from stdin.\n");
input = stdin;
}
- notmuch = notmuch_database_open (NULL);
- if (notmuch == NULL) {
- ret = 1;
- goto DONE;
- }
-
/* Dump output is one line per message. We match a sequence of
* non-space characters for the message-id, then one or more
* spaces, then a list of space-separated tags as a sequence of
regfree (®ex);
- DONE:
if (line)
free (line);
- if (notmuch)
- notmuch_database_close (notmuch);
- if (input && input != stdin)
+
+ notmuch_database_close (notmuch);
+ if (input != stdin)
fclose (input);
- return ret;
+ return 0;
}
int
notmuch_search_command (void *ctx, int argc, char *argv[])
{
- void *local = talloc_new (ctx);
- notmuch_database_t *notmuch = NULL;
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
notmuch_query_t *query;
notmuch_threads_t *threads;
notmuch_thread_t *thread;
char *query_str;
const char *relative_date;
time_t date;
- notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
- 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_str = query_string_from_args (local, argc, argv);
+ query_str = query_string_from_args (ctx, argc, argv);
+ if (query_str == NULL) {
+ fprintf (stderr, "Out of moemory.\n");
+ return 1;
+ }
query = notmuch_query_create (notmuch, query_str);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
- ret = 1;
- goto DONE;
+ return 1;
}
for (threads = notmuch_query_search_threads (query);
thread = notmuch_threads_get (threads);
date = notmuch_thread_get_oldest_date (thread);
- relative_date = notmuch_time_relative_date (local, date);
+ relative_date = notmuch_time_relative_date (ctx, date);
printf ("thread:%s %12s %s",
notmuch_thread_get_thread_id (thread),
}
notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
- talloc_free (local);
-
- return ret;
+ return 0;
}
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"
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;
- query_string = query_string_from_args (local, argc, argv);
+ notmuch = notmuch_database_open (notmuch_config_get_database_path (config));
+ if (notmuch == NULL)
+ return 1;
+
+ 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);
printf ("\fheader{\n");
- printf ("%s\n", _get_one_line_summary (local, message));
+ printf ("%s\n", _get_one_line_summary (ctx, message));
printf ("%s\n", notmuch_message_get_header (message, "subject"));
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;
}
int
notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
{
- void *local;
int *add_tags, *remove_tags;
int add_tags_count = 0;
int remove_tags_count = 0;
char *query_string;
- notmuch_database_t *notmuch = NULL;
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
notmuch_query_t *query;
notmuch_messages_t *messages;
notmuch_message_t *message;
- int ret = 0;
int i;
- local = talloc_new (ctx);
- if (local == NULL) {
- ret = 1;
- goto DONE;
- }
-
- add_tags = talloc_size (local, argc * sizeof (int));
+ add_tags = talloc_size (ctx, argc * sizeof (int));
if (add_tags == NULL) {
- ret = 1;
- goto DONE;
+ fprintf (stderr, "Out of memory.\n");
+ return 1;
}
- remove_tags = talloc_size (local, argc * sizeof (int));
+ remove_tags = talloc_size (ctx, argc * sizeof (int));
if (remove_tags == NULL) {
- ret = 1;
- goto DONE;
+ fprintf (stderr, "Out of memory.\n");
+ return 1;
}
for (i = 0; i < argc; i++) {
if (add_tags_count == 0 && remove_tags_count == 0) {
fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
- ret = 1;
- goto DONE;
+ return 1;
}
if (i == argc) {
fprintf (stderr, "Error: 'notmuch tag' requires at least one search term.\n");
- ret = 1;
- goto DONE;
+ return 1;
}
- 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 - i, &argv[i]);
+ query_string = query_string_from_args (ctx, argc - i, &argv[i]);
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);
}
notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
-
- talloc_free (local);
-
- return ret;
+ return 0;
}