--- /dev/null
+Return-Path: <jrollins@finestructure.net>\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 A9A6E431FB6\r
+ for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:49 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] 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 UWcHN8OU-AA8 for <notmuch@notmuchmail.org>;\r
+ Fri, 18 May 2012 10:32:46 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+ [131.215.239.19])\r
+ by olra.theworths.org (Postfix) with ESMTP id 8CE69431FBC\r
+ for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:46 -0700 (PDT)\r
+Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+ by fire-doxen-postvirus (Postfix) with ESMTP id 4B17A328091\r
+ for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:44 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
+Received: from finestructure.net (cpe-98-14-81-93.nyc.res.rr.com\r
+ [98.14.81.93]) (Authenticated sender: jrollins) by fire-doxen-submit\r
+ (Postfix) with ESMTP id D21FC328076 for <notmuch@notmuchmail.org>; Fri, 18\r
+ May 2012 10:32:41 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+ id 407992F4; Fri, 18 May 2012 10:32:40 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v2 1/5] cli: new crypto structure to store crypto contexts and\r
+ parameters\r
+Date: Fri, 18 May 2012 10:32:33 -0700\r
+Message-Id: <1337362357-31281-2-git-send-email-jrollins@finestructure.net>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1337362357-31281-1-git-send-email-jrollins@finestructure.net>\r
+References: <1337362357-31281-1-git-send-email-jrollins@finestructure.net>\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: Fri, 18 May 2012 17:32:50 -0000\r
+\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
+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 | 36 +++++++++++++++++++-----------------\r
+ notmuch-show.c | 30 ++++++++++++++++++------------\r
+ 3 files changed, 47 insertions(+), 35 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..8d608e1 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,10 @@ 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 = {\r
++ .decrypt = FALSE\r
++ };\r
+ int format = FORMAT_DEFAULT;\r
+ int reply_all = TRUE;\r
+ \r
+@@ -689,7 +691,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 +708,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 +752,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..7779c3e 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
+@@ -984,7 +984,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ char *query_string;\r
+ int opt_index, ret;\r
+ const notmuch_show_format_t *format = &format_text;\r
+- notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };\r
++ notmuch_show_params_t params = {\r
++ .part = -1,\r
++ .omit_excluded = TRUE,\r
++ .crypto = {\r
++ .decrypt = FALSE\r
++ }\r
++ };\r
+ int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
+ notmuch_bool_t verify = FALSE;\r
+ int exclude = EXCLUDE_TRUE;\r
+@@ -1002,7 +1008,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 +1053,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 +1124,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