Skip to content

Commit 283ee15

Browse files
Upgrade Database to notmuch2 python module afewmail#278
Signed-off-by: Guillaume Seren <[email protected]>
1 parent 0840dca commit 283ee15

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

afew/Database.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
import logging
77

8-
import notmuch
8+
import notmuch2
99

1010
from afew.NotmuchSettings import notmuch_settings, get_notmuch_new_tags
1111

@@ -48,17 +48,17 @@ def __exit__(self, exc_type, exc_value, traceback):
4848

4949
def open(self, rw=False, retry_for=180, retry_delay=1, create=False):
5050
if rw:
51-
if self.handle and self.handle.mode == notmuch.Database.MODE.READ_WRITE:
51+
if self.handle and self.handle.mode == notmuch2.Database.MODE.READ_WRITE:
5252
return self.handle
5353

5454
start_time = time.time()
5555
while True:
5656
try:
57-
self.handle = notmuch.Database(self.db_path,
58-
mode=notmuch.Database.MODE.READ_WRITE,
59-
create=create)
57+
self.handle = notmuch2.Database(self.db_path,
58+
mode=notmuch2.Database.MODE.READ_WRITE,
59+
create=create)
6060
break
61-
except notmuch.NotmuchError:
61+
except notmuch2.NotmuchError:
6262
time_left = int(retry_for - (time.time() - start_time))
6363

6464
if time_left <= 0:
@@ -71,7 +71,8 @@ def open(self, rw=False, retry_for=180, retry_delay=1, create=False):
7171
time.sleep(retry_delay)
7272
else:
7373
if not self.handle:
74-
self.handle = notmuch.Database(self.db_path, create=create)
74+
self.handle = notmuch2.Database(self.db_path,
75+
mode=notmuch2.Database.MODE.READ_WRITE)
7576

7677
return self.handle
7778

@@ -93,7 +94,7 @@ def do_query(self, query):
9394
:rtype: :class:`notmuch.Query`
9495
"""
9596
logging.debug('Executing query %r' % query)
96-
return notmuch.Query(self.open(), query)
97+
return notmuch2.Database.messages(self.open(), query)
9798

9899
def get_messages(self, query, full_thread=False):
99100
"""
@@ -106,10 +107,10 @@ def get_messages(self, query, full_thread=False):
106107
:returns: an iterator over :class:`notmuch.Message` objects
107108
"""
108109
if not full_thread:
109-
for message in self.do_query(query).search_messages():
110+
for message in self.do_query(query):
110111
yield message
111112
else:
112-
for thread in self.do_query(query).search_threads():
113+
for thread in self.do_query(query):
113114
for message in self.walk_thread(thread):
114115
yield message
115116

@@ -163,12 +164,12 @@ def add_message(self, path, sync_maildir_flags=False, new_mail_handler=None):
163164
"""
164165
# TODO: it would be nice to update notmuchs directory index here
165166
handle = self.open(rw=True)
166-
if hasattr(notmuch.Database, 'index_file'):
167+
if hasattr(notmuch2.Database, 'index_file'):
167168
message, status = handle.index_file(path, sync_maildir_flags=sync_maildir_flags)
168169
else:
169170
message, status = handle.add_message(path, sync_maildir_flags=sync_maildir_flags)
170171

171-
if status != notmuch.STATUS.DUPLICATE_MESSAGE_ID:
172+
if status != notmuch2.STATUS.DUPLICATE_MESSAGE_ID:
172173
logging.info('Found new mail in {}'.format(path))
173174

174175
for tag in get_notmuch_new_tags():

0 commit comments

Comments
 (0)