X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.c;h=a7559fc7a6266a034f6b8580819ff0ca9a2be1e9;hp=fd0e0b253c56388a8c5fd2bec01053016c4cb7b6;hb=b0190e59ac14851a0b79a00d58aad2e8febea92f;hpb=8e96a87fff4d34a154d1456e9ad47e7b0c322d54 diff --git a/notmuch.c b/notmuch.c index fd0e0b25..a7559fc7 100644 --- a/notmuch.c +++ b/notmuch.c @@ -67,6 +67,8 @@ typedef struct command { const char *usage; } command_t; +typedef void (*add_files_callback_t) (notmuch_message_t *message); + typedef struct { int ignore_read_only_directories; int saw_read_only_directory; @@ -75,6 +77,8 @@ typedef struct { int processed_files; int added_messages; struct timeval tv_start; + + add_files_callback_t callback; } add_files_state_t; static void @@ -176,6 +180,7 @@ add_files_recursive (notmuch_database_t *notmuch, char *next = NULL; time_t path_mtime, path_dbtime; notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS; + notmuch_message_t *message = NULL, **closure; /* If we're told to, we bail out on encountering a read-only * directory, (with this being a clear clue from the user to @@ -249,11 +254,18 @@ add_files_recursive (notmuch_database_t *notmuch, if (st->st_mtime > path_dbtime) { state->processed_files++; - status = notmuch_database_add_message (notmuch, next); + if (state->callback) + closure = &message; + else + closure = NULL; + + status = notmuch_database_add_message (notmuch, next, closure); switch (status) { /* success */ case NOTMUCH_STATUS_SUCCESS: state->added_messages++; + if (state->callback) + (state->callback) (message); break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: @@ -274,10 +286,17 @@ add_files_recursive (notmuch_database_t *notmuch, case NOTMUCH_STATUS_FILE_ERROR: case NOTMUCH_STATUS_NULL_POINTER: case NOTMUCH_STATUS_TAG_TOO_LONG: + case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: case NOTMUCH_STATUS_LAST_STATUS: INTERNAL_ERROR ("add_message returned unexpected value: %d", status); goto DONE; } + + if (message) { + notmuch_message_destroy (message); + message = NULL; + } + if (state->processed_files % 1000 == 0) add_files_print_progress (state); } @@ -495,6 +514,7 @@ setup_command (unused (int argc), unused (char *argv[])) add_files_state.total_files = count; add_files_state.processed_files = 0; add_files_state.added_messages = 0; + add_files_state.callback = NULL; gettimeofday (&add_files_state.tv_start, NULL); ret = add_files (notmuch, mail_directory, &add_files_state); @@ -537,6 +557,13 @@ setup_command (unused (int argc), unused (char *argv[])) return ret; } +static void +tag_inbox_and_unread (notmuch_message_t *message) +{ + notmuch_message_add_tag (message, "inbox"); + notmuch_message_add_tag (message, "unread"); +} + static int new_command (unused (int argc), unused (char *argv[])) { @@ -560,6 +587,7 @@ new_command (unused (int argc), unused (char *argv[])) add_files_state.total_files = 0; add_files_state.processed_files = 0; add_files_state.added_messages = 0; + add_files_state.callback = tag_inbox_and_unread; gettimeofday (&add_files_state.tv_start, NULL); ret = add_files (notmuch, mail_directory, &add_files_state); @@ -651,8 +679,11 @@ search_command (int argc, char *argv[]) thread = notmuch_thread_results_get (results); - printf ("%s (", notmuch_thread_get_thread_id (thread)); + printf ("%s %s", + notmuch_thread_get_thread_id (thread), + notmuch_thread_get_subject (thread)); + printf (" ("); for (tags = notmuch_thread_get_tags (thread); notmuch_tags_has_more (tags); notmuch_tags_advance (tags)) @@ -662,7 +693,6 @@ search_command (int argc, char *argv[]) printf ("%s", notmuch_tags_get (tags)); first = 0; } - printf (")\n"); notmuch_thread_destroy (thread); @@ -825,35 +855,34 @@ 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 (", + fprintf (stderr, "Warning: Cannot apply tags to missing message: %s\n", message_id); + goto NEXT_LINE; } + notmuch_message_freeze (message); + + notmuch_message_remove_all_tags (message); + next = tags; while (next) { tag = strsep (&next, " "); if (*tag == '\0') continue; - 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%s", - tag == tags ? "" : " ", tag); + 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)); } } - if (message) - notmuch_message_destroy (message); - else - fprintf (stderr, ")\n"); + notmuch_message_thaw (message); + notmuch_message_destroy (message); } + NEXT_LINE: free (message_id); free (tags); } @@ -878,10 +907,13 @@ command_t commands[] = { "\t\tthe setup command has not previously been completed." }, { "new", new_command, "Find and import any new messages.\n\n" - "\t\tScans all sub-directories of the database, adding new files\n" - "\t\tthat are found. Note: \"notmuch new\" will skip any\n" - "\t\tread-only directories, so you can use that to mark\n" - "\t\tdirectories that will not receive any new mail."}, + "\t\tScans all sub-directories of the database, adding new messages\n" + "\t\tthat are found. Each new message will be tagges as both\n" + "\t\t\"inbox\" and \"unread\".\n" + "\n" + "\t\tNote: \"notmuch new\" will skip any read-only directories,\n" + "\t\tso you can use that to mark tdirectories that will not\n" + "\t\treceive any new mail (and make \"notmuch new\" faster)." }, { "search", search_command, " [...]\n\n" "\t\tSearch for threads matching the given search terms.\n"