Re: Avoiding the "huge INBOX of death"
[notmuch-archives.git] / dc / a2cf160124a2a5e523b337bbcf485b492125e8
1 Return-Path: <tomi.ollila@iki.fi>\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 22FC9431FBC\r
6         for <notmuch@notmuchmail.org>; Thu,  6 Dec 2012 07:08:49 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 6CCyqLY-BuWk for <notmuch@notmuchmail.org>;\r
16         Thu,  6 Dec 2012 07:08:48 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id F2C58431FB6\r
19         for <notmuch@notmuchmail.org>; Thu,  6 Dec 2012 07:08:47 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 7E9BF100045;\r
22         Thu,  6 Dec 2012 17:08:44 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Peter Feigl <craven@gmx.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH v4 2/5] Rename the -json printer functions in\r
26         notmuch-reply and notmuch-show to generic -sprinter functions.\r
27 In-Reply-To:\r
28  <785c9f89c35c861fbbe3ead3fe7289b65d31e216.1354794428.git.craven@gmx.net>\r
29 References: <cover.1354794428.git.craven@gmx.net>\r
30         <785c9f89c35c861fbbe3ead3fe7289b65d31e216.1354794428.git.craven@gmx.net>\r
31 User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1\r
32         (x86_64-unknown-linux-gnu)\r
33 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
34         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
35         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
36 Date: Thu, 06 Dec 2012 17:08:44 +0200\r
37 Message-ID: <m21uf3qkub.fsf@guru.guru-group.fi>\r
38 MIME-Version: 1.0\r
39 Content-Type: text/plain\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Thu, 06 Dec 2012 15:08:49 -0000\r
53 \r
54 On Thu, Dec 06 2012, Peter Feigl <craven@gmx.net> wrote:\r
55 \r
56 > All the structured output functions in notmuch-reply and notmuch-show\r
57 > are renamed to a generic name (as they do not contain any json-specific\r
58 > code anyway). This patch is a preparation to actually using the new\r
59 > S-Expression sprinter in notmuch-reply and notmuch-show.\r
60 > ---\r
61 >  notmuch-client.h |  8 ++++----\r
62 >  notmuch-reply.c  | 43 ++++++++++++++++++++++++++-----------------\r
63 >  notmuch-show.c   | 30 +++++++++++++++---------------\r
64 >  3 files changed, 45 insertions(+), 36 deletions(-)\r
65 >\r
66 > diff --git a/notmuch-client.h b/notmuch-client.h\r
67 > index ae9344b..1c336dc 100644\r
68 > --- a/notmuch-client.h\r
69 > +++ b/notmuch-client.h\r
70 > @@ -175,12 +175,12 @@ notmuch_status_t\r
71 >  show_one_part (const char *filename, int part);\r
72 >  \r
73 >  void\r
74 > -format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,\r
75 > -               notmuch_bool_t first, notmuch_bool_t output_body);\r
76 > +format_part_sprinter (const void *ctx, struct sprinter *sp, mime_node_t *node,\r
77 > +                   notmuch_bool_t first, notmuch_bool_t output_body);\r
78 >  \r
79 >  void\r
80 > -format_headers_json (struct sprinter *sp, GMimeMessage *message,\r
81 > -                  notmuch_bool_t reply);\r
82 > +format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,\r
83 > +                      notmuch_bool_t reply);\r
84 >  \r
85 >  typedef enum {\r
86 >      NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,\r
87 > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
88 > index e60a264..6103d6e 100644\r
89 > --- a/notmuch-reply.c\r
90 > +++ b/notmuch-reply.c\r
91 > @@ -548,7 +548,8 @@ notmuch_reply_format_default(void *ctx,\r
92 >                            notmuch_config_t *config,\r
93 >                            notmuch_query_t *query,\r
94 >                            notmuch_show_params_t *params,\r
95 > -                          notmuch_bool_t reply_all)\r
96 > +                          notmuch_bool_t reply_all,\r
97 > +                          unused (sprinter_t *sp))\r
98 >  {\r
99 >      GMimeMessage *reply;\r
100 >      notmuch_messages_t *messages;\r
101 > @@ -587,17 +588,17 @@ notmuch_reply_format_default(void *ctx,\r
102 >  }\r
103 >  \r
104 >  static int\r
105 > -notmuch_reply_format_json(void *ctx,\r
106 > -                       notmuch_config_t *config,\r
107 > -                       notmuch_query_t *query,\r
108 > -                       notmuch_show_params_t *params,\r
109 > -                       notmuch_bool_t reply_all)\r
110 > +notmuch_reply_format_sprinter(void *ctx,\r
111 > +                           notmuch_config_t *config,\r
112 > +                           notmuch_query_t *query,\r
113 > +                           notmuch_show_params_t *params,\r
114 > +                           notmuch_bool_t reply_all,\r
115 > +                           sprinter_t *sp)\r
116 >  {\r
117 >      GMimeMessage *reply;\r
118 >      notmuch_messages_t *messages;\r
119 >      notmuch_message_t *message;\r
120 >      mime_node_t *node;\r
121 > -    sprinter_t *sp;\r
122 >  \r
123 >      if (notmuch_query_count_messages (query) != 1) {\r
124 >       fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
125 > @@ -613,18 +614,17 @@ notmuch_reply_format_json(void *ctx,\r
126 >      if (!reply)\r
127 >       return 1;\r
128 >  \r
129 > -    sp = sprinter_json_create (ctx, stdout);\r
130 >      sp->begin_map (sp);\r
131 >  \r
132 >      /* The headers of the reply message we've created */\r
133 >      sp->map_key (sp, "reply-headers");\r
134 > -    format_headers_json (sp, reply, TRUE);\r
135 > +    format_headers_sprinter (sp, reply, TRUE);\r
136 >      g_object_unref (G_OBJECT (reply));\r
137 >      reply = NULL;\r
138 >  \r
139 >      /* Start the original */\r
140 >      sp->map_key (sp, "original");\r
141 > -    format_part_json (ctx, sp, node, TRUE, TRUE);\r
142 > +    format_part_sprinter (ctx, sp, node, TRUE, TRUE);\r
143 >  \r
144 >      /* End */\r
145 >      sp->end (sp);\r
146 > @@ -639,7 +639,8 @@ notmuch_reply_format_headers_only(void *ctx,\r
147 >                                 notmuch_config_t *config,\r
148 >                                 notmuch_query_t *query,\r
149 >                                 unused (notmuch_show_params_t *params),\r
150 > -                               notmuch_bool_t reply_all)\r
151 > +                               notmuch_bool_t reply_all,\r
152 > +                               unused (sprinter_t *sp))\r
153 >  {\r
154 >      GMimeMessage *reply;\r
155 >      notmuch_messages_t *messages;\r
156 > @@ -707,7 +708,12 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
157 >      notmuch_query_t *query;\r
158 >      char *query_string;\r
159 >      int opt_index, ret = 0;\r
160 > -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
161 > +    int (*reply_format_func)(void *ctx,\r
162 \r
163 There should be spave between ) & ( but the original did not have that;\r
164 alsu uncrustify (>= 0.53) cannot add those :(\r
165 .. hmm, so, ignore for the time beign ;)\r
166 \r
167 > +                          notmuch_config_t *config,\r
168 > +                          notmuch_query_t *query,\r
169 > +                          notmuch_show_params_t *params,\r
170 > +                          notmuch_bool_t reply_all,\r
171 > +                          struct sprinter *sp);\r
172 >      notmuch_show_params_t params = {\r
173 >       .part = -1,\r
174 >       .crypto = {\r
175 > @@ -717,6 +723,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
176 >      };\r
177 >      int format = FORMAT_DEFAULT;\r
178 >      int reply_all = TRUE;\r
179 > +    struct sprinter *sp = NULL;\r
180 >  \r
181 >      notmuch_opt_desc_t options[] = {\r
182 >       { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
183 > @@ -738,12 +745,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
184 >       return 1;\r
185 >      }\r
186 >  \r
187 > -    if (format == FORMAT_HEADERS_ONLY)\r
188 > +    if (format == FORMAT_HEADERS_ONLY) {\r
189 >       reply_format_func = notmuch_reply_format_headers_only;\r
190 > -    else if (format == FORMAT_JSON)\r
191 > -     reply_format_func = notmuch_reply_format_json;\r
192 > -    else\r
193 > +    } else if (format == FORMAT_JSON) {\r
194 > +     reply_format_func = notmuch_reply_format_sprinter;\r
195 > +     sp = sprinter_json_create (ctx, stdout);\r
196 > +    } else {\r
197 >       reply_format_func = notmuch_reply_format_default;\r
198 > +    }\r
199 >  \r
200 >      config = notmuch_config_open (ctx, NULL, NULL);\r
201 >      if (config == NULL)\r
202 > @@ -770,7 +779,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
203 >       return 1;\r
204 >      }\r
205 >  \r
206 > -    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
207 > +    if (reply_format_func (ctx, config, query, &params, reply_all, sp) != 0)\r
208 >       return 1;\r
209 >  \r
210 >      notmuch_crypto_cleanup (&params.crypto);\r
211 > diff --git a/notmuch-show.c b/notmuch-show.c\r
212 > index 2fa2292..38c621f 100644\r
213 > --- a/notmuch-show.c\r
214 > +++ b/notmuch-show.c\r
215 > @@ -32,12 +32,12 @@ static const notmuch_show_format_t format_text = {\r
216 >  };\r
217 >  \r
218 >  static notmuch_status_t\r
219 > -format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
220 > +format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
221 >                       int indent, const notmuch_show_params_t *params);\r
222 \r
223 In many of these s/_json_/_sprinter_/ changes the following line indents\r
224 are missing. It sure makes the diff smaller but... ;)\r
225 \r
226 >  \r
227 >  static const notmuch_show_format_t format_json = {\r
228 >      .new_sprinter = sprinter_json_create,\r
229 > -    .part = format_part_json_entry,\r
230 > +    .part = format_part_sprinter_entry,\r
231 >  };\r
232 >  \r
233 >  static notmuch_status_t\r
234 > @@ -108,7 +108,7 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
235 >  /* Emit a sequence of key/value pairs for the metadata of message.\r
236 >   * The caller should begin a map before calling this. */\r
237 >  static void\r
238 > -format_message_json (sprinter_t *sp, notmuch_message_t *message)\r
239 > +format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)\r
240 >  {\r
241 >      /* Any changes to the JSON format should be reflected in the file\r
242 >       * devel/schemata. */\r
243 > @@ -208,7 +208,7 @@ _is_from_line (const char *line)\r
244 >  }\r
245 >  \r
246 >  void\r
247 > -format_headers_json (sprinter_t *sp, GMimeMessage *message,\r
248 > +format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,\r
249 >                    notmuch_bool_t reply)\r
250 \r
251 ditto :) (skipping rest dittos ;)\r
252 \r
253 >  {\r
254 >      /* Any changes to the JSON format should be reflected in the file\r
255 > @@ -363,7 +363,7 @@ signer_status_to_string (GMimeSignerStatus x)\r
256 >  \r
257 >  #ifdef GMIME_ATLEAST_26\r
258 >  static void\r
259 > -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
260 > +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)\r
261 >  {\r
262 >      /* Any changes to the JSON format should be reflected in the file\r
263 >       * devel/schemata. */\r
264 > @@ -438,7 +438,7 @@ format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
265 >  }\r
266 >  #else\r
267 >  static void\r
268 > -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
269 > +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)\r
270 >  {\r
271 >      const GMimeSignatureValidity* validity = node->sig_validity;\r
272 >  \r
273 > @@ -595,7 +595,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
274 >  }\r
275 >  \r
276 >  void\r
277 > -format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
278 > +format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
279 >                 notmuch_bool_t first, notmuch_bool_t output_body)\r
280 >  {\r
281 >      /* Any changes to the JSON format should be reflected in the file\r
282 > @@ -603,15 +603,15 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
283 >  \r
284 >      if (node->envelope_file) {\r
285 >       sp->begin_map (sp);\r
286 > -     format_message_json (sp, node->envelope_file);\r
287 > +     format_message_sprinter (sp, node->envelope_file);\r
288 >  \r
289 >       sp->map_key (sp, "headers");\r
290 > -     format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
291 > +     format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);\r
292 >  \r
293 >       if (output_body) {\r
294 >           sp->map_key (sp, "body");\r
295 >           sp->begin_list (sp);\r
296 > -         format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
297 > +         format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
298 >           sp->end (sp);\r
299 >       }\r
300 >       sp->end (sp);\r
301 > @@ -646,7 +646,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
302 >  \r
303 >      if (node->verify_attempted) {\r
304 >       sp->map_key (sp, "sigstatus");\r
305 > -     format_part_sigstatus_json (sp, node);\r
306 > +     format_part_sigstatus_sprinter (sp, node);\r
307 >      }\r
308 >  \r
309 >      sp->map_key (sp, "content-type");\r
310 > @@ -698,7 +698,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
311 >       sp->begin_map (sp);\r
312 >  \r
313 >       sp->map_key (sp, "headers");\r
314 > -     format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
315 > +     format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);\r
316 >  \r
317 >       sp->map_key (sp, "body");\r
318 >       sp->begin_list (sp);\r
319 > @@ -706,7 +706,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
320 >      }\r
321 >  \r
322 >      for (i = 0; i < node->nchildren; i++)\r
323 > -     format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
324 > +     format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
325 >  \r
326 >      /* Close content structures */\r
327 >      for (i = 0; i < nclose; i++)\r
328 > @@ -716,11 +716,11 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
329 >  }\r
330 >  \r
331 >  static notmuch_status_t\r
332 > -format_part_json_entry (const void *ctx, sprinter_t *sp,\r
333 > +format_part_sprinter_entry (const void *ctx, sprinter_t *sp,\r
334 >                       mime_node_t *node, unused (int indent),\r
335 >                       const notmuch_show_params_t *params)\r
336 >  {\r
337 > -    format_part_json (ctx, sp, node, TRUE, params->output_body);\r
338 > +    format_part_sprinter (ctx, sp, node, TRUE, params->output_body);\r
339 >  \r
340 >      return NOTMUCH_STATUS_SUCCESS;\r
341 >  }\r
342 > -- \r
343 > 1.8.0\r
344 >\r
345 > _______________________________________________\r
346 > notmuch mailing list\r
347 > notmuch@notmuchmail.org\r
348 > http://notmuchmail.org/mailman/listinfo/notmuch\r