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 BF7D2431FAF
\r
6 for <notmuch@notmuchmail.org>; Sat, 22 Dec 2012 14:51:53 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id UnsWovTc0W48 for <notmuch@notmuchmail.org>;
\r
16 Sat, 22 Dec 2012 14:51:53 -0800 (PST)
\r
17 Received: from mail-la0-f47.google.com (mail-la0-f47.google.com
\r
18 [209.85.215.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id BBECD431FAE
\r
21 for <notmuch@notmuchmail.org>; Sat, 22 Dec 2012 14:51:52 -0800 (PST)
\r
22 Received: by mail-la0-f47.google.com with SMTP id u2so6877313lag.6
\r
23 for <notmuch@notmuchmail.org>; Sat, 22 Dec 2012 14:51:51 -0800 (PST)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=x-received:from:to:subject:in-reply-to:references:user-agent:date
\r
27 :message-id:mime-version:content-type:x-gm-message-state;
\r
28 bh=C0RdW4pOciaxBQIxGM59F39bR1ZRgAILhgQ/D2hR96Q=;
\r
29 b=ncvklRlcUuQmD2lWk6OZYMSBzKOqbxB2F4oI9jzfrVxFsZwiy0+Qe5PU4Ada1wFP5+
\r
30 drrB/4+qs2h+hEuufQEyCxipbhADUQ0gZPnBbcJ+eMdOC/jnxiOTLA3y1B7oxwMkmvVK
\r
31 HnpKLGBUfeBdaQCwlxInKNtcbQsDvNExTs0eSh+oeH4g+0ZyINcHSW03jmW9CfqGnYNn
\r
32 M3WV1bS8c45D53k+GZxSZYnDQQkYC4MyMoAzBWPfMWVUyZUA9OsQrbjzO+O5LLgp7U0l
\r
33 yxK8/YItYpYPaEd3HT2gWjYw1F/ITUmJcf+VJDHUwIquHUexh4yMSFYSiifp8pNMS5c/
\r
35 X-Received: by 10.152.113.66 with SMTP id iw2mr15986738lab.37.1356216709806;
\r
36 Sat, 22 Dec 2012 14:51:49 -0800 (PST)
\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
39 by mx.google.com with ESMTPS id jk8sm6133019lab.7.2012.12.22.14.51.47
\r
40 (version=SSLv3 cipher=OTHER); Sat, 22 Dec 2012 14:51:48 -0800 (PST)
\r
41 From: Jani Nikula <jani@nikula.org>
\r
42 To: david@tethera.net, notmuch@notmuchmail.org
\r
43 Subject: Re: [Patch v8 09/18] cli: add support for batch tagging operations to
\r
45 In-Reply-To: <1356095307-22895-9-git-send-email-david@tethera.net>
\r
46 References: <1356095307-22895-1-git-send-email-david@tethera.net>
\r
47 <1356095307-22895-9-git-send-email-david@tethera.net>
\r
48 User-Agent: Notmuch/0.14+211~gc8d6546 (http://notmuchmail.org) Emacs/24.2.1
\r
49 (x86_64-pc-linux-gnu)
\r
50 Date: Sun, 23 Dec 2012 00:51:45 +0200
\r
51 Message-ID: <87wqw9hf9a.fsf@oiva.home.nikula.org>
\r
53 Content-Type: text/plain
\r
55 ALoCoQmJkgYpMaI6BhHPcsUO8ybBhDLUqqUh3xTF+aOxOSlYLiPR+GjWDglcUY7qq8l7Ikyjp6Pi
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Sat, 22 Dec 2012 22:51:53 -0000
\r
70 On Fri, 21 Dec 2012, david@tethera.net wrote:
\r
71 > From: Jani Nikula <jani@nikula.org>
\r
73 > Add support for batch tagging operations through stdin to "notmuch
\r
74 > tag". This can be enabled with the new --batch command line option to
\r
75 > "notmuch tag". The input must consist of lines of the format:
\r
77 > +<tag>|-<tag> [...] [--] <search-term> [...]
\r
79 > Each line is interpreted similarly to "notmuch tag" command line
\r
80 > arguments. The delimiter is one or more spaces ' '. Any characters in
\r
81 > <tag> and <search-term> MAY be hex encoded with %NN where NN is the
\r
82 > hexadecimal value of the character. Any ' ' and '%' characters in
\r
83 > <tag> and <search-term> MUST be hex encoded (using %20 and %25,
\r
84 > respectively). Any characters that are not part of <tag> or
\r
85 > <search-term> MUST NOT be hex encoded.
\r
87 > Leading and trailing space ' ' is ignored. Empty lines and lines
\r
88 > beginning with '#' are ignored.
\r
90 > Signed-off-by: Jani Nikula <jani@nikula.org>
\r
92 > Hacked-like-crazy-by: David Bremner <david@tethera.net>
\r
94 > notmuch-tag.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
\r
95 > 1 file changed, 83 insertions(+), 8 deletions(-)
\r
97 > diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
98 > index a480215..5c8bad4 100644
\r
99 > --- a/notmuch-tag.c
\r
100 > +++ b/notmuch-tag.c
\r
101 > @@ -132,6 +132,46 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
102 > return interrupted;
\r
106 > +tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,
\r
109 > + char *line = NULL;
\r
110 > + char *query_string = NULL;
\r
111 > + size_t line_size = 0;
\r
112 > + ssize_t line_len;
\r
114 > + tag_op_list_t *tag_ops;
\r
116 > + tag_ops = tag_op_list_create (ctx);
\r
117 > + if (tag_ops == NULL) {
\r
118 > + fprintf (stderr, "Out of memory.\n");
\r
122 > + while ((line_len = getline (&line, &line_size, input)) != -1 &&
\r
123 > + ! interrupted) {
\r
125 > + ret = parse_tag_line (ctx, line, TAG_FLAG_NONE,
\r
126 > + &query_string, tag_ops);
\r
134 > + ret = tag_query (ctx, notmuch, query_string, tag_ops, flags);
\r
146 > notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
148 > @@ -141,6 +181,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
149 > notmuch_database_t *notmuch;
\r
150 > struct sigaction action;
\r
151 > tag_op_flag_t tag_flags = TAG_FLAG_NONE;
\r
152 > + notmuch_bool_t batch = FALSE;
\r
153 > + FILE *input = stdin;
\r
154 > + char *input_file_name = NULL;
\r
158 > /* Setup our handler for SIGINT */
\r
159 > @@ -150,15 +194,43 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
160 > action.sa_flags = SA_RESTART;
\r
161 > sigaction (SIGINT, &action, NULL);
\r
163 > - tag_ops = tag_op_list_create (ctx);
\r
164 > - if (tag_ops == NULL) {
\r
165 > - fprintf (stderr, "Out of memory.\n");
\r
166 > + notmuch_opt_desc_t options[] = {
\r
167 > + { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
\r
168 > + { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
169 > + { 0, 0, 0, 0, 0 }
\r
172 > + opt_index = parse_arguments (argc, argv, options, 1);
\r
173 > + if (opt_index < 0)
\r
176 > + if (input_file_name) {
\r
178 > + input = fopen (input_file_name, "r");
\r
179 > + if (input == NULL) {
\r
180 > + fprintf (stderr, "Error opening %s for reading: %s\n",
\r
181 > + input_file_name, strerror (errno));
\r
186 > - if (parse_tag_command_line (ctx, argc - 1, argv + 1,
\r
187 > - &query_string, tag_ops))
\r
190 > + if (opt_index != argc) {
\r
191 > + fprintf (stderr, "Can't specify both cmdline and stdin!\n");
\r
196 > + tag_ops = tag_op_list_create (ctx);
\r
197 > + if (tag_ops == NULL) {
\r
198 > + fprintf (stderr, "Out of memory.\n");
\r
202 > + if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,
\r
203 > + &query_string, tag_ops))
\r
207 > config = notmuch_config_open (ctx, NULL, NULL);
\r
208 > if (config == NULL)
\r
209 > @@ -171,9 +243,12 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
210 > if (notmuch_config_get_maildir_synchronize_flags (config))
\r
211 > tag_flags |= TAG_FLAG_MAILDIR_SYNC;
\r
213 > - ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);
\r
215 > + ret = tag_file (ctx, notmuch, tag_flags, input);
\r
217 > + ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);
\r
219 > notmuch_database_destroy (notmuch);
\r
221 Nitpick, missing fclose if input != stdin.
\r
228 > + return ret || interrupted;
\r