]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-show.c
cli: use new notmuch_crypto_get_context in mime-node.c
[notmuch] / notmuch-show.c
index cc509a6f5e779e1af9eb520349c985360837d94b..8247f1d52c6c34d3bb1a3370c2531d26f88170f3 100644 (file)
@@ -810,8 +810,7 @@ show_message (void *ctx,
     mime_node_t *root, *part;
     notmuch_status_t status;
 
-    status = mime_node_open (local, message, params->crypto.gpgctx,
-                            params->crypto.decrypt, &root);
+    status = mime_node_open (local, message, &(params->crypto), &root);
     if (status)
        goto DONE;
     part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));
@@ -988,11 +987,11 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        .part = -1,
        .omit_excluded = TRUE,
        .crypto = {
+           .verify = FALSE,
            .decrypt = FALSE
        }
     };
     int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
-    notmuch_bool_t verify = FALSE;
     int exclude = EXCLUDE_TRUE;
 
     notmuch_opt_desc_t options[] = {
@@ -1009,7 +1008,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        { NOTMUCH_OPT_INT, &params.part, "part", 'p', 0 },
        { NOTMUCH_OPT_BOOLEAN, &params.entire_thread, "entire-thread", 't', 0 },
        { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },
-       { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 },
+       { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -1019,6 +1018,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        return 1;
     }
 
+    /* decryption implies verification */
+    if (params.crypto.decrypt)
+       params.crypto.verify = TRUE;
+
     if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
        /* if part was requested and format was not specified, use format=raw */
        if (params.part >= 0)
@@ -1053,25 +1056,6 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        break;
     }
 
-    if (params.crypto.decrypt || 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 {
-           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;