[PATCH] notmuch new: add a --in-directory option

Subject: [PATCH] notmuch new: add a --in-directory option

Date: Thu, 6 Mar 2014 20:58:27 +0000

To: notmuch@notmuchmail.org

Cc:

From: Mark Walters


This patch adds a --in-directory=folder option to notmuch new which
tells it to only check for new messages inside folder (relative to the
database root)
---

NOTE This is only very lightly tested (but seems to work) so please
make sure you backup the notmuch database before testing!


 notmuch-new.c    |   10 +++++++++-
 test/T050-new.sh |   15 +++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 8529fdd..d3526ac 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -922,6 +922,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_bool_t timer_is_active = FALSE;
     notmuch_bool_t no_hooks = FALSE;
     notmuch_bool_t quiet = FALSE, verbose = FALSE;
+    char *directory = NULL;
+    char *path = NULL;
 
     add_files_state.verbosity = VERBOSITY_NORMAL;
     add_files_state.debug = FALSE;
@@ -932,6 +934,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
 	{ NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },
 	{ NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },
 	{ NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },
+	{ NOTMUCH_OPT_STRING, &directory, "in-directory", 'i', 0  },
 	{ 0, 0, 0, 0, 0 }
     };
 
@@ -1021,7 +1024,12 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
 	timer_is_active = TRUE;
     }
 
-    ret = add_files (notmuch, db_path, &add_files_state);
+    if (directory)
+	path = talloc_asprintf (config, "%s/%s", db_path, directory);
+    else
+	path = talloc_strdup (config, db_path);
+
+    ret = add_files (notmuch, path, &add_files_state);
     if (ret)
 	goto DONE;
 
diff --git a/test/T050-new.sh b/test/T050-new.sh
index b7668ff..b8e68a3 100755
--- a/test/T050-new.sh
+++ b/test/T050-new.sh
@@ -263,4 +263,19 @@ notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0
 output=$(NOTMUCH_NEW --quiet)
 test_expect_equal "$output" ""
 
+test_begin_subtest "In-directory"
+rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
+mkdir "${MAIL_DIR}"/def
+mkdir "${MAIL_DIR}"/ghi
+generate_message [dir]=def
+generate_message [dir]=ghi
+generate_message
+
+output=$(NOTMUCH_NEW --in-directory=def)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+test_begin_subtest "New after --in-directory"
+output=$(NOTMUCH_NEW)
+test_expect_equal "$output" "Added 2 new messages to the database."
+
 test_done
-- 
1.7.9.1


Thread: