+ GMimeSignatureList *siglist = node->sig_list;
+
+ sp->begin_list (sp);
+
+ if (!siglist) {
+ sp->end (sp);
+ return;
+ }
+
+ int i;
+ for (i = 0; i < g_mime_signature_list_length (siglist); i++) {
+ GMimeSignature *signature = g_mime_signature_list_get_signature (siglist, i);
+
+ sp->begin_map (sp);
+
+ /* status */
+ GMimeSignatureStatus status = g_mime_signature_get_status (signature);
+ sp->map_key (sp, "status");
+ sp->string (sp, signature_status_to_string (status));
+
+ GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
+ if (status == GMIME_SIGNATURE_STATUS_GOOD) {
+ if (certificate) {
+ sp->map_key (sp, "fingerprint");
+ sp->string (sp, g_mime_certificate_get_fingerprint (certificate));
+ }
+ /* these dates are seconds since the epoch; should we
+ * provide a more human-readable format string? */
+ time_t created = g_mime_signature_get_created (signature);
+ if (created != -1) {
+ sp->map_key (sp, "created");
+ sp->integer (sp, created);
+ }
+ time_t expires = g_mime_signature_get_expires (signature);
+ if (expires > 0) {
+ sp->map_key (sp, "expires");
+ sp->integer (sp, expires);
+ }
+ /* output user id only if validity is FULL or ULTIMATE. */
+ /* note that gmime is using the term "trust" here, which
+ * is WRONG. It's actually user id "validity". */
+ if (certificate) {
+ const char *name = g_mime_certificate_get_name (certificate);
+ GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate);
+ if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) {
+ sp->map_key (sp, "userid");
+ sp->string (sp, name);
+ }
+ }
+ } else if (certificate) {
+ const char *key_id = g_mime_certificate_get_key_id (certificate);
+ if (key_id) {
+ sp->map_key (sp, "keyid");
+ sp->string (sp, key_id);
+ }
+ }
+
+ if (notmuch_format_version <= 3) {
+ GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+ if (errors != GMIME_SIGNATURE_ERROR_NONE) {
+ sp->map_key (sp, "errors");
+ sp->integer (sp, errors);
+ }
+ } else {
+ format_signature_errors (sp, signature);
+ }
+
+ sp->end (sp);
+ }
+
+ sp->end (sp);
+}
+
+static notmuch_status_t
+format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
+ int indent, const notmuch_show_params_t *params)
+{
+ /* 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 notmuch_bool_t 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);
+ InternetAddressList *recipients;
+ 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_sender (message));
+ recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
+ recipients_string = internet_address_list_to_string (recipients, 0);
+ if (recipients_string)
+ g_mime_stream_printf (stream, "To: %s\n", recipients_string);
+ g_free (recipients_string);
+ recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
+ recipients_string = internet_address_list_to_string (recipients, 0);
+ 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) {