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 B9F32431FAF for ; Sat, 9 Mar 2013 06:57:10 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 k7YA-ZpecUEQ for ; Sat, 9 Mar 2013 06:57:07 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B9E4F431FC3 for ; Sat, 9 Mar 2013 06:57:00 -0800 (PST) Received: by mail-lb0-f179.google.com with SMTP id j14so2082029lbo.38 for ; Sat, 09 Mar 2013 06:56:59 -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:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=uNxZjcHFstTaa1S/Bche4AauVzm5p+WGaNwXt9pBcug=; b=BeJDkl7BxTFCAzaUyPLOdby65ywprK5Qa0LPi30svDrjF/FSdvczYzHOszoPfKTnrj HJVlFmkU622G+mfNR/vykV3Qf2p4zhAuL1LBbDZHKYEWIUPi2OH16hYNGqIOJIujXOJe y4y/zL8YeFkjX6qw1xIRjIVlB+R88xEZwxVfSGQoxqy2HLb7g0hvAQPisdWZ08+a78Dc FVE+7kplmpZEHKT2Kl7AjmZpJTsyYzkVCrMDw4mRquysFFp14y2ZtyYUgiP4lkTkMEM7 +x5cJIs/X3QnRMTUZq4EAkp9WAVP7vdTTAX5UWu6GiFDSmbxUh6EZ+mE6b0OkxOjdmfv TO4g== X-Received: by 10.152.132.170 with SMTP id ov10mr5172922lab.21.1362841019268; Sat, 09 Mar 2013 06:56:59 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id v7sm2679351lbg.13.2013.03.09.06.56.57 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 09 Mar 2013 06:56:58 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 2/4] cli: add --remove-all option to "notmuch tag" Date: Sat, 9 Mar 2013 16:56:49 +0200 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQk/EzLPwkyOR5vgPlO393IR8hbqfrqasp+sxsRsZkeq6aoVRoQnqfM2akNKAD2Xd0TcDRWI 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: Sat, 09 Mar 2013 14:57:11 -0000 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 --- notmuch-tag.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/notmuch-tag.c b/notmuch-tag.c index bc61aab..9a5d3e7 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; @@ -186,6 +189,7 @@ notmuch_tag_command (notmuch_config_t *config, 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; @@ -201,6 +205,7 @@ notmuch_tag_command (notmuch_config_t *config, 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 } }; @@ -223,6 +228,10 @@ notmuch_tag_command (notmuch_config_t *config, 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 (config); if (tag_ops == NULL) { @@ -234,7 +243,7 @@ notmuch_tag_command (notmuch_config_t *config, 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; } @@ -247,6 +256,9 @@ notmuch_tag_command (notmuch_config_t *config, 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 (config, notmuch, tag_flags, input); else -- 1.7.10.4