1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
| | """
This file is part of notmuch.
Notmuch is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
Notmuch is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see <http://www.gnu.org/licenses/>.
Copyright 2015 Daniel Kahn Gillmor <dkg@fifthhorseman.net>
"""
from ctypes import c_char_p, c_bool, c_int
from .globals import (
nmlib,
NotmuchIndexoptsP,
)
from .errors import (
STATUS,
NullPointerError,
NotInitializedError,
)
class Indexopts(object):
"""Represents available options for notmuch indexing.
"""
# create
_create = nmlib.notmuch_indexopts_create
_create.argtypes = []
_create.restype = NotmuchIndexoptsP
def __init__(self, try_decrypt=False, gpg_path=None):
"""
:param try_decrypt: True if notmuch should try to decrypt messages
while indexing, and index the cleartext.
:param gpg_path: the name or path to the preferred GnuPG binary.
"""
self._indexopts = Indexopts._create()
self.gpg_path = gpg_path
self.try_decrypt = try_decrypt
# try_decrypt
_get_try_decrypt = nmlib.notmuch_indexopts_get_try_decrypt
_get_try_decrypt.argtypes = [NotmuchIndexoptsP]
_get_try_decrypt.restype = bool
_set_try_decrypt = nmlib.notmuch_indexopts_set_try_decrypt
_set_try_decrypt.argtypes = [NotmuchIndexoptsP, c_bool]
_set_try_decrypt.restype = c_int
@property
def try_decrypt(self):
return Indexopts._get_try_decrypt(self._indexopts)
@try_decrypt.setter
def try_decrypt(self, try_decrypt):
status = Indexopts._set_try_decrypt(self._indexopts, try_decrypt)
if status != STATUS.SUCCESS:
raise NotmuchError(status)
# gpg_path
_get_gpg_path = nmlib.notmuch_indexopts_get_gpg_path
_get_gpg_path.argtypes = [NotmuchIndexoptsP]
_get_gpg_path.restype = c_char_p
_set_gpg_path = nmlib.notmuch_indexopts_set_gpg_path
_set_gpg_path.argtypes = [NotmuchIndexoptsP, c_char_p]
_set_gpg_path.restype = c_int
@property
def gpg_path(self):
return Indexopts._get_gpg_path(self._indexopts)
@gpg_path.setter
def gpg_path(self, gpg_path):
status = Indexopts._set_gpg_path(self._indexopts, gpg_path)
if status != STATUS.SUCCESS:
raise NotmuchError(status)
_destroy = nmlib.notmuch_indexopts_destroy
_destroy.argtypes = [NotmuchIndexoptsP]
_destroy.restype = None
def __del__(self):
"""Close and free the indexopts"""
if self._indexopts:
self._destroy(self._indexopts)
|