[PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3

Subject: [PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3

Date: Sat, 15 Jul 2017 15:57:43 -0300

To: Daniel Kahn Gillmor, Notmuch Mail

Cc:

From: David Bremner


gmime 3.0 knows how to select the correct GMimeCryptoContext
automatically, so a bunch of the code in notmuch can be dropped in
that case.

The #ifdef removal of the crypto stuff is better than #define aliasing
in gmime-extra.h for this stuff.  When built against gmime 3.0:

    * it reduces compiled code, and
    * it avoids initializing unused gpgme contexts

(based on a patch from dkg)
---
 crypto.c        | 3 ++-
 mime-node.c     | 2 ++
 notmuch-reply.c | 2 ++
 notmuch-show.c  | 2 ++
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/crypto.c b/crypto.c
index 3e8ce7ca..05c05a47 100644
--- a/crypto.c
+++ b/crypto.c
@@ -19,7 +19,7 @@
  */
 
 #include "notmuch-client.h"
-
+#if (GMIME_MAJOR_VERSION < 3)
 /* Create a GPG context (GMime 2.6) */
 static notmuch_crypto_context_t *
 create_gpg_context (notmuch_crypto_t *crypto)
@@ -132,3 +132,4 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
 
     return 0;
 }
+#endif
diff --git a/mime-node.c b/mime-node.c
index bc41b752..bb0870d0 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -240,6 +240,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	return NULL;
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
 	|| (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
 	GMimeContentType *content_type = g_mime_object_get_content_type (part);
@@ -248,6 +249,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	if (!cryptoctx)
 	    return NULL;
     }
+#endif
 
     /* Handle PGP/MIME parts */
     if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 40201b80..4df29b82 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -759,7 +759,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
     if (do_reply (config, query, &params, format, reply_all) != 0)
 	return EXIT_FAILURE;
 
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_cleanup (&params.crypto);
+#endif
     notmuch_query_destroy (query);
     notmuch_database_destroy (notmuch);
 
diff --git a/notmuch-show.c b/notmuch-show.c
index 74e77249..4feba07b 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1241,7 +1241,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     g_mime_stream_flush (params.out_stream);
     g_object_unref (params.out_stream);
 
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_cleanup (&params.crypto);
+#endif
     notmuch_query_destroy (query);
     notmuch_database_destroy (notmuch);
 
-- 
2.13.2


Thread: