--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 76FFA431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 17 May 2012 00:36:16 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id cnfEI171w897 for <notmuch@notmuchmail.org>;\r
+ Thu, 17 May 2012 00:36:15 -0700 (PDT)\r
+Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
+ [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 09847431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 17 May 2012 00:36:14 -0700 (PDT)\r
+Received: by lagu2 with SMTP id u2so1266293lag.26\r
+ for <notmuch@notmuchmail.org>; Thu, 17 May 2012 00:36:12 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+ :mime-version:content-type:x-gm-message-state;\r
+ bh=Ve+d0ggxO1BwdZf1iDi1ZMOqwj8MsIgXOObjp4NBo6k=;\r
+ b=kt07yKDse0CqkPRyprQAJBGXXEfSob/3EaxOMb2UE1KfAEoGj5NBA2v07Jtaokwrrn\r
+ 7Q2vgxKA8WEYtmCeDBa9Kqdgq4pSnWnCUVjFrgiVOlYtF7Vg4iPiTdmVOP9zhZIPrJKV\r
+ /5wzL7NE61shXamR0ikYVF+o60O26qNpOw2jS7PuQUoCIdj+E/i5/F+rV0PAuofRJ9ua\r
+ Oog0Lm+HKF889kmhgPaVe0kKEVN2EPsdaYGQDXEegQeGB6JM0Y1ozjik10lqFhpXEv9k\r
+ tNYZ9YSrhVah+/LaRk5G9RjKqQcrgrMoK7J35buJaVV8aFLY5HKvTzJr/bR9JNLz7onZ\r
+ J0og==\r
+Received: by 10.112.44.163 with SMTP id f3mr2555757lbm.59.1337240171964;\r
+ Thu, 17 May 2012 00:36:11 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.\r
+ [80.220.80.68])\r
+ by mx.google.com with ESMTPS id u4sm6702346lad.5.2012.05.17.00.36.09\r
+ (version=SSLv3 cipher=OTHER); Thu, 17 May 2012 00:36:11 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Jameson Graef Rollins <jrollins@finestructure.net>,\r
+ Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: Re: [PATCH 1/6] cli: new crypto structure to store crypto contexts\r
+ and parameters\r
+In-Reply-To: <1337205359-2444-2-git-send-email-jrollins@finestructure.net>\r
+References: <1337205359-2444-1-git-send-email-jrollins@finestructure.net>\r
+ <1337205359-2444-2-git-send-email-jrollins@finestructure.net>\r
+User-Agent: Notmuch/0.13+13~gc259b9a (http://notmuchmail.org) Emacs/23.3.1\r
+ (i686-pc-linux-gnu)\r
+Date: Thu, 17 May 2012 10:36:08 +0300\r
+Message-ID: <87ehqji7iv.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQk0LQR9yVcQdVFEszhY4ElvDlaotsnLpzzLxbXpgUGJ8HeWXAI3pognWz1KDgTHKzEOd29H\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 17 May 2012 07:36:16 -0000\r
+\r
+On Thu, 17 May 2012, Jameson Graef Rollins <jrollins@finestructure.net> wrote:\r
+> The main point here is to keep track of the crypto stuff together in\r
+> one place. In notmuch-show the crypto struct is a sub structure of\r
+> the parameters struct. In notmuch-reply, which had been using a\r
+> notmuch_show_params_t to store the crypto parameters, we can now just\r
+> use the general crypto struct.\r
+\r
+Looks good. My only (potentially unwarranted) worry is dropping the use\r
+of notmuch_show_params_t in reply. This diverges the show/reply code,\r
+making any future unification of them slightly harder. And if reply ever\r
+needs params, we'll need to bring it back. But perhaps I worry too\r
+much. :)\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+>\r
+> I slip in a name change of the crypto context itself to better reflect\r
+> what the context is specifically for: it's actually a GPG context,\r
+> which is a sub type of Crypto context. There are other types of\r
+> Crypto contexts (Pkcs7 in particular) so we want to be clear.\r
+>\r
+> The following patches will use this to simplify some function\r
+> interfaces.\r
+> ---\r
+> notmuch-client.h | 16 ++++++++++------\r
+> notmuch-reply.c | 34 +++++++++++++++++-----------------\r
+> notmuch-show.c | 22 +++++++++++-----------\r
+> 3 files changed, 38 insertions(+), 34 deletions(-)\r
+>\r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index 19b7f01..2ad24cf 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -74,17 +74,21 @@ typedef struct notmuch_show_format {\r
+> const char *message_set_end;\r
+> } notmuch_show_format_t;\r
+> \r
+> +typedef struct notmuch_crypto {\r
+> +#ifdef GMIME_ATLEAST_26\r
+> + GMimeCryptoContext* gpgctx;\r
+> +#else\r
+> + GMimeCipherContext* gpgctx;\r
+> +#endif\r
+> + notmuch_bool_t decrypt;\r
+> +} notmuch_crypto_t;\r
+> +\r
+> typedef struct notmuch_show_params {\r
+> notmuch_bool_t entire_thread;\r
+> notmuch_bool_t omit_excluded;\r
+> notmuch_bool_t raw;\r
+> int part;\r
+> -#ifdef GMIME_ATLEAST_26\r
+> - GMimeCryptoContext* cryptoctx;\r
+> -#else\r
+> - GMimeCipherContext* cryptoctx;\r
+> -#endif\r
+> - notmuch_bool_t decrypt;\r
+> + notmuch_crypto_t crypto;\r
+> } notmuch_show_params_t;\r
+> \r
+> /* There's no point in continuing when we've detected that we've done\r
+> diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+> index 7184a5d..ed87899 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -515,7 +515,7 @@ static int\r
+> notmuch_reply_format_default(void *ctx,\r
+> notmuch_config_t *config,\r
+> notmuch_query_t *query,\r
+> - notmuch_show_params_t *params,\r
+> + notmuch_crypto_t *crypto,\r
+> notmuch_bool_t reply_all)\r
+> {\r
+> GMimeMessage *reply;\r
+> @@ -544,7 +544,7 @@ notmuch_reply_format_default(void *ctx,\r
+> g_object_unref (G_OBJECT (reply));\r
+> reply = NULL;\r
+> \r
+> - if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
+> + if (mime_node_open (ctx, message, crypto->gpgctx, crypto->decrypt,\r
+> &root) == NOTMUCH_STATUS_SUCCESS) {\r
+> format_part_reply (root);\r
+> talloc_free (root);\r
+> @@ -559,7 +559,7 @@ static int\r
+> notmuch_reply_format_json(void *ctx,\r
+> notmuch_config_t *config,\r
+> notmuch_query_t *query,\r
+> - notmuch_show_params_t *params,\r
+> + notmuch_crypto_t *crypto,\r
+> notmuch_bool_t reply_all)\r
+> {\r
+> GMimeMessage *reply;\r
+> @@ -574,7 +574,7 @@ notmuch_reply_format_json(void *ctx,\r
+> \r
+> messages = notmuch_query_search_messages (query);\r
+> message = notmuch_messages_get (messages);\r
+> - if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
+> + if (mime_node_open (ctx, message, crypto->gpgctx, crypto->decrypt,\r
+> &node) != NOTMUCH_STATUS_SUCCESS)\r
+> return 1;\r
+> \r
+> @@ -605,7 +605,7 @@ static int\r
+> notmuch_reply_format_headers_only(void *ctx,\r
+> notmuch_config_t *config,\r
+> notmuch_query_t *query,\r
+> - unused (notmuch_show_params_t *params),\r
+> + unused (notmuch_crypto_t *crypto),\r
+> notmuch_bool_t reply_all)\r
+> {\r
+> GMimeMessage *reply;\r
+> @@ -674,8 +674,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+> notmuch_query_t *query;\r
+> char *query_string;\r
+> int opt_index, ret = 0;\r
+> - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
+> - notmuch_show_params_t params = { .part = -1 };\r
+> + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_crypto_t *crypto, notmuch_bool_t reply_all);\r
+> + notmuch_crypto_t crypto = { .decrypt = FALSE };\r
+> int format = FORMAT_DEFAULT;\r
+> int reply_all = TRUE;\r
+> \r
+> @@ -689,7 +689,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+> (notmuch_keyword_t []){ { "all", TRUE },\r
+> { "sender", FALSE },\r
+> { 0, 0 } } },\r
+> - { NOTMUCH_OPT_BOOLEAN, ¶ms.decrypt, "decrypt", 'd', 0 },\r
+> + { NOTMUCH_OPT_BOOLEAN, &crypto.decrypt, "decrypt", 'd', 0 },\r
+> { 0, 0, 0, 0, 0 }\r
+> };\r
+> \r
+> @@ -706,18 +706,18 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+> else\r
+> reply_format_func = notmuch_reply_format_default;\r
+> \r
+> - if (params.decrypt) {\r
+> + if (crypto.decrypt) {\r
+> #ifdef GMIME_ATLEAST_26\r
+> /* TODO: GMimePasswordRequestFunc */\r
+> - params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
+> + crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
+> #else\r
+> GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
+> - params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
+> + crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
+> #endif\r
+> - if (params.cryptoctx) {\r
+> - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
+> + if (crypto.gpgctx) {\r
+> + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto.gpgctx, FALSE);\r
+> } else {\r
+> - params.decrypt = FALSE;\r
+> + crypto.decrypt = FALSE;\r
+> fprintf (stderr, "Failed to construct gpg context.\n");\r
+> }\r
+> #ifndef GMIME_ATLEAST_26\r
+> @@ -750,14 +750,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+> return 1;\r
+> }\r
+> \r
+> - if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0)\r
+> + if (reply_format_func (ctx, config, query, &crypto, reply_all) != 0)\r
+> return 1;\r
+> \r
+> notmuch_query_destroy (query);\r
+> notmuch_database_destroy (notmuch);\r
+> \r
+> - if (params.cryptoctx)\r
+> - g_object_unref(params.cryptoctx);\r
+> + if (crypto.gpgctx)\r
+> + g_object_unref(crypto.gpgctx);\r
+> \r
+> return ret;\r
+> }\r
+> diff --git a/notmuch-show.c b/notmuch-show.c\r
+> index 95427d4..d254179 100644\r
+> --- a/notmuch-show.c\r
+> +++ b/notmuch-show.c\r
+> @@ -810,8 +810,8 @@ show_message (void *ctx,\r
+> mime_node_t *root, *part;\r
+> notmuch_status_t status;\r
+> \r
+> - status = mime_node_open (local, message, params->cryptoctx,\r
+> - params->decrypt, &root);\r
+> + status = mime_node_open (local, message, params->crypto.gpgctx,\r
+> + params->crypto.decrypt, &root);\r
+> if (status)\r
+> goto DONE;\r
+> part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));\r
+> @@ -1002,7 +1002,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+> { 0, 0 } } },\r
+> { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 },\r
+> { NOTMUCH_OPT_BOOLEAN, ¶ms.entire_thread, "entire-thread", 't', 0 },\r
+> - { NOTMUCH_OPT_BOOLEAN, ¶ms.decrypt, "decrypt", 'd', 0 },\r
+> + { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },\r
+> { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 },\r
+> { 0, 0, 0, 0, 0 }\r
+> };\r
+> @@ -1047,18 +1047,18 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+> break;\r
+> }\r
+> \r
+> - if (params.decrypt || verify) {\r
+> + if (params.crypto.decrypt || verify) {\r
+> #ifdef GMIME_ATLEAST_26\r
+> /* TODO: GMimePasswordRequestFunc */\r
+> - params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
+> + params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
+> #else\r
+> GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
+> - params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
+> + params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
+> #endif\r
+> - if (params.cryptoctx) {\r
+> - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
+> + if (params.crypto.gpgctx) {\r
+> + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
+> } else {\r
+> - params.decrypt = FALSE;\r
+> + params.crypto.decrypt = FALSE;\r
+> fprintf (stderr, "Failed to construct gpg context.\n");\r
+> }\r
+> #ifndef GMIME_ATLEAST_26\r
+> @@ -1118,8 +1118,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+> notmuch_query_destroy (query);\r
+> notmuch_database_destroy (notmuch);\r
+> \r
+> - if (params.cryptoctx)\r
+> - g_object_unref(params.cryptoctx);\r
+> + if (params.crypto.gpgctx)\r
+> + g_object_unref(params.crypto.gpgctx);\r
+> \r
+> return ret;\r
+> }\r
+> -- \r
+> 1.7.10\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r