-static void
-format_part_content_json (GMimeObject *part)
-{
- GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
- GMimeStream *stream_memory = g_mime_stream_mem_new ();
- const char *cid = g_mime_object_get_content_id (part);
- void *ctx = talloc_new (NULL);
- GByteArray *part_content;
-
- printf (", \"content-type\": %s",
- json_quote_str (ctx, g_mime_content_type_to_string (content_type)));
-
- if (cid != NULL)
- printf(", \"content-id\": %s", json_quote_str (ctx, cid));
-
- if (GMIME_IS_PART (part))
- {
- const char *filename = g_mime_part_get_filename (GMIME_PART (part));
- if (filename)
- printf (", \"filename\": %s", json_quote_str (ctx, filename));
- }
-
- if (g_mime_content_type_is_type (content_type, "text", "*"))
- {
- /* For non-HTML text parts, we include the content in the
- * JSON. Since JSON must be Unicode, we handle charset
- * decoding here and do not report a charset to the caller.
- * For text/html parts, we do not include the content. If a
- * caller is interested in text/html parts, it should retrieve
- * them separately and they will not be decoded. Since this
- * makes charset decoding the responsibility on the caller, we
- * report the charset for text/html parts.
- */
- if (g_mime_content_type_is_type (content_type, "text", "html"))
- {
- const char *content_charset = g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset");
-
- if (content_charset != NULL)
- printf (", \"content-charset\": %s", json_quote_str (ctx, content_charset));
- }
- else
- {
- show_text_part_content (part, stream_memory);
- part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
-
- printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));
- }
- }
- else if (g_mime_content_type_is_type (content_type, "multipart", "*"))
- {
- printf (", \"content\": [");
- }
- else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
- {
- printf (", \"content\": [{");
- }
-
- talloc_free (ctx);
- if (stream_memory)
- g_object_unref (stream_memory);
-}
-
-static void
-format_part_end_json (GMimeObject *part)
-{
- GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
-
- if (g_mime_content_type_is_type (content_type, "multipart", "*"))
- printf ("]");
- else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
- printf ("}]");
-
- printf ("}");
-}
-
-static void
-format_part_content_raw (GMimeObject *part)
-{
- if (! GMIME_IS_PART (part))
- return;
-
- GMimeStream *stream_stdout;
- GMimeStream *stream_filter = NULL;
- GMimeDataWrapper *wrapper;
-
- stream_stdout = g_mime_stream_file_new (stdout);
- g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
-
- stream_filter = g_mime_stream_filter_new (stream_stdout);
-
- wrapper = g_mime_part_get_content_object (GMIME_PART (part));
-
- if (wrapper && stream_filter)
- g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
-
- if (stream_filter)
- g_object_unref (stream_filter);
-
- if (stream_stdout)
- g_object_unref(stream_stdout);
-}
-
-static void
-format_part_text (const void *ctx, mime_node_t *node,