]> git.notmuchmail.org Git - notmuch/blob - lib/indexopts.c
debian upload 0.29.2-2: goodbye python2 support
[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 notmuch_indexopts_t *
24 notmuch_database_get_default_indexopts (notmuch_database_t *db)
25 {
26     notmuch_indexopts_t *ret = talloc_zero (db, notmuch_indexopts_t);
27     if (!ret)
28         return ret;
29     ret->crypto.decrypt = NOTMUCH_DECRYPT_AUTO;
30
31     char * decrypt_policy;
32     notmuch_status_t err = notmuch_database_get_config (db, "index.decrypt", &decrypt_policy);
33     if (err)
34         return ret;
35
36     if (decrypt_policy) {
37         if ((!(strcasecmp(decrypt_policy, "true"))) ||
38             (!(strcasecmp(decrypt_policy, "yes"))) ||
39             (!(strcasecmp(decrypt_policy, "1"))))
40             notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_TRUE);
41         else if ((!(strcasecmp(decrypt_policy, "false"))) ||
42                  (!(strcasecmp(decrypt_policy, "no"))) ||
43                  (!(strcasecmp(decrypt_policy, "0"))))
44             notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_FALSE);
45         else if (!strcasecmp(decrypt_policy, "nostash"))
46             notmuch_indexopts_set_decrypt_policy (ret, NOTMUCH_DECRYPT_NOSTASH);
47     }
48
49     free (decrypt_policy);
50     return ret;
51 }
52
53 notmuch_status_t
54 notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
55                                       notmuch_decryption_policy_t decrypt_policy)
56 {
57     if (!indexopts)
58         return NOTMUCH_STATUS_NULL_POINTER;
59     indexopts->crypto.decrypt = decrypt_policy;
60     return NOTMUCH_STATUS_SUCCESS;
61 }
62
63 notmuch_decryption_policy_t
64 notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts)
65 {
66     if (!indexopts)
67         return false;
68     return indexopts->crypto.decrypt;
69 }
70
71 void
72 notmuch_indexopts_destroy (notmuch_indexopts_t *indexopts)
73 {
74     talloc_free (indexopts);
75 }