Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d9 / 2c894329378291744d35a93cde865bda363510
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 DC6656DE1BC8\r
6  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:34 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.022\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.022 tagged_above=-999 required=5\r
12  tests=[AWL=-0.022] autolearn=disabled\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 M8w8ci7xGJyE for <notmuch@notmuchmail.org>;\r
16  Tue, 19 Jan 2016 18:53:31 -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 1C1976DE178E\r
19  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:17 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 57D02F99C\r
22  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 21:53:14 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id 0906B2092E; Tue, 19 Jan 2016 18:53:11 -0800 (PST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v2 13/16] add indexopts to notmuch python bindings.\r
28 Date: Tue, 19 Jan 2016 21:52:46 -0500\r
29 Message-Id: <1453258369-7366-14-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.7.0.rc3\r
31 In-Reply-To: <1453258369-7366-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1453258369-7366-1-git-send-email-dkg@fifthhorseman.net>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.20\r
35 Precedence: list\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: Wed, 20 Jan 2016 02:53:35 -0000\r
46 \r
47 Make notmuch indexing options are not available in python as\r
48 the notmuch.Indexopts class.  Users can do something like:\r
49 \r
50  import notmuch\r
51  d = notmuch.Database()\r
52  indexopts = notmuch.Indexopts(try_decrypt=true)\r
53  d.add_message(fname, indexopts=indexopts)\r
54 ---\r
55  bindings/python/notmuch/__init__.py  |  1 +\r
56  bindings/python/notmuch/database.py  | 21 +++++---\r
57  bindings/python/notmuch/globals.py   |  5 ++\r
58  bindings/python/notmuch/indexopts.py | 97 ++++++++++++++++++++++++++++++++++++\r
59  4 files changed, 117 insertions(+), 7 deletions(-)\r
60  create mode 100644 bindings/python/notmuch/indexopts.py\r
61 \r
62 diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py\r
63 index 29416a5..fe2d886 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 93e7b7a..1b0ee1a 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
79      NotmuchDirectoryP,\r
80      NotmuchMessageP,\r
81      NotmuchTagsP,\r
82 +    NotmuchIndexoptsP,\r
83  )\r
84  from .errors import (\r
85      STATUS,\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
89  \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
94 -\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
101 +        \r
102 +    def add_message(self, filename, sync_maildir_flags=False, indexopts=None):\r
103          """Adds a new message to the database\r
104  \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
109  \r
110 +        :param indexopts: a nomtuch.Indexopts object indicating custom\r
111 +            options desired for indexing.\r
112 +\r
113          :returns: On success, we return\r
114  \r
115             1) a :class:`Message` object that can be used for things\r
116 @@ -436,10 +441,12 @@ class Database(object):\r
117                :attr:`STATUS`.READ_ONLY_DATABASE\r
118                        Database was opened in read-only mode so no message can\r
119                        be added.\r
120 +\r
121          """\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
125 +\r
126 +        status = self._add_message_with_indexopts(self._db, _str(filename), indexopts._indexopts, byref(msg_p))\r
127  \r
128          if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:\r
129              raise NotmuchError(status)\r
130 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py\r
131 index 6872a29..c4b9832 100644\r
132 --- a/bindings/python/notmuch/globals.py\r
133 +++ b/bindings/python/notmuch/globals.py\r
134 @@ -88,3 +88,8 @@ NotmuchDirectoryP = POINTER(NotmuchDirectoryS)\r
135  class NotmuchFilenamesS(Structure):\r
136      pass\r
137  NotmuchFilenamesP = POINTER(NotmuchFilenamesS)\r
138 +\r
139 +\r
140 +class NotmuchIndexoptsS(Structure):\r
141 +    pass\r
142 +NotmuchIndexoptsP = POINTER(NotmuchIndexoptsS)\r
143 diff --git a/bindings/python/notmuch/indexopts.py b/bindings/python/notmuch/indexopts.py\r
144 new file mode 100644\r
145 index 0000000..b0d4603\r
146 --- /dev/null\r
147 +++ b/bindings/python/notmuch/indexopts.py\r
148 @@ -0,0 +1,97 @@\r
149 +"""\r
150 +This file is part of notmuch.\r
151 +\r
152 +Notmuch is free software: you can redistribute it and/or modify it\r
153 +under the terms of the GNU General Public License as published by the\r
154 +Free Software Foundation, either version 3 of the License, or (at your\r
155 +option) any later version.\r
156 +\r
157 +Notmuch is distributed in the hope that it will be useful, but WITHOUT\r
158 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
159 +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
160 +for more details.\r
161 +\r
162 +You should have received a copy of the GNU General Public License\r
163 +along with notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
164 +\r
165 +Copyright 2015 Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
166 +"""\r
167 +from ctypes import c_char_p, c_bool, c_int\r
168 +from .globals import (\r
169 +    nmlib,\r
170 +    NotmuchIndexoptsP,\r
171 +)\r
172 +from .errors import (\r
173 +    STATUS,\r
174 +    NullPointerError,\r
175 +    NotInitializedError,\r
176 +)\r
177 +\r
178 +\r
179 +class Indexopts(object):\r
180 +    """Represents available options for notmuch indexing.\r
181 +    """\r
182 +\r
183 +    # create\r
184 +    _create = nmlib.notmuch_indexopts_create\r
185 +    _create.argtypes = []\r
186 +    _create.restype = NotmuchIndexoptsP\r
187 +\r
188 +    def __init__(self, try_decrypt=False, gpg_path=None):\r
189 +        """\r
190 +        :param try_decrypt: True if notmuch should try to decrypt messages\r
191 +             while indexing, and index the cleartext.\r
192 +\r
193 +        :param gpg_path: the name or path to the preferred GnuPG binary.\r
194 +        """\r
195 +        self._indexopts = Indexopts._create()\r
196 +        self.gpg_path = gpg_path\r
197 +        self.try_decrypt = try_decrypt\r
198 +\r
199 +    # try_decrypt\r
200 +    _get_try_decrypt = nmlib.notmuch_indexopts_get_try_decrypt\r
201 +    _get_try_decrypt.argtypes = [NotmuchIndexoptsP]\r
202 +    _get_try_decrypt.restype = bool\r
203 +\r
204 +    _set_try_decrypt = nmlib.notmuch_indexopts_set_try_decrypt\r
205 +    _set_try_decrypt.argtypes = [NotmuchIndexoptsP, c_bool]\r
206 +    _set_try_decrypt.restype = c_int\r
207 +\r
208 +    @property\r
209 +    def try_decrypt(self):\r
210 +        return Indexopts._get_try_decrypt(self._indexopts)\r
211 +\r
212 +    @try_decrypt.setter\r
213 +    def try_decrypt(self, try_decrypt):\r
214 +        status = Indexopts._set_try_decrypt(self._indexopts, try_decrypt)\r
215 +        if status != STATUS.SUCCESS:\r
216 +            raise NotmuchError(status)\r
217 +\r
218 +    # gpg_path\r
219 +    _get_gpg_path = nmlib.notmuch_indexopts_get_gpg_path\r
220 +    _get_gpg_path.argtypes = [NotmuchIndexoptsP]\r
221 +    _get_gpg_path.restype = c_char_p\r
222 +\r
223 +    _set_gpg_path = nmlib.notmuch_indexopts_set_gpg_path\r
224 +    _set_gpg_path.argtypes = [NotmuchIndexoptsP, c_char_p]\r
225 +    _set_gpg_path.restype = c_int\r
226 +\r
227 +    @property\r
228 +    def gpg_path(self):\r
229 +        return Indexopts._get_gpg_path(self._indexopts)\r
230 +\r
231 +    @gpg_path.setter\r
232 +    def gpg_path(self, gpg_path):\r
233 +        status = Indexopts._set_gpg_path(self._indexopts, gpg_path)\r
234 +        if status != STATUS.SUCCESS:\r
235 +            raise NotmuchError(status)\r
236 +    \r
237 +\r
238 +    _destroy = nmlib.notmuch_indexopts_destroy\r
239 +    _destroy.argtypes = [NotmuchIndexoptsP]\r
240 +    _destroy.restype = None\r
241 +\r
242 +    def __del__(self):\r
243 +        """Close and free the indexopts"""\r
244 +        if self._indexopts:\r
245 +            self._destroy(self._indexopts)\r
246 -- \r
247 2.7.0.rc3\r
248 \r