From e6144ce15b476b5b6fb53099550d13f229f82f48 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Mon, 25 Feb 2013 21:34:09 +0200 Subject: [PATCH] Re: [PATCH 2/4] cli: add --remove-all option to "notmuch tag" --- dd/c3524d22184f31f68cc9fe15e91b4df6188088 | 183 ++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 dd/c3524d22184f31f68cc9fe15e91b4df6188088 diff --git a/dd/c3524d22184f31f68cc9fe15e91b4df6188088 b/dd/c3524d22184f31f68cc9fe15e91b4df6188088 new file mode 100644 index 000000000..e79867d4a --- /dev/null +++ b/dd/c3524d22184f31f68cc9fe15e91b4df6188088 @@ -0,0 +1,183 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B3963431FB6 + for ; Mon, 25 Feb 2013 11:34:13 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id FZoKcaEOAPJO for ; + Mon, 25 Feb 2013 11:34:13 -0800 (PST) +Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id BF51B431FAF + for ; Mon, 25 Feb 2013 11:34:12 -0800 (PST) +Received: by mail-lb0-f181.google.com with SMTP id gm6so2470862lbb.26 + for ; Mon, 25 Feb 2013 11:34:09 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-received:from:to:cc:subject:in-reply-to:references:user-agent + :date:message-id:mime-version:content-type:x-gm-message-state; + bh=qvNatpg9st7SuGZhVn1AJvtE8b7tNr2xnTJxYFOG6z0=; + b=PFPzzRC549cEbOPBU6QUBLX0p7GkU9NReXVQJ1jstuxo4TcS3offemVEVYI8Z0Ry6H + k1ui5ZZQ6iyg/0HU9ibQfGcxjRhkLJ9txMMw1ryNy0KlClz0jt7oy6Qmt4pSedcVY7K5 + PFV5dvOtO5mq3AW+MGg1K5+xQxSnNsjkuT/CbNvjXIo6ny9TZbccxAsrLDbd2R1veyH7 + RwBcc6XcKDz2ddBRdwJc5J0M5HbYwyNYK5nks1siKBZXm/g2JSkQllbziwPqq+pdHLpc + 5hs/E4TjBsGuNxsNhw+9F7wOe2PDmBtjLLRDjO6bNzKCeyTXxFQX0xfWh4fPcK2JGmrm + 5UKw== +X-Received: by 10.152.105.17 with SMTP id gi17mr10804325lab.46.1361820848548; + Mon, 25 Feb 2013 11:34:08 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. + [80.223.81.27]) + by mx.google.com with ESMTPS id fm8sm4483305lbb.17.2013.02.25.11.34.06 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 25 Feb 2013 11:34:07 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: Re: [PATCH 2/4] cli: add --remove-all option to "notmuch tag" +In-Reply-To: + +References: + <1a2c09adc1c963f1aa209c09143f85dca7634e11.1358876448.git.jani@nikula.org> + +User-Agent: Notmuch/0.14+255~gff3cc55 (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-pc-linux-gnu) +Date: Mon, 25 Feb 2013 21:34:09 +0200 +Message-ID: <87obf8ur0u.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain +X-Gm-Message-State: + ALoCoQlTOpbpCKsly8q57nCHKKXCgu+Ulv85GGVLLIqc34ELLjHMK/jaQiWxg3vfbkNiIX+gscQR +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 25 Feb 2013 19:34:13 -0000 + +On Tue, 22 Jan 2013, Jani Nikula wrote: +> Add --remove-all option to "notmuch tag" to remove all tags from the +> messages matching query before applying the tag changes. This allows +> removal of all tags and unconditional setting of the tags of a +> message: +> +> $ notmuch tag --remove-all id:foo@example.com +> $ notmuch tag --remove-all +foo +bar id:foo@example.com +> +> without having to resort to the complicated (and still quoting +> broken): +> +> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \ +> id:foo@example.com +> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \ +> +foo +bar id:foo@example.com + +Just today there was another question on IRC about removing all tags, +and the reply from amdragon was along the lines of the above. This +series would make things so much easier... reviews, anyone? ;) + +BR, +Jani. + + +> --- +> notmuch-tag.c | 28 ++++++++++++++++++++-------- +> 1 file changed, 20 insertions(+), 8 deletions(-) +> +> diff --git a/notmuch-tag.c b/notmuch-tag.c +> index b2b22f7..e674215 100644 +> --- a/notmuch-tag.c +> +++ b/notmuch-tag.c +> @@ -99,12 +99,15 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string, +> notmuch_message_t *message; +> int ret = NOTMUCH_STATUS_SUCCESS; +> +> - /* Optimize the query so it excludes messages that already have +> - * the specified set of tags. */ +> - query_string = _optimize_tag_query (ctx, query_string, tag_ops); +> - if (query_string == NULL) { +> - fprintf (stderr, "Out of memory.\n"); +> - return 1; +> + if (! (flags & TAG_FLAG_REMOVE_ALL)) { +> + /* Optimize the query so it excludes messages that already +> + * have the specified set of tags. */ +> + query_string = _optimize_tag_query (ctx, query_string, tag_ops); +> + if (query_string == NULL) { +> + fprintf (stderr, "Out of memory.\n"); +> + return 1; +> + } +> + flags |= TAG_FLAG_PRE_OPTIMIZED; +> } +> +> query = notmuch_query_create (notmuch, query_string); +> @@ -120,7 +123,7 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string, +> notmuch_messages_valid (messages) && ! interrupted; +> notmuch_messages_move_to_next (messages)) { +> message = notmuch_messages_get (messages); +> - ret = tag_op_list_apply (message, tag_ops, flags | TAG_FLAG_PRE_OPTIMIZED); +> + ret = tag_op_list_apply (message, tag_ops, flags); +> notmuch_message_destroy (message); +> if (ret != NOTMUCH_STATUS_SUCCESS) +> break; +> @@ -187,6 +190,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) +> struct sigaction action; +> tag_op_flag_t tag_flags = TAG_FLAG_NONE; +> notmuch_bool_t batch = FALSE; +> + notmuch_bool_t remove_all = FALSE; +> FILE *input = stdin; +> char *input_file_name = NULL; +> int opt_index; +> @@ -202,6 +206,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) +> notmuch_opt_desc_t options[] = { +> { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 }, +> { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 }, +> + { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 }, +> { 0, 0, 0, 0, 0 } +> }; +> +> @@ -224,6 +229,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) +> fprintf (stderr, "Can't specify both cmdline and stdin!\n"); +> return 1; +> } +> + if (remove_all) { +> + fprintf (stderr, "Can't specify both --remove-all and --batch\n"); +> + return 1; +> + } +> } else { +> tag_ops = tag_op_list_create (ctx); +> if (tag_ops == NULL) { +> @@ -235,7 +244,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) +> &query_string, tag_ops)) +> return 1; +> +> - if (tag_op_list_size (tag_ops) == 0) { +> + if (tag_op_list_size (tag_ops) == 0 && ! remove_all) { +> fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); +> return 1; +> } +> @@ -252,6 +261,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) +> if (notmuch_config_get_maildir_synchronize_flags (config)) +> tag_flags |= TAG_FLAG_MAILDIR_SYNC; +> +> + if (remove_all) +> + tag_flags |= TAG_FLAG_REMOVE_ALL; +> + +> if (batch) +> ret = tag_file (ctx, notmuch, tag_flags, input); +> else +> -- +> 1.7.10.4 -- 2.26.2