From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 473C76DE0B2F for ; Fri, 20 Oct 2017 19:26:05 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.022 X-Spam-Level: X-Spam-Status: No, score=-0.022 tagged_above=-999 required=5 tests=[AWL=-0.022] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s96AKV7TPROq for ; Fri, 20 Oct 2017 19:26:04 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTP id 19F8E6DE0B00 for ; Fri, 20 Oct 2017 19:26:00 -0700 (PDT) Received: from fifthhorseman.net (ool-6c3a0662.static.optonline.net [108.58.6.98]) by che.mayfirst.org (Postfix) with ESMTPSA id 4FED4F9A6 for ; Fri, 20 Oct 2017 22:25:59 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id 4B27D21105; Fri, 20 Oct 2017 22:25:54 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 07/12] cli: set up shared command-line arguments for indexing Date: Fri, 20 Oct 2017 22:25:44 -0400 Message-Id: <20171021022549.2724-8-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171021022549.2724-1-dkg@fifthhorseman.net> References: <20171021022549.2724-1-dkg@fifthhorseman.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Oct 2017 02:26:05 -0000 We have an indexopts structure for manipulating indexing in different ways, but we also have three command-line invocations that can trigger indexing: new, insert, and reindex. This changeset prepares a common parser that these subcommands can share. Note: if the deprecated crypto.gpg_path configuration option is set to anything other than "gpg", we ignore it (and print a warning on stderr, if built against gmime < 3.0). At the moment, it's just --try-decrypt, but others will likely follow. --- notmuch-client.h | 14 ++++++++++++++ notmuch.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/notmuch-client.h b/notmuch-client.h index d17cdf01..f7524e59 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -495,4 +495,18 @@ void notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch); void notmuch_process_shared_options (const char* subcommand_name); int notmuch_minimal_options (const char* subcommand_name, int argc, char **argv); + + +/* the state chosen by the user invoking one of the notmuch + * subcommands that does indexing */ +struct _notmuch_client_indexing_cli_choices { + bool try_decrypt; + bool try_decrypt_set; + notmuch_indexopts_t * opts; +}; +extern struct _notmuch_client_indexing_cli_choices indexing_cli_choices; +extern const notmuch_opt_desc_t notmuch_shared_indexing_options []; +notmuch_status_t +notmuch_process_shared_indexing_options (notmuch_database_t *notmuch, notmuch_config_t *config); + #endif diff --git a/notmuch.c b/notmuch.c index 02148f2e..539ac58c 100644 --- a/notmuch.c +++ b/notmuch.c @@ -96,6 +96,46 @@ int notmuch_minimal_options (const char *subcommand_name, return opt_index; } + +struct _notmuch_client_indexing_cli_choices indexing_cli_choices = { }; +const notmuch_opt_desc_t notmuch_shared_indexing_options [] = { + { .opt_bool = &indexing_cli_choices.try_decrypt, + .present = &indexing_cli_choices.try_decrypt_set, + .name = "try-decrypt" }, + { } +}; + + +notmuch_status_t +notmuch_process_shared_indexing_options (notmuch_database_t *notmuch, g_mime_3_unused(notmuch_config_t *config)) +{ + if (indexing_cli_choices.opts == NULL) + indexing_cli_choices.opts = notmuch_database_get_default_indexopts (notmuch); + if (indexing_cli_choices.try_decrypt_set) { + notmuch_status_t status; + if (indexing_cli_choices.opts == NULL) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + status = notmuch_indexopts_set_try_decrypt (indexing_cli_choices.opts, indexing_cli_choices.try_decrypt); + if (status != NOTMUCH_STATUS_SUCCESS) { + fprintf (stderr, "Error: Failed to set try_decrypt to %s. (%s)\n", + indexing_cli_choices.try_decrypt ? "True" : "False", notmuch_status_to_string (status)); + notmuch_indexopts_destroy (indexing_cli_choices.opts); + indexing_cli_choices.opts = NULL; + return status; + } + } +#if (GMIME_MAJOR_VERSION < 3) + if (indexing_cli_choices.opts && notmuch_indexopts_get_try_decrypt (indexing_cli_choices.opts)) { + const char* gpg_path = notmuch_config_get_crypto_gpg_path (config); + if (gpg_path && strcmp(gpg_path, "gpg")) + fprintf (stderr, "Warning: deprecated crypto.gpg_path is set to '%s'\n" + "\tbut ignoring (use $PATH instead)\n", gpg_path); + } +#endif + return NOTMUCH_STATUS_SUCCESS; +} + + static command_t commands[] = { { NULL, notmuch_command, NOTMUCH_CONFIG_OPEN | NOTMUCH_CONFIG_CREATE, "Notmuch main command." }, -- 2.14.2