--- /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 2DDF9429E34\r
+ for <notmuch@notmuchmail.org>; Fri, 2 May 2014 01:23:33 -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 p-mRLSGE+BAP for <notmuch@notmuchmail.org>;\r
+ Fri, 2 May 2014 01:23:28 -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 944F1431FCF\r
+ for <notmuch@notmuchmail.org>; Fri, 2 May 2014 01:23:17 -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 DB7825005F2;\r
+ Fri, 2 May 2014 09:16:11 +0100 (BST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+ id BC04E103453; Fri, 2 May 2014 09:16:10 +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 09:15:51 +0100\r
+Message-Id: <1399018555-1994-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.9.2\r
+In-Reply-To: <1399018555-1994-1-git-send-email-dme@dme.org>\r
+References: <1399018555-1994-1-git-send-email-dme@dme.org>\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 08:23:33 -0000\r
+\r
+Rather than hand-coding the application of tags to new messages, use\r
+the existing tag_op_list_apply().\r
+---\r
+ notmuch-new.c | 31 ++++++++++++++++---------------\r
+ 1 file changed, 16 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index d269c7c..b53401a 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_MAILDIR_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
+-- \r
+1.9.2\r
+\r