2 This file is part of notmuch.
4 Notmuch is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation, either version 3 of the License, or (at your
7 option) any later version.
9 Notmuch is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with notmuch. If not, see <http://www.gnu.org/licenses/>.
17 Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
20 from ctypes import CDLL, Structure, POINTER
22 #-----------------------------------------------------------------------------
23 #package-global instance of the notmuch library
25 nmlib = CDLL("libnotmuch.so.2")
27 raise ImportError("Could not find shared 'notmuch' library.")
30 if sys.version_info[0] == 2:
31 class Python3StringMixIn(object):
33 return unicode(self).encode('utf-8')
37 """Ensure a nicely utf-8 encoded string to pass to libnotmuch
39 C++ code expects strings to be well formatted and
40 unicode strings to have no null bytes."""
41 if not isinstance(value, basestring):
42 raise TypeError("Expected str or unicode, got %s" % type(value))
43 if isinstance(value, unicode):
44 return value.encode('UTF-8')
47 class Python3StringMixIn(object):
49 return self.__unicode__()
53 """Ensure a nicely utf-8 encoded string to pass to libnotmuch
55 C++ code expects strings to be well formatted and
56 unicode strings to have no null bytes."""
57 if not isinstance(value, str):
58 raise TypeError("Expected str, got %s" % type(value))
59 return value.encode('UTF-8')
63 """Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc..."""
64 def __init__(self, names):
65 for number, name in enumerate(names):
66 setattr(self, name, number)
69 class NotmuchDatabaseS(Structure):
71 NotmuchDatabaseP = POINTER(NotmuchDatabaseS)
74 class NotmuchQueryS(Structure):
76 NotmuchQueryP = POINTER(NotmuchQueryS)
79 class NotmuchThreadsS(Structure):
81 NotmuchThreadsP = POINTER(NotmuchThreadsS)
84 class NotmuchThreadS(Structure):
86 NotmuchThreadP = POINTER(NotmuchThreadS)
89 class NotmuchMessagesS(Structure):
91 NotmuchMessagesP = POINTER(NotmuchMessagesS)
94 class NotmuchMessageS(Structure):
96 NotmuchMessageP = POINTER(NotmuchMessageS)
99 class NotmuchTagsS(Structure):
101 NotmuchTagsP = POINTER(NotmuchTagsS)
104 class NotmuchDirectoryS(Structure):
106 NotmuchDirectoryP = POINTER(NotmuchDirectoryS)
109 class NotmuchFilenamesS(Structure):
111 NotmuchFilenamesP = POINTER(NotmuchFilenamesS)