+ if (ret) {
+ printf ("Note: At least one error was encountered: %s\n",
+ notmuch_status_to_string (ret));
+ }
+
+ DONE:
+ if (mail_directory)
+ free (mail_directory);
+ if (notmuch)
+ notmuch_database_close (notmuch);
+
+ return ret;
+}
+
+int
+new_command (int argc, char *argv[])
+{
+ notmuch_database_t *notmuch;
+ const char *mail_directory;
+ add_files_state_t add_files_state;
+ double elapsed;
+ struct timeval tv_now;
+ int ret = 0;
+
+ notmuch = notmuch_database_open (NULL);
+ if (notmuch == NULL) {
+ ret = 1;
+ goto DONE;
+ }
+
+ mail_directory = notmuch_database_get_path (notmuch);
+
+ add_files_state.ignore_read_only_directories = TRUE;
+ add_files_state.saw_read_only_directory = FALSE;
+ add_files_state.total_files = 0;
+ add_files_state.processed_files = 0;
+ add_files_state.added_messages = 0;
+ gettimeofday (&add_files_state.tv_start, NULL);
+
+ ret = add_files (notmuch, mail_directory, &add_files_state);
+
+ gettimeofday (&tv_now, NULL);
+ elapsed = tv_elapsed (add_files_state.tv_start,
+ tv_now);
+ if (add_files_state.processed_files) {
+ printf ("Processed %d %s in ", add_files_state.processed_files,
+ add_files_state.processed_files == 1 ?
+ "file" : "total files");
+ print_formatted_seconds (elapsed);
+ if (elapsed > 1) {
+ printf (" (%d files/sec.). \n",
+ (int) (add_files_state.processed_files / elapsed));
+ } else {
+ printf (". \n");
+ }
+ }
+ if (add_files_state.added_messages) {
+ printf ("Added %d new %s to the database (not much, really).\n",
+ add_files_state.added_messages,
+ add_files_state.added_messages == 1 ?
+ "message" : "messages");
+ } else {
+ printf ("No new mail---and that's not much.\n");
+ }
+
+ if (elapsed > 1 && ! add_files_state.saw_read_only_directory) {
+ printf ("\nTip: If you have any sub-directories that are archives (that is,\n"
+ "they will never receive new mail), marking these directores as\n"
+ "read-only (chmod u-w /path/to/dir) will make \"notmuch new\"\n"
+ "much more efficient (it won't even look in those directories).\n");
+ }
+
+ if (ret) {
+ printf ("\nNote: At least one error was encountered: %s\n",
+ notmuch_status_to_string (ret));
+ }
+
+ DONE:
+ if (notmuch)
+ notmuch_database_close (notmuch);
+
+ return ret;