X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.c;h=24a447970db868c55ac21904083be4d8b722ee8a;hp=bc04bc1b7ea5c788fb36d610702a930ee60a31d3;hb=fd11c8e150c1b41ca1efc0ba4a3465eb325457f2;hpb=f232f0a797b4fb657e630ca4bd664f9dcfe90dac diff --git a/notmuch.c b/notmuch.c index bc04bc1b..24a44797 100644 --- a/notmuch.c +++ b/notmuch.c @@ -18,11 +18,12 @@ * Author: Carl Worth */ -#include "notmuch.h" - #ifndef _GNU_SOURCE #define _GNU_SOURCE /* for getline */ #endif +#include + +#include "notmuch.h" /* This is separate from notmuch-private.h because we're trying to * keep notmuch.c from looking into any internals, (which helps us @@ -30,7 +31,6 @@ */ #include "xutil.h" -#include #include #include #include @@ -266,13 +266,14 @@ count_files (const char *path, int *count) int setup_command (int argc, char *argv[]) { - notmuch_database_t *notmuch; - char *mail_directory, *default_path; + notmuch_database_t *notmuch = NULL; + char *default_path, *mail_directory = NULL; size_t line_size; int count; add_files_state_t add_files_state; double elapsed; struct timeval tv_now; + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; printf ("Welcome to notmuch!\n\n"); @@ -298,7 +299,6 @@ setup_command (int argc, char *argv[]) printf ("Top-level mail directory [%s]: ", default_path); fflush (stdout); - mail_directory = NULL; getline (&mail_directory, &line_size, stdin); chomp_newline (mail_directory); @@ -328,8 +328,8 @@ setup_command (int argc, char *argv[]) if (notmuch == NULL) { fprintf (stderr, "Failed to create new notmuch database at %s\n", mail_directory); - free (mail_directory); - return 1; + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; } printf ("OK. Let's take a look at the mail we can find in the directory\n"); @@ -355,11 +355,13 @@ setup_command (int argc, char *argv[]) print_formatted_seconds (elapsed); printf (" (%d messages/sec.). \n", (int) (add_files_state.count / elapsed)); - notmuch_database_close (notmuch); - - free (mail_directory); + DONE: + if (mail_directory) + free (mail_directory); + if (notmuch) + notmuch_database_close (notmuch); - return 0; + return ret; } int @@ -380,7 +382,7 @@ int dump_command (int argc, char *argv[]) { FILE *output; - notmuch_database_t *notmuch = NULL; + notmuch_database_t *notmuch; notmuch_query_t *query; notmuch_results_t *results; notmuch_message_t *message; @@ -456,7 +458,7 @@ int restore_command (int argc, char *argv[]) { FILE *input; - notmuch_database_t *notmuch = NULL; + notmuch_database_t *notmuch; char *line = NULL; size_t line_size, line_len; regex_t regex; @@ -515,9 +517,8 @@ restore_command (int argc, char *argv[]) message = notmuch_database_find_message (notmuch, message_id); if (message == NULL) { - fprintf (stderr, "Warning: Cannot apply tags to missing message: %s\n", + fprintf (stderr, "Warning: Cannot apply tags to missing message: %s (", message_id); - goto NEXT_LINE; } next = tags; @@ -525,16 +526,25 @@ restore_command (int argc, char *argv[]) tag = strsep (&next, " "); if (*tag == '\0') continue; - status = notmuch_message_add_tag (message, tag); - if (status) { - fprintf (stderr, "Error applying tag %s to message %s.\n", - tag, message_id); + if (message) { + status = notmuch_message_add_tag (message, tag); + if (status) { + fprintf (stderr, + "Error applying tag %s to message %s:\n", + tag, message_id); + fprintf (stderr, "%s\n", + notmuch_status_to_string (status)); + } + } else { + fprintf (stderr, "%s ", tag); } } - notmuch_message_destroy (message); + if (message) + notmuch_message_destroy (message); + else + fprintf (stderr, ")\n"); } - NEXT_LINE: free (message_id); free (tags); }