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 DA2ED6DE1BC3
\r
6 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:26 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 ut-R4ICYnAMI for <notmuch@notmuchmail.org>;
\r
16 Sun, 31 Jan 2016 12:40:24 -0800 (PST)
\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id F23946DE1ADF
\r
19 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:09 -0800 (PST)
\r
20 Received: from fifthhorseman.net (ip-64-134-185-108.public.wayport.net
\r
22 by che.mayfirst.org (Postfix) with ESMTPSA id DE7C7F9A3
\r
23 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 15:40:06 -0500 (EST)
\r
24 Received: by fifthhorseman.net (Postfix, from userid 1000)
\r
25 id 5A72820382; Sun, 31 Jan 2016 15:40:06 -0500 (EST)
\r
26 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
27 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
28 Subject: [PATCH v3 13/16] add indexopts to notmuch python bindings.
\r
29 Date: Sun, 31 Jan 2016 15:39:58 -0500
\r
30 Message-Id: <1454272801-23623-14-git-send-email-dkg@fifthhorseman.net>
\r
31 X-Mailer: git-send-email 2.7.0.rc3
\r
32 In-Reply-To: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
\r
33 References: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 31 Jan 2016 20:40:27 -0000
\r
48 Make notmuch indexing options are not available in python as
\r
49 the notmuch.Indexopts class. Users can do something like:
\r
52 d = notmuch.Database()
\r
53 indexopts = notmuch.Indexopts(try_decrypt=true)
\r
54 d.add_message(fname, indexopts=indexopts)
\r
56 bindings/python/notmuch/__init__.py | 1 +
\r
57 bindings/python/notmuch/database.py | 21 +++++---
\r
58 bindings/python/notmuch/globals.py | 5 ++
\r
59 bindings/python/notmuch/indexopts.py | 97 ++++++++++++++++++++++++++++++++++++
\r
60 4 files changed, 117 insertions(+), 7 deletions(-)
\r
61 create mode 100644 bindings/python/notmuch/indexopts.py
\r
63 diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
\r
64 index 29416a5..fe2d886 100644
\r
65 --- a/bindings/python/notmuch/__init__.py
\r
66 +++ b/bindings/python/notmuch/__init__.py
\r
67 @@ -54,6 +54,7 @@ Copyright 2010-2011 Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
68 from .database import Database
\r
69 from .directory import Directory
\r
70 from .filenames import Filenames
\r
71 +from .indexopts import Indexopts
\r
72 from .message import Message
\r
73 from .messages import Messages
\r
74 from .query import Query
\r
75 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
\r
76 index 93e7b7a..1b0ee1a 100644
\r
77 --- a/bindings/python/notmuch/database.py
\r
78 +++ b/bindings/python/notmuch/database.py
\r
79 @@ -29,6 +29,7 @@ from .globals import (
\r
83 + NotmuchIndexoptsP,
\r
85 from .errors import (
\r
87 @@ -383,12 +384,13 @@ class Database(object):
\r
88 # return the Directory, init it with the absolute path
\r
89 return Directory(abs_dirpath, dir_p, self)
\r
91 - _add_message = nmlib.notmuch_database_add_message
\r
92 - _add_message.argtypes = [NotmuchDatabaseP, c_char_p,
\r
93 - POINTER(NotmuchMessageP)]
\r
94 - _add_message.restype = c_uint
\r
96 - def add_message(self, filename, sync_maildir_flags=False):
\r
97 + _add_message_with_indexopts = nmlib.notmuch_database_add_message_with_indexopts
\r
98 + _add_message_with_indexopts.argtypes = [NotmuchDatabaseP, c_char_p,
\r
99 + NotmuchIndexoptsP,
\r
100 + POINTER(NotmuchMessageP)]
\r
101 + _add_message_with_indexopts.restype = c_uint
\r
103 + def add_message(self, filename, sync_maildir_flags=False, indexopts=None):
\r
104 """Adds a new message to the database
\r
106 :param filename: should be a path relative to the path of the
\r
107 @@ -409,6 +411,9 @@ class Database(object):
\r
108 API. You might want to look into the underlying method
\r
109 :meth:`Message.maildir_flags_to_tags`.
\r
111 + :param indexopts: a nomtuch.Indexopts object indicating custom
\r
112 + options desired for indexing.
\r
114 :returns: On success, we return
\r
116 1) a :class:`Message` object that can be used for things
\r
117 @@ -436,10 +441,12 @@ class Database(object):
\r
118 :attr:`STATUS`.READ_ONLY_DATABASE
\r
119 Database was opened in read-only mode so no message can
\r
123 self._assert_db_is_initialized()
\r
124 msg_p = NotmuchMessageP()
\r
125 - status = self._add_message(self._db, _str(filename), byref(msg_p))
\r
127 + status = self._add_message_with_indexopts(self._db, _str(filename), indexopts._indexopts, byref(msg_p))
\r
129 if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
\r
130 raise NotmuchError(status)
\r
131 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
\r
132 index 6872a29..c4b9832 100644
\r
133 --- a/bindings/python/notmuch/globals.py
\r
134 +++ b/bindings/python/notmuch/globals.py
\r
135 @@ -88,3 +88,8 @@ NotmuchDirectoryP = POINTER(NotmuchDirectoryS)
\r
136 class NotmuchFilenamesS(Structure):
\r
138 NotmuchFilenamesP = POINTER(NotmuchFilenamesS)
\r
141 +class NotmuchIndexoptsS(Structure):
\r
143 +NotmuchIndexoptsP = POINTER(NotmuchIndexoptsS)
\r
144 diff --git a/bindings/python/notmuch/indexopts.py b/bindings/python/notmuch/indexopts.py
\r
145 new file mode 100644
\r
146 index 0000000..b0d4603
\r
148 +++ b/bindings/python/notmuch/indexopts.py
\r
151 +This file is part of notmuch.
\r
153 +Notmuch is free software: you can redistribute it and/or modify it
\r
154 +under the terms of the GNU General Public License as published by the
\r
155 +Free Software Foundation, either version 3 of the License, or (at your
\r
156 +option) any later version.
\r
158 +Notmuch is distributed in the hope that it will be useful, but WITHOUT
\r
159 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
160 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
163 +You should have received a copy of the GNU General Public License
\r
164 +along with notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
166 +Copyright 2015 Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
168 +from ctypes import c_char_p, c_bool, c_int
\r
169 +from .globals import (
\r
171 + NotmuchIndexoptsP,
\r
173 +from .errors import (
\r
175 + NullPointerError,
\r
176 + NotInitializedError,
\r
180 +class Indexopts(object):
\r
181 + """Represents available options for notmuch indexing.
\r
185 + _create = nmlib.notmuch_indexopts_create
\r
186 + _create.argtypes = []
\r
187 + _create.restype = NotmuchIndexoptsP
\r
189 + def __init__(self, try_decrypt=False, gpg_path=None):
\r
191 + :param try_decrypt: True if notmuch should try to decrypt messages
\r
192 + while indexing, and index the cleartext.
\r
194 + :param gpg_path: the name or path to the preferred GnuPG binary.
\r
196 + self._indexopts = Indexopts._create()
\r
197 + self.gpg_path = gpg_path
\r
198 + self.try_decrypt = try_decrypt
\r
201 + _get_try_decrypt = nmlib.notmuch_indexopts_get_try_decrypt
\r
202 + _get_try_decrypt.argtypes = [NotmuchIndexoptsP]
\r
203 + _get_try_decrypt.restype = bool
\r
205 + _set_try_decrypt = nmlib.notmuch_indexopts_set_try_decrypt
\r
206 + _set_try_decrypt.argtypes = [NotmuchIndexoptsP, c_bool]
\r
207 + _set_try_decrypt.restype = c_int
\r
210 + def try_decrypt(self):
\r
211 + return Indexopts._get_try_decrypt(self._indexopts)
\r
213 + @try_decrypt.setter
\r
214 + def try_decrypt(self, try_decrypt):
\r
215 + status = Indexopts._set_try_decrypt(self._indexopts, try_decrypt)
\r
216 + if status != STATUS.SUCCESS:
\r
217 + raise NotmuchError(status)
\r
220 + _get_gpg_path = nmlib.notmuch_indexopts_get_gpg_path
\r
221 + _get_gpg_path.argtypes = [NotmuchIndexoptsP]
\r
222 + _get_gpg_path.restype = c_char_p
\r
224 + _set_gpg_path = nmlib.notmuch_indexopts_set_gpg_path
\r
225 + _set_gpg_path.argtypes = [NotmuchIndexoptsP, c_char_p]
\r
226 + _set_gpg_path.restype = c_int
\r
229 + def gpg_path(self):
\r
230 + return Indexopts._get_gpg_path(self._indexopts)
\r
233 + def gpg_path(self, gpg_path):
\r
234 + status = Indexopts._set_gpg_path(self._indexopts, gpg_path)
\r
235 + if status != STATUS.SUCCESS:
\r
236 + raise NotmuchError(status)
\r
239 + _destroy = nmlib.notmuch_indexopts_destroy
\r
240 + _destroy.argtypes = [NotmuchIndexoptsP]
\r
241 + _destroy.restype = None
\r
243 + def __del__(self):
\r
244 + """Close and free the indexopts"""
\r
245 + if self._indexopts:
\r
246 + self._destroy(self._indexopts)
\r