unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jan Janak <jan@ryngle.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 5/5] notmuch-new: Option to disable tags from the configuration file.
Date: Thu, 26 Nov 2009 00:30:16 +0100	[thread overview]
Message-ID: <1259191816-1982-5-git-send-email-jan@ryngle.com> (raw)
In-Reply-To: <1259191816-1982-4-git-send-email-jan@ryngle.com>

This patch slightly changes behavior of the command line option --tag.
Any tags specified by the user on the command line will be added
*in addition* to tags configured in the configuration file.

This behavior can be changed with the new command line option
--no-config-tags. The user can use this option to ignore any tags from
the configuration file (i.e. only tags specified on the command line
will be applied).

With this new option the user can configure 'notmuch new' not to apply
any tags (and that was not possible before):

  notmuch new --no-config-tags

Suggested by Karl Wiberg.

Bugfix: Fix parsing of --verbose cmdline option.

This is a revised version of the patch, incorporating suggestions made
by Bart Trojanowski. Thanks Bart!

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 notmuch-new.c |   21 ++++++++++++---------
 notmuch.c     |   13 +++++++++++--
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index cfbc6aa..eaed701 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -28,6 +28,7 @@ static notmuch_config_t *config = NULL;
 
 static char **cmdline_tags = NULL;
 static size_t cmdline_tags_count = 0;
+static int add_config_tags = 1;
 
 static void
 handle_sigalrm (unused (int signal))
@@ -79,19 +80,19 @@ apply_tags (notmuch_message_t *message)
     char** tags;
     size_t count, i;
 
+    if (add_config_tags) {
+	tags = notmuch_config_get_new_tags (config, &count);
+	for (i = 0; tags && (i < count); i++) {
+	    if (tags[i])
+		notmuch_message_add_tag (message, tags[i]);
+	}
+    }
+
     if (cmdline_tags_count) {
 	for (i = 0; i < cmdline_tags_count; i++) {
 	    if (cmdline_tags[i])
 		notmuch_message_add_tag (message, cmdline_tags[i]);
 	}
-    } else {
-	if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)
-	    return;
-
-	for (i = 0; i < count; i++) {
-	    if (tags[i])
-		notmuch_message_add_tag (message, tags[i]);
-	}
     }
 }
 
@@ -432,7 +433,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     add_files_state.output_is_a_tty = isatty (fileno (stdout));
 
     for (i = 0; i < argc && argv[i][0] == '-'; i++) {
-	if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
+	if (strcmp (argv[i], "--verbose") == 0) {
 	    add_files_state.verbose = 1;
 	} else if (STRNCMP_LITERAL (argv[i], "--tag=") == 0) {
 	    opt = argv[i] + sizeof ("--tag=") - 1;
@@ -451,6 +452,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
 	    }
 	    tmp[cmdline_tags_count++] = opt;
 	    cmdline_tags = tmp;
+	} else if (strcmp (argv[i], "--no-config-tags") == 0) {
+	    add_config_tags = 0;
 	} else {
 	    fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
 	    return 1;
diff --git a/notmuch.c b/notmuch.c
index 1bd3265..2bb38f3 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -123,7 +123,7 @@ command_t commands[] = {
       "\t\tInvoking notmuch with no command argument will run setup if\n"
       "\t\tthe setup command has not previously been completed." },
     { "new", notmuch_new_command,
-      "[--verbose] [--tag=<name>]",
+      "[--verbose] [--tag=<name>] [--no-config-tags]",
       "\t\tFind and import new messages to the notmuch database.",
       "\t\tScans all sub-directories of the mail directory, performing\n"
       "\t\tfull-text indexing on new messages that are found. Each new\n"
@@ -149,7 +149,16 @@ command_t commands[] = {
       "\n"
       "\t\t\tAdd the tag <name> to all messages newly added to the\n"
       "\t\t\tdatabase. You may repeat this option several times if\n"
-      "\t\t\tyou want to add more tags.\n"
+      "\t\t\tyou want to add more tags. Any tags configured in the\n"
+      "\t\t\tconfiguration file will still be added, unless you also\n"
+      "\t\t\tuse the option --no-config-tags.\n"
+      "\n"
+      "\t\t--no-config-tags\n"
+      "\n"
+      "\t\t\tDo not add tags configured in the configuration file.\n"
+      "\t\t\tUse this option if you only want to add tags specified\n"
+      "\t\t\ton the command line with --tag or if do not want to add\n"
+      "\t\t\tany tags at all.\n"
       "\n"
       "\t\tNote: \"notmuch new\" runs (other than the first run) will\n"
       "\t\tskip any read-only directories, so you can use that to mark\n"
-- 
1.6.3.3

  reply	other threads:[~2009-11-25 23:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-24 22:10 [PATCH 0/4] Make tags applied by 'notmuch new' configurable Jan Janak
2009-11-24 22:10 ` [PATCH 1/4] notmuch-new: Remove tag_add_inbox_unread in favor of a generic solution Jan Janak
2009-11-24 22:10   ` [PATCH 2/4] notmuch: Config option to specify tags to be applied by 'notmuch new' Jan Janak
2009-11-24 22:10     ` [PATCH 3/4] notmuch-setup: Copy/create the new section with tags for 'notmuch-new' Jan Janak
2009-11-24 22:10       ` [PATCH 4/4] notmuch-new: New cmdline option --tag=<name> Jan Janak
2009-11-25  6:21         ` Karl Wiberg
2009-11-25 17:59           ` Jan Janak
2009-11-25 18:37         ` [PATCH] notmuch-new: Option to disable tags from the configuration file Jan Janak
2009-11-25 19:55           ` Bart Trojanowski
2009-11-25 21:25             ` Jan Janak
2009-11-25 20:56     ` [PATCH 2/4] notmuch: Config option to specify tags to be applied by 'notmuch new' Bart Trojanowski
2009-11-25 21:50       ` Jan Janak
2009-12-02 21:42         ` Carl Worth
2009-11-24 22:50 ` [PATCH 0/4] Make tags applied by 'notmuch new' configurable Brett Viren
2009-11-25  3:07 ` Bdale Garbee
2009-11-25  3:35 ` Bart Trojanowski
2009-11-25 23:30 ` [PATCH 1/5] notmuch-new: Remove tag_add_inbox_unread in favor of a generic solution Jan Janak
2009-11-25 23:30   ` [PATCH 2/5] notmuch: Config option to specify tags to be applied by 'notmuch new' Jan Janak
2009-11-25 23:30     ` [PATCH 3/5] notmuch-setup: Copy/create the new section with tags for 'notmuch-new' Jan Janak
2009-11-25 23:30       ` [PATCH 4/5] notmuch-new: New cmdline option --tag=<name> Jan Janak
2009-11-25 23:30         ` Jan Janak [this message]
2009-11-25 23:48 ` [PATCH 0/4] Make tags applied by 'notmuch new' configurable Jan Janak
2009-12-02 21:36 ` Carl Worth
2009-12-03  9:48   ` Marten Veldthuis
2009-12-04  6:17     ` Carl Worth

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=1259191816-1982-5-git-send-email-jan@ryngle.com \
    --to=jan@ryngle.com \
    --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).