+ /* The disposition and content-type metadata are associated with
+ * the envelope for message parts */
+ GMimeObject *meta = node->envelope_part ?
+ GMIME_OBJECT (node->envelope_part) : node->part;
+ GMimeContentType *content_type = g_mime_object_get_content_type (meta);
+ const bool leaf = GMIME_IS_PART (node->part);
+ GMimeStream *stream = params->out_stream;
+ const char *part_type;
+ int i;
+
+ if (node->envelope_file) {
+ notmuch_message_t *message = node->envelope_file;
+
+ part_type = "message";
+ g_mime_stream_printf (stream, "\f%s{ id:%s depth:%d match:%d excluded:%d filename:%s\n",
+ part_type,
+ notmuch_message_get_message_id (message),
+ indent,
+ notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0,
+ notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0,
+ notmuch_message_get_filename (message));
+ } else {
+ char *content_string;
+ const char *disposition = _get_disposition (meta);
+ const char *cid = g_mime_object_get_content_id (meta);
+ const char *filename = leaf ?
+ g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;
+
+ if (disposition &&
+ strcasecmp (disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
+ part_type = "attachment";
+ else
+ part_type = "part";
+
+ g_mime_stream_printf (stream, "\f%s{ ID: %d", part_type, node->part_num);
+ if (filename)
+ g_mime_stream_printf (stream, ", Filename: %s", filename);
+ if (cid)
+ g_mime_stream_printf (stream, ", Content-id: %s", cid);
+
+ content_string = g_mime_content_type_to_string (content_type);
+ g_mime_stream_printf (stream, ", Content-type: %s\n", content_string);
+ g_free (content_string);
+ }
+
+ if (GMIME_IS_MESSAGE (node->part)) {
+ GMimeMessage *message = GMIME_MESSAGE (node->part);
+ char *recipients_string;
+ char *date_string;
+
+ g_mime_stream_printf (stream, "\fheader{\n");
+ if (node->envelope_file)
+ g_mime_stream_printf (stream, "%s\n", _get_one_line_summary (ctx, node->envelope_file));
+ g_mime_stream_printf (stream, "Subject: %s\n", g_mime_message_get_subject (message));
+ g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_from_string (message));
+ recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
+ if (recipients_string)
+ g_mime_stream_printf (stream, "To: %s\n", recipients_string);
+ g_free (recipients_string);
+ recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
+ if (recipients_string)
+ g_mime_stream_printf (stream, "Cc: %s\n", recipients_string);
+ g_free (recipients_string);
+ date_string = g_mime_message_get_date_string (node, message);
+ g_mime_stream_printf (stream, "Date: %s\n", date_string);
+ g_mime_stream_printf (stream, "\fheader}\n");
+
+ g_mime_stream_printf (stream, "\fbody{\n");
+ }
+
+ if (leaf) {
+ if (g_mime_content_type_is_type (content_type, "text", "*") &&
+ !g_mime_content_type_is_type (content_type, "text", "html"))
+ {
+ show_text_part_content (node->part, stream, 0);
+ } else {
+ char *content_string = g_mime_content_type_to_string (content_type);
+ g_mime_stream_printf (stream, "Non-text part: %s\n", content_string);
+ g_free (content_string);
+ }
+ }
+
+ for (i = 0; i < node->nchildren; i++)
+ format_part_text (ctx, sp, mime_node_child (node, i), indent, params);
+
+ if (GMIME_IS_MESSAGE (node->part))
+ g_mime_stream_printf (stream, "\fbody}\n");
+
+ g_mime_stream_printf (stream, "\f%s}\n", part_type);
+
+ return NOTMUCH_STATUS_SUCCESS;