X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;h=faeb8f0a5896a4e23b012c2ba6c0be986b5a01b4;hp=3a60f7cae47fee568d8002f5db178b6ea7587d7a;hb=f2ed177e6260d835b8a13d2a53e1c8d5fa76edf2;hpb=85c830405886207196aedbd0a2b757b227ba769d diff --git a/notmuch-new.c b/notmuch-new.c index 3a60f7ca..faeb8f0a 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -234,6 +234,12 @@ _entries_resemble_maildir (const char *path, struct dirent **entries, int count) return 0; } +static notmuch_bool_t +_special_directory (const char *entry) +{ + return strcmp (entry, ".") == 0 || strcmp (entry, "..") == 0; +} + /* Test if the file/directory is to be ignored. */ static notmuch_bool_t @@ -261,16 +267,22 @@ add_file (notmuch_database_t *notmuch, const char *filename, if (status) goto DONE; - status = notmuch_database_add_message (notmuch, filename, &message); + status = notmuch_database_index_file (notmuch, filename, NULL, &message); switch (status) { /* Success. */ case NOTMUCH_STATUS_SUCCESS: state->added_messages++; notmuch_message_freeze (message); - for (tag = state->new_tags; *tag != NULL; tag++) - notmuch_message_add_tag (message, *tag); if (state->synchronize_flags) notmuch_message_maildir_flags_to_tags (message); + + for (tag = state->new_tags; *tag != NULL; tag++) { + if (strcmp ("unread", *tag) !=0 || + !notmuch_message_has_maildir_flag (message, 'S')) { + notmuch_message_add_tag (message, *tag); + } + } + notmuch_message_thaw (message); break; /* Non-fatal issues (go on to next file). */ @@ -291,8 +303,7 @@ add_file (notmuch_database_t *notmuch, const char *filename, case NOTMUCH_STATUS_READ_ONLY_DATABASE: case NOTMUCH_STATUS_XAPIAN_EXCEPTION: case NOTMUCH_STATUS_OUT_OF_MEMORY: - fprintf (stderr, "Error: %s. Halting processing.\n", - notmuch_status_to_string (status)); + (void) print_status_database("add_file", notmuch, status); goto DONE; default: INTERNAL_ERROR ("add_message returned unexpected value: %d", status); @@ -438,10 +449,7 @@ add_files (notmuch_database_t *notmuch, /* Pass 1: Recurse into all sub-directories. */ is_maildir = _entries_resemble_maildir (path, fs_entries, num_fs_entries); - for (i = 0; i < num_fs_entries; i++) { - if (interrupted) - break; - + for (i = 0; i < num_fs_entries && ! interrupted; i++) { entry = fs_entries[i]; /* Ignore any files/directories the user has configured to @@ -473,8 +481,7 @@ add_files (notmuch_database_t *notmuch, * Also ignore the .notmuch directory and any "tmp" directory * that appears within a maildir. */ - if (strcmp (entry->d_name, ".") == 0 || - strcmp (entry->d_name, "..") == 0 || + if (_special_directory (entry->d_name) || (is_maildir && strcmp (entry->d_name, "tmp") == 0) || strcmp (entry->d_name, ".notmuch") == 0) continue; @@ -509,11 +516,7 @@ add_files (notmuch_database_t *notmuch, } /* Pass 2: Scan for new files, removed files, and removed directories. */ - for (i = 0; i < num_fs_entries; i++) - { - if (interrupted) - break; - + for (i = 0; i < num_fs_entries && ! interrupted; i++) { entry = fs_entries[i]; /* Ignore files & directories user has configured to be ignored */ @@ -740,8 +743,7 @@ count_files (const char *path, int *count, add_files_state_t *state) /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory. */ - if (strcmp (entry->d_name, ".") == 0 || - strcmp (entry->d_name, "..") == 0 || + if (_special_directory (entry->d_name) || strcmp (entry->d_name, ".notmuch") == 0) continue;