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 0F6466DE0B7C for ; Mon, 11 Dec 2017 18:52:34 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.028 X-Spam-Level: X-Spam-Status: No, score=-0.028 tagged_above=-999 required=5 tests=[AWL=-0.028] 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 xttX0MMEXKdt for ; Mon, 11 Dec 2017 18:52:33 -0800 (PST) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTPS id 803546DE0941 for ; Mon, 11 Dec 2017 18:52:33 -0800 (PST) Received: from fifthhorseman.net (unknown [38.109.115.130]) by che.mayfirst.org (Postfix) with ESMTPSA id E2CABF99A for ; Mon, 11 Dec 2017 21:52:32 -0500 (EST) Received: by fifthhorseman.net (Postfix, from userid 1000) id ECA8721008; Mon, 11 Dec 2017 21:52:27 -0500 (EST) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 4/5] cli/show: reindex when we learned new session keys about a message Date: Mon, 11 Dec 2017 21:52:24 -0500 Message-Id: <20171212025225.11854-5-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171212025225.11854-1-dkg@fifthhorseman.net> References: <20171212025225.11854-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: Tue, 12 Dec 2017 02:52:34 -0000 If the number of session keys for a given message increased after running "notmuch show" then we just learned something new that might let us do automatic decryption. We should reindex this message using our newfound knowledge. --- notmuch-show.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/notmuch-show.c b/notmuch-show.c index 9871159d..90e45cd9 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -873,6 +873,11 @@ show_message (void *ctx, void *local = talloc_new (ctx); mime_node_t *root, *part; notmuch_status_t status; + unsigned int session_keys = 0; + notmuch_status_t session_key_count_error = NOTMUCH_STATUS_SUCCESS; + + if (params->crypto.decrypt == NOTMUCH_DECRYPT_TRUE) + session_key_count_error = notmuch_message_count_properties (message, "session-key", &session_keys); status = mime_node_open (local, message, &(params->crypto), &root); if (status) @@ -880,6 +885,21 @@ show_message (void *ctx, part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part)); if (part) status = format->part (local, sp, part, indent, params); + + if (params->crypto.decrypt == NOTMUCH_DECRYPT_TRUE && session_key_count_error == NOTMUCH_STATUS_SUCCESS) { + unsigned int new_session_keys = 0; + if (notmuch_message_count_properties (message, "session-key", &new_session_keys) == NOTMUCH_STATUS_SUCCESS && + new_session_keys > session_keys) { + /* try a quiet re-indexing */ + notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch_message_get_database (message)); + if (indexopts) { + notmuch_indexopts_set_decrypt_policy (indexopts, NOTMUCH_DECRYPT_AUTO); + status = notmuch_message_reindex (message, indexopts); + if (status) + fprintf (stderr, "Error re-indexing message with --decrypt=stash. (%d) %s\n", status, notmuch_status_to_string (status)); + } + } + } DONE: talloc_free (local); return status; -- 2.15.1