[PATCH 22/23] cli: make keyid from fingerprint in gmime 3.0

David Bremner david at tethera.net
Sat Jun 3 10:47:53 PDT 2017


The "key_id" field seems to used for userid in gmime-3.0, while the
keyid is dropped in the fingerprint field if the full fingerprint is
not available.
---
 notmuch-show.c     |  2 +-
 util/gmime-extra.c | 10 ++++++++++
 util/gmime-extra.h |  5 +++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 3234ab95..b1f58428 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -461,7 +461,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 		}
 	    }
 	} else if (certificate) {
-	    const char *key_id = g_mime_certificate_get_key_id (certificate);
+	    const char *key_id = g_mime_certificate_get_fpr16 (certificate);
 	    if (key_id) {
 		sp->map_key (sp, "keyid");
 		sp->string (sp, key_id);
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 3c50a293..ed53e0ab 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -1,4 +1,5 @@
 #include "gmime-extra.h"
+#include <string.h>
 
 GMimeStream *
 g_mime_stream_stdout_new()
@@ -106,6 +107,15 @@ g_mime_utils_header_decode_date_unix (const char *date) {
 
 #else /* GMime >= 3.0 */
 
+const char*
+g_mime_certificate_get_fpr16 (GMimeCertificate *cert) {
+    const char *fpr = g_mime_certificate_get_fingerprint (cert);
+    if (!fpr || strlen (fpr) < 16)
+	return fpr;
+
+    return fpr + (strlen (fpr) - 16);
+}
+
 char *
 g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
 {
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 7688129a..4407be33 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -14,6 +14,7 @@ GMimeStream *g_mime_stream_stdout_new(void);
 #define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
 
 #define g_mime_2_6_unref(obj) g_object_unref (obj)
+#define g_mime_certificate_get_fpr16(cert) g_mime_certificate_get_key_id (cert)
 
 #else /* GMime >= 3.0 */
 typedef GMimeAddressType GMimeRecipientType;
@@ -57,6 +58,10 @@ typedef GMimeTrust GMimeCertificateTrust;
 #endif
 
 /**
+ * Get last 16 hex digits of fingerprint ("keyid")
+ */
+const char *g_mime_certificate_get_fpr16 (GMimeCertificate *cert);
+/**
  * Return the contents of the appropriate address header as a string
  * Should be freed using g_free
  */
-- 
2.11.0



More information about the notmuch mailing list