5
5
import time
6
6
import logging
7
7
8
- import notmuch
8
+ import notmuch2
9
9
10
10
from afew .NotmuchSettings import notmuch_settings , get_notmuch_new_tags
11
11
@@ -48,17 +48,17 @@ def __exit__(self, exc_type, exc_value, traceback):
48
48
49
49
def open (self , rw = False , retry_for = 180 , retry_delay = 1 , create = False ):
50
50
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 :
52
52
return self .handle
53
53
54
54
start_time = time .time ()
55
55
while True :
56
56
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 )
60
60
break
61
- except notmuch .NotmuchError :
61
+ except notmuch2 .NotmuchError :
62
62
time_left = int (retry_for - (time .time () - start_time ))
63
63
64
64
if time_left <= 0 :
@@ -71,7 +71,8 @@ def open(self, rw=False, retry_for=180, retry_delay=1, create=False):
71
71
time .sleep (retry_delay )
72
72
else :
73
73
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 )
75
76
76
77
return self .handle
77
78
@@ -93,7 +94,7 @@ def do_query(self, query):
93
94
:rtype: :class:`notmuch.Query`
94
95
"""
95
96
logging .debug ('Executing query %r' % query )
96
- return notmuch . Query (self .open (), query )
97
+ return notmuch2 . Database . messages (self .open (), query )
97
98
98
99
def get_messages (self , query , full_thread = False ):
99
100
"""
@@ -106,10 +107,10 @@ def get_messages(self, query, full_thread=False):
106
107
:returns: an iterator over :class:`notmuch.Message` objects
107
108
"""
108
109
if not full_thread :
109
- for message in self .do_query (query ). search_messages () :
110
+ for message in self .do_query (query ):
110
111
yield message
111
112
else :
112
- for thread in self .do_query (query ). search_threads () :
113
+ for thread in self .do_query (query ):
113
114
for message in self .walk_thread (thread ):
114
115
yield message
115
116
@@ -163,12 +164,12 @@ def add_message(self, path, sync_maildir_flags=False, new_mail_handler=None):
163
164
"""
164
165
# TODO: it would be nice to update notmuchs directory index here
165
166
handle = self .open (rw = True )
166
- if hasattr (notmuch .Database , 'index_file' ):
167
+ if hasattr (notmuch2 .Database , 'index_file' ):
167
168
message , status = handle .index_file (path , sync_maildir_flags = sync_maildir_flags )
168
169
else :
169
170
message , status = handle .add_message (path , sync_maildir_flags = sync_maildir_flags )
170
171
171
- if status != notmuch .STATUS .DUPLICATE_MESSAGE_ID :
172
+ if status != notmuch2 .STATUS .DUPLICATE_MESSAGE_ID :
172
173
logging .info ('Found new mail in {}' .format (path ))
173
174
174
175
for tag in get_notmuch_new_tags ():
0 commit comments