{
mime_node_t *node = talloc_zero (parent, mime_node_t);
GError *err = NULL;
+ notmuch_crypto_context_t *cryptoctx = NULL;
/* Set basic node properties */
node->part = part;
return NULL;
}
+ 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);
+ const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
+ cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
+ }
+
/* Handle PGP/MIME parts */
- if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
+ if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
if (node->nchildren != 2) {
/* this violates RFC 3156 section 4, so we won't bother with it. */
fprintf (stderr, "Error: %d part(s) for a multipart/encrypted "
#ifdef GMIME_ATLEAST_26
GMimeDecryptResult *decrypt_result = NULL;
node->decrypted_child = g_mime_multipart_encrypted_decrypt
- (encrypteddata, node->ctx->crypto->gpgctx, &decrypt_result, &err);
+ (encrypteddata, cryptoctx, &decrypt_result, &err);
#else
node->decrypted_child = g_mime_multipart_encrypted_decrypt
- (encrypteddata, node->ctx->crypto->gpgctx, &err);
+ (encrypteddata, cryptoctx, &err);
#endif
if (node->decrypted_child) {
node->decrypt_success = node->verify_attempted = TRUE;
(err ? err->message : "no error explanation given"));
}
}
- } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify) {
+ } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
if (node->nchildren != 2) {
/* this violates RFC 3156 section 5, so we won't bother with it. */
fprintf (stderr, "Error: %d part(s) for a multipart/signed message "
} else {
#ifdef GMIME_ATLEAST_26
node->sig_list = g_mime_multipart_signed_verify
- (GMIME_MULTIPART_SIGNED (part), node->ctx->crypto->gpgctx, &err);
+ (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
node->verify_attempted = TRUE;
if (!node->sig_list)
* In GMime 2.6, they're both non-const, so we'll be able
* to clean up this asymmetry. */
GMimeSignatureValidity *sig_validity = g_mime_multipart_signed_verify
- (GMIME_MULTIPART_SIGNED (part), node->ctx->crypto->gpgctx, &err);
+ (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
node->verify_attempted = TRUE;
node->sig_validity = sig_validity;
if (sig_validity) {
else
reply_format_func = notmuch_reply_format_default;
- if (params.crypto.decrypt) {
-#ifdef GMIME_ATLEAST_26
- /* TODO: GMimePasswordRequestFunc */
- params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");
-#else
- GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
- params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");
-#endif
- if (params.crypto.gpgctx) {
- g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);
- } else {
- params.crypto.decrypt = FALSE;
- fprintf (stderr, "Failed to construct gpg context.\n");
- }
-#ifndef GMIME_ATLEAST_26
- g_object_unref (session);
-#endif
- }
-
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
break;
}
- if (params.crypto.decrypt || params.crypto.verify) {
-#ifdef GMIME_ATLEAST_26
- /* TODO: GMimePasswordRequestFunc */
- params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");
-#else
- GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
- params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");
-#endif
- if (params.crypto.gpgctx) {
- g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);
- } else {
- /* If we fail to create the gpgctx set the verify and
- * decrypt flags to FALSE so we don't try to do any
- * further verification or decryption */
- params.crypto.verify = FALSE;
- params.crypto.decrypt = FALSE;
- fprintf (stderr, "Failed to construct gpg context.\n");
- }
-#ifndef GMIME_ATLEAST_26
- g_object_unref (session);
-#endif
- }
-
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;