+ printf ("{\"id\": %d", *part_count);
+}
+
+static void
+format_part_encstatus_json (int status)
+{
+ printf (", \"encstatus\": [{\"status\": ");
+ if (status) {
+ printf ("\"good\"");
+ } else {
+ printf ("\"bad\"");
+ }
+ printf ("}]");
+}
+
+static void
+format_part_sigstatus_json (const GMimeSignatureValidity* validity)
+{
+ printf (", \"sigstatus\": [");
+
+ if (!validity) {
+ printf ("]");
+ return;
+ }
+
+ const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
+ int first = 1;
+ void *ctx_quote = talloc_new (NULL);
+
+ while (signer) {
+ if (first)
+ first = 0;
+ else
+ printf (", ");
+
+ printf ("{");
+
+ /* status */
+ printf ("\"status\": %s",
+ json_quote_str (ctx_quote,
+ signer_status_to_string (signer->status)));
+
+ if (signer->status == GMIME_SIGNER_STATUS_GOOD)
+ {
+ if (signer->fingerprint)
+ printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint));
+ /* these dates are seconds since the epoch; should we
+ * provide a more human-readable format string? */
+ if (signer->created)
+ printf (", \"created\": %d", (int) signer->created);
+ if (signer->expires)
+ printf (", \"expires\": %d", (int) signer->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 ((signer->name) && (signer->trust)) {
+ if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE))
+ printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name));
+ }
+ } else {
+ if (signer->keyid)
+ printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid));
+ }
+ if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
+ printf (", \"errors\": %x", signer->errors);
+ }
+
+ printf ("}");
+ signer = signer->next;
+ }
+
+ printf ("]");
+
+ talloc_free (ctx_quote);
+}
+
+static void
+format_part_content_json (GMimeObject *part)
+{
+ GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));