1 Return-Path: <dkg@fifthhorseman.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id DD0EF6DE02AC
\r
6 for <notmuch@notmuchmail.org>; Fri, 8 Jul 2016 03:13:33 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0.108 tagged_above=-999 required=5 tests=[AWL=0.108]
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id eo15abrp6g-e for <notmuch@notmuchmail.org>;
\r
16 Fri, 8 Jul 2016 03:13:24 -0700 (PDT)
\r
17 Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id 94C316DE02AF
\r
19 for <notmuch@notmuchmail.org>; Fri, 8 Jul 2016 03:13:09 -0700 (PDT)
\r
20 Received: from fifthhorseman.net (unknown [88.128.80.54])
\r
21 by che.mayfirst.org (Postfix) with ESMTPSA id EFA0DF99D
\r
22 for <notmuch@notmuchmail.org>; Fri, 8 Jul 2016 06:13:07 -0400 (EDT)
\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)
\r
24 id C12D4215CD; Fri, 8 Jul 2016 11:27:34 +0200 (CEST)
\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
27 Subject: [PATCH v4 13/16] add indexopts to notmuch python bindings.
\r
28 Date: Fri, 8 Jul 2016 11:27:24 +0200
\r
29 Message-Id: <1467970047-8013-14-git-send-email-dkg@fifthhorseman.net>
\r
30 X-Mailer: git-send-email 2.8.1
\r
31 In-Reply-To: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>
\r
32 References: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.20
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Fri, 08 Jul 2016 10:13:34 -0000
\r
47 Make notmuch indexing options are not available in python as
\r
48 the notmuch.Indexopts class. Users can do something like:
\r
51 d = notmuch.Database()
\r
52 indexopts = notmuch.Indexopts(try_decrypt=true)
\r
53 d.add_message(fname, indexopts=indexopts)
\r
55 bindings/python/notmuch/__init__.py | 1 +
\r
56 bindings/python/notmuch/database.py | 24 ++++++---
\r
57 bindings/python/notmuch/globals.py | 5 ++
\r
58 bindings/python/notmuch/indexopts.py | 97 ++++++++++++++++++++++++++++++++++++
\r
59 4 files changed, 120 insertions(+), 7 deletions(-)
\r
60 create mode 100644 bindings/python/notmuch/indexopts.py
\r
62 diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
\r
63 index cf627ff..5c19532 100644
\r
64 --- a/bindings/python/notmuch/__init__.py
\r
65 +++ b/bindings/python/notmuch/__init__.py
\r
66 @@ -54,6 +54,7 @@ Copyright 2010-2011 Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
67 from .database import Database
\r
68 from .directory import Directory
\r
69 from .filenames import Filenames
\r
70 +from .indexopts import Indexopts
\r
71 from .message import Message
\r
72 from .messages import Messages
\r
73 from .query import Query
\r
74 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
\r
75 index 67fb1c4..a13b9bb 100644
\r
76 --- a/bindings/python/notmuch/database.py
\r
77 +++ b/bindings/python/notmuch/database.py
\r
78 @@ -29,6 +29,7 @@ from .globals import (
\r
82 + NotmuchIndexoptsP,
\r
84 from .errors import (
\r
86 @@ -383,12 +384,13 @@ class Database(object):
\r
87 # return the Directory, init it with the absolute path
\r
88 return Directory(abs_dirpath, dir_p, self)
\r
90 - _add_message = nmlib.notmuch_database_add_message
\r
91 - _add_message.argtypes = [NotmuchDatabaseP, c_char_p,
\r
92 - POINTER(NotmuchMessageP)]
\r
93 - _add_message.restype = c_uint
\r
95 - def add_message(self, filename, sync_maildir_flags=False):
\r
96 + _add_message_with_indexopts = nmlib.notmuch_database_add_message_with_indexopts
\r
97 + _add_message_with_indexopts.argtypes = [NotmuchDatabaseP, c_char_p,
\r
98 + NotmuchIndexoptsP,
\r
99 + POINTER(NotmuchMessageP)]
\r
100 + _add_message_with_indexopts.restype = c_uint
\r
102 + def add_message(self, filename, sync_maildir_flags=False, indexopts=None):
\r
103 """Adds a new message to the database
\r
105 :param filename: should be a path relative to the path of the
\r
106 @@ -409,6 +411,9 @@ class Database(object):
\r
107 API. You might want to look into the underlying method
\r
108 :meth:`Message.maildir_flags_to_tags`.
\r
110 + :param indexopts: a nomtuch.Indexopts object indicating custom
\r
111 + options desired for indexing.
\r
113 :returns: On success, we return
\r
115 1) a :class:`Message` object that can be used for things
\r
116 @@ -436,10 +441,15 @@ class Database(object):
\r
117 :attr:`STATUS`.READ_ONLY_DATABASE
\r
118 Database was opened in read-only mode so no message can
\r
122 self._assert_db_is_initialized()
\r
123 msg_p = NotmuchMessageP()
\r
124 - status = self._add_message(self._db, _str(filename), byref(msg_p))
\r
127 + if indexopts is not None:
\r
128 + io = indexopts._indexopts
\r
129 + status = self._add_message_with_indexopts(self._db, _str(filename), io, byref(msg_p))
\r
131 if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
\r
132 raise NotmuchError(status)
\r
133 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
\r
134 index b1eec2c..71426c8 100644
\r
135 --- a/bindings/python/notmuch/globals.py
\r
136 +++ b/bindings/python/notmuch/globals.py
\r
137 @@ -88,3 +88,8 @@ NotmuchDirectoryP = POINTER(NotmuchDirectoryS)
\r
138 class NotmuchFilenamesS(Structure):
\r
140 NotmuchFilenamesP = POINTER(NotmuchFilenamesS)
\r
143 +class NotmuchIndexoptsS(Structure):
\r
145 +NotmuchIndexoptsP = POINTER(NotmuchIndexoptsS)
\r
146 diff --git a/bindings/python/notmuch/indexopts.py b/bindings/python/notmuch/indexopts.py
\r
147 new file mode 100644
\r
148 index 0000000..b0d4603
\r
150 +++ b/bindings/python/notmuch/indexopts.py
\r
153 +This file is part of notmuch.
\r
155 +Notmuch is free software: you can redistribute it and/or modify it
\r
156 +under the terms of the GNU General Public License as published by the
\r
157 +Free Software Foundation, either version 3 of the License, or (at your
\r
158 +option) any later version.
\r
160 +Notmuch is distributed in the hope that it will be useful, but WITHOUT
\r
161 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
162 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
165 +You should have received a copy of the GNU General Public License
\r
166 +along with notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
168 +Copyright 2015 Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
170 +from ctypes import c_char_p, c_bool, c_int
\r
171 +from .globals import (
\r
173 + NotmuchIndexoptsP,
\r
175 +from .errors import (
\r
177 + NullPointerError,
\r
178 + NotInitializedError,
\r
182 +class Indexopts(object):
\r
183 + """Represents available options for notmuch indexing.
\r
187 + _create = nmlib.notmuch_indexopts_create
\r
188 + _create.argtypes = []
\r
189 + _create.restype = NotmuchIndexoptsP
\r
191 + def __init__(self, try_decrypt=False, gpg_path=None):
\r
193 + :param try_decrypt: True if notmuch should try to decrypt messages
\r
194 + while indexing, and index the cleartext.
\r
196 + :param gpg_path: the name or path to the preferred GnuPG binary.
\r
198 + self._indexopts = Indexopts._create()
\r
199 + self.gpg_path = gpg_path
\r
200 + self.try_decrypt = try_decrypt
\r
203 + _get_try_decrypt = nmlib.notmuch_indexopts_get_try_decrypt
\r
204 + _get_try_decrypt.argtypes = [NotmuchIndexoptsP]
\r
205 + _get_try_decrypt.restype = bool
\r
207 + _set_try_decrypt = nmlib.notmuch_indexopts_set_try_decrypt
\r
208 + _set_try_decrypt.argtypes = [NotmuchIndexoptsP, c_bool]
\r
209 + _set_try_decrypt.restype = c_int
\r
212 + def try_decrypt(self):
\r
213 + return Indexopts._get_try_decrypt(self._indexopts)
\r
215 + @try_decrypt.setter
\r
216 + def try_decrypt(self, try_decrypt):
\r
217 + status = Indexopts._set_try_decrypt(self._indexopts, try_decrypt)
\r
218 + if status != STATUS.SUCCESS:
\r
219 + raise NotmuchError(status)
\r
222 + _get_gpg_path = nmlib.notmuch_indexopts_get_gpg_path
\r
223 + _get_gpg_path.argtypes = [NotmuchIndexoptsP]
\r
224 + _get_gpg_path.restype = c_char_p
\r
226 + _set_gpg_path = nmlib.notmuch_indexopts_set_gpg_path
\r
227 + _set_gpg_path.argtypes = [NotmuchIndexoptsP, c_char_p]
\r
228 + _set_gpg_path.restype = c_int
\r
231 + def gpg_path(self):
\r
232 + return Indexopts._get_gpg_path(self._indexopts)
\r
235 + def gpg_path(self, gpg_path):
\r
236 + status = Indexopts._set_gpg_path(self._indexopts, gpg_path)
\r
237 + if status != STATUS.SUCCESS:
\r
238 + raise NotmuchError(status)
\r
241 + _destroy = nmlib.notmuch_indexopts_destroy
\r
242 + _destroy.argtypes = [NotmuchIndexoptsP]
\r
243 + _destroy.restype = None
\r
245 + def __del__(self):
\r
246 + """Close and free the indexopts"""
\r
247 + if self._indexopts:
\r
248 + self._destroy(self._indexopts)
\r