Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / bf / 2c876c1b3f8aa7f56821871665837357239b27
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 374D9431FAF\r
6         for <notmuch@notmuchmail.org>; Thu,  3 Jan 2013 10:42:45 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 l6yRDpCwTdPa for <notmuch@notmuchmail.org>;\r
16         Thu,  3 Jan 2013 10:42:41 -0800 (PST)\r
17 Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com\r
18         [209.85.212.170]) (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 2244F431FAE\r
21         for <notmuch@notmuchmail.org>; Thu,  3 Jan 2013 10:42:41 -0800 (PST)\r
22 Received: by mail-wi0-f170.google.com with SMTP id hq7so7992294wib.3\r
23         for <notmuch@notmuchmail.org>; Thu, 03 Jan 2013 10:42:38 -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=JQz6/403c9vuI04EhvhuO2KmfyQIz4KE6whOmCvmYzc=;\r
29         b=gQStqMVNnNNU09QHIQC/qvG9qZxouTTA8l0s3lTWMtAD/Qx3FF41IanBthtu6jA9T5\r
30         mbo908K10ll62Q/6bLhUlEtb10YHT5vAbAsFV4Zce2N/jQCIhKSnDMub7J2hWumtpu7F\r
31         3ZK2UBPxDQrBxHwFSMcKCkIdCW42WuEKjJqGe1lj41UnSPJAH9UFoVuUYfJXuqgghpKK\r
32         PlALE8DDDUt8nFrDJ6k3ynhjbEwAKkXTnkkeaIKv6kkpZL/ff3LKl5XFiBNURiPS6Cwx\r
33         DI3hucJlEcbFdRRpeQxhSx9tu/1SFyOufyh0mwk6RDzN4ESDeTM7bIgmYQ9Gz4YrTd/R\r
34         t7kw==\r
35 X-Received: by 10.180.19.136 with SMTP id f8mr77909083wie.0.1357238558696;\r
36         Thu, 03 Jan 2013 10:42:38 -0800 (PST)\r
37 Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
38         by mx.google.com with ESMTPS id e6sm32875868wiz.1.2013.01.03.10.42.36\r
39         (version=SSLv3 cipher=OTHER); Thu, 03 Jan 2013 10:42:37 -0800 (PST)\r
40 From: Jani Nikula <jani@nikula.org>\r
41 To: david@tethera.net, notmuch@notmuchmail.org\r
42 Subject: Re: [PATCH 04/11] cli: add support for batch tagging operations to\r
43         "notmuch tag"\r
44 In-Reply-To: <1356464567-21779-5-git-send-email-david@tethera.net>\r
45 References: <1356464567-21779-1-git-send-email-david@tethera.net>\r
46         <1356464567-21779-5-git-send-email-david@tethera.net>\r
47 User-Agent: Notmuch/0.14+235~gdaf492b (http://notmuchmail.org) Emacs/23.2.1\r
48         (x86_64-pc-linux-gnu)\r
49 Date: Thu, 03 Jan 2013 19:42:30 +0100\r
50 Message-ID: <87pq1mglbd.fsf@nikula.org>\r
51 MIME-Version: 1.0\r
52 Content-Type: text/plain; charset=us-ascii\r
53 X-Gm-Message-State:\r
54  ALoCoQlLSPQGottqs0FLxsr9392rGi3xGF4wKdi2Hp13hqdjhCg/QQeeFeixPrMNITUsbXv8u2Vx\r
55 X-BeenThere: notmuch@notmuchmail.org\r
56 X-Mailman-Version: 2.1.13\r
57 Precedence: list\r
58 List-Id: "Use and development of the notmuch mail system."\r
59         <notmuch.notmuchmail.org>\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
63 List-Post: <mailto:notmuch@notmuchmail.org>\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
67 X-List-Received-Date: Thu, 03 Jan 2013 18:42:45 -0000\r
68 \r
69 On Tue, 25 Dec 2012, david@tethera.net wrote:\r
70 > From: Jani Nikula <jani@nikula.org>\r
71 >\r
72 > Add support for batch tagging operations through stdin to "notmuch\r
73 > tag". This can be enabled with the new --batch command line option to\r
74 > "notmuch tag". The input must consist of lines of the format:\r
75 >\r
76 > +<tag>|-<tag> [...] [--] <query> [...]\r
77 >\r
78 > Each line is interpreted similarly to "notmuch tag" command line\r
79 > arguments. The delimiter is one or more spaces ' '. Any characters in\r
80 > <tag> MAP be hex encoded with %NN where NN is the\r
81 \r
82 MAY\r
83 \r
84 > hexadecimal value of the character. Any ' ' and '%' characters in\r
85 > <tag> and <search-term> MUST be hex encoded (using %20 and %25,\r
86 \r
87 If we also required double quotes '"' to be hex encoded, we would have\r
88 an easier transition to using xapian quoting for tags too if we so\r
89 choose. notmuch dump already does this. If we additionally require % to\r
90 be quoted when using xapian quoting, we could detect hex vs. xapian\r
91 automatically.\r
92 \r
93 > respectively). Any characters that are not part of <tag> or\r
94 \r
95 -or\r
96 \r
97 > MUST NOT be hex encoded.\r
98 >\r
99 > <query> is passed verbatim to Xapian\r
100 >\r
101 > Leading and trailing space ' ' is ignored. Empty lines and lines\r
102 > beginning with '#' are ignored.\r
103 >\r
104 > Signed-off-by: Jani Nikula <jani@nikula.org>\r
105 >\r
106 > Hacked-like-crazy-by: David Bremner <david@tethera.net>\r
107 > ---\r
108 >  notmuch-tag.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----\r
109 >  1 file changed, 86 insertions(+), 8 deletions(-)\r
110 >\r
111 > diff --git a/notmuch-tag.c b/notmuch-tag.c\r
112 > index 8129912..7fc614d 100644\r
113 > --- a/notmuch-tag.c\r
114 > +++ b/notmuch-tag.c\r
115 > @@ -128,6 +128,46 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
116 >      return interrupted;\r
117 >  }\r
118 >  \r
119 > +static int\r
120 > +tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,\r
121 > +       FILE *input)\r
122 > +{\r
123 > +    char *line = NULL;\r
124 > +    char *query_string = NULL;\r
125 > +    size_t line_size = 0;\r
126 > +    ssize_t line_len;\r
127 > +    int ret = 0;\r
128 > +    tag_op_list_t *tag_ops;\r
129 > +\r
130 > +    tag_ops = tag_op_list_create (ctx);\r
131 > +    if (tag_ops == NULL) {\r
132 > +     fprintf (stderr, "Out of memory.\n");\r
133 > +     return 1;\r
134 > +    }\r
135 > +\r
136 > +    while ((line_len = getline (&line, &line_size, input)) != -1 &&\r
137 > +        ! interrupted) {\r
138 > +\r
139 > +     ret = parse_tag_line (ctx, line, TAG_FLAG_NONE,\r
140 > +                           &query_string, tag_ops);\r
141 > +\r
142 > +     if (ret > 0)\r
143 > +         continue;\r
144 > +\r
145 > +     if (ret < 0)\r
146 > +         break;\r
147 > +\r
148 > +     ret = tag_query (ctx, notmuch, query_string, tag_ops, flags);\r
149 > +     if (ret)\r
150 > +         break;\r
151 > +    }\r
152 > +\r
153 > +    if (line)\r
154 > +     free (line);\r
155 > +\r
156 > +    return ret;\r
157 > +}\r
158 > +\r
159 >  int\r
160 >  notmuch_tag_command (void *ctx, int argc, char *argv[])\r
161 >  {\r
162 > @@ -137,6 +177,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
163 >      notmuch_database_t *notmuch;\r
164 >      struct sigaction action;\r
165 >      tag_op_flag_t tag_flags = TAG_FLAG_NONE;\r
166 > +    notmuch_bool_t batch = FALSE;\r
167 > +    FILE *input = stdin;\r
168 > +    char *input_file_name = NULL;\r
169 > +    int opt_index;\r
170 >      int ret = 0;\r
171 >  \r
172 >      /* Setup our handler for SIGINT */\r
173 > @@ -146,15 +190,43 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
174 >      action.sa_flags = SA_RESTART;\r
175 >      sigaction (SIGINT, &action, NULL);\r
176 >  \r
177 > -    tag_ops = tag_op_list_create (ctx);\r
178 > -    if (tag_ops == NULL) {\r
179 > -     fprintf (stderr, "Out of memory.\n");\r
180 > +    notmuch_opt_desc_t options[] = {\r
181 > +     { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
182 > +     { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
183 > +     { 0, 0, 0, 0, 0 }\r
184 > +    };\r
185 > +\r
186 > +    opt_index = parse_arguments (argc, argv, options, 1);\r
187 > +    if (opt_index < 0)\r
188 >       return 1;\r
189 > +\r
190 > +    if (input_file_name) {\r
191 > +     batch = TRUE;\r
192 > +     input = fopen (input_file_name, "r");\r
193 > +     if (input == NULL) {\r
194 > +         fprintf (stderr, "Error opening %s for reading: %s\n",\r
195 > +                  input_file_name, strerror (errno));\r
196 > +         return 1;\r
197 > +     }\r
198 >      }\r
199 >  \r
200 > -    if (parse_tag_command_line (ctx, argc - 1, argv + 1,\r
201 > -                             &query_string, tag_ops))\r
202 > -     return 1;\r
203 > +    if (batch) {\r
204 > +     if (opt_index != argc) {\r
205 > +         fprintf (stderr, "Can't specify both cmdline and stdin!\n");\r
206 > +         return 1;\r
207 > +     }\r
208 > +    } else {\r
209 > +\r
210 > +     tag_ops = tag_op_list_create (ctx);\r
211 > +     if (tag_ops == NULL) {\r
212 > +         fprintf (stderr, "Out of memory.\n");\r
213 > +         return 1;\r
214 > +     }\r
215 > +\r
216 > +     if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,\r
217 > +                                 &query_string, tag_ops))\r
218 > +         return 1;\r
219 > +    }\r
220 >  \r
221 >      config = notmuch_config_open (ctx, NULL, NULL);\r
222 >      if (config == NULL)\r
223 > @@ -167,9 +239,15 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
224 >      if (notmuch_config_get_maildir_synchronize_flags (config))\r
225 >       tag_flags |= TAG_FLAG_MAILDIR_SYNC;\r
226 >  \r
227 > -    ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);\r
228 > +    if (batch)\r
229 > +     ret = tag_file (ctx, notmuch, tag_flags, input);\r
230 > +    else\r
231 > +     ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);\r
232 >  \r
233 >      notmuch_database_destroy (notmuch);\r
234 >  \r
235 > -    return ret;\r
236 > +    if (input != stdin)\r
237 > +     fclose (input);\r
238 > +\r
239 > +    return ret || interrupted;\r
240 >  }\r
241 > -- \r
242 > 1.7.10.4\r