[PATCH 09/18] insert: apply default tags to new message

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


Apply the new.tags to messages added by 'insert'.  This mirrors the
behaviour if the message were delivered by a separate tool followed by
'notmuch new'.
---
 notmuch-insert.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index ee51a87..4fb3ea3 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -145,10 +145,12 @@ copy_fd_data (int fdin, int fdout)
 }
 
 static notmuch_bool_t
-save_database (notmuch_database_t *notmuch, const char *path)
+save_database (notmuch_database_t *notmuch, const char *path,
+	       const char **new_tags)
 {
     notmuch_message_t *message;
     notmuch_status_t status;
+    int i;
 
     status = notmuch_database_add_message (notmuch, path, &message);
     switch (status) {
@@ -173,6 +175,14 @@ save_database (notmuch_database_t *notmuch, const char *path)
 	return FALSE;
     }
 
+    notmuch_message_freeze (message);
+
+    for (i = 0; new_tags[i]; i++) {
+	notmuch_message_add_tag (message, new_tags[i]);
+    }
+
+    notmuch_message_thaw (message);
+
     notmuch_message_tags_to_maildir_flags (message);
 
     notmuch_message_destroy (message);
@@ -182,7 +192,7 @@ 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 *dir, const char **new_tags)
 {
     char *tmppath;
     char *newpath;
@@ -207,7 +217,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
 	return FALSE;
     }
 
-    ret = save_database (notmuch, newpath);
+    ret = save_database (notmuch, newpath, new_tags);
 
     if (!ret) {
 	/* XXX maybe there should be an option to keep the file in maildir? */
@@ -223,6 +233,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
     notmuch_config_t *config;
     notmuch_database_t *notmuch;
     const char *db_path;
+    const char **new_tags;
+    size_t new_tags_length;
     const char *folder = NULL;
     char *maildir;
     int opt_index;
@@ -246,6 +258,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
 	return 1;
 
     db_path = notmuch_config_get_database_path (config);
+    new_tags = notmuch_config_get_new_tags (config, &new_tags_length);
 
     if (folder != NULL) {
 	if (! check_folder_name (folder)) {
@@ -261,7 +274,7 @@ 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);
+    ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags);
 
     notmuch_database_destroy (notmuch);
 
-- 
1.7.4.4



More information about the notmuch mailing list