1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-client.h"
25 typedef struct _filename_node {
27 struct _filename_node *next;
30 typedef struct _filename_list {
32 _filename_node_t *head;
33 _filename_node_t **tail;
39 const char **new_tags;
40 size_t new_tags_length;
45 struct timeval tv_start;
47 _filename_list_t *removed_files;
48 _filename_list_t *removed_directories;
50 notmuch_bool_t synchronize_flags;
51 _filename_list_t *message_ids_to_sync;
54 static volatile sig_atomic_t do_print_progress = 0;
57 handle_sigalrm (unused (int signal))
59 do_print_progress = 1;
62 static volatile sig_atomic_t interrupted;
65 handle_sigint (unused (int sig))
67 static char msg[] = "Stopping... \n";
69 write(2, msg, sizeof(msg)-1);
73 static _filename_list_t *
74 _filename_list_create (const void *ctx)
76 _filename_list_t *list;
78 list = talloc (ctx, _filename_list_t);
83 list->tail = &list->head;
90 _filename_list_add (_filename_list_t *list,
93 _filename_node_t *node = talloc (list, _filename_node_t);
97 node->filename = talloc_strdup (list, filename);
100 *(list->tail) = node;
101 list->tail = &node->next;
105 generic_print_progress (const char *action, const char *object,
106 struct timeval tv_start, unsigned processed, unsigned total)
108 struct timeval tv_now;
109 double elapsed_overall, rate_overall;
111 gettimeofday (&tv_now, NULL);
113 elapsed_overall = notmuch_time_elapsed (tv_start, tv_now);
114 rate_overall = processed / elapsed_overall;
116 printf ("%s %d ", action, processed);
119 printf ("of %d %s", total, object);
120 if (processed > 0 && elapsed_overall > 0.5) {
121 double time_remaining = ((total - processed) / rate_overall);
123 notmuch_time_print_formatted_seconds (time_remaining);
124 printf (" remaining)");
127 printf ("%s", object);
128 if (elapsed_overall > 0.5)
129 printf (" (%d %s/sec.)", (int) rate_overall, object);
131 printf (".\033[K\r");
137 dirent_sort_inode (const struct dirent **a, const struct dirent **b)
139 return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
143 dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
145 return strcmp ((*a)->d_name, (*b)->d_name);
148 /* Test if the directory looks like a Maildir directory.
150 * Search through the array of directory entries to see if we can find all
151 * three subdirectories typical for Maildir, that is "new", "cur", and "tmp".
153 * Return 1 if the directory looks like a Maildir and 0 otherwise.
156 _entries_resemble_maildir (struct dirent **entries, int count)
160 for (i = 0; i < count; i++) {
161 if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
164 if (strcmp(entries[i]->d_name, "new") == 0 ||
165 strcmp(entries[i]->d_name, "cur") == 0 ||
166 strcmp(entries[i]->d_name, "tmp") == 0)
177 /* Examine 'path' recursively as follows:
179 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
180 * o Ask the database for its timestamp of 'path' (db_mtime)
182 * o Ask the filesystem for files and directories within 'path'
183 * (via scandir and stored in fs_entries)
185 * o Pass 1: For each directory in fs_entries, recursively call into
186 * this same function.
188 * o Compare fs_mtime to db_mtime. If they are equivalent, terminate
189 * the algorithm at this point, (this directory has not been
190 * updated in the filesystem since the last database scan of PASS
193 * o Ask the database for files and directories within 'path'
194 * (db_files and db_subdirs)
196 * o Pass 2: Walk fs_entries simultaneously with db_files and
197 * db_subdirs. Look for one of three interesting cases:
199 * 1. Regular file in fs_entries and not in db_files
200 * This is a new file to add_message into the database.
202 * 2. Filename in db_files not in fs_entries.
203 * This is a file that has been removed from the mail store.
205 * 3. Directory in db_subdirs not in fs_entries
206 * This is a directory that has been removed from the mail store.
208 * Note that the addition of a directory is not interesting here,
209 * since that will have been taken care of in pass 1. Also, we
210 * don't immediately act on file/directory removal since we must
211 * ensure that in the case of a rename that the new filename is
212 * added before the old filename is removed, (so that no
213 * information is lost from the database).
215 * o Tell the database to update its time of 'path' to 'fs_mtime'
217 static notmuch_status_t
218 add_files_recursive (notmuch_database_t *notmuch,
220 add_files_state_t *state)
223 struct dirent *entry = NULL;
225 time_t fs_mtime, db_mtime;
226 notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
227 notmuch_message_t *message = NULL;
228 struct dirent **fs_entries = NULL;
229 int i, num_fs_entries;
230 notmuch_directory_t *directory;
231 notmuch_filenames_t *db_files = NULL;
232 notmuch_filenames_t *db_subdirs = NULL;
234 notmuch_bool_t is_maildir, new_directory;
237 if (stat (path, &st)) {
238 fprintf (stderr, "Error reading directory %s: %s\n",
239 path, strerror (errno));
240 return NOTMUCH_STATUS_FILE_ERROR;
243 /* This is not an error since we may have recursed based on a
244 * symlink to a regular file, not a directory, and we don't know
245 * that until this stat. */
246 if (! S_ISDIR (st.st_mode))
247 return NOTMUCH_STATUS_SUCCESS;
249 fs_mtime = st.st_mtime;
251 directory = notmuch_database_get_directory (notmuch, path);
252 db_mtime = notmuch_directory_get_mtime (directory);
254 new_directory = db_mtime ? FALSE : TRUE;
256 /* If the database knows about this directory, then we sort based
257 * on strcmp to match the database sorting. Otherwise, we can do
258 * inode-based sorting for faster filesystem operation. */
259 num_fs_entries = scandir (path, &fs_entries, 0,
261 dirent_sort_inode : dirent_sort_strcmp_name);
263 if (num_fs_entries == -1) {
264 fprintf (stderr, "Error opening directory %s: %s\n",
265 path, strerror (errno));
266 ret = NOTMUCH_STATUS_FILE_ERROR;
270 /* Pass 1: Recurse into all sub-directories. */
271 is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
273 for (i = 0; i < num_fs_entries; i++) {
277 entry = fs_entries[i];
279 /* We only want to descend into directories.
280 * But symlinks can be to directories too, of course.
282 * And if the filesystem doesn't tell us the file type in the
283 * scandir results, then it might be a directory (and if not,
284 * then we'll stat and return immediately in the next level of
286 if (entry->d_type != DT_DIR &&
287 entry->d_type != DT_LNK &&
288 entry->d_type != DT_UNKNOWN)
293 /* Ignore special directories to avoid infinite recursion.
294 * Also ignore the .notmuch directory and any "tmp" directory
295 * that appears within a maildir.
297 /* XXX: Eventually we'll want more sophistication to let the
298 * user specify files to be ignored. */
299 if (strcmp (entry->d_name, ".") == 0 ||
300 strcmp (entry->d_name, "..") == 0 ||
301 (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
302 strcmp (entry->d_name, ".notmuch") ==0)
307 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
308 status = add_files_recursive (notmuch, next, state);
309 if (status && ret == NOTMUCH_STATUS_SUCCESS)
315 /* If the directory's modification time in the filesystem is the
316 * same as what we recorded in the database the last time we
317 * scanned it, then we can skip the second pass entirely.
319 * We test for strict equality here to avoid a bug that can happen
320 * if the system clock jumps backward, (preventing new mail from
321 * being discovered until the clock catches up and the directory
322 * is modified again).
324 if (fs_mtime == db_mtime)
327 /* new_directory means a directory that the database has never
328 * seen before. In that case, we can simply leave db_files and
329 * db_subdirs NULL. */
330 if (!new_directory) {
331 db_files = notmuch_directory_get_child_files (directory);
332 db_subdirs = notmuch_directory_get_child_directories (directory);
335 /* Pass 2: Scan for new files, removed files, and removed directories. */
336 for (i = 0; i < num_fs_entries; i++)
341 entry = fs_entries[i];
343 /* Check if we've walked past any names in db_files or
344 * db_subdirs. If so, these have been deleted. */
345 while (notmuch_filenames_valid (db_files) &&
346 strcmp (notmuch_filenames_get (db_files), entry->d_name) < 0)
348 char *absolute = talloc_asprintf (state->removed_files,
350 notmuch_filenames_get (db_files));
352 _filename_list_add (state->removed_files, absolute);
354 notmuch_filenames_move_to_next (db_files);
357 while (notmuch_filenames_valid (db_subdirs) &&
358 strcmp (notmuch_filenames_get (db_subdirs), entry->d_name) <= 0)
360 const char *filename = notmuch_filenames_get (db_subdirs);
362 if (strcmp (filename, entry->d_name) < 0)
364 char *absolute = talloc_asprintf (state->removed_directories,
365 "%s/%s", path, filename);
367 _filename_list_add (state->removed_directories, absolute);
370 notmuch_filenames_move_to_next (db_subdirs);
373 /* If we're looking at a symlink, we only want to add it if it
374 * links to a regular file, (and not to a directory, say).
376 * Similarly, if the file is of unknown type (due to filesytem
377 * limitations), then we also need to look closer.
379 * In either case, a stat does the trick.
381 if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
384 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
385 err = stat (next, &st);
389 /* Don't emit an error for a link pointing nowhere, since
390 * the directory-traversal pass will have already done
395 if (! S_ISREG (st.st_mode))
397 } else if (entry->d_type != DT_REG) {
401 /* Don't add a file that we've added before. */
402 if (notmuch_filenames_valid (db_files) &&
403 strcmp (notmuch_filenames_get (db_files), entry->d_name) == 0)
405 notmuch_filenames_move_to_next (db_files);
409 /* We're now looking at a regular file that doesn't yet exist
410 * in the database, so add it. */
411 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
413 state->processed_files++;
415 if (state->verbose) {
416 if (state->output_is_a_tty)
420 state->processed_files,
424 putchar((state->output_is_a_tty) ? '\r' : '\n');
428 status = notmuch_database_add_message (notmuch, next, &message);
431 case NOTMUCH_STATUS_SUCCESS:
432 state->added_messages++;
433 notmuch_message_freeze (message);
434 for (tag=state->new_tags; *tag != NULL; tag++)
435 notmuch_message_add_tag (message, *tag);
436 if (state->synchronize_flags == TRUE)
437 notmuch_message_maildir_flags_to_tags (message);
438 notmuch_message_thaw (message);
440 /* Non-fatal issues (go on to next file) */
441 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
442 /* Defer sync of maildir flags until after old filenames
443 * are removed in the case of a rename. */
444 if (state->synchronize_flags == TRUE)
445 _filename_list_add (state->message_ids_to_sync,
446 notmuch_message_get_message_id (message));
448 case NOTMUCH_STATUS_FILE_NOT_EMAIL:
449 fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
452 /* Fatal issues. Don't process anymore. */
453 case NOTMUCH_STATUS_READ_ONLY_DATABASE:
454 case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
455 case NOTMUCH_STATUS_OUT_OF_MEMORY:
456 fprintf (stderr, "Error: %s. Halting processing.\n",
457 notmuch_status_to_string (status));
461 case NOTMUCH_STATUS_FILE_ERROR:
462 case NOTMUCH_STATUS_NULL_POINTER:
463 case NOTMUCH_STATUS_TAG_TOO_LONG:
464 case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
465 case NOTMUCH_STATUS_LAST_STATUS:
466 INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
471 notmuch_message_destroy (message);
475 if (do_print_progress) {
476 do_print_progress = 0;
477 generic_print_progress ("Processed", "files", state->tv_start,
478 state->processed_files, state->total_files);
488 /* Now that we've walked the whole filesystem list, anything left
489 * over in the database lists has been deleted. */
490 while (notmuch_filenames_valid (db_files))
492 char *absolute = talloc_asprintf (state->removed_files,
494 notmuch_filenames_get (db_files));
496 _filename_list_add (state->removed_files, absolute);
498 notmuch_filenames_move_to_next (db_files);
501 while (notmuch_filenames_valid (db_subdirs))
503 char *absolute = talloc_asprintf (state->removed_directories,
505 notmuch_filenames_get (db_subdirs));
507 _filename_list_add (state->removed_directories, absolute);
509 notmuch_filenames_move_to_next (db_subdirs);
513 status = notmuch_directory_set_mtime (directory, fs_mtime);
514 if (status && ret == NOTMUCH_STATUS_SUCCESS)
528 notmuch_filenames_destroy (db_subdirs);
530 notmuch_filenames_destroy (db_files);
532 notmuch_directory_destroy (directory);
538 setup_progress_printing_timer (void)
540 struct sigaction action;
541 struct itimerval timerval;
543 /* Setup our handler for SIGALRM */
544 memset (&action, 0, sizeof (struct sigaction));
545 action.sa_handler = handle_sigalrm;
546 sigemptyset (&action.sa_mask);
547 action.sa_flags = SA_RESTART;
548 sigaction (SIGALRM, &action, NULL);
550 /* Then start a timer to send SIGALRM once per second. */
551 timerval.it_interval.tv_sec = 1;
552 timerval.it_interval.tv_usec = 0;
553 timerval.it_value.tv_sec = 1;
554 timerval.it_value.tv_usec = 0;
555 setitimer (ITIMER_REAL, &timerval, NULL);
559 stop_progress_printing_timer (void)
561 struct sigaction action;
562 struct itimerval timerval;
564 /* Now stop the timer. */
565 timerval.it_interval.tv_sec = 0;
566 timerval.it_interval.tv_usec = 0;
567 timerval.it_value.tv_sec = 0;
568 timerval.it_value.tv_usec = 0;
569 setitimer (ITIMER_REAL, &timerval, NULL);
571 /* And disable the signal handler. */
572 action.sa_handler = SIG_IGN;
573 sigaction (SIGALRM, &action, NULL);
577 /* This is the top-level entry point for add_files. It does a couple
578 * of error checks and then calls into the recursive function. */
579 static notmuch_status_t
580 add_files (notmuch_database_t *notmuch,
582 add_files_state_t *state)
584 notmuch_status_t status;
587 if (stat (path, &st)) {
588 fprintf (stderr, "Error reading directory %s: %s\n",
589 path, strerror (errno));
590 return NOTMUCH_STATUS_FILE_ERROR;
593 if (! S_ISDIR (st.st_mode)) {
594 fprintf (stderr, "Error: %s is not a directory.\n", path);
595 return NOTMUCH_STATUS_FILE_ERROR;
598 status = add_files_recursive (notmuch, path, state);
603 /* XXX: This should be merged with the add_files function since it
604 * shares a lot of logic with it. */
605 /* Recursively count all regular files in path and all sub-directories
606 * of path. The result is added to *count (which should be
607 * initialized to zero by the top-level caller before calling
610 count_files (const char *path, int *count)
612 struct dirent *entry = NULL;
615 struct dirent **fs_entries = NULL;
616 int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
619 if (num_fs_entries == -1) {
620 fprintf (stderr, "Warning: failed to open directory %s: %s\n",
621 path, strerror (errno));
625 while (!interrupted) {
626 if (i == num_fs_entries)
629 entry = fs_entries[i++];
631 /* Ignore special directories to avoid infinite recursion.
632 * Also ignore the .notmuch directory.
634 /* XXX: Eventually we'll want more sophistication to let the
635 * user specify files to be ignored. */
636 if (strcmp (entry->d_name, ".") == 0 ||
637 strcmp (entry->d_name, "..") == 0 ||
638 strcmp (entry->d_name, ".notmuch") == 0)
643 if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
645 fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
646 path, entry->d_name);
652 if (S_ISREG (st.st_mode)) {
654 if (*count % 1000 == 0) {
655 printf ("Found %d files so far.\r", *count);
658 } else if (S_ISDIR (st.st_mode)) {
659 count_files (next, count);
673 upgrade_print_progress (void *closure,
676 add_files_state_t *state = closure;
678 printf ("Upgrading database: %.2f%% complete", progress * 100.0);
681 struct timeval tv_now;
682 double elapsed, time_remaining;
684 gettimeofday (&tv_now, NULL);
686 elapsed = notmuch_time_elapsed (state->tv_start, tv_now);
687 time_remaining = (elapsed / progress) * (1.0 - progress);
689 notmuch_time_print_formatted_seconds (time_remaining);
690 printf (" remaining)");
698 /* Recursively remove all filenames from the database referring to
699 * 'path' (or to any of its children). */
701 _remove_directory (void *ctx,
702 notmuch_database_t *notmuch,
707 notmuch_directory_t *directory;
708 notmuch_filenames_t *files, *subdirs;
709 notmuch_status_t status;
712 directory = notmuch_database_get_directory (notmuch, path);
714 for (files = notmuch_directory_get_child_files (directory);
715 notmuch_filenames_valid (files);
716 notmuch_filenames_move_to_next (files))
718 absolute = talloc_asprintf (ctx, "%s/%s", path,
719 notmuch_filenames_get (files));
720 status = notmuch_database_remove_message (notmuch, absolute);
721 if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
722 *renamed_files = *renamed_files + 1;
724 *removed_files = *removed_files + 1;
725 talloc_free (absolute);
728 for (subdirs = notmuch_directory_get_child_directories (directory);
729 notmuch_filenames_valid (subdirs);
730 notmuch_filenames_move_to_next (subdirs))
732 absolute = talloc_asprintf (ctx, "%s/%s", path,
733 notmuch_filenames_get (subdirs));
734 _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);
735 talloc_free (absolute);
738 notmuch_directory_destroy (directory);
742 notmuch_new_command (void *ctx, int argc, char *argv[])
744 notmuch_config_t *config;
745 notmuch_database_t *notmuch;
746 add_files_state_t add_files_state;
748 struct timeval tv_now, tv_start;
752 char *dot_notmuch_path;
753 struct sigaction action;
755 int renamed_files, removed_files;
756 notmuch_status_t status;
758 notmuch_bool_t timer_is_active = FALSE;
760 add_files_state.verbose = 0;
761 add_files_state.output_is_a_tty = isatty (fileno (stdout));
763 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
764 if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
765 add_files_state.verbose = 1;
767 fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
771 config = notmuch_config_open (ctx, NULL, NULL);
775 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
776 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
777 add_files_state.message_ids_to_sync = _filename_list_create (ctx);
778 db_path = notmuch_config_get_database_path (config);
780 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
782 if (stat (dot_notmuch_path, &st)) {
786 count_files (db_path, &count);
790 printf ("Found %d total files (that's not much mail).\n", count);
791 notmuch = notmuch_database_create (db_path);
792 add_files_state.total_files = count;
794 notmuch = notmuch_database_open (db_path,
795 NOTMUCH_DATABASE_MODE_READ_WRITE);
799 if (notmuch_database_needs_upgrade (notmuch)) {
800 printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");
801 gettimeofday (&add_files_state.tv_start, NULL);
802 notmuch_database_upgrade (notmuch, upgrade_print_progress,
804 printf ("Your notmuch database has now been upgraded to database format version %u.\n",
805 notmuch_database_get_version (notmuch));
808 add_files_state.total_files = 0;
814 /* Setup our handler for SIGINT. We do this after having
815 * potentially done a database upgrade we this interrupt handler
817 memset (&action, 0, sizeof (struct sigaction));
818 action.sa_handler = handle_sigint;
819 sigemptyset (&action.sa_mask);
820 action.sa_flags = SA_RESTART;
821 sigaction (SIGINT, &action, NULL);
823 talloc_free (dot_notmuch_path);
824 dot_notmuch_path = NULL;
826 add_files_state.processed_files = 0;
827 add_files_state.added_messages = 0;
828 gettimeofday (&add_files_state.tv_start, NULL);
830 add_files_state.removed_files = _filename_list_create (ctx);
831 add_files_state.removed_directories = _filename_list_create (ctx);
833 if (! debugger_is_active () && add_files_state.output_is_a_tty
834 && ! add_files_state.verbose) {
835 setup_progress_printing_timer ();
836 timer_is_active = TRUE;
839 ret = add_files (notmuch, db_path, &add_files_state);
843 gettimeofday (&tv_start, NULL);
844 for (f = add_files_state.removed_files->head; f; f = f->next) {
845 status = notmuch_database_remove_message (notmuch, f->filename);
846 if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
850 if (do_print_progress) {
851 do_print_progress = 0;
852 generic_print_progress ("Cleaned up", "messages",
853 tv_start, removed_files + renamed_files,
854 add_files_state.removed_files->count);
858 gettimeofday (&tv_start, NULL);
859 for (f = add_files_state.removed_directories->head, i = 0; f; f = f->next, i++) {
860 _remove_directory (ctx, notmuch, f->filename,
861 &renamed_files, &removed_files);
862 if (do_print_progress) {
863 do_print_progress = 0;
864 generic_print_progress ("Cleaned up", "directories",
866 add_files_state.removed_directories->count);
870 talloc_free (add_files_state.removed_files);
871 talloc_free (add_files_state.removed_directories);
873 /* Now that removals are done (hence the database is aware of all
874 * renames), we can synchronize maildir_flags to tags for all
875 * messages that had new filenames appear on this run. */
876 gettimeofday (&tv_start, NULL);
877 if (add_files_state.synchronize_flags) {
878 _filename_node_t *node;
879 notmuch_message_t *message;
880 for (node = add_files_state.message_ids_to_sync->head, i = 0;
882 node = node->next, i++)
884 message = notmuch_database_find_message (notmuch, node->filename);
885 notmuch_message_maildir_flags_to_tags (message);
886 notmuch_message_destroy (message);
887 if (do_print_progress) {
888 do_print_progress = 0;
889 generic_print_progress (
890 "Synchronized tags for", "messages",
891 tv_start, i, add_files_state.message_ids_to_sync->count);
896 talloc_free (add_files_state.message_ids_to_sync);
897 add_files_state.message_ids_to_sync = NULL;
900 stop_progress_printing_timer ();
902 gettimeofday (&tv_now, NULL);
903 elapsed = notmuch_time_elapsed (add_files_state.tv_start,
906 if (add_files_state.processed_files) {
907 printf ("Processed %d %s in ", add_files_state.processed_files,
908 add_files_state.processed_files == 1 ?
909 "file" : "total files");
910 notmuch_time_print_formatted_seconds (elapsed);
912 printf (" (%d files/sec.).\033[K\n",
913 (int) (add_files_state.processed_files / elapsed));
915 printf (".\033[K\n");
919 if (add_files_state.added_messages) {
920 printf ("Added %d new %s to the database.",
921 add_files_state.added_messages,
922 add_files_state.added_messages == 1 ?
923 "message" : "messages");
925 printf ("No new mail.");
929 printf (" Removed %d %s.",
931 removed_files == 1 ? "message" : "messages");
935 printf (" Detected %d file %s.",
937 renamed_files == 1 ? "rename" : "renames");
943 printf ("\nNote: At least one error was encountered: %s\n",
944 notmuch_status_to_string (ret));
947 notmuch_database_close (notmuch);
949 return ret || interrupted;