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))
68 static char msg[] = "Stopping... \n";
70 ignored = write(2, msg, sizeof(msg)-1);
74 static _filename_list_t *
75 _filename_list_create (const void *ctx)
77 _filename_list_t *list;
79 list = talloc (ctx, _filename_list_t);
84 list->tail = &list->head;
91 _filename_list_add (_filename_list_t *list,
94 _filename_node_t *node = talloc (list, _filename_node_t);
98 node->filename = talloc_strdup (list, filename);
101 *(list->tail) = node;
102 list->tail = &node->next;
106 generic_print_progress (const char *action, const char *object,
107 struct timeval tv_start, unsigned processed, unsigned total)
109 struct timeval tv_now;
110 double elapsed_overall, rate_overall;
112 gettimeofday (&tv_now, NULL);
114 elapsed_overall = notmuch_time_elapsed (tv_start, tv_now);
115 rate_overall = processed / elapsed_overall;
117 printf ("%s %d ", action, processed);
120 printf ("of %d %s", total, object);
121 if (processed > 0 && elapsed_overall > 0.5) {
122 double time_remaining = ((total - processed) / rate_overall);
124 notmuch_time_print_formatted_seconds (time_remaining);
125 printf (" remaining)");
128 printf ("%s", object);
129 if (elapsed_overall > 0.5)
130 printf (" (%d %s/sec.)", (int) rate_overall, object);
132 printf (".\033[K\r");
138 dirent_sort_inode (const struct dirent **a, const struct dirent **b)
140 return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
144 dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
146 return strcmp ((*a)->d_name, (*b)->d_name);
149 /* Test if the directory looks like a Maildir directory.
151 * Search through the array of directory entries to see if we can find all
152 * three subdirectories typical for Maildir, that is "new", "cur", and "tmp".
154 * Return 1 if the directory looks like a Maildir and 0 otherwise.
157 _entries_resemble_maildir (struct dirent **entries, int count)
161 for (i = 0; i < count; i++) {
162 if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
165 if (strcmp(entries[i]->d_name, "new") == 0 ||
166 strcmp(entries[i]->d_name, "cur") == 0 ||
167 strcmp(entries[i]->d_name, "tmp") == 0)
178 /* Examine 'path' recursively as follows:
180 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
181 * o Ask the database for its timestamp of 'path' (db_mtime)
183 * o Ask the filesystem for files and directories within 'path'
184 * (via scandir and stored in fs_entries)
186 * o Pass 1: For each directory in fs_entries, recursively call into
187 * this same function.
189 * o Compare fs_mtime to db_mtime. If they are equivalent, terminate
190 * the algorithm at this point, (this directory has not been
191 * updated in the filesystem since the last database scan of PASS
194 * o Ask the database for files and directories within 'path'
195 * (db_files and db_subdirs)
197 * o Pass 2: Walk fs_entries simultaneously with db_files and
198 * db_subdirs. Look for one of three interesting cases:
200 * 1. Regular file in fs_entries and not in db_files
201 * This is a new file to add_message into the database.
203 * 2. Filename in db_files not in fs_entries.
204 * This is a file that has been removed from the mail store.
206 * 3. Directory in db_subdirs not in fs_entries
207 * This is a directory that has been removed from the mail store.
209 * Note that the addition of a directory is not interesting here,
210 * since that will have been taken care of in pass 1. Also, we
211 * don't immediately act on file/directory removal since we must
212 * ensure that in the case of a rename that the new filename is
213 * added before the old filename is removed, (so that no
214 * information is lost from the database).
216 * o Tell the database to update its time of 'path' to 'fs_mtime'
218 static notmuch_status_t
219 add_files_recursive (notmuch_database_t *notmuch,
221 add_files_state_t *state)
224 struct dirent *entry = NULL;
226 time_t fs_mtime, db_mtime;
227 notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
228 notmuch_message_t *message = NULL;
229 struct dirent **fs_entries = NULL;
230 int i, num_fs_entries;
231 notmuch_directory_t *directory;
232 notmuch_filenames_t *db_files = NULL;
233 notmuch_filenames_t *db_subdirs = NULL;
235 notmuch_bool_t is_maildir, new_directory;
238 if (stat (path, &st)) {
239 fprintf (stderr, "Error reading directory %s: %s\n",
240 path, strerror (errno));
241 return NOTMUCH_STATUS_FILE_ERROR;
244 /* This is not an error since we may have recursed based on a
245 * symlink to a regular file, not a directory, and we don't know
246 * that until this stat. */
247 if (! S_ISDIR (st.st_mode))
248 return NOTMUCH_STATUS_SUCCESS;
250 fs_mtime = st.st_mtime;
252 directory = notmuch_database_get_directory (notmuch, path);
253 db_mtime = notmuch_directory_get_mtime (directory);
255 new_directory = db_mtime ? FALSE : TRUE;
257 /* If the database knows about this directory, then we sort based
258 * on strcmp to match the database sorting. Otherwise, we can do
259 * inode-based sorting for faster filesystem operation. */
260 num_fs_entries = scandir (path, &fs_entries, 0,
262 dirent_sort_inode : dirent_sort_strcmp_name);
264 if (num_fs_entries == -1) {
265 fprintf (stderr, "Error opening directory %s: %s\n",
266 path, strerror (errno));
267 ret = NOTMUCH_STATUS_FILE_ERROR;
271 /* Pass 1: Recurse into all sub-directories. */
272 is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
274 for (i = 0; i < num_fs_entries; i++) {
278 entry = fs_entries[i];
280 /* We only want to descend into directories.
281 * But symlinks can be to directories too, of course.
283 * And if the filesystem doesn't tell us the file type in the
284 * scandir results, then it might be a directory (and if not,
285 * then we'll stat and return immediately in the next level of
287 if (entry->d_type != DT_DIR &&
288 entry->d_type != DT_LNK &&
289 entry->d_type != DT_UNKNOWN)
294 /* Ignore special directories to avoid infinite recursion.
295 * Also ignore the .notmuch directory and any "tmp" directory
296 * that appears within a maildir.
298 /* XXX: Eventually we'll want more sophistication to let the
299 * user specify files to be ignored. */
300 if (strcmp (entry->d_name, ".") == 0 ||
301 strcmp (entry->d_name, "..") == 0 ||
302 (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
303 strcmp (entry->d_name, ".notmuch") ==0)
308 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
309 status = add_files_recursive (notmuch, next, state);
310 if (status && ret == NOTMUCH_STATUS_SUCCESS)
316 /* If the directory's modification time in the filesystem is the
317 * same as what we recorded in the database the last time we
318 * scanned it, then we can skip the second pass entirely.
320 * We test for strict equality here to avoid a bug that can happen
321 * if the system clock jumps backward, (preventing new mail from
322 * being discovered until the clock catches up and the directory
323 * is modified again).
325 if (fs_mtime == db_mtime)
328 /* new_directory means a directory that the database has never
329 * seen before. In that case, we can simply leave db_files and
330 * db_subdirs NULL. */
331 if (!new_directory) {
332 db_files = notmuch_directory_get_child_files (directory);
333 db_subdirs = notmuch_directory_get_child_directories (directory);
336 /* Pass 2: Scan for new files, removed files, and removed directories. */
337 for (i = 0; i < num_fs_entries; i++)
342 entry = fs_entries[i];
344 /* Check if we've walked past any names in db_files or
345 * db_subdirs. If so, these have been deleted. */
346 while (notmuch_filenames_valid (db_files) &&
347 strcmp (notmuch_filenames_get (db_files), entry->d_name) < 0)
349 char *absolute = talloc_asprintf (state->removed_files,
351 notmuch_filenames_get (db_files));
353 _filename_list_add (state->removed_files, absolute);
355 notmuch_filenames_move_to_next (db_files);
358 while (notmuch_filenames_valid (db_subdirs) &&
359 strcmp (notmuch_filenames_get (db_subdirs), entry->d_name) <= 0)
361 const char *filename = notmuch_filenames_get (db_subdirs);
363 if (strcmp (filename, entry->d_name) < 0)
365 char *absolute = talloc_asprintf (state->removed_directories,
366 "%s/%s", path, filename);
368 _filename_list_add (state->removed_directories, absolute);
371 notmuch_filenames_move_to_next (db_subdirs);
374 /* If we're looking at a symlink, we only want to add it if it
375 * links to a regular file, (and not to a directory, say).
377 * Similarly, if the file is of unknown type (due to filesytem
378 * limitations), then we also need to look closer.
380 * In either case, a stat does the trick.
382 if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
385 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
386 err = stat (next, &st);
390 /* Don't emit an error for a link pointing nowhere, since
391 * the directory-traversal pass will have already done
396 if (! S_ISREG (st.st_mode))
398 } else if (entry->d_type != DT_REG) {
402 /* Don't add a file that we've added before. */
403 if (notmuch_filenames_valid (db_files) &&
404 strcmp (notmuch_filenames_get (db_files), entry->d_name) == 0)
406 notmuch_filenames_move_to_next (db_files);
410 /* We're now looking at a regular file that doesn't yet exist
411 * in the database, so add it. */
412 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
414 state->processed_files++;
416 if (state->verbose) {
417 if (state->output_is_a_tty)
421 state->processed_files,
425 putchar((state->output_is_a_tty) ? '\r' : '\n');
429 status = notmuch_database_add_message (notmuch, next, &message);
432 case NOTMUCH_STATUS_SUCCESS:
433 state->added_messages++;
434 notmuch_message_freeze (message);
435 for (tag=state->new_tags; *tag != NULL; tag++)
436 notmuch_message_add_tag (message, *tag);
437 if (state->synchronize_flags == TRUE)
438 notmuch_message_maildir_flags_to_tags (message);
439 notmuch_message_thaw (message);
441 /* Non-fatal issues (go on to next file) */
442 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
443 /* Defer sync of maildir flags until after old filenames
444 * are removed in the case of a rename. */
445 if (state->synchronize_flags == TRUE)
446 _filename_list_add (state->message_ids_to_sync,
447 notmuch_message_get_message_id (message));
449 case NOTMUCH_STATUS_FILE_NOT_EMAIL:
450 fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
453 /* Fatal issues. Don't process anymore. */
454 case NOTMUCH_STATUS_READ_ONLY_DATABASE:
455 case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
456 case NOTMUCH_STATUS_OUT_OF_MEMORY:
457 fprintf (stderr, "Error: %s. Halting processing.\n",
458 notmuch_status_to_string (status));
462 case NOTMUCH_STATUS_FILE_ERROR:
463 case NOTMUCH_STATUS_NULL_POINTER:
464 case NOTMUCH_STATUS_TAG_TOO_LONG:
465 case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
466 case NOTMUCH_STATUS_LAST_STATUS:
467 INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
472 notmuch_message_destroy (message);
476 if (do_print_progress) {
477 do_print_progress = 0;
478 generic_print_progress ("Processed", "files", state->tv_start,
479 state->processed_files, state->total_files);
489 /* Now that we've walked the whole filesystem list, anything left
490 * over in the database lists has been deleted. */
491 while (notmuch_filenames_valid (db_files))
493 char *absolute = talloc_asprintf (state->removed_files,
495 notmuch_filenames_get (db_files));
497 _filename_list_add (state->removed_files, absolute);
499 notmuch_filenames_move_to_next (db_files);
502 while (notmuch_filenames_valid (db_subdirs))
504 char *absolute = talloc_asprintf (state->removed_directories,
506 notmuch_filenames_get (db_subdirs));
508 _filename_list_add (state->removed_directories, absolute);
510 notmuch_filenames_move_to_next (db_subdirs);
514 status = notmuch_directory_set_mtime (directory, fs_mtime);
515 if (status && ret == NOTMUCH_STATUS_SUCCESS)
529 notmuch_filenames_destroy (db_subdirs);
531 notmuch_filenames_destroy (db_files);
533 notmuch_directory_destroy (directory);
539 setup_progress_printing_timer (void)
541 struct sigaction action;
542 struct itimerval timerval;
544 /* Setup our handler for SIGALRM */
545 memset (&action, 0, sizeof (struct sigaction));
546 action.sa_handler = handle_sigalrm;
547 sigemptyset (&action.sa_mask);
548 action.sa_flags = SA_RESTART;
549 sigaction (SIGALRM, &action, NULL);
551 /* Then start a timer to send SIGALRM once per second. */
552 timerval.it_interval.tv_sec = 1;
553 timerval.it_interval.tv_usec = 0;
554 timerval.it_value.tv_sec = 1;
555 timerval.it_value.tv_usec = 0;
556 setitimer (ITIMER_REAL, &timerval, NULL);
560 stop_progress_printing_timer (void)
562 struct sigaction action;
563 struct itimerval timerval;
565 /* Now stop the timer. */
566 timerval.it_interval.tv_sec = 0;
567 timerval.it_interval.tv_usec = 0;
568 timerval.it_value.tv_sec = 0;
569 timerval.it_value.tv_usec = 0;
570 setitimer (ITIMER_REAL, &timerval, NULL);
572 /* And disable the signal handler. */
573 action.sa_handler = SIG_IGN;
574 sigaction (SIGALRM, &action, NULL);
578 /* This is the top-level entry point for add_files. It does a couple
579 * of error checks and then calls into the recursive function. */
580 static notmuch_status_t
581 add_files (notmuch_database_t *notmuch,
583 add_files_state_t *state)
585 notmuch_status_t status;
588 if (stat (path, &st)) {
589 fprintf (stderr, "Error reading directory %s: %s\n",
590 path, strerror (errno));
591 return NOTMUCH_STATUS_FILE_ERROR;
594 if (! S_ISDIR (st.st_mode)) {
595 fprintf (stderr, "Error: %s is not a directory.\n", path);
596 return NOTMUCH_STATUS_FILE_ERROR;
599 status = add_files_recursive (notmuch, path, state);
604 /* XXX: This should be merged with the add_files function since it
605 * shares a lot of logic with it. */
606 /* Recursively count all regular files in path and all sub-directories
607 * of path. The result is added to *count (which should be
608 * initialized to zero by the top-level caller before calling
611 count_files (const char *path, int *count)
613 struct dirent *entry = NULL;
616 struct dirent **fs_entries = NULL;
617 int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
620 if (num_fs_entries == -1) {
621 fprintf (stderr, "Warning: failed to open directory %s: %s\n",
622 path, strerror (errno));
626 while (!interrupted) {
627 if (i == num_fs_entries)
630 entry = fs_entries[i++];
632 /* Ignore special directories to avoid infinite recursion.
633 * Also ignore the .notmuch directory.
635 /* XXX: Eventually we'll want more sophistication to let the
636 * user specify files to be ignored. */
637 if (strcmp (entry->d_name, ".") == 0 ||
638 strcmp (entry->d_name, "..") == 0 ||
639 strcmp (entry->d_name, ".notmuch") == 0)
644 if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
646 fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
647 path, entry->d_name);
653 if (S_ISREG (st.st_mode)) {
655 if (*count % 1000 == 0) {
656 printf ("Found %d files so far.\r", *count);
659 } else if (S_ISDIR (st.st_mode)) {
660 count_files (next, count);
674 upgrade_print_progress (void *closure,
677 add_files_state_t *state = closure;
679 printf ("Upgrading database: %.2f%% complete", progress * 100.0);
682 struct timeval tv_now;
683 double elapsed, time_remaining;
685 gettimeofday (&tv_now, NULL);
687 elapsed = notmuch_time_elapsed (state->tv_start, tv_now);
688 time_remaining = (elapsed / progress) * (1.0 - progress);
690 notmuch_time_print_formatted_seconds (time_remaining);
691 printf (" remaining)");
699 /* Recursively remove all filenames from the database referring to
700 * 'path' (or to any of its children). */
702 _remove_directory (void *ctx,
703 notmuch_database_t *notmuch,
708 notmuch_directory_t *directory;
709 notmuch_filenames_t *files, *subdirs;
710 notmuch_status_t status;
713 directory = notmuch_database_get_directory (notmuch, path);
715 for (files = notmuch_directory_get_child_files (directory);
716 notmuch_filenames_valid (files);
717 notmuch_filenames_move_to_next (files))
719 absolute = talloc_asprintf (ctx, "%s/%s", path,
720 notmuch_filenames_get (files));
721 status = notmuch_database_remove_message (notmuch, absolute);
722 if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
723 *renamed_files = *renamed_files + 1;
725 *removed_files = *removed_files + 1;
726 talloc_free (absolute);
729 for (subdirs = notmuch_directory_get_child_directories (directory);
730 notmuch_filenames_valid (subdirs);
731 notmuch_filenames_move_to_next (subdirs))
733 absolute = talloc_asprintf (ctx, "%s/%s", path,
734 notmuch_filenames_get (subdirs));
735 _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);
736 talloc_free (absolute);
739 notmuch_directory_destroy (directory);
743 notmuch_new_command (void *ctx, int argc, char *argv[])
745 notmuch_config_t *config;
746 notmuch_database_t *notmuch;
747 add_files_state_t add_files_state;
749 struct timeval tv_now, tv_start;
753 char *dot_notmuch_path;
754 struct sigaction action;
756 int renamed_files, removed_files;
757 notmuch_status_t status;
759 notmuch_bool_t timer_is_active = FALSE;
761 add_files_state.verbose = 0;
762 add_files_state.output_is_a_tty = isatty (fileno (stdout));
764 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
765 if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
766 add_files_state.verbose = 1;
768 fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
772 config = notmuch_config_open (ctx, NULL, NULL);
776 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
777 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
778 add_files_state.message_ids_to_sync = _filename_list_create (ctx);
779 db_path = notmuch_config_get_database_path (config);
781 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
783 if (stat (dot_notmuch_path, &st)) {
787 count_files (db_path, &count);
791 printf ("Found %d total files (that's not much mail).\n", count);
792 notmuch = notmuch_database_create (db_path);
793 add_files_state.total_files = count;
795 notmuch = notmuch_database_open (db_path,
796 NOTMUCH_DATABASE_MODE_READ_WRITE);
800 if (notmuch_database_needs_upgrade (notmuch)) {
801 printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");
802 gettimeofday (&add_files_state.tv_start, NULL);
803 notmuch_database_upgrade (notmuch, upgrade_print_progress,
805 printf ("Your notmuch database has now been upgraded to database format version %u.\n",
806 notmuch_database_get_version (notmuch));
809 add_files_state.total_files = 0;
815 /* Setup our handler for SIGINT. We do this after having
816 * potentially done a database upgrade we this interrupt handler
818 memset (&action, 0, sizeof (struct sigaction));
819 action.sa_handler = handle_sigint;
820 sigemptyset (&action.sa_mask);
821 action.sa_flags = SA_RESTART;
822 sigaction (SIGINT, &action, NULL);
824 talloc_free (dot_notmuch_path);
825 dot_notmuch_path = NULL;
827 add_files_state.processed_files = 0;
828 add_files_state.added_messages = 0;
829 gettimeofday (&add_files_state.tv_start, NULL);
831 add_files_state.removed_files = _filename_list_create (ctx);
832 add_files_state.removed_directories = _filename_list_create (ctx);
834 if (! debugger_is_active () && add_files_state.output_is_a_tty
835 && ! add_files_state.verbose) {
836 setup_progress_printing_timer ();
837 timer_is_active = TRUE;
840 ret = add_files (notmuch, db_path, &add_files_state);
844 gettimeofday (&tv_start, NULL);
845 for (f = add_files_state.removed_files->head; f; f = f->next) {
846 status = notmuch_database_remove_message (notmuch, f->filename);
847 if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
851 if (do_print_progress) {
852 do_print_progress = 0;
853 generic_print_progress ("Cleaned up", "messages",
854 tv_start, removed_files + renamed_files,
855 add_files_state.removed_files->count);
859 gettimeofday (&tv_start, NULL);
860 for (f = add_files_state.removed_directories->head, i = 0; f; f = f->next, i++) {
861 _remove_directory (ctx, notmuch, f->filename,
862 &renamed_files, &removed_files);
863 if (do_print_progress) {
864 do_print_progress = 0;
865 generic_print_progress ("Cleaned up", "directories",
867 add_files_state.removed_directories->count);
871 talloc_free (add_files_state.removed_files);
872 talloc_free (add_files_state.removed_directories);
874 /* Now that removals are done (hence the database is aware of all
875 * renames), we can synchronize maildir_flags to tags for all
876 * messages that had new filenames appear on this run. */
877 gettimeofday (&tv_start, NULL);
878 if (add_files_state.synchronize_flags) {
879 _filename_node_t *node;
880 notmuch_message_t *message;
881 for (node = add_files_state.message_ids_to_sync->head, i = 0;
883 node = node->next, i++)
885 message = notmuch_database_find_message (notmuch, node->filename);
886 notmuch_message_maildir_flags_to_tags (message);
887 notmuch_message_destroy (message);
888 if (do_print_progress) {
889 do_print_progress = 0;
890 generic_print_progress (
891 "Synchronized tags for", "messages",
892 tv_start, i, add_files_state.message_ids_to_sync->count);
897 talloc_free (add_files_state.message_ids_to_sync);
898 add_files_state.message_ids_to_sync = NULL;
901 stop_progress_printing_timer ();
903 gettimeofday (&tv_now, NULL);
904 elapsed = notmuch_time_elapsed (add_files_state.tv_start,
907 if (add_files_state.processed_files) {
908 printf ("Processed %d %s in ", add_files_state.processed_files,
909 add_files_state.processed_files == 1 ?
910 "file" : "total files");
911 notmuch_time_print_formatted_seconds (elapsed);
913 printf (" (%d files/sec.).\033[K\n",
914 (int) (add_files_state.processed_files / elapsed));
916 printf (".\033[K\n");
920 if (add_files_state.added_messages) {
921 printf ("Added %d new %s to the database.",
922 add_files_state.added_messages,
923 add_files_state.added_messages == 1 ?
924 "message" : "messages");
926 printf ("No new mail.");
930 printf (" Removed %d %s.",
932 removed_files == 1 ? "message" : "messages");
936 printf (" Detected %d file %s.",
938 renamed_files == 1 ? "rename" : "renames");
944 printf ("\nNote: At least one error was encountered: %s\n",
945 notmuch_status_to_string (ret));
948 notmuch_database_close (notmuch);
950 return ret || interrupted;