From: Andreas Rammhold <andreas@rammhold.de> This introduces a new argument to notmuch-new(1) that allows specfying the tags that should be applied to new messages. The new option takes precedence over the new.tags setting configured in the configuration file. The need for this option did arise while due to race-conditions between notmuch tagging messages as new, running my post-new hook and unsetting the new tag as last step of my processing. --- doc/man1/notmuch-new.rst | 7 +++++++ notmuch-new.c | 16 +++++++++++++++- test/T050-new.sh | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/man1/notmuch-new.rst b/doc/man1/notmuch-new.rst index 9cb4a54e..d1ed5536 100644 --- a/doc/man1/notmuch-new.rst +++ b/doc/man1/notmuch-new.rst @@ -78,6 +78,13 @@ Supported options for **new** include to optimize the scanning of directories for new mail. This option turns that optimization off. +.. option:: --new-tags=<tags> + + If set defines an alternative value for the new tags that will be applied to + all newly added messages. + + See also ``new.tags`` in :any:`notmuch-config(1)`. + EXIT STATUS =========== diff --git a/notmuch-new.c b/notmuch-new.c index b7a5f2ea..80ef35d5 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1125,6 +1125,8 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[]) bool timer_is_active = false; bool hooks = true; bool quiet = false, verbose = false; + const char *new_tags = NULL; + notmuch_config_values_t *new_tags_config = NULL; notmuch_status_t status; notmuch_opt_desc_t options[] = { @@ -1133,6 +1135,7 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[]) { .opt_bool = &add_files_state.debug, .name = "debug" }, { .opt_bool = &add_files_state.full_scan, .name = "full-scan" }, { .opt_bool = &hooks, .name = "hooks" }, + { .opt_string = &new_tags, .name = "new-tags" }, { .opt_inherit = notmuch_shared_indexing_options }, { .opt_inherit = notmuch_shared_options }, { } @@ -1150,7 +1153,15 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[]) else if (verbose) add_files_state.verbosity = VERBOSITY_VERBOSE; - add_files_state.new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS); + if (! new_tags) { + add_files_state.new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS); + } else { + new_tags_config = notmuch_config_values_from_string (notmuch, new_tags); + if (! new_tags_config) + return EXIT_FAILURE; + + add_files_state.new_tags = new_tags_config; + } if (print_status_database ( "notmuch new", @@ -1290,6 +1301,9 @@ notmuch_new_command (notmuch_database_t *notmuch, int argc, char *argv[]) talloc_free (add_files_state.removed_directories); talloc_free (add_files_state.directory_mtimes); + if (new_tags_config) + talloc_free (new_tags_config); + if (timer_is_active) stop_progress_printing_timer (); diff --git a/test/T050-new.sh b/test/T050-new.sh index 1141c1e3..6b6f5071 100755 --- a/test/T050-new.sh +++ b/test/T050-new.sh @@ -37,6 +37,12 @@ test_begin_subtest "No new messages (full-scan)" output=$(NOTMUCH_NEW --debug --full-scan 2>&1) test_expect_equal "$output" "No new mail." +test_begin_subtest "Single new message with custom tags" +generate_message +NOTMUCH_NEW --debug --new-tags="foo-new;bar-new" +output=$(notmuch count tag:foo-new and tag:bar-new) +test_expect_equal "$output" "1" + test_begin_subtest "New directories" rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch mkdir "${MAIL_DIR}"/def -- 2.32.0 _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-leave@notmuchmail.org