Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 12 / 87b429dc6687f4736b791cb390d776320054b3
1 Return-Path: <nex@nexoid.at>\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 C8A13429E3A\r
6         for <notmuch@notmuchmail.org>; Tue,  4 Dec 2012 06:46:42 -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
9 X-Spam-Flag: NO\r
10 X-Spam-Score: 0.001\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5\r
13         tests=[FREEMAIL_FROM=0.001] 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 3IjcTmRQmtLy for <notmuch@notmuchmail.org>;\r
17         Tue,  4 Dec 2012 06:46:40 -0800 (PST)\r
18 Received: from mail.nexoid.at (www.nexoid.at [178.79.130.240])\r
19         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 77DBA431FD5\r
22         for <notmuch@notmuchmail.org>; Tue,  4 Dec 2012 06:46:40 -0800 (PST)\r
23 Received: by mail.nexoid.at (Postfix, from userid 1000)\r
24         id 7C5D611C10B; Tue,  4 Dec 2012 15:46:39 +0100 (CET)\r
25 From: Peter Feigl <craven@gmx.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [PATCH v2 2/5] Rename the -json printer functions in notmuch-reply\r
28         and notmuch-show to generic -sprinter functions.\r
29 Date: Tue,  4 Dec 2012 15:46:19 +0100\r
30 Message-Id: <1354632382-15609-3-git-send-email-craven@gmx.net>\r
31 X-Mailer: git-send-email 1.8.0\r
32 In-Reply-To: <1354632382-15609-1-git-send-email-craven@gmx.net>\r
33 References: <1354632382-15609-1-git-send-email-craven@gmx.net>\r
34 In-Reply-To: <1354264143-30173-1-git-send-email-craven@gmx.net>\r
35 References: <1354264143-30173-1-git-send-email-craven@gmx.net>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Tue, 04 Dec 2012 14:46:43 -0000\r
49 \r
50 All the structured output functions in notmuch-reply and notmuch-show\r
51 are renamed to a generic name (as they do not contain any json-specific\r
52 code anyway). This patch is a preparation to actually using the new\r
53 S-Expression sprinter in notmuch-reply and notmuch-show.\r
54 ---\r
55  notmuch-client.h |  8 ++++----\r
56  notmuch-reply.c  | 38 +++++++++++++++++++++-----------------\r
57  notmuch-show.c   | 30 +++++++++++++++---------------\r
58  3 files changed, 40 insertions(+), 36 deletions(-)\r
59 \r
60 diff --git a/notmuch-client.h b/notmuch-client.h\r
61 index ae9344b..1c336dc 100644\r
62 --- a/notmuch-client.h\r
63 +++ b/notmuch-client.h\r
64 @@ -175,12 +175,12 @@ notmuch_status_t\r
65  show_one_part (const char *filename, int part);\r
66  \r
67  void\r
68 -format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,\r
69 -                 notmuch_bool_t first, notmuch_bool_t output_body);\r
70 +format_part_sprinter (const void *ctx, struct sprinter *sp, mime_node_t *node,\r
71 +                     notmuch_bool_t first, notmuch_bool_t output_body);\r
72  \r
73  void\r
74 -format_headers_json (struct sprinter *sp, GMimeMessage *message,\r
75 -                    notmuch_bool_t reply);\r
76 +format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,\r
77 +                        notmuch_bool_t reply);\r
78  \r
79  typedef enum {\r
80      NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,\r
81 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
82 index e60a264..53aefa7 100644\r
83 --- a/notmuch-reply.c\r
84 +++ b/notmuch-reply.c\r
85 @@ -548,7 +548,8 @@ notmuch_reply_format_default(void *ctx,\r
86                              notmuch_config_t *config,\r
87                              notmuch_query_t *query,\r
88                              notmuch_show_params_t *params,\r
89 -                            notmuch_bool_t reply_all)\r
90 +                            notmuch_bool_t reply_all,\r
91 +                            unused (sprinter_t *sp))\r
92  {\r
93      GMimeMessage *reply;\r
94      notmuch_messages_t *messages;\r
95 @@ -587,17 +588,17 @@ notmuch_reply_format_default(void *ctx,\r
96  }\r
97  \r
98  static int\r
99 -notmuch_reply_format_json(void *ctx,\r
100 -                         notmuch_config_t *config,\r
101 -                         notmuch_query_t *query,\r
102 -                         notmuch_show_params_t *params,\r
103 -                         notmuch_bool_t reply_all)\r
104 +notmuch_reply_format_sprinter(void *ctx,\r
105 +                             notmuch_config_t *config,\r
106 +                             notmuch_query_t *query,\r
107 +                             notmuch_show_params_t *params,\r
108 +                             notmuch_bool_t reply_all,\r
109 +                             sprinter_t *sp)\r
110  {\r
111      GMimeMessage *reply;\r
112      notmuch_messages_t *messages;\r
113      notmuch_message_t *message;\r
114      mime_node_t *node;\r
115 -    sprinter_t *sp;\r
116  \r
117      if (notmuch_query_count_messages (query) != 1) {\r
118         fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
119 @@ -613,18 +614,17 @@ notmuch_reply_format_json(void *ctx,\r
120      if (!reply)\r
121         return 1;\r
122  \r
123 -    sp = sprinter_json_create (ctx, stdout);\r
124      sp->begin_map (sp);\r
125  \r
126      /* The headers of the reply message we've created */\r
127      sp->map_key (sp, "reply-headers");\r
128 -    format_headers_json (sp, reply, TRUE);\r
129 +    format_headers_sprinter (sp, reply, TRUE);\r
130      g_object_unref (G_OBJECT (reply));\r
131      reply = NULL;\r
132  \r
133      /* Start the original */\r
134      sp->map_key (sp, "original");\r
135 -    format_part_json (ctx, sp, node, TRUE, TRUE);\r
136 +    format_part_sprinter (ctx, sp, node, TRUE, TRUE);\r
137  \r
138      /* End */\r
139      sp->end (sp);\r
140 @@ -639,7 +639,8 @@ notmuch_reply_format_headers_only(void *ctx,\r
141                                   notmuch_config_t *config,\r
142                                   notmuch_query_t *query,\r
143                                   unused (notmuch_show_params_t *params),\r
144 -                                 notmuch_bool_t reply_all)\r
145 +                                 notmuch_bool_t reply_all,\r
146 +                                 unused (sprinter_t *sp))\r
147  {\r
148      GMimeMessage *reply;\r
149      notmuch_messages_t *messages;\r
150 @@ -707,7 +708,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
151      notmuch_query_t *query;\r
152      char *query_string;\r
153      int opt_index, ret = 0;\r
154 -    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
155 +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all, struct sprinter *sp);\r
156      notmuch_show_params_t params = {\r
157         .part = -1,\r
158         .crypto = {\r
159 @@ -717,6 +718,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
160      };\r
161      int format = FORMAT_DEFAULT;\r
162      int reply_all = TRUE;\r
163 +    struct sprinter *sp = NULL;\r
164  \r
165      notmuch_opt_desc_t options[] = {\r
166         { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
167 @@ -738,12 +740,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
168         return 1;\r
169      }\r
170  \r
171 -    if (format == FORMAT_HEADERS_ONLY)\r
172 +    if (format == FORMAT_HEADERS_ONLY) {\r
173         reply_format_func = notmuch_reply_format_headers_only;\r
174 -    else if (format == FORMAT_JSON)\r
175 -       reply_format_func = notmuch_reply_format_json;\r
176 -    else\r
177 +    } else if (format == FORMAT_JSON) {\r
178 +       reply_format_func = notmuch_reply_format_sprinter;\r
179 +       sp = sprinter_json_create (ctx, stdout);\r
180 +    } else {\r
181         reply_format_func = notmuch_reply_format_default;\r
182 +    }\r
183  \r
184      config = notmuch_config_open (ctx, NULL, NULL);\r
185      if (config == NULL)\r
186 @@ -770,7 +774,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
187         return 1;\r
188      }\r
189  \r
190 -    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
191 +    if (reply_format_func (ctx, config, query, &params, reply_all, sp) != 0)\r
192         return 1;\r
193  \r
194      notmuch_crypto_cleanup (&params.crypto);\r
195 diff --git a/notmuch-show.c b/notmuch-show.c\r
196 index 2fa2292..38c621f 100644\r
197 --- a/notmuch-show.c\r
198 +++ b/notmuch-show.c\r
199 @@ -32,12 +32,12 @@ static const notmuch_show_format_t format_text = {\r
200  };\r
201  \r
202  static notmuch_status_t\r
203 -format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
204 +format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
205                         int indent, const notmuch_show_params_t *params);\r
206  \r
207  static const notmuch_show_format_t format_json = {\r
208      .new_sprinter = sprinter_json_create,\r
209 -    .part = format_part_json_entry,\r
210 +    .part = format_part_sprinter_entry,\r
211  };\r
212  \r
213  static notmuch_status_t\r
214 @@ -108,7 +108,7 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
215  /* Emit a sequence of key/value pairs for the metadata of message.\r
216   * The caller should begin a map before calling this. */\r
217  static void\r
218 -format_message_json (sprinter_t *sp, notmuch_message_t *message)\r
219 +format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)\r
220  {\r
221      /* Any changes to the JSON format should be reflected in the file\r
222       * devel/schemata. */\r
223 @@ -208,7 +208,7 @@ _is_from_line (const char *line)\r
224  }\r
225  \r
226  void\r
227 -format_headers_json (sprinter_t *sp, GMimeMessage *message,\r
228 +format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,\r
229                      notmuch_bool_t reply)\r
230  {\r
231      /* Any changes to the JSON format should be reflected in the file\r
232 @@ -363,7 +363,7 @@ signer_status_to_string (GMimeSignerStatus x)\r
233  \r
234  #ifdef GMIME_ATLEAST_26\r
235  static void\r
236 -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
237 +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)\r
238  {\r
239      /* Any changes to the JSON format should be reflected in the file\r
240       * devel/schemata. */\r
241 @@ -438,7 +438,7 @@ format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
242  }\r
243  #else\r
244  static void\r
245 -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
246 +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)\r
247  {\r
248      const GMimeSignatureValidity* validity = node->sig_validity;\r
249  \r
250 @@ -595,7 +595,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
251  }\r
252  \r
253  void\r
254 -format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
255 +format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
256                   notmuch_bool_t first, notmuch_bool_t output_body)\r
257  {\r
258      /* Any changes to the JSON format should be reflected in the file\r
259 @@ -603,15 +603,15 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
260  \r
261      if (node->envelope_file) {\r
262         sp->begin_map (sp);\r
263 -       format_message_json (sp, node->envelope_file);\r
264 +       format_message_sprinter (sp, node->envelope_file);\r
265  \r
266         sp->map_key (sp, "headers");\r
267 -       format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
268 +       format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);\r
269  \r
270         if (output_body) {\r
271             sp->map_key (sp, "body");\r
272             sp->begin_list (sp);\r
273 -           format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
274 +           format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
275             sp->end (sp);\r
276         }\r
277         sp->end (sp);\r
278 @@ -646,7 +646,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
279  \r
280      if (node->verify_attempted) {\r
281         sp->map_key (sp, "sigstatus");\r
282 -       format_part_sigstatus_json (sp, node);\r
283 +       format_part_sigstatus_sprinter (sp, node);\r
284      }\r
285  \r
286      sp->map_key (sp, "content-type");\r
287 @@ -698,7 +698,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
288         sp->begin_map (sp);\r
289  \r
290         sp->map_key (sp, "headers");\r
291 -       format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
292 +       format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);\r
293  \r
294         sp->map_key (sp, "body");\r
295         sp->begin_list (sp);\r
296 @@ -706,7 +706,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
297      }\r
298  \r
299      for (i = 0; i < node->nchildren; i++)\r
300 -       format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
301 +       format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
302  \r
303      /* Close content structures */\r
304      for (i = 0; i < nclose; i++)\r
305 @@ -716,11 +716,11 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
306  }\r
307  \r
308  static notmuch_status_t\r
309 -format_part_json_entry (const void *ctx, sprinter_t *sp,\r
310 +format_part_sprinter_entry (const void *ctx, sprinter_t *sp,\r
311                         mime_node_t *node, unused (int indent),\r
312                         const notmuch_show_params_t *params)\r
313  {\r
314 -    format_part_json (ctx, sp, node, TRUE, params->output_body);\r
315 +    format_part_sprinter (ctx, sp, node, TRUE, params->output_body);\r
316  \r
317      return NOTMUCH_STATUS_SUCCESS;\r
318  }\r
319 -- \r
320 1.8.0\r
321 \r