--- /dev/null
+Return-Path: <novalazy@gmail.com>\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 B4CB2431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:18:13 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 xexACAUHANPC for <notmuch@notmuchmail.org>;\r
+ Sat, 24 Nov 2012 17:18:12 -0800 (PST)\r
+Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com\r
+ [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id BF89A431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:18:12 -0800 (PST)\r
+Received: by mail-pa0-f53.google.com with SMTP id hz1so3911431pad.26\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:18:12 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=C/OKiYOj1R2YY88A/3izhtdqhpAObijV7xGH0v3i6zU=;\r
+ b=pI5XW9ikv4pp/7MqnklEzKCBeNk9zrjt/YDt05pNaaakKB2EMqMf8gbqC7XbQ64dIr\r
+ eH7kDLOijtf+07lxEPrBQBpRaVPHQX3DB5A9LooCYP7VBnbLb90AZWO6AjUUI9NMiFI8\r
+ lKZi1VtnE2fyKUUN2QCmpacoblkbkTPAPaBdhtIwPwRrnEh3dK9S/q+n74N1qa6iMn6u\r
+ +s3O7V0mJ2ST9GCbcKPSQ2RpDCUSS7SSr3JH6SDeJPfLpq1xCVH3LwVAhqBXbeFNX8Ka\r
+ t0+Bt3IZZLcWvDJDFuVVlGB+TD8kzf+XQrmSrZ8zM15ANBEqmUk5eWT+nJCAaq4lpT93\r
+ kIcg==\r
+Received: by 10.69.1.35 with SMTP id bd3mr26639614pbd.141.1353806292536;\r
+ Sat, 24 Nov 2012 17:18:12 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215])\r
+ by mx.google.com with ESMTPS id uk9sm6220363pbc.63.2012.11.24.17.18.09\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 24 Nov 2012 17:18:11 -0800 (PST)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 12/20] insert: apply command-line tag operations\r
+Date: Sun, 25 Nov 2012 12:16:38 +1100\r
+Message-Id: <1353806206-29133-13-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.7.12.1\r
+In-Reply-To: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\r
+References: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\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: Sun, 25 Nov 2012 01:18:14 -0000\r
+\r
+Apply the +tag and -tag operations specified on the command-line.\r
+---\r
+ notmuch-insert.c | 19 +++++++++++++++----\r
+ 1 file changed, 15 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index e4631a2..81a528c 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -174,7 +174,8 @@ copy_fd_data (int fdin, int fdout)\r
+ * The file is renamed to encode notmuch tags as maildir flags. */\r
+ static notmuch_bool_t\r
+ add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
+- const char **new_tags)\r
++ const char **new_tags,\r
++ const notmuch_tag_operation_t *tag_ops)\r
+ {\r
+ notmuch_message_t *message;\r
+ notmuch_status_t status;\r
+@@ -211,6 +212,14 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
+ notmuch_message_add_tag (message, new_tags[i]);\r
+ }\r
+ \r
++ /* Apply the tags specified on the command-line. */\r
++ for (i = 0; tag_ops[i].tag; i++) {\r
++ if (tag_ops[i].remove)\r
++ notmuch_message_remove_tag (message, tag_ops[i].tag);\r
++ else\r
++ notmuch_message_add_tag (message, tag_ops[i].tag);\r
++ }\r
++\r
+ notmuch_message_thaw (message);\r
+ \r
+ notmuch_message_tags_to_maildir_flags (message);\r
+@@ -222,7 +231,8 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
+ \r
+ static notmuch_bool_t\r
+ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+- const char *dir, const char **new_tags)\r
++ const char *dir, const char **new_tags,\r
++ const notmuch_tag_operation_t *tag_ops)\r
+ {\r
+ char *tmppath;\r
+ char *newpath;\r
+@@ -243,7 +253,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+ return FALSE;\r
+ }\r
+ \r
+- ret = add_file_to_database (notmuch, newpath, new_tags);\r
++ ret = add_file_to_database (notmuch, newpath, new_tags, tag_ops);\r
+ if (!ret) {\r
+ /* XXX maybe there should be an option to keep the file in maildir? */\r
+ unlink (newpath);\r
+@@ -327,7 +337,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return 1;\r
+ \r
+- ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags);\r
++ ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags,\r
++ tag_ops);\r
+ \r
+ notmuch_database_destroy (notmuch);\r
+ \r
+-- \r
+1.7.12.1\r
+\r