aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2017-12-08 01:23:52 -0500
committerDavid Bremner <david@tethera.net>2017-12-08 08:07:02 -0400
commit798aa789b5d117cf11697bc97dd982bd5a2c2ac8 (patch)
tree0424270f3f7c5c8764ce4301ee2b9c05ffa4531d /lib
parentb62045a18680720b407173140d79b459e45e6039 (diff)
lib: convert notmuch decryption policy to an enum
Future patches in this series will introduce new policies; this merely readies the way for them. We also convert --try-decrypt to a keyword argument instead of a boolean.
Diffstat (limited to 'lib')
-rw-r--r--lib/index.cc2
-rw-r--r--lib/indexopts.c21
-rw-r--r--lib/notmuch.h14
3 files changed, 24 insertions, 13 deletions
diff --git a/lib/index.cc b/lib/index.cc
index ff14e408..905366ae 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -525,7 +525,7 @@ _index_encrypted_mime_part (notmuch_message_t *message,
notmuch_database_t * notmuch = NULL;
GMimeObject *clear = NULL;
- if (!indexopts || !notmuch_indexopts_get_decrypt_policy (indexopts))
+ if (!indexopts || (notmuch_indexopts_get_decrypt_policy (indexopts) == NOTMUCH_DECRYPT_FALSE))
return;
notmuch = _notmuch_message_database (message);
diff --git a/lib/indexopts.c b/lib/indexopts.c
index 0f65b97c..78f53391 100644
--- a/lib/indexopts.c
+++ b/lib/indexopts.c
@@ -26,25 +26,26 @@ notmuch_database_get_default_indexopts (notmuch_database_t *db)
notmuch_indexopts_t *ret = talloc_zero (db, notmuch_indexopts_t);
if (!ret)
return ret;
+ ret->crypto.decrypt = NOTMUCH_DECRYPT_FALSE;
- char * decrypt;
- notmuch_status_t err = notmuch_database_get_config (db, "index.decrypt", &decrypt);
+ char * decrypt_policy;
+ notmuch_status_t err = notmuch_database_get_config (db, "index.decrypt", &decrypt_policy);
if (err)
return ret;
- if (decrypt &&
- ((!(strcasecmp(decrypt, "true"))) ||
- (!(strcasecmp(decrypt, "yes"))) ||
- (!(strcasecmp(decrypt, "1")))))
- notmuch_indexopts_set_decrypt_policy (ret, true);
+ if (decrypt_policy &&
+ ((!(strcasecmp(decrypt_policy, "true"))) ||
+ (!(strcasecmp(decrypt_policy, "yes"))) ||
+ (!(strcasecmp(decrypt_policy, "1")))))
+ notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_TRUE);
- free (decrypt);
+ free (decrypt_policy);
return ret;
}
notmuch_status_t
notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
- notmuch_bool_t decrypt_policy)
+ notmuch_decryption_policy_t decrypt_policy)
{
if (!indexopts)
return NOTMUCH_STATUS_NULL_POINTER;
@@ -52,7 +53,7 @@ notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
return NOTMUCH_STATUS_SUCCESS;
}
-notmuch_bool_t
+notmuch_decryption_policy_t
notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts)
{
if (!indexopts)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index ef463090..47633496 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2234,6 +2234,16 @@ notmuch_indexopts_t *
notmuch_database_get_default_indexopts (notmuch_database_t *db);
/**
+ * Stating a policy about how to decrypt messages.
+ *
+ * See index.decrypt in notmuch-config(1) for more details.
+ */
+typedef enum {
+ NOTMUCH_DECRYPT_FALSE,
+ NOTMUCH_DECRYPT_TRUE,
+} notmuch_decryption_policy_t;
+
+/**
* Specify whether to decrypt encrypted parts while indexing.
*
* Be aware that the index is likely sufficient to reconstruct the
@@ -2245,7 +2255,7 @@ notmuch_database_get_default_indexopts (notmuch_database_t *db);
*/
notmuch_status_t
notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
- notmuch_bool_t decrypt_policy);
+ notmuch_decryption_policy_t decrypt_policy);
/**
* Return whether to decrypt encrypted parts while indexing.
@@ -2253,7 +2263,7 @@ notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
*
* @since libnotmuch 5.1 (notmuch 0.26)
*/
-notmuch_bool_t
+notmuch_decryption_policy_t
notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts);
/**