--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 3A495431FC4\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 12:41:03 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 j0+jkCkpVI2V for <notmuch@notmuchmail.org>;\r
+ Sun, 16 Dec 2012 12:40:59 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 62FB0431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 12:40:59 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1TkL13-0005nd-3g; Sun, 16 Dec 2012 20:40:55 +0000\r
+Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1TkL12-0000ip-Ma; Sun, 16 Dec 2012 20:40:52 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [RFC PATCH] cli: add --remove-all option to "notmuch tag"\r
+In-Reply-To: <1354572764-28701-1-git-send-email-jani@nikula.org>\r
+References: <1354572764-28701-1-git-send-email-jani@nikula.org>\r
+User-Agent: Notmuch/0.14+226~ge56ae2a (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 16 Dec 2012 20:40:56 +0000\r
+Message-ID: <87fw35enmv.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 93.97.24.31\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: d14b80d6c548e91ea60119cb13eefc1e (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * 0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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, 16 Dec 2012 20:41:03 -0000\r
+\r
+\r
+On Mon, 03 Dec 2012, Jani Nikula <jani@nikula.org> wrote:\r
+> Add --remove-all option to "notmuch tag" to remove all tags matching\r
+> query before applying the tag changes. This allows removal and\r
+> unconditional setting of the tags of a message:\r
+>\r
+> $ notmuch tag --remove-all id:foo@example.com\r
+> $ notmuch tag --remove-all +foo +bar id:foo@example.com\r
+>\r
+> without having to resort to the complicated (and still quoting broken):\r
+>\r
+> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') id:foo@example.com\r
+> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') +foo +bar id:foo@example.com\r
+>\r
+> ---\r
+>\r
+> It's completely untested...\r
+>\r
+> This is on top of David's batch tagging branch new-tagging at\r
+> git://pivot.cs.unb.ca/notmuch.git\r
+>\r
+> If there's interest, I'll spin a new version with tests and man page\r
+> changes after David's stuff has been merged.\r
+\r
+I like this: the possibility of setting the tags to something seems\r
+nice. \r
+\r
+I am not very keen on the option name but don't have anything much\r
+better: maybe --remove-all-first or --set-to? \r
+\r
+Incidentally, does this (or should this) give an error if the user calls\r
+--remove-all with -some_tag (as opposed to +some_tag)?\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+> ---\r
+> notmuch-tag.c | 32 ++++++++++++++++++++------------\r
+> 1 file changed, 20 insertions(+), 12 deletions(-)\r
+>\r
+> diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+> index e4fca67..67624cc 100644\r
+> --- a/notmuch-tag.c\r
+> +++ b/notmuch-tag.c\r
+> @@ -119,12 +119,15 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+> notmuch_messages_t *messages;\r
+> notmuch_message_t *message;\r
+> \r
+> - /* Optimize the query so it excludes messages that already have\r
+> - * the specified set of tags. */\r
+> - query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
+> - if (query_string == NULL) {\r
+> - fprintf (stderr, "Out of memory.\n");\r
+> - return 1;\r
+> + if (! (flags & TAG_FLAG_REMOVE_ALL)) {\r
+> + /* Optimize the query so it excludes messages that already\r
+> + * have the specified set of tags. */\r
+> + query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
+> + if (query_string == NULL) {\r
+> + fprintf (stderr, "Out of memory.\n");\r
+> + return 1;\r
+> + }\r
+> + flags |= TAG_FLAG_PRE_OPTIMIZED;\r
+> }\r
+> \r
+> query = notmuch_query_create (notmuch, query_string);\r
+> @@ -140,7 +143,7 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+> notmuch_messages_valid (messages) && ! interrupted;\r
+> notmuch_messages_move_to_next (messages)) {\r
+> message = notmuch_messages_get (messages);\r
+> - tag_op_list_apply (message, tag_ops, flags | TAG_FLAG_PRE_OPTIMIZED);\r
+> + tag_op_list_apply (message, tag_ops, flags);\r
+> notmuch_message_destroy (message);\r
+> }\r
+> \r
+> @@ -157,8 +160,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+> notmuch_config_t *config;\r
+> notmuch_database_t *notmuch;\r
+> struct sigaction action;\r
+> - tag_op_flag_t synchronize_flags = TAG_FLAG_NONE;\r
+> + tag_op_flag_t flags = TAG_FLAG_NONE;\r
+> notmuch_bool_t batch = FALSE;\r
+> + notmuch_bool_t remove_all = FALSE;\r
+> FILE *input = stdin;\r
+> char *input_file_name = NULL;\r
+> int i, opt_index;\r
+> @@ -174,6 +178,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+> notmuch_opt_desc_t options[] = {\r
+> { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
+> { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
+> + { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },\r
+> { 0, 0, 0, 0, 0 }\r
+> };\r
+> \r
+> @@ -230,7 +235,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+> }\r
+> }\r
+> \r
+> - if (tag_op_list_size (tag_ops) == 0) {\r
+> + if (tag_op_list_size (tag_ops) == 0 && !remove_all) {\r
+> fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");\r
+> return 1;\r
+> }\r
+> @@ -252,7 +257,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+> return 1;\r
+> \r
+> if (notmuch_config_get_maildir_synchronize_flags (config))\r
+> - synchronize_flags = TAG_FLAG_MAILDIR_SYNC;\r
+> + flags |= TAG_FLAG_MAILDIR_SYNC;\r
+> +\r
+> + if (remove_all)\r
+> + flags |= TAG_FLAG_REMOVE_ALL;\r
+> \r
+> if (batch) {\r
+> \r
+> @@ -280,14 +288,14 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+> continue;\r
+> \r
+> if (ret < 0 || tag_query (ctx, notmuch, query_string,\r
+> - tag_ops, synchronize_flags))\r
+> + tag_ops, flags))\r
+> break;\r
+> }\r
+> \r
+> if (line)\r
+> free (line);\r
+> } else\r
+> - ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);\r
+> + ret = tag_query (ctx, notmuch, query_string, tag_ops, flags);\r
+> \r
+> notmuch_database_destroy (notmuch);\r
+> \r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r