+ if (errors == GMIME_SIGNATURE_ERROR_NONE)
+ return;
+
+ struct key_map_struct key_map[] = {
+ { GMIME_SIGNATURE_ERROR_EXPSIG, "sig-expired" },
+ { GMIME_SIGNATURE_ERROR_NO_PUBKEY, "key-missing"},
+ { GMIME_SIGNATURE_ERROR_EXPKEYSIG, "key-expired"},
+ { GMIME_SIGNATURE_ERROR_REVKEYSIG, "key-revoked"},
+ { GMIME_SIGNATURE_ERROR_UNSUPP_ALGO, "alg-unsupported"},
+ };
+
+ do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
+}
+#else
+static void
+format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
+{
+ GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+
+ if (!(errors & GMIME_SIGNATURE_STATUS_ERROR_MASK))
+ return;
+
+ struct key_map_struct key_map[] = {
+ { GMIME_SIGNATURE_STATUS_KEY_REVOKED, "key-revoked"},
+ { GMIME_SIGNATURE_STATUS_KEY_EXPIRED, "key-expired"},
+ { GMIME_SIGNATURE_STATUS_SIG_EXPIRED, "sig-expired" },
+ { GMIME_SIGNATURE_STATUS_KEY_MISSING, "key-missing"},
+ { GMIME_SIGNATURE_STATUS_CRL_MISSING, "crl-missing"},
+ { GMIME_SIGNATURE_STATUS_CRL_TOO_OLD, "crl-too-old"},
+ { GMIME_SIGNATURE_STATUS_BAD_POLICY, "bad-policy"},
+ { GMIME_SIGNATURE_STATUS_SYS_ERROR, "sys-error"},
+ { GMIME_SIGNATURE_STATUS_TOFU_CONFLICT, "tofu-conflict"},
+ };
+
+ do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
+}
+#endif
+
+/* Signature status sprinter (GMime 2.6) */
+static void
+format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
+{
+ /* Any changes to the JSON or S-Expression format should be
+ * reflected in the file devel/schemata. */
+
+ 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 (g_mime_signature_status_good (status)) {
+ 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);
+ }
+ if (certificate) {
+ const char *uid = g_mime_certificate_get_valid_userid (certificate);
+ if (uid) {
+ sp->map_key (sp, "userid");
+ sp->string (sp, uid);
+ }
+ }
+ } else if (certificate) {
+ const char *key_id = g_mime_certificate_get_fpr16 (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 (g_mime_signature_status_error (errors)) {
+ sp->map_key (sp, "errors");
+ sp->integer (sp, errors);
+ }
+ } else {
+ format_signature_errors (sp, signature);
+ }