1 Return-Path: <glasse@cs.rpi.edu>
\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 olra.theworths.org (Postfix) with ESMTP id 3E774429E43
\r
6 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:06:01 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,
\r
14 RCVD_IN_SORBS_WEB=0.614] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id AGWL35BsDslV for <notmuch@notmuchmail.org>;
\r
18 Wed, 15 Feb 2012 14:05:57 -0800 (PST)
\r
19 Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu
\r
20 [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
21 (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS
\r
22 id 4865F431E84 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:05:57 -0800
\r
25 S|a5576c7a0879cdcb947f4f187d2cb881f84fe767|3108d4ff51f659d951563fa092480fc6
\r
26 X-Countries: Cameroon, United States
\r
27 X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]
\r
28 (localhost) {Cameroon}
\r
29 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from
\r
30 :to:cc:subject:date:message-id:in-reply-to:references; s=
\r
31 default; i=glasse@cs.rpi.edu; t=1329343555; x=1329948355; l=6302;
\r
32 bh=xqCkkenyPqaR9+qkgrhnSOEGp8c=; b=E28AwTlbi+ZvfI6i/WJgSSd
\r
33 72/sQMaeuBwnOkH8K8DYEAJb75uImAOaBOrTAXNBka7xQoE2E6X6dnujDSCiucSF
\r
34 +6tfHj1+b9jFt8IICMX1GvjIJOC4gcGnmbGO8Iuo93HwkQitBzJqgpPecb3heRFR
\r
35 88ZyxZ4cBo+wo6x0nkyA=
\r
36 DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc
\r
37 :subject:date:message-id:in-reply-to:references; q=dns; s=
\r
38 default; b=Xmcurs/GUda4Y5HviM8tJTMfcm4qcwtMVwxRTv+hksoFexm4N9Ai7
\r
39 0CtFflAdbYASlcgG/SK82SeklNukDlLjprgdbW8sCkKiIbq8RmDZ83+3FbD6z/Ea
\r
40 9IckCs1CRKzPQcZkJrZ57TXBAHCWW7o3v4pCKJHgJpKUVoVLSpXbek=
\r
41 X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00
\r
42 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit
\r
44 Authentication-Results: cliffclavin.cs.rpi.edu;
\r
45 DKIM=neutral (none) header.from=glasse@cs.rpi.edu;
\r
47 Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu
\r
48 X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FM5RID008763 Auth:glasse
\r
49 X-Virus-Scanned-By: cliffclavin.cs.rpi.edu
\r
50 Received: from localhost ([195.24.209.20]) (authenticated bits=0)
\r
51 by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FM5RID008763
\r
52 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);
\r
53 Wed, 15 Feb 2012 17:05:40 -0500 (EST)
\r
54 (envelope-from glasse@cs.rpi.edu)
\r
55 From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
\r
56 To: notmuch@notmuchmail.org
\r
57 Subject: [RFC PATCH 03/13] Introduce mailstore in the python bindings
\r
58 Date: Wed, 15 Feb 2012 17:01:56 -0500
\r
59 Message-Id: <1329343326-16410-4-git-send-email-glasse@cs.rpi.edu>
\r
60 X-Mailer: git-send-email 1.7.5.4
\r
61 In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
62 References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
63 X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25
\r
64 Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
65 X-BeenThere: notmuch@notmuchmail.org
\r
66 X-Mailman-Version: 2.1.13
\r
68 List-Id: "Use and development of the notmuch mail system."
\r
69 <notmuch.notmuchmail.org>
\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
73 List-Post: <mailto:notmuch@notmuchmail.org>
\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
76 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
77 X-List-Received-Date: Wed, 15 Feb 2012 22:06:01 -0000
\r
79 From: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
82 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
84 bindings/python/notmuch/database.py | 31 +++++++++++++++++---------
\r
85 bindings/python/notmuch/globals.py | 3 ++
\r
86 bindings/python/notmuch/mailstore.py | 38 ++++++++++++++++++++++++++++++++++
\r
87 3 files changed, 61 insertions(+), 11 deletions(-)
\r
88 create mode 100644 bindings/python/notmuch/mailstore.py
\r
90 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
\r
91 index 36b65ec..638ade3 100644
\r
92 --- a/bindings/python/notmuch/database.py
\r
93 +++ b/bindings/python/notmuch/database.py
\r
94 @@ -23,7 +23,9 @@ from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
\r
95 from notmuch.globals import (nmlib, STATUS, NotmuchError, NotInitializedError,
\r
96 NullPointerError, Enum, _str,
\r
97 NotmuchDatabaseP, NotmuchDirectoryP, NotmuchMessageP, NotmuchTagsP,
\r
98 - NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP)
\r
99 + NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP,
\r
100 + NotmuchMailstoreP)
\r
101 +from notmuch.mailstore import Mailstore
\r
102 from notmuch.thread import Threads
\r
103 from notmuch.message import Messages, Message
\r
104 from notmuch.tag import Tags
\r
105 @@ -78,7 +80,7 @@ class Database(object):
\r
107 """notmuch_database_open"""
\r
108 _open = nmlib.notmuch_database_open
\r
109 - _open.argtypes = [c_char_p, c_uint]
\r
110 + _open.argtypes = [NotmuchMailstoreP, c_char_p, c_uint]
\r
111 _open.restype = NotmuchDatabaseP
\r
113 """notmuch_database_upgrade"""
\r
114 @@ -105,11 +107,13 @@ class Database(object):
\r
116 """notmuch_database_create"""
\r
117 _create = nmlib.notmuch_database_create
\r
118 - _create.argtypes = [c_char_p]
\r
119 + _create.argtypes = [NotmuchMailstoreP, c_char_p]
\r
120 _create.restype = NotmuchDatabaseP
\r
122 - def __init__(self, path=None, create=False, mode=0):
\r
123 - """If *path* is `None`, we will try to read a users notmuch
\r
124 + def __init__(self, mailstore=None, path=None, create=False, mode=0):
\r
125 + """If *mailstore* is `None`, we will just use 'maildir'.
\r
127 + If *path* is `None`, we will try to read a users notmuch
\r
128 configuration and use his configured database. The location of the
\r
129 configuration file can be specified through the environment variable
\r
130 *NOTMUCH_CONFIG*, falling back to the default `~/.notmuch-config`.
\r
131 @@ -130,6 +134,9 @@ class Database(object):
\r
135 + if mailstore == None:
\r
136 + mailstore = Mailstore('maildir')
\r
139 # no path specified. use a user's default database
\r
140 if Database._std_db_path is None:
\r
141 @@ -138,16 +145,16 @@ class Database(object):
\r
142 path = Database._std_db_path
\r
144 if create == False:
\r
145 - self.open(path, mode)
\r
146 + self.open(mailstore, path, mode)
\r
148 - self.create(path)
\r
149 + self.create(mailstore, path)
\r
151 def _assert_db_is_initialized(self):
\r
152 """Raises :exc:`NotInitializedError` if self._db is `None`"""
\r
153 if self._db is None:
\r
154 raise NotInitializedError()
\r
156 - def create(self, path):
\r
157 + def create(self, mailstore, path):
\r
158 """Creates a new notmuch database
\r
160 This function is used by __init__() and usually does not need
\r
161 @@ -167,14 +174,15 @@ class Database(object):
\r
162 raise NotmuchError(message="Cannot create db, this Database() "
\r
163 "already has an open one.")
\r
165 - res = Database._create(_str(path), Database.MODE.READ_WRITE)
\r
166 + mailstore = mailstore._mailstore
\r
167 + res = Database._create(mailstore, _str(path), Database.MODE.READ_WRITE)
\r
170 raise NotmuchError(
\r
171 message="Could not create the specified database")
\r
174 - def open(self, path, mode=0):
\r
175 + def open(self, mailstore, path, mode=0):
\r
176 """Opens an existing database
\r
178 This function is used by __init__() and usually does not need
\r
179 @@ -187,7 +195,8 @@ class Database(object):
\r
180 :exception: Raises :exc:`NotmuchError` in case of any failure
\r
181 (possibly after printing an error message on stderr).
\r
183 - res = Database._open(_str(path), mode)
\r
184 + mailstore = mailstore._mailstore # unwrap mailstore
\r
185 + res = Database._open(mailstore, _str(path), mode)
\r
188 raise NotmuchError(message="Could not open the specified database")
\r
189 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
\r
190 index 4138460..5f01dce 100644
\r
191 --- a/bindings/python/notmuch/globals.py
\r
192 +++ b/bindings/python/notmuch/globals.py
\r
193 @@ -228,6 +228,9 @@ class NotmuchDatabaseS(Structure):
\r
195 NotmuchDatabaseP = POINTER(NotmuchDatabaseS)
\r
197 +class NotmuchMailstoreS(Structure):
\r
199 +NotmuchMailstoreP = POINTER(NotmuchMailstoreS)
\r
201 class NotmuchQueryS(Structure):
\r
203 diff --git a/bindings/python/notmuch/mailstore.py b/bindings/python/notmuch/mailstore.py
\r
204 new file mode 100644
\r
205 index 0000000..315ea70
\r
207 +++ b/bindings/python/notmuch/mailstore.py
\r
210 +This file is part of notmuch.
\r
212 +Notmuch is free software: you can redistribute it and/or modify it
\r
213 +under the terms of the GNU General Public License as published by the
\r
214 +Free Software Foundation, either version 3 of the License, or (at your
\r
215 +option) any later version.
\r
217 +Notmuch is distributed in the hope that it will be useful, but WITHOUT
\r
218 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
219 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
222 +You should have received a copy of the GNU General Public License
\r
223 +along with notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
225 +Copyright 2012 Ethan Glasser-Camp <ethan@betacantrips.com>'
\r
228 +# This is all kind of cargo-culted from database.py. I hope someone
\r
229 +# else takes a good look at this!
\r
232 +from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
\r
233 +from notmuch.globals import (nmlib, STATUS, NotmuchError, NotInitializedError,
\r
234 + NullPointerError, Enum, _str,
\r
235 + NotmuchDatabaseP, NotmuchDirectoryP, NotmuchMessageP, NotmuchTagsP,
\r
236 + NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP,
\r
237 + NotmuchMailstoreP,)
\r
239 +class Mailstore(object):
\r
240 + """The :class:`Mailstore` represents "where the mail lives"."""
\r
241 + _get_by_name = nmlib.notmuch_mailstore_get_by_name
\r
242 + _get_by_name.argtypes = [c_char_p]
\r
243 + _get_by_name.restype = NotmuchMailstoreP
\r
245 + def __init__(self, type=None, path=None):
\r
246 + self._mailstore = self._get_by_name(type)
\r