1 Return-Path: <amdragon@mit.edu>
\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 EF512431FD7
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Jul 2012 19:35:06 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 PEuWIeXz8wSt for <notmuch@notmuchmail.org>;
\r
16 Tue, 24 Jul 2012 19:35:05 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id A4293431FAF
\r
20 for <notmuch@notmuchmail.org>; Tue, 24 Jul 2012 19:35:05 -0700 (PDT)
\r
21 X-AuditID: 1209190e-b7fb56d0000008b2-fb-500f5b59f02f
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 03.7F.02226.95B5F005; Tue, 24 Jul 2012 22:35:05 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6P2Z5pd011175;
\r
27 Tue, 24 Jul 2012 22:35:05 -0400
\r
28 Received: from drake.dyndns.org
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6P2Z2dB025128
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Tue, 24 Jul 2012 22:35:04 -0400 (EDT)
\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)
\r
36 (envelope-from <amdragon@mit.edu>)
\r
37 id 1StrRG-0004a2-MY; Tue, 24 Jul 2012 22:35:02 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 09/13] show: Convert non-envelope format_part_json to use
\r
42 Date: Tue, 24 Jul 2012 22:34:49 -0400
\r
43 Message-Id: <1343183693-17134-10-git-send-email-amdragon@mit.edu>
\r
44 X-Mailer: git-send-email 1.7.10
\r
45 In-Reply-To: <1343183693-17134-1-git-send-email-amdragon@mit.edu>
\r
46 References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrBsZzR9gsH2XqMXehnZGi+s3ZzI7
\r
49 MHks3rSfzePZqlvMAUxRXDYpqTmZZalF+nYJXBmn3jxmKdioVNH89xRTA+NE6S5GTg4JAROJ
\r
50 b8e6WSBsMYkL99azgdhCAvsYJfrOl3cxcgHZGxglXp+cxgThPGKSePnoHzOEM5dR4sO8iWDt
\r
51 bAIaEtv2L2cEsUUEpCV23p3NCmIzC5hJzP05EWgsB4ewQJBE30lxkDCLgKrE2Z5OsBJeAUeJ
\r
52 I5u3skJcIS/x9H4f2BWcQPHzSxYyQlzkINGz+Br7BEb+BYwMqxhlU3KrdHMTM3OKU5N1i5MT
\r
53 8/JSi3SN9XIzS/RSU0o3MYIDSZJvB+PXg0qHGAU4GJV4eH8/4QsQYk0sK67MPcQoycGkJMpb
\r
54 EcwfIMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEtygMKMebklhZlVqUD5OS5mBREue9knLTX0gg
\r
55 PbEkNTs1tSC1CCYrw8GhJMHbGgXUKFiUmp5akZaZU4KQZuLgBBnOAzR8N0gNb3FBYm5xZjpE
\r
56 /hSjopQ471yQhABIIqM0D64XFumvGMWBXhHmbQap4gEmCbjuV0CDmYAGPw/jAxlckoiQkmpg
\r
57 FDTWmSLw7aJQ5e0pK4+EiBoGuBmvXvjb1TUqYdbUb0y3QrbU9mxX8/jbtXn7DK5nYhGcQZMv
\r
58 75l3ubYzTqbtX+c3wWO7WyY4bYmZfGLiQsOLkotEbic7dEY0xHzdsMNM+sSmFasT5rS/y1zL
\r
59 tlmo0U9v9qyzbA+6znsUHfjGfkP+obwDy6/IRCWW4oxEQy3mouJEAIOcPvfPAgAA
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Wed, 25 Jul 2012 02:35:07 -0000
\r
75 notmuch-show.c | 74 +++++++++++++++++++++++++++++++++++---------------------
\r
76 1 file changed, 46 insertions(+), 28 deletions(-)
\r
78 diff --git a/notmuch-show.c b/notmuch-show.c
\r
79 index 3ff32df..afbd9d0 100644
\r
80 --- a/notmuch-show.c
\r
81 +++ b/notmuch-show.c
\r
82 @@ -588,7 +588,6 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
86 - void *local = talloc_new (ctx);
\r
87 /* The disposition and content-type metadata are associated with
\r
88 * the envelope for message parts */
\r
89 GMimeObject *meta = node->envelope_part ?
\r
90 @@ -597,31 +596,41 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
91 const char *cid = g_mime_object_get_content_id (meta);
\r
92 const char *filename = GMIME_IS_PART (node->part) ?
\r
93 g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;
\r
94 - const char *terminator = "";
\r
100 + sp->begin_map (sp);
\r
102 - printf ("{\"id\": %d", node->part_num);
\r
103 + sp->map_key (sp, "id");
\r
104 + sp->integer (sp, node->part_num);
\r
106 - if (node->decrypt_attempted)
\r
107 - printf (", \"encstatus\": [{\"status\": \"%s\"}]",
\r
108 - node->decrypt_success ? "good" : "bad");
\r
109 + if (node->decrypt_attempted) {
\r
110 + sp->map_key (sp, "encstatus");
\r
111 + sp->begin_list (sp);
\r
112 + sp->begin_map (sp);
\r
113 + sp->map_key (sp, "status");
\r
114 + sp->string (sp, node->decrypt_success ? "good" : "bad");
\r
119 if (node->verify_attempted) {
\r
120 - printf (", \"sigstatus\": ");
\r
121 + sp->map_key (sp, "sigstatus");
\r
122 format_part_sigstatus_json (sp, node);
\r
125 - printf (", \"content-type\": %s",
\r
126 - json_quote_str (local, g_mime_content_type_to_string (content_type)));
\r
127 + sp->map_key (sp, "content-type");
\r
128 + sp->string (sp, g_mime_content_type_to_string (content_type));
\r
131 - printf (", \"content-id\": %s", json_quote_str (local, cid));
\r
133 + sp->map_key (sp, "content-id");
\r
134 + sp->string (sp, cid);
\r
138 - printf (", \"filename\": %s", json_quote_str (local, filename));
\r
140 + sp->map_key (sp, "filename");
\r
141 + sp->string (sp, filename);
\r
144 if (GMIME_IS_PART (node->part)) {
\r
145 /* For non-HTML text parts, we include the content in the
\r
146 @@ -636,35 +645,44 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
147 if (g_mime_content_type_is_type (content_type, "text", "html")) {
\r
148 const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");
\r
150 - if (content_charset != NULL)
\r
151 - printf (", \"content-charset\": %s", json_quote_str (local, content_charset));
\r
152 + if (content_charset != NULL) {
\r
153 + sp->map_key (sp, "content-charset");
\r
154 + sp->string (sp, content_charset);
\r
156 } else if (g_mime_content_type_is_type (content_type, "text", "*")) {
\r
157 GMimeStream *stream_memory = g_mime_stream_mem_new ();
\r
158 GByteArray *part_content;
\r
159 show_text_part_content (node->part, stream_memory, 0);
\r
160 part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
\r
162 - printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len));
\r
163 + sp->map_key (sp, "content");
\r
164 + sp->string_len (sp, (char *) part_content->data, part_content->len);
\r
165 g_object_unref (stream_memory);
\r
167 } else if (GMIME_IS_MULTIPART (node->part)) {
\r
168 - printf (", \"content\": [");
\r
169 - terminator = "]";
\r
170 + sp->map_key (sp, "content");
\r
171 + sp->begin_list (sp);
\r
173 } else if (GMIME_IS_MESSAGE (node->part)) {
\r
174 - printf (", \"content\": [{");
\r
175 - printf ("\"headers\": ");
\r
176 + sp->map_key (sp, "content");
\r
177 + sp->begin_list (sp);
\r
178 + sp->begin_map (sp);
\r
180 + sp->map_key (sp, "headers");
\r
181 format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
\r
183 - printf (", \"body\": [");
\r
184 - terminator = "]}]";
\r
185 + sp->map_key (sp, "body");
\r
186 + sp->begin_list (sp);
\r
190 - talloc_free (local);
\r
192 for (i = 0; i < node->nchildren; i++)
\r
193 format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
\r
195 - printf ("%s}", terminator);
\r
196 + /* Close content structures */
\r
197 + for (i = 0; i < nclose; i++)
\r
199 + /* Close part map */
\r
203 static notmuch_status_t
\r