1 Return-Path: <awg@lagos.xvx.ca>
\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 B6A51431FD6
\r
6 for <notmuch@notmuchmail.org>; Tue, 21 Feb 2012 22:46:48 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 k2iBzwk5M00Q for <notmuch@notmuchmail.org>;
\r
16 Tue, 21 Feb 2012 22:46:46 -0800 (PST)
\r
17 Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9])
\r
18 by olra.theworths.org (Postfix) with ESMTP id D6F18431FC0
\r
19 for <notmuch@notmuchmail.org>; Tue, 21 Feb 2012 22:46:45 -0800 (PST)
\r
20 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd7ml2no-ssvc.prod.shaw.ca)
\r
22 by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 21 Feb 2012 23:46:45 -0700
\r
23 X-Cloudmark-SP-Filtered: true
\r
24 X-Cloudmark-SP-Result: v=1.1 cv=GZn8e3lTBEeJrlGK3+GUWyR5aYe1SJcDn5uEERMe9yQ=
\r
26 a=tXneHAB9HJoA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17
\r
27 a=bz-zy3QpAAAA:8 a=zj4l01KfgLfMms7IjnsA:9 a=tvKH82Il3pz4rfUQjx0A:7
\r
28 a=NFWI-YhVVZsA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117
\r
29 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])
\r
30 by pd7ml2no-dmz.prod.shaw.ca with ESMTP; 21 Feb 2012 23:46:45 -0700
\r
31 Received: by lagos.xvx.ca (Postfix, from userid 1000)
\r
32 id BF63B8095C4E; Tue, 21 Feb 2012 23:46:44 -0700 (MST)
\r
33 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>
\r
34 To: notmuch@notmuchmail.org
\r
35 Subject: [PATCH v6 05/10] reply: Add a JSON reply format.
\r
36 Date: Tue, 21 Feb 2012 23:46:34 -0700
\r
37 Message-Id: <1329893199-21630-6-git-send-email-awg+notmuch@xvx.ca>
\r
38 X-Mailer: git-send-email 1.7.5.4
\r
39 In-Reply-To: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>
\r
40 References: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Wed, 22 Feb 2012 06:46:49 -0000
\r
55 This new JSON format for replies includes headers generated for a
\r
56 reply message as well as the headers of the original message. Using
\r
57 this data, a client can intelligently create a reply. For example, the
\r
58 emacs client will be able to create replies with quoted HTML parts by
\r
59 parsing the HTML parts.
\r
61 notmuch-client.h | 10 ++++++++--
\r
62 notmuch-reply.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
63 notmuch-show.c | 30 ++++++++++++++++++++++--------
\r
64 test/multipart | 1 -
\r
65 4 files changed, 79 insertions(+), 11 deletions(-)
\r
67 diff --git a/notmuch-client.h b/notmuch-client.h
\r
68 index f4a62cc..ef4eaba 100644
\r
69 --- a/notmuch-client.h
\r
70 +++ b/notmuch-client.h
\r
72 #define STRINGIFY(s) STRINGIFY_(s)
\r
73 #define STRINGIFY_(s) #s
\r
76 +typedef struct mime_node mime_node_t;
\r
77 struct notmuch_show_params;
\r
79 typedef struct notmuch_show_format {
\r
80 const char *message_set_start;
\r
81 void (*part) (const void *ctx,
\r
82 - struct mime_node *node, int indent,
\r
83 + mime_node_t *node, int indent,
\r
84 const struct notmuch_show_params *params);
\r
85 const char *message_start;
\r
86 void (*message) (const void *ctx,
\r
87 @@ -191,6 +191,12 @@ show_message_body (notmuch_message_t *message,
\r
89 show_one_part (const char *filename, int part);
\r
92 +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);
\r
95 +format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);
\r
98 json_quote_chararray (const void *ctx, const char *str, const size_t len);
\r
100 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
101 index 177e6ca..017c6ae 100644
\r
102 --- a/notmuch-reply.c
\r
103 +++ b/notmuch-reply.c
\r
104 @@ -601,6 +601,51 @@ notmuch_reply_format_default(void *ctx,
\r
109 +notmuch_reply_format_json(void *ctx,
\r
110 + notmuch_config_t *config,
\r
111 + notmuch_query_t *query,
\r
112 + notmuch_show_params_t *params,
\r
113 + notmuch_bool_t reply_all)
\r
115 + GMimeMessage *reply;
\r
116 + notmuch_messages_t *messages;
\r
117 + notmuch_message_t *message;
\r
118 + mime_node_t *node;
\r
120 + if (notmuch_query_count_messages (query) != 1) {
\r
121 + fprintf (stderr, "Error: search term did not match precisely one message.\n");
\r
125 + messages = notmuch_query_search_messages (query);
\r
126 + message = notmuch_messages_get (messages);
\r
127 + if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,
\r
128 + &node) != NOTMUCH_STATUS_SUCCESS)
\r
131 + reply = create_reply_message (ctx, config, message, reply_all);
\r
135 + /* The headers of the reply message we've created */
\r
136 + printf ("{\"reply-headers\": ");
\r
137 + format_headers_json (ctx, reply, TRUE);
\r
138 + g_object_unref (G_OBJECT (reply));
\r
141 + /* Start the original */
\r
142 + printf (", \"original\": ");
\r
144 + format_part_json (ctx, node, TRUE);
\r
148 + notmuch_message_destroy (message);
\r
153 /* This format is currently tuned for a git send-email --notmuch hook */
\r
155 notmuch_reply_format_headers_only(void *ctx,
\r
156 @@ -663,6 +708,7 @@ notmuch_reply_format_headers_only(void *ctx,
\r
161 FORMAT_HEADERS_ONLY,
\r
164 @@ -682,6 +728,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
165 notmuch_opt_desc_t options[] = {
\r
166 { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
\r
167 (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
\r
168 + { "json", FORMAT_JSON },
\r
169 { "headers-only", FORMAT_HEADERS_ONLY },
\r
171 { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',
\r
172 @@ -700,6 +747,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
174 if (format == FORMAT_HEADERS_ONLY)
\r
175 reply_format_func = notmuch_reply_format_headers_only;
\r
176 + else if (format == FORMAT_JSON)
\r
177 + reply_format_func = notmuch_reply_format_json;
\r
179 reply_format_func = notmuch_reply_format_default;
\r
181 diff --git a/notmuch-show.c b/notmuch-show.c
\r
182 index 6a171a4..2126d78 100644
\r
183 --- a/notmuch-show.c
\r
184 +++ b/notmuch-show.c
\r
185 @@ -290,8 +290,8 @@ format_headers_message_part_text (GMimeMessage *message)
\r
186 printf ("Date: %s\n", g_mime_message_get_date_as_string (message));
\r
190 -format_headers_json (const void *ctx, GMimeMessage *message)
\r
192 +format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply)
\r
194 void *local = talloc_new (ctx);
\r
195 InternetAddressList *recipients;
\r
196 @@ -315,9 +315,23 @@ format_headers_json (const void *ctx, GMimeMessage *message)
\r
197 printf (", %s: %s",
\r
198 json_quote_str (local, "Cc"),
\r
199 json_quote_str (local, recipients_string));
\r
200 - printf (", %s: %s}",
\r
201 - json_quote_str (local, "Date"),
\r
202 - json_quote_str (local, g_mime_message_get_date_as_string (message)));
\r
205 + printf (", %s: %s",
\r
206 + json_quote_str (local, "Date"),
\r
207 + json_quote_str (local, g_mime_message_get_date_as_string (message)));
\r
210 + printf (", %s: %s",
\r
211 + json_quote_str (local, "In-reply-to"),
\r
212 + json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to")));
\r
214 + printf (", %s: %s",
\r
215 + json_quote_str (local, "References"),
\r
216 + json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "References")));
\r
221 talloc_free (local);
\r
223 @@ -652,7 +666,7 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
224 printf ("\f%s}\n", part_type);
\r
229 format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
231 /* Any changes to the JSON format should be reflected in the file
\r
232 @@ -663,7 +677,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
233 format_message_json (ctx, node->envelope_file);
\r
235 printf ("\"headers\": ");
\r
236 - format_headers_json (ctx, GMIME_MESSAGE (node->part));
\r
237 + format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);
\r
239 printf (", \"body\": [");
\r
240 format_part_json (ctx, mime_node_child (node, 0), first);
\r
241 @@ -737,7 +751,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
242 } else if (GMIME_IS_MESSAGE (node->part)) {
\r
243 printf (", \"content\": [{");
\r
244 printf ("\"headers\": ");
\r
245 - format_headers_json (local, GMIME_MESSAGE (node->part));
\r
246 + format_headers_json (local, GMIME_MESSAGE (node->part), FALSE);
\r
248 printf (", \"body\": [");
\r
249 terminator = "]}]";
\r
250 diff --git a/test/multipart b/test/multipart
\r
251 index f102294..e7abcc2 100755
\r
252 --- a/test/multipart
\r
253 +++ b/test/multipart
\r
254 @@ -590,7 +590,6 @@ EOF
\r
255 test_expect_equal_file OUTPUT EXPECTED
\r
257 test_begin_subtest "'notmuch reply' to a multipart message with json format"
\r
258 -test_subtest_known_broken
\r
259 notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
\r
260 cat <<EOF >EXPECTED
\r
261 {"reply-headers": {"Subject": "Re: Multipart message",
\r