[PATCH 11/18] insert: apply command-line tag operations

Peter Wang novalazy at gmail.com
Wed Jul 25 06:42:40 PDT 2012


Apply the +tag and -tag operations which were specified on the
command-line.
---
 notmuch-insert.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index 6db03e3..5fd79be 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -151,7 +151,7 @@ copy_fd_data (int fdin, int fdout)
 
 static notmuch_bool_t
 save_database (notmuch_database_t *notmuch, const char *path,
-	       const char **new_tags)
+	       const char **new_tags, const tag_operation_t *tag_ops)
 {
     notmuch_message_t *message;
     notmuch_status_t status;
@@ -186,6 +186,14 @@ save_database (notmuch_database_t *notmuch, const char *path,
 	notmuch_message_add_tag (message, new_tags[i]);
     }
 
+    for (i = 0; tag_ops[i].tag; i++) {
+	if (tag_ops[i].remove) {
+	    notmuch_message_remove_tag (message, tag_ops[i].tag);
+	} else {
+	    notmuch_message_add_tag (message, tag_ops[i].tag);
+	}
+    }
+
     notmuch_message_thaw (message);
 
     notmuch_message_tags_to_maildir_flags (message);
@@ -197,7 +205,8 @@ save_database (notmuch_database_t *notmuch, const char *path,
 
 static notmuch_bool_t
 insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
-		const char *dir, const char **new_tags)
+		const char *dir, const char **new_tags,
+		const tag_operation_t *tag_ops)
 {
     char *tmppath;
     char *newpath;
@@ -222,7 +231,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
 	return FALSE;
     }
 
-    ret = save_database (notmuch, newpath, new_tags);
+    ret = save_database (notmuch, newpath, new_tags, tag_ops);
 
     if (!ret) {
 	/* XXX maybe there should be an option to keep the file in maildir? */
@@ -324,7 +333,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
 			       NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
 	return 1;
 
-    ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags);
+    ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags,
+			  tag_ops);
 
     notmuch_database_destroy (notmuch);
 
-- 
1.7.4.4



More information about the notmuch mailing list