unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] notmuch new: add a --in-directory option
@ 2014-03-06 20:58 Mark Walters
  2014-03-06 21:06 ` Austin Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Walters @ 2014-03-06 20:58 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-07 11:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-06 20:58 [PATCH] notmuch new: add a --in-directory option Mark Walters
2014-03-06 21:06 ` Austin Clements
2014-03-06 21:16   ` Adam Wolfe Gordon
2014-03-07 11:53     ` Tomi Ollila

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).