unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org, Rob Browning <rlb@defaultvalue.org>
Subject: [PATCH 2/3] cli: make sure notmuch new and insert don't add invalid tags
Date: Sun, 23 Feb 2014 18:55:22 +0200	[thread overview]
Message-ID: <edc2bc900f75bb2e72be2037e2df9105be7f0273.1393174108.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1393174108.git.jani@nikula.org>
In-Reply-To: <cover.1393174108.git.jani@nikula.org>

Check new.tags configuration values before doing anything, and bail
out on invalid values.
---
 notmuch-insert.c |  9 +++++++++
 notmuch-new.c    | 14 +++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index cd6de88f6891..6752fc8de255 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -431,6 +431,15 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 	return EXIT_FAILURE;
     }
     for (i = 0; i < new_tags_length; i++) {
+	const char *error_msg;
+
+	error_msg = illegal_tag (new_tags[i], FALSE);
+	if (error_msg) {
+	    fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",
+		     new_tags[i],  error_msg);
+	    return EXIT_FAILURE;
+	}
+
 	if (tag_op_list_append (tag_ops, new_tags[i], FALSE))
 	    return EXIT_FAILURE;
     }
diff --git a/notmuch-new.c b/notmuch-new.c
index 8529fdd3eac7..82acf695353e 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -19,6 +19,7 @@
  */
 
 #include "notmuch-client.h"
+#include "tag-util.h"
 
 #include <unistd.h>
 
@@ -918,7 +919,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     struct sigaction action;
     _filename_node_t *f;
     int opt_index;
-    int i;
+    unsigned int i;
     notmuch_bool_t timer_is_active = FALSE;
     notmuch_bool_t no_hooks = FALSE;
     notmuch_bool_t quiet = FALSE, verbose = FALSE;
@@ -950,6 +951,17 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
     db_path = notmuch_config_get_database_path (config);
 
+    for (i = 0; i < add_files_state.new_tags_length; i++) {
+	const char *error_msg;
+
+	error_msg = illegal_tag (add_files_state.new_tags[i], FALSE);
+	if (error_msg) {
+	    fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",
+		     add_files_state.new_tags[i], error_msg);
+	    return EXIT_FAILURE;
+	}
+    }
+
     if (!no_hooks) {
 	ret = notmuch_run_hook (db_path, "pre-new");
 	if (ret)
-- 
1.8.5.3

  parent reply	other threads:[~2014-02-23 16:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-23  2:29 [BUG] Putting "tags=;" into .notmuch-config will create empty tags Rob Browning
2014-02-23 16:55 ` [PATCH 0/3] check new.tags for invalid tags Jani Nikula
2014-02-23 16:55   ` [PATCH 1/3] cli: export function for illegal tag checking Jani Nikula
2014-02-23 16:55   ` Jani Nikula [this message]
2014-02-23 16:55   ` [PATCH 3/3] test: add tests for invalid new.tags Jani Nikula
2014-02-23 18:21   ` [PATCH 0/3] check new.tags for invalid tags Tomi Ollila
2014-03-04 16:51     ` [PATCH] cli: add missing \n in error message Jani Nikula
2014-03-06 11:51   ` [PATCH 0/3] check new.tags for invalid tags 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=edc2bc900f75bb2e72be2037e2df9105be7f0273.1393174108.git.jani@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    --cc=rlb@defaultvalue.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).