show: Make JSON helper functions print complete objects

This makes the main recursive function easier to follow because helper
functions don't add fields to the running object.
This commit is contained in:
Austin Clements 2012-02-19 19:26:28 -05:00 committed by David Bremner
parent 63ee244c8e
commit 1f0ead385a

View file

@ -297,7 +297,7 @@ format_headers_json (const void *ctx, GMimeMessage *message)
InternetAddressList *recipients; InternetAddressList *recipients;
const char *recipients_string; const char *recipients_string;
printf ("%s: %s", printf ("{%s: %s",
json_quote_str (local, "Subject"), json_quote_str (local, "Subject"),
json_quote_str (local, g_mime_message_get_subject (message))); json_quote_str (local, g_mime_message_get_subject (message)));
printf (", %s: %s", printf (", %s: %s",
@ -315,7 +315,7 @@ format_headers_json (const void *ctx, GMimeMessage *message)
printf (", %s: %s", printf (", %s: %s",
json_quote_str (local, "Cc"), json_quote_str (local, "Cc"),
json_quote_str (local, recipients_string)); json_quote_str (local, recipients_string));
printf (", %s: %s", printf (", %s: %s}",
json_quote_str (local, "Date"), json_quote_str (local, "Date"),
json_quote_str (local, g_mime_message_get_date_as_string (message))); json_quote_str (local, g_mime_message_get_date_as_string (message)));
@ -406,7 +406,7 @@ signer_status_to_string (GMimeSignerStatus x)
static void static void
format_part_sigstatus_json (GMimeSignatureList *siglist) format_part_sigstatus_json (GMimeSignatureList *siglist)
{ {
printf (", \"sigstatus\": ["); printf ("[");
if (!siglist) { if (!siglist) {
printf ("]"); printf ("]");
@ -472,7 +472,7 @@ format_part_sigstatus_json (GMimeSignatureList *siglist)
static void static void
format_part_sigstatus_json (const GMimeSignatureValidity* validity) format_part_sigstatus_json (const GMimeSignatureValidity* validity)
{ {
printf (", \"sigstatus\": ["); printf ("[");
if (!validity) { if (!validity) {
printf ("]"); printf ("]");
@ -658,9 +658,8 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
printf ("{"); printf ("{");
format_message_json (ctx, node->envelope_file); format_message_json (ctx, node->envelope_file);
printf ("\"headers\": {"); printf ("\"headers\": ");
format_headers_json (ctx, GMIME_MESSAGE (node->part)); format_headers_json (ctx, GMIME_MESSAGE (node->part));
printf ("}");
printf (", \"body\": ["); printf (", \"body\": [");
format_part_json (ctx, mime_node_child (node, 0), first); format_part_json (ctx, mime_node_child (node, 0), first);
@ -696,6 +695,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
} }
if (node->verify_attempted) { if (node->verify_attempted) {
printf (", \"sigstatus\": ");
#ifdef GMIME_ATLEAST_26 #ifdef GMIME_ATLEAST_26
format_part_sigstatus_json (node->sig_list); format_part_sigstatus_json (node->sig_list);
#else #else
@ -746,9 +746,8 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
g_object_unref (stream_memory); g_object_unref (stream_memory);
if (GMIME_IS_MESSAGE (node->part)) { if (GMIME_IS_MESSAGE (node->part)) {
printf ("\"headers\": {"); printf ("\"headers\": ");
format_headers_json (local, GMIME_MESSAGE (node->part)); format_headers_json (local, GMIME_MESSAGE (node->part));
printf ("}");
printf (", \"body\": ["); printf (", \"body\": [");
} }