Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / ef / 9283536a26dac38f03f15f2502c72578d97063
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 26A37431FC3\r
6         for <notmuch@notmuchmail.org>; Fri,  9 Mar 2012 15:09:08 -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 VjsFzxUkPuvS for <notmuch@notmuchmail.org>;\r
16         Fri,  9 Mar 2012 15:09:04 -0800 (PST)\r
17 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
18         [209.85.215.53]) (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 DDDE5431FAE\r
21         for <notmuch@notmuchmail.org>; Fri,  9 Mar 2012 15:09:03 -0800 (PST)\r
22 Received: by lahc1 with SMTP id c1so2275980lah.26\r
23         for <notmuch@notmuchmail.org>; Fri, 09 Mar 2012 15:09:02 -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=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
27         :mime-version:content-type:x-gm-message-state;\r
28         bh=iGTAKEuykInJLscHrAgJXloAni6J/gmB/gjImATZpZc=;\r
29         b=nI70bU5msarKhwpXMzp6etG9VGc6ImnR3KqQEX+h8bFhoqGH9m1ilve/bC+dSmnWlo\r
30         QHXSIw3Vasu79zO1HXNQsJ/hY9usNeWPeFuoHuMh9vZspvqajdT3rmaOg+HPOGlARTPs\r
31         9lkKF9dy0EA01Hzn5aDizucp7yFfH37ki3EfoU5Av6aw/iFFCWzGWOITig2hTlp29a8e\r
32         nHGkOe0Mq4q7J9y74E/2qjrs1lTqNuvpB4O/OAZnvAKPIKG+0LKUklUG4nLDtgc6u+kg\r
33         uLYhtR8Q7B1TyhIa5VfbGiAbdKIetlV2DATE3CBERcpJkDg1wwcHXDllkZ2WXq/QlXkO\r
34         Wlkg==\r
35 Received: by 10.112.38.3 with SMTP id c3mr1445266lbk.94.1331334542180;\r
36         Fri, 09 Mar 2012 15:09:02 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
38         [84.248.80.253])\r
39         by mx.google.com with ESMTPS id nh5sm5972532lab.5.2012.03.09.15.08.59\r
40         (version=SSLv3 cipher=OTHER); Fri, 09 Mar 2012 15:09:00 -0800 (PST)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: Adam Wolfe Gordon <awg+notmuch@xvx.ca>, notmuch@notmuchmail.org\r
43 Subject: Re: [PATCH v6 05/10] reply: Add a JSON reply format.\r
44 In-Reply-To: <1329893199-21630-6-git-send-email-awg+notmuch@xvx.ca>\r
45 References: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>\r
46         <1329893199-21630-6-git-send-email-awg+notmuch@xvx.ca>\r
47 User-Agent: Notmuch/0.11.1+295~g780f284 (http://notmuchmail.org) Emacs/23.3.1\r
48         (i686-pc-linux-gnu)\r
49 Date: Sat, 10 Mar 2012 01:08:58 +0200\r
50 Message-ID: <87d38l8j91.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  ALoCoQkAIH0T9yfAEPf7yqPlYWQ2M4KDGiS0tBACl6rntLAEQgeHqpc+r6STfHpkD56mHE0tRA+Y\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: Fri, 09 Mar 2012 23:09:08 -0000\r
68 \r
69 On Tue, 21 Feb 2012 23:46:34 -0700, Adam Wolfe Gordon <awg+notmuch@xvx.ca> wrote:\r
70 > This new JSON format for replies includes headers generated for a\r
71 > reply message as well as the headers of the original message.  Using\r
72 > this data, a client can intelligently create a reply. For example, the\r
73 > emacs client will be able to create replies with quoted HTML parts by\r
74 > parsing the HTML parts.\r
75 > ---\r
76 >  notmuch-client.h |   10 ++++++++--\r
77 >  notmuch-reply.c  |   49 +++++++++++++++++++++++++++++++++++++++++++++++++\r
78 >  notmuch-show.c   |   30 ++++++++++++++++++++++--------\r
79 >  test/multipart   |    1 -\r
80 >  4 files changed, 79 insertions(+), 11 deletions(-)\r
81\r
82 > diff --git a/notmuch-client.h b/notmuch-client.h\r
83 > index f4a62cc..ef4eaba 100644\r
84 > --- a/notmuch-client.h\r
85 > +++ b/notmuch-client.h\r
86 > @@ -62,13 +62,13 @@\r
87 >  #define STRINGIFY(s) STRINGIFY_(s)\r
88 >  #define STRINGIFY_(s) #s\r
89 >  \r
90 > -struct mime_node;\r
91 > +typedef struct mime_node mime_node_t;\r
92 >  struct notmuch_show_params;\r
93 >  \r
94 >  typedef struct notmuch_show_format {\r
95 >      const char *message_set_start;\r
96 >      void (*part) (const void *ctx,\r
97 > -               struct mime_node *node, int indent,\r
98 > +               mime_node_t *node, int indent,\r
99 >                 const struct notmuch_show_params *params);\r
100 >      const char *message_start;\r
101 >      void (*message) (const void *ctx,\r
102 > @@ -191,6 +191,12 @@ show_message_body (notmuch_message_t *message,\r
103 >  notmuch_status_t\r
104 >  show_one_part (const char *filename, int part);\r
105 >  \r
106 > +void\r
107 > +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);\r
108 > +\r
109 > +void\r
110 > +format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);\r
111 > +\r
112 >  char *\r
113 >  json_quote_chararray (const void *ctx, const char *str, const size_t len);\r
114 >  \r
115 > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
116 > index 177e6ca..017c6ae 100644\r
117 > --- a/notmuch-reply.c\r
118 > +++ b/notmuch-reply.c\r
119 > @@ -601,6 +601,51 @@ notmuch_reply_format_default(void *ctx,\r
120 >      return 0;\r
121 >  }\r
122 >  \r
123 > +static int\r
124 > +notmuch_reply_format_json(void *ctx,\r
125 > +                       notmuch_config_t *config,\r
126 > +                       notmuch_query_t *query,\r
127 > +                       notmuch_show_params_t *params,\r
128 > +                       notmuch_bool_t reply_all)\r
129 > +{\r
130 > +    GMimeMessage *reply;\r
131 > +    notmuch_messages_t *messages;\r
132 > +    notmuch_message_t *message;\r
133 > +    mime_node_t *node;\r
134 > +\r
135 > +    if (notmuch_query_count_messages (query) != 1) {\r
136 > +     fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
137 > +     return 1;\r
138 > +    }\r
139 > +\r
140 > +    messages = notmuch_query_search_messages (query);\r
141 > +    message = notmuch_messages_get (messages);\r
142 > +    if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
143 > +                     &node) != NOTMUCH_STATUS_SUCCESS)\r
144 > +     return 1;\r
145 > +\r
146 > +    reply = create_reply_message (ctx, config, message, reply_all);\r
147 > +    if (!reply)\r
148 > +     return 1;\r
149 > +\r
150 > +    /* The headers of the reply message we've created */\r
151 > +    printf ("{\"reply-headers\": ");\r
152 > +    format_headers_json (ctx, reply, TRUE);\r
153 > +    g_object_unref (G_OBJECT (reply));\r
154 > +    reply = NULL;\r
155 > +\r
156 > +    /* Start the original */\r
157 > +    printf (", \"original\": ");\r
158 > +\r
159 > +    format_part_json (ctx, node, TRUE);\r
160 > +\r
161 > +    /* End */\r
162 > +    printf ("}\n");\r
163 > +    notmuch_message_destroy (message);\r
164 > +\r
165 > +    return 0;\r
166 > +}\r
167 > +\r
168 >  /* This format is currently tuned for a git send-email --notmuch hook */\r
169 >  static int\r
170 >  notmuch_reply_format_headers_only(void *ctx,\r
171 > @@ -663,6 +708,7 @@ notmuch_reply_format_headers_only(void *ctx,\r
172 >  \r
173 >  enum {\r
174 >      FORMAT_DEFAULT,\r
175 > +    FORMAT_JSON,\r
176 >      FORMAT_HEADERS_ONLY,\r
177 >  };\r
178 >  \r
179 > @@ -682,6 +728,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
180 >      notmuch_opt_desc_t options[] = {\r
181 >       { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
182 >         (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
183 > +                               { "json", FORMAT_JSON },\r
184 >                                 { "headers-only", FORMAT_HEADERS_ONLY },\r
185 >                                 { 0, 0 } } },\r
186 >       { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',\r
187 > @@ -700,6 +747,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
188 >  \r
189 >      if (format == FORMAT_HEADERS_ONLY)\r
190 >       reply_format_func = notmuch_reply_format_headers_only;\r
191 > +    else if (format == FORMAT_JSON)\r
192 > +     reply_format_func = notmuch_reply_format_json;\r
193 >      else\r
194 >       reply_format_func = notmuch_reply_format_default;\r
195 >  \r
196 > diff --git a/notmuch-show.c b/notmuch-show.c\r
197 > index 6a171a4..2126d78 100644\r
198 > --- a/notmuch-show.c\r
199 > +++ b/notmuch-show.c\r
200 > @@ -290,8 +290,8 @@ format_headers_message_part_text (GMimeMessage *message)\r
201 >      printf ("Date: %s\n", g_mime_message_get_date_as_string (message));\r
202 >  }\r
203 >  \r
204 > -static void\r
205 > -format_headers_json (const void *ctx, GMimeMessage *message)\r
206 > +void\r
207 > +format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply)\r
208 >  {\r
209 >      void *local = talloc_new (ctx);\r
210 >      InternetAddressList *recipients;\r
211 > @@ -315,9 +315,23 @@ format_headers_json (const void *ctx, GMimeMessage *message)\r
212 >       printf (", %s: %s",\r
213 >               json_quote_str (local, "Cc"),\r
214 >               json_quote_str (local, recipients_string));\r
215 > -    printf (", %s: %s}",\r
216 > -         json_quote_str (local, "Date"),\r
217 > -         json_quote_str (local, g_mime_message_get_date_as_string (message)));\r
218 > +\r
219 > +    if (!reply)\r
220 > +     printf (", %s: %s",\r
221 > +             json_quote_str (local, "Date"),\r
222 > +             json_quote_str (local, g_mime_message_get_date_as_string (message)));\r
223 > +\r
224 > +    if (reply) {\r
225 \r
226 Isn't that an "else"?\r
227 \r
228 Otherwise looks good.\r
229 \r
230 BR,\r
231 Jani.\r
232 \r
233 \r
234 > +     printf (", %s: %s",\r
235 > +             json_quote_str (local, "In-reply-to"),\r
236 > +             json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to")));\r
237 > +\r
238 > +     printf (", %s: %s",\r
239 > +             json_quote_str (local, "References"),\r
240 > +             json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "References")));\r
241 > +    }\r
242 > +\r
243 > +    printf ("}");\r
244 >  \r
245 >      talloc_free (local);\r
246 >  }\r
247 > @@ -652,7 +666,7 @@ format_part_text (const void *ctx, mime_node_t *node,\r
248 >      printf ("\f%s}\n", part_type);\r
249 >  }\r
250 >  \r
251 > -static void\r
252 > +void\r
253 >  format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
254 >  {\r
255 >      /* Any changes to the JSON format should be reflected in the file\r
256 > @@ -663,7 +677,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
257 >       format_message_json (ctx, node->envelope_file);\r
258 >  \r
259 >       printf ("\"headers\": ");\r
260 > -     format_headers_json (ctx, GMIME_MESSAGE (node->part));\r
261 > +     format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);\r
262 >  \r
263 >       printf (", \"body\": [");\r
264 >       format_part_json (ctx, mime_node_child (node, 0), first);\r
265 > @@ -737,7 +751,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
266 >      } else if (GMIME_IS_MESSAGE (node->part)) {\r
267 >       printf (", \"content\": [{");\r
268 >       printf ("\"headers\": ");\r
269 > -     format_headers_json (local, GMIME_MESSAGE (node->part));\r
270 > +     format_headers_json (local, GMIME_MESSAGE (node->part), FALSE);\r
271 >  \r
272 >       printf (", \"body\": [");\r
273 >       terminator = "]}]";\r
274 > diff --git a/test/multipart b/test/multipart\r
275 > index f102294..e7abcc2 100755\r
276 > --- a/test/multipart\r
277 > +++ b/test/multipart\r
278 > @@ -590,7 +590,6 @@ EOF\r
279 >  test_expect_equal_file OUTPUT EXPECTED\r
280 >  \r
281 >  test_begin_subtest "'notmuch reply' to a multipart message with json format"\r
282 > -test_subtest_known_broken\r
283 >  notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT\r
284 >  cat <<EOF >EXPECTED\r
285 >  {"reply-headers": {"Subject": "Re: Multipart message",\r
286 > -- \r
287 > 1.7.5.4\r
288\r
289 > _______________________________________________\r
290 > notmuch mailing list\r
291 > notmuch@notmuchmail.org\r
292 > http://notmuchmail.org/mailman/listinfo/notmuch\r