1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 31B9F431FCB
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 Jan 2013 09:41:25 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 1yB24R5LWqTC for <notmuch@notmuchmail.org>;
\r
17 Tue, 22 Jan 2013 09:41:24 -0800 (PST)
\r
18 Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com
\r
19 [209.85.217.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 0AE5D431FC7
\r
22 for <notmuch@notmuchmail.org>; Tue, 22 Jan 2013 09:41:22 -0800 (PST)
\r
23 Received: by mail-lb0-f172.google.com with SMTP id n8so3707635lbj.3
\r
24 for <notmuch@notmuchmail.org>; Tue, 22 Jan 2013 09:41:21 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
28 :references:in-reply-to:references:x-gm-message-state;
\r
29 bh=aQ/ISI7jfLHsw/RL6AeOlsUjc/7h2lqQDZam/yTWccQ=;
\r
30 b=Sn++Yiha+1x43EowmRivFk/N7TBNf2OXlclfQREQ6jCo4+fAvppYXP+tngqfuOoPGS
\r
31 8EXwV5fSPh44t8nvMT7rGegjqzF5SnwF+C1qYIX8oqiGBh+J1rcnYNk3e/3fcky06xuE
\r
32 PPi3b//ViE4cZz/QDbW6rMylxPHk6UW/T0mi67AiEnPoxnyqXldPM6sn592jge8a0Flv
\r
33 dfpasdfXLQRjC/8PDB1sED8SmRMgD2ZDaeeqaPbDn2VsAmmjGuEFqBCiOFaoBXBCV9ZR
\r
34 P+itlj4ZRpA2Cc5fQz4okH0x8im7e0bKBVNyEUHSTa1ipi8BsxDk5C2sxgt0gqFXTK+h
\r
36 X-Received: by 10.112.46.66 with SMTP id t2mr9419708lbm.115.1358876481267;
\r
37 Tue, 22 Jan 2013 09:41:21 -0800 (PST)
\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id hc20sm7320873lab.11.2013.01.22.09.41.18
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Tue, 22 Jan 2013 09:41:20 -0800 (PST)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 2/4] cli: add --remove-all option to "notmuch tag"
\r
46 Date: Tue, 22 Jan 2013 19:41:07 +0200
\r
48 <e9dd76463809998cdb68bb5078a8d679e98560c2.1358876448.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.10.4
\r
51 <1a2c09adc1c963f1aa209c09143f85dca7634e11.1358876448.git.jani@nikula.org>
\r
53 <1a2c09adc1c963f1aa209c09143f85dca7634e11.1358876448.git.jani@nikula.org>
\r
55 <1a2c09adc1c963f1aa209c09143f85dca7634e11.1358876448.git.jani@nikula.org>
\r
57 <1a2c09adc1c963f1aa209c09143f85dca7634e11.1358876448.git.jani@nikula.org>
\r
59 ALoCoQnZ5gJz83ioBtN8fsZVLat3wtM1tH7OzeT1xlziNa0l3zWvYJU5KQE4A5o8APFnHjtXnJED
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Tue, 22 Jan 2013 17:41:25 -0000
\r
74 Add --remove-all option to "notmuch tag" to remove all tags from the
\r
75 messages matching query before applying the tag changes. This allows
\r
76 removal of all tags and unconditional setting of the tags of a
\r
79 $ notmuch tag --remove-all id:foo@example.com
\r
80 $ notmuch tag --remove-all +foo +bar id:foo@example.com
\r
82 without having to resort to the complicated (and still quoting
\r
85 $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \
\r
87 $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \
\r
88 +foo +bar id:foo@example.com
\r
90 notmuch-tag.c | 28 ++++++++++++++++++++--------
\r
91 1 file changed, 20 insertions(+), 8 deletions(-)
\r
93 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
94 index b2b22f7..e674215 100644
\r
97 @@ -99,12 +99,15 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
98 notmuch_message_t *message;
\r
99 int ret = NOTMUCH_STATUS_SUCCESS;
\r
101 - /* Optimize the query so it excludes messages that already have
\r
102 - * the specified set of tags. */
\r
103 - query_string = _optimize_tag_query (ctx, query_string, tag_ops);
\r
104 - if (query_string == NULL) {
\r
105 - fprintf (stderr, "Out of memory.\n");
\r
107 + if (! (flags & TAG_FLAG_REMOVE_ALL)) {
\r
108 + /* Optimize the query so it excludes messages that already
\r
109 + * have the specified set of tags. */
\r
110 + query_string = _optimize_tag_query (ctx, query_string, tag_ops);
\r
111 + if (query_string == NULL) {
\r
112 + fprintf (stderr, "Out of memory.\n");
\r
115 + flags |= TAG_FLAG_PRE_OPTIMIZED;
\r
118 query = notmuch_query_create (notmuch, query_string);
\r
119 @@ -120,7 +123,7 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
120 notmuch_messages_valid (messages) && ! interrupted;
\r
121 notmuch_messages_move_to_next (messages)) {
\r
122 message = notmuch_messages_get (messages);
\r
123 - ret = tag_op_list_apply (message, tag_ops, flags | TAG_FLAG_PRE_OPTIMIZED);
\r
124 + ret = tag_op_list_apply (message, tag_ops, flags);
\r
125 notmuch_message_destroy (message);
\r
126 if (ret != NOTMUCH_STATUS_SUCCESS)
\r
128 @@ -187,6 +190,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
129 struct sigaction action;
\r
130 tag_op_flag_t tag_flags = TAG_FLAG_NONE;
\r
131 notmuch_bool_t batch = FALSE;
\r
132 + notmuch_bool_t remove_all = FALSE;
\r
133 FILE *input = stdin;
\r
134 char *input_file_name = NULL;
\r
136 @@ -202,6 +206,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
137 notmuch_opt_desc_t options[] = {
\r
138 { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
\r
139 { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
140 + { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },
\r
144 @@ -224,6 +229,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
145 fprintf (stderr, "Can't specify both cmdline and stdin!\n");
\r
148 + if (remove_all) {
\r
149 + fprintf (stderr, "Can't specify both --remove-all and --batch\n");
\r
153 tag_ops = tag_op_list_create (ctx);
\r
154 if (tag_ops == NULL) {
\r
155 @@ -235,7 +244,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
156 &query_string, tag_ops))
\r
159 - if (tag_op_list_size (tag_ops) == 0) {
\r
160 + if (tag_op_list_size (tag_ops) == 0 && ! remove_all) {
\r
161 fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
\r
164 @@ -252,6 +261,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
165 if (notmuch_config_get_maildir_synchronize_flags (config))
\r
166 tag_flags |= TAG_FLAG_MAILDIR_SYNC;
\r
169 + tag_flags |= TAG_FLAG_REMOVE_ALL;
\r
172 ret = tag_file (ctx, notmuch, tag_flags, input);
\r