From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH v3 13/16] add indexopts to notmuch python bindings.
Date: Sun, 31 Jan 2016 15:39:58 -0500 [thread overview]
Message-ID: <1454272801-23623-14-git-send-email-dkg@fifthhorseman.net> (raw)
In-Reply-To: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
Make notmuch indexing options are not available in python as
the notmuch.Indexopts class. Users can do something like:
import notmuch
d = notmuch.Database()
indexopts = notmuch.Indexopts(try_decrypt=true)
d.add_message(fname, indexopts=indexopts)
---
bindings/python/notmuch/__init__.py | 1 +
bindings/python/notmuch/database.py | 21 +++++---
bindings/python/notmuch/globals.py | 5 ++
bindings/python/notmuch/indexopts.py | 97 ++++++++++++++++++++++++++++++++++++
4 files changed, 117 insertions(+), 7 deletions(-)
create mode 100644 bindings/python/notmuch/indexopts.py
diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
index 29416a5..fe2d886 100644
--- a/bindings/python/notmuch/__init__.py
+++ b/bindings/python/notmuch/__init__.py
@@ -54,6 +54,7 @@ Copyright 2010-2011 Sebastian Spaeth <Sebastian@SSpaeth.de>
from .database import Database
from .directory import Directory
from .filenames import Filenames
+from .indexopts import Indexopts
from .message import Message
from .messages import Messages
from .query import Query
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 93e7b7a..1b0ee1a 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -29,6 +29,7 @@ from .globals import (
NotmuchDirectoryP,
NotmuchMessageP,
NotmuchTagsP,
+ NotmuchIndexoptsP,
)
from .errors import (
STATUS,
@@ -383,12 +384,13 @@ class Database(object):
# return the Directory, init it with the absolute path
return Directory(abs_dirpath, dir_p, self)
- _add_message = nmlib.notmuch_database_add_message
- _add_message.argtypes = [NotmuchDatabaseP, c_char_p,
- POINTER(NotmuchMessageP)]
- _add_message.restype = c_uint
-
- def add_message(self, filename, sync_maildir_flags=False):
+ _add_message_with_indexopts = nmlib.notmuch_database_add_message_with_indexopts
+ _add_message_with_indexopts.argtypes = [NotmuchDatabaseP, c_char_p,
+ NotmuchIndexoptsP,
+ POINTER(NotmuchMessageP)]
+ _add_message_with_indexopts.restype = c_uint
+
+ def add_message(self, filename, sync_maildir_flags=False, indexopts=None):
"""Adds a new message to the database
:param filename: should be a path relative to the path of the
@@ -409,6 +411,9 @@ class Database(object):
API. You might want to look into the underlying method
:meth:`Message.maildir_flags_to_tags`.
+ :param indexopts: a nomtuch.Indexopts object indicating custom
+ options desired for indexing.
+
:returns: On success, we return
1) a :class:`Message` object that can be used for things
@@ -436,10 +441,12 @@ class Database(object):
:attr:`STATUS`.READ_ONLY_DATABASE
Database was opened in read-only mode so no message can
be added.
+
"""
self._assert_db_is_initialized()
msg_p = NotmuchMessageP()
- status = self._add_message(self._db, _str(filename), byref(msg_p))
+
+ status = self._add_message_with_indexopts(self._db, _str(filename), indexopts._indexopts, byref(msg_p))
if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
raise NotmuchError(status)
diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index 6872a29..c4b9832 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -88,3 +88,8 @@ NotmuchDirectoryP = POINTER(NotmuchDirectoryS)
class NotmuchFilenamesS(Structure):
pass
NotmuchFilenamesP = POINTER(NotmuchFilenamesS)
+
+
+class NotmuchIndexoptsS(Structure):
+ pass
+NotmuchIndexoptsP = POINTER(NotmuchIndexoptsS)
diff --git a/bindings/python/notmuch/indexopts.py b/bindings/python/notmuch/indexopts.py
new file mode 100644
index 0000000..b0d4603
--- /dev/null
+++ b/bindings/python/notmuch/indexopts.py
@@ -0,0 +1,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)
--
2.7.0.rc3
next prev parent reply other threads:[~2016-01-31 20:40 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-31 20:39 Allow indexing cleartext of encrypted messages (v3) Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 01/16] add util/search-path.{c, h} to test for executables in $PATH Daniel Kahn Gillmor
2016-02-09 12:57 ` David Bremner
2016-02-09 21:52 ` [PATCH v4] " Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 02/16] Move crypto.c into libutil Daniel Kahn Gillmor
2016-02-10 2:21 ` David Bremner
2016-02-10 14:34 ` Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 03/16] make shared crypto code behave library-like Daniel Kahn Gillmor
2016-02-10 2:37 ` David Bremner
2016-02-10 16:18 ` Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 04/16] Provide _notmuch_crypto_{set,get}_gpg_path Daniel Kahn Gillmor
2016-02-10 11:45 ` David Bremner
2016-02-10 16:31 ` Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 05/16] Use a blank _notmuch_crypto to choose the default gpg_path Daniel Kahn Gillmor
2016-02-10 11:49 ` David Bremner
2016-02-10 16:37 ` Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 06/16] Prefer gpg2 in the test suite if available Daniel Kahn Gillmor
2016-02-10 11:54 ` David Bremner
2016-02-10 16:39 ` Daniel Kahn Gillmor
2016-02-10 20:28 ` David Bremner
2016-02-11 7:16 ` Tomi Ollila
2016-01-31 20:39 ` [PATCH v3 07/16] create a notmuch_indexopts_t index options object Daniel Kahn Gillmor
2016-02-27 13:06 ` David Bremner
2016-01-31 20:39 ` [PATCH v3 08/16] reorganize indexing of multipart/signed and multipart/encrypted Daniel Kahn Gillmor
2016-02-27 13:14 ` David Bremner
2016-01-31 20:39 ` [PATCH v3 09/16] index encrypted parts when asked Daniel Kahn Gillmor
2016-02-27 15:49 ` David Bremner
2016-01-31 20:39 ` [PATCH v3 10/16] Add n_d_add_message_with_indexopts (extension of n_d_add_message) Daniel Kahn Gillmor
2016-01-31 20:39 ` [PATCH v3 11/16] add --try-decrypt to notmuch insert Daniel Kahn Gillmor
2016-02-27 15:55 ` David Bremner
2016-01-31 20:39 ` [PATCH v3 12/16] add --try-decrypt to notmuch new Daniel Kahn Gillmor
2016-01-31 20:39 ` Daniel Kahn Gillmor [this message]
2016-02-28 14:22 ` [PATCH v3 13/16] add indexopts to notmuch python bindings David Bremner
2016-01-31 20:39 ` [PATCH v3 14/16] test indexing cleartext version of delivered messages Daniel Kahn Gillmor
2016-01-31 20:40 ` [PATCH v3 15/16] added notmuch_message_reindex Daniel Kahn Gillmor
2016-02-10 0:41 ` Jameson Graef Rollins
2016-02-10 1:01 ` Daniel Kahn Gillmor
2016-02-10 17:21 ` Daniel Kahn Gillmor
2016-02-13 18:13 ` David Bremner
2016-02-28 14:52 ` David Bremner
2016-01-31 20:40 ` [PATCH v3 16/16] add "notmuch reindex" subcommand Daniel Kahn Gillmor
2016-02-28 15:05 ` David Bremner
2016-02-06 20:48 ` Allow indexing cleartext of encrypted messages (v3) Tomi Ollila
2016-02-09 8:08 ` Jameson Graef Rollins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454272801-23623-14-git-send-email-dkg@fifthhorseman.net \
--to=dkg@fifthhorseman.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).