]> git.notmuchmail.org Git - notmuch/blob - lib/indexopts.c
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / lib / indexopts.c
1 /* indexopts.c - options for indexing messages (currently a stub)
2  *
3  * Copyright © 2017 Daniel Kahn Gillmor
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see https://www.gnu.org/licenses/ .
17  *
18  * Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
19  */
20
21 #include "notmuch-private.h"
22
23 struct _notmuch_indexopts {
24     _notmuch_crypto_t crypto;
25 };
26
27 notmuch_indexopts_t *
28 notmuch_database_get_default_indexopts (notmuch_database_t *db)
29 {
30     notmuch_indexopts_t *ret = talloc_zero (db, notmuch_indexopts_t);
31
32     if (! ret)
33         return ret;
34     ret->crypto.decrypt = NOTMUCH_DECRYPT_AUTO;
35
36     char *decrypt_policy;
37     notmuch_status_t err = notmuch_database_get_config (db, "index.decrypt", &decrypt_policy);
38
39     if (err)
40         return NULL;
41
42     if (decrypt_policy) {
43         if ((! (strcasecmp (decrypt_policy, "true"))) ||
44             (! (strcasecmp (decrypt_policy, "yes"))) ||
45             (! (strcasecmp (decrypt_policy, "1"))))
46             notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_TRUE);
47         else if ((! (strcasecmp (decrypt_policy, "false"))) ||
48                  (! (strcasecmp (decrypt_policy, "no"))) ||
49                  (! (strcasecmp (decrypt_policy, "0"))))
50             notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_FALSE);
51         else if (! strcasecmp (decrypt_policy, "nostash"))
52             notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_NOSTASH);
53     }
54
55     free (decrypt_policy);
56     return ret;
57 }
58
59 notmuch_status_t
60 notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
61                                       notmuch_decryption_policy_t decrypt_policy)
62 {
63     if (! indexopts)
64         return NOTMUCH_STATUS_NULL_POINTER;
65     indexopts->crypto.decrypt = decrypt_policy;
66     return NOTMUCH_STATUS_SUCCESS;
67 }
68
69 notmuch_decryption_policy_t
70 notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts)
71 {
72     if (! indexopts)
73         return false;
74     return indexopts->crypto.decrypt;
75 }
76
77 void
78 notmuch_indexopts_destroy (notmuch_indexopts_t *indexopts)
79 {
80     talloc_free (indexopts);
81 }