--- /dev/null
+Return-Path: <dme@hotblack-desiato.hh.sledj.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 8EABB429E34\r
+ for <notmuch@notmuchmail.org>; Fri, 2 May 2014 05:15:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.379\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.379 tagged_above=-999 required=5\r
+ tests=[NO_DNS_FOR_FROM=0.379] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id Bg4jBL8POnFQ for <notmuch@notmuchmail.org>;\r
+ Fri, 2 May 2014 05:15:06 -0700 (PDT)\r
+Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net\r
+ [81.149.164.25])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id AAAAF431FD6\r
+ for <notmuch@notmuchmail.org>; Fri, 2 May 2014 05:14:59 -0700 (PDT)\r
+Received: from hotblack-desiato.hh.sledj.net (hotblack-desiato.hh.sledj.net\r
+ [172.16.100.105])\r
+ by disaster-area.hh.sledj.net (Postfix) with ESMTPSA id 10F1E5012F1;\r
+ Fri, 2 May 2014 13:14:57 +0100 (BST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+ id A713910345B; Fri, 2 May 2014 13:14:56 +0100 (BST)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than\r
+ hand-coding the same.\r
+Date: Fri, 2 May 2014 13:14:43 +0100\r
+Message-Id: <1399032887-25896-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.9.2\r
+In-Reply-To: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>\r
+References: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 02 May 2014 12:15:07 -0000\r
+\r
+Rather than hand-coding the application of tags to new messages, use\r
+the existing tag_op_list_apply().\r
+fixup.\r
+---\r
+ notmuch-new.c | 31 ++++++++++++++++---------------\r
+ tag-util.c | 8 ++++++++\r
+ tag-util.h | 10 +++++++---\r
+ 3 files changed, 31 insertions(+), 18 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index d269c7c..2c3d680 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -45,10 +45,9 @@ typedef struct {\r
+ int output_is_a_tty;\r
+ enum verbosity verbosity;\r
+ notmuch_bool_t debug;\r
+- const char **new_tags;\r
+- size_t new_tags_length;\r
+ const char **new_ignore;\r
+ size_t new_ignore_length;\r
++ tag_op_list_t *tag_ops;\r
+ \r
+ int total_files;\r
+ int processed_files;\r
+@@ -253,7 +252,6 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
+ add_files_state_t *state)\r
+ {\r
+ notmuch_message_t *message = NULL;\r
+- const char **tag;\r
+ notmuch_status_t status;\r
+ \r
+ status = notmuch_database_begin_atomic (notmuch);\r
+@@ -263,14 +261,13 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
+ status = notmuch_database_add_message (notmuch, filename, &message);\r
+ switch (status) {\r
+ /* Success. */\r
+- case NOTMUCH_STATUS_SUCCESS:\r
+- state->added_messages++;\r
+- notmuch_message_freeze (message);\r
+- for (tag = state->new_tags; *tag != NULL; tag++)\r
+- notmuch_message_add_tag (message, *tag);\r
++ case NOTMUCH_STATUS_SUCCESS:;\r
++ tag_op_flag_t flags = 0;\r
++\r
+ if (state->synchronize_flags)\r
+- notmuch_message_maildir_flags_to_tags (message);\r
+- notmuch_message_thaw (message);\r
++ flags |= TAG_FLAG_TAG_SYNC;\r
++ state->added_messages++;\r
++ (void) tag_op_list_apply (message, state->tag_ops, flags);\r
+ break;\r
+ /* Non-fatal issues (go on to next file). */\r
+ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+@@ -923,6 +920,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ notmuch_bool_t timer_is_active = FALSE;\r
+ notmuch_bool_t no_hooks = FALSE;\r
+ notmuch_bool_t quiet = FALSE, verbose = FALSE;\r
++ const char **new_tags;\r
++ size_t new_tags_length;\r
+ \r
+ add_files_state.verbosity = VERBOSITY_NORMAL;\r
+ add_files_state.debug = FALSE;\r
+@@ -946,20 +945,22 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ else if (verbose)\r
+ add_files_state.verbosity = VERBOSITY_VERBOSE;\r
+ \r
+- add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
++ new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
+ add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
+ add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
++ add_files_state.tag_ops = tag_op_list_create (config);\r
+ db_path = notmuch_config_get_database_path (config);\r
+ \r
+- for (i = 0; i < add_files_state.new_tags_length; i++) {\r
++ for (i = 0; i < new_tags_length; i++) {\r
+ const char *error_msg;\r
+ \r
+- error_msg = illegal_tag (add_files_state.new_tags[i], FALSE);\r
++ error_msg = illegal_tag (new_tags[i], FALSE);\r
+ if (error_msg) {\r
+- fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",\r
+- add_files_state.new_tags[i], error_msg);\r
++ fprintf (stderr, "Error: tag '%s' in new.tags: %s\n", new_tags[i], error_msg);\r
+ return EXIT_FAILURE;\r
+ }\r
++ if (tag_op_list_append (add_files_state.tag_ops, new_tags[i], FALSE) != 0)\r
++ return EXIT_FAILURE;\r
+ }\r
+ \r
+ if (!no_hooks) {\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 343c161..1dee2f3 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -327,6 +327,14 @@ tag_op_list_apply (notmuch_message_t *message,\r
+ }\r
+ }\r
+ \r
++ if (flags & TAG_FLAG_TAG_SYNC) {\r
++ status = notmuch_message_maildir_flags_to_tags (message);\r
++ if (status) {\r
++ message_error (message, status, "synching maildir to tags");\r
++ return status;\r
++ }\r
++ }\r
++\r
+ return NOTMUCH_STATUS_SUCCESS;\r
+ \r
+ }\r
+diff --git a/tag-util.h b/tag-util.h\r
+index 8a4074c..512cfac 100644\r
+--- a/tag-util.h\r
++++ b/tag-util.h\r
+@@ -14,19 +14,23 @@ typedef enum {\r
+ */\r
+ TAG_FLAG_MAILDIR_SYNC = (1 << 0),\r
+ \r
++ /* Operations are synced from maildir, if possible.\r
++ */\r
++ TAG_FLAG_TAG_SYNC = (1 << 1),\r
++\r
+ /* Remove all tags from message before applying list.\r
+ */\r
+- TAG_FLAG_REMOVE_ALL = (1 << 1),\r
++ TAG_FLAG_REMOVE_ALL = (1 << 2),\r
+ \r
+ /* Don't try to avoid database operations. Useful when we\r
+ * know that message passed needs these operations.\r
+ */\r
+- TAG_FLAG_PRE_OPTIMIZED = (1 << 2),\r
++ TAG_FLAG_PRE_OPTIMIZED = (1 << 3),\r
+ \r
+ /* Accept strange tags that might be user error;\r
+ * intended for use by notmuch-restore.\r
+ */\r
+- TAG_FLAG_BE_GENEROUS = (1 << 3)\r
++ TAG_FLAG_BE_GENEROUS = (1 << 4)\r
+ \r
+ } tag_op_flag_t;\r
+ \r
+-- \r
+1.9.2\r
+\r