All of the following commands:
notmuch dump
notmuch reply
notmuch restore
notmuch search
notmuch show
notmuch tag
were calling notmuch_database_open with an argument of NULL. This was
a legitimate call until the recent addition of configuration, after
which it is expected that all commands will lookup the correct path in
the configuration file. So fix all these commands to do that.
Also, while touching all of these commands, we fix them to use the
talloc context that is passed in rather than creating a local talloc
context. We also switch from using goto for return values, to doing
direct returns as soon as an error is detected, (which can be leak
free thanks to talloc).
int
notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
{
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_messages_t *messages;
notmuch_message_t *message;
notmuch_tags_t *tags;
notmuch_messages_t *messages;
notmuch_message_t *message;
notmuch_tags_t *tags;
+
+ 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));
if (argc) {
output = fopen (argv[0], "w");
if (output == NULL) {
fprintf (stderr, "Error opening %s for writing: %s\n",
argv[0], strerror (errno));
}
} else {
output = stdout;
}
}
} 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))
for (messages = notmuch_query_search_messages (query);
notmuch_messages_has_more (messages);
notmuch_messages_advance (messages))
notmuch_message_destroy (message);
}
notmuch_message_destroy (message);
}
- notmuch_query_destroy (query);
-
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
- if (output && output != stdout)
+ notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
+
+ return 0;
int
notmuch_reply_command (void *ctx, int argc, char *argv[])
{
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;
char *query_string;
notmuch_messages_t *messages;
notmuch_message_t *message;
- 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");
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
}
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
}
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
}
for (messages = notmuch_query_search_messages (query);
}
for (messages = notmuch_query_search_messages (query);
reply = g_mime_message_new (1);
if (reply == NULL) {
fprintf (stderr, "Out of memory\n");
reply = g_mime_message_new (1);
if (reply == NULL) {
fprintf (stderr, "Out of memory\n");
}
/* XXX: We need a configured email address (or addresses) for
}
/* XXX: We need a configured email address (or addresses) for
notmuch_message_destroy (message);
}
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);
int
notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
{
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;
char *line = NULL;
size_t line_size;
ssize_t line_len;
regex_t regex;
int rerr;
+
+ 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));
if (argc) {
input = fopen (argv[0], "r");
if (input == NULL) {
fprintf (stderr, "Error opening %s for reading: %s\n",
argv[0], strerror (errno));
}
} else {
printf ("No filename given. Reading dump from stdin.\n");
input = stdin;
}
}
} 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
/* 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
- if (notmuch)
- notmuch_database_close (notmuch);
- if (input && input != stdin)
+
+ notmuch_database_close (notmuch);
+ if (input != stdin)
int
notmuch_search_command (void *ctx, int argc, char *argv[])
{
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;
notmuch_query_t *query;
notmuch_threads_t *threads;
notmuch_thread_t *thread;
char *query_str;
const char *relative_date;
time_t date;
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");
query = notmuch_query_create (notmuch, query_str);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
}
for (threads = notmuch_query_search_threads (query);
}
for (threads = notmuch_query_search_threads (query);
thread = notmuch_threads_get (threads);
date = notmuch_thread_get_oldest_date (thread);
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),
printf ("thread:%s %12s %s",
notmuch_thread_get_thread_id (thread),
}
notmuch_query_destroy (query);
}
notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
- talloc_free (local);
-
- return ret;
int
notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
{
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;
notmuch_messages_t *messages;
notmuch_message_t *message;
const char *headers[] = {
"From", "To", "Cc", "Bcc", "Date"
const char *headers[] = {
"From", "To", "Cc", "Bcc", "Date"
const char *name, *value;
unsigned int i;
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");
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
}
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
}
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
}
for (messages = notmuch_query_search_messages (query);
}
for (messages = notmuch_query_search_messages (query);
- 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"));
printf ("%s\n", notmuch_message_get_header (message, "subject"));
notmuch_message_destroy (message);
}
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);
int
notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
{
int
notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
{
int *add_tags, *remove_tags;
int add_tags_count = 0;
int remove_tags_count = 0;
char *query_string;
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;
notmuch_query_t *query;
notmuch_messages_t *messages;
notmuch_message_t *message;
- 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));
+ 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) {
if (remove_tags == NULL) {
+ fprintf (stderr, "Out of memory.\n");
+ return 1;
}
for (i = 0; i < argc; i++) {
}
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");
if (add_tags_count == 0 && remove_tags_count == 0) {
fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
}
if (i == argc) {
fprintf (stderr, "Error: 'notmuch tag' requires at least one search term.\n");
}
if (i == argc) {
fprintf (stderr, "Error: 'notmuch tag' requires at least one search term.\n");
- 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");
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory.\n");
}
for (messages = notmuch_query_search_messages (query);
}
for (messages = notmuch_query_search_messages (query);
}
notmuch_query_destroy (query);
}
notmuch_query_destroy (query);
+ notmuch_database_close (notmuch);
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
-
- talloc_free (local);
-
- return ret;