unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: andreas@rammhold.de
To: notmuch@notmuchmail.org
Cc: Andreas Rammhold <andreas@rammhold.de>
Subject: [RFC 2/2] CLI/notmuch: add --new-tags argument to notmuch-new(1)
Date: Thu, 16 Sep 2021 12:25:17 +0200	[thread overview]
Message-ID: <20210916102517.1744389-3-andreas@rammhold.de> (raw)
In-Reply-To: <20210916102517.1744389-1-andreas@rammhold.de>

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

  parent reply	other threads:[~2021-09-16 11:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16 10:25 [RFC 0/2] add --new-tags= to notmuch-new(1) andreas
2021-09-16 10:25 ` [RFC 1/2] lib/config: introduce notmuch_config_values_from_string function andreas
2021-09-16 10:25 ` andreas [this message]
2021-09-16 12:03 ` [RFC 0/2] add --new-tags= to notmuch-new(1) Michael J Gruber
2021-09-16 12:24   ` andreas
2021-09-16 14:43     ` Michael J Gruber
2021-09-20 23:57 ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210916102517.1744389-3-andreas@rammhold.de \
    --to=andreas@rammhold.de \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).