[PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated.

David Edmondson dme at dme.org
Fri May 2 01:15:52 PDT 2014


Add support for specifying a set of tags to be added/removed from
messages added to the database by 'notmuch new'. These tags are
addition to those specified in .notmuch-config. They can be used to
override the pre-configured tags (e.g. -inbox).
---
 notmuch-new.c |  5 +++++
 tag-util.c    | 20 +++++++++++++++-----
 tag-util.h    | 15 +++++++++++++++
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index b53401a..855e1e2 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -951,6 +951,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     add_files_state.tag_ops = tag_op_list_create (config);
     db_path = notmuch_config_get_database_path (config);
 
+    /* Add the configured tags to the list applied. */
     for (i = 0; i < new_tags_length; i++) {
 	const char *error_msg;
 
@@ -963,6 +964,10 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
 	    return EXIT_FAILURE;
     }
 
+    /* Add any command line tags to the list applied. */
+    if (process_tag_command_line (argc - opt_index, &argv[opt_index], add_files_state.tag_ops) < 0)
+	return EXIT_FAILURE;
+
     if (!no_hooks) {
 	ret = notmuch_run_hook (db_path, "pre-new");
 	if (ret)
diff --git a/tag-util.c b/tag-util.c
index 343c161..5ad78aa 100644
--- a/tag-util.c
+++ b/tag-util.c
@@ -151,11 +151,9 @@ parse_tag_line (void *ctx, char *line,
     return ret;
 }
 
-tag_parse_status_t
-parse_tag_command_line (void *ctx, int argc, char **argv,
-			char **query_str, tag_op_list_t *tag_ops)
+int
+process_tag_command_line (int argc, char **argv, tag_op_list_t *tag_ops)
 {
-
     int i;
 
     for (i = 0; i < argc; i++) {
@@ -173,12 +171,24 @@ parse_tag_command_line (void *ctx, int argc, char **argv,
 	msg = illegal_tag (argv[i] + 1, is_remove);
 	if (msg) {
 	    fprintf (stderr, "Error: %s\n", msg);
-	    return TAG_PARSE_INVALID;
+	    return -1;
 	}
 
 	tag_op_list_append (tag_ops, argv[i] + 1, is_remove);
     }
 
+    return i;
+}
+
+tag_parse_status_t
+parse_tag_command_line (void *ctx, int argc, char **argv,
+			char **query_str, tag_op_list_t *tag_ops)
+{
+    int i = process_tag_command_line (argc, argv, tag_ops);
+
+    if (i < 0)
+	return TAG_PARSE_INVALID;
+
     *query_str = query_string_from_args (ctx, argc - i, &argv[i]);
 
     if (*query_str == NULL) {
diff --git a/tag-util.h b/tag-util.h
index 8a4074c..9f2c18c 100644
--- a/tag-util.h
+++ b/tag-util.h
@@ -74,6 +74,21 @@ parse_tag_line (void *ctx, char *line,
 
 
 
+/* Process a command line of the following format:
+ *
+ * +<tag>|-<tag> [...] [--]
+ *
+ * Return the number of tags operations, or -1 for failure to parse.
+ *
+ * Output Parameters:
+ *	ops	contains a list of tag operations
+ *
+ * The ops argument is not cleared.
+ */
+
+int
+process_tag_command_line (int argc, char **argv, tag_op_list_t *ops);
+
 /* Parse a command line of the following format:
  *
  * +<tag>|-<tag> [...] [--] <search-terms>
-- 
1.9.2



More information about the notmuch mailing list