aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Spaeth <sebastian@sspaeth.de>2010-03-16 15:53:54 +0100
committerSebastian Spaeth <sebastian@sspaeth.de>2010-03-16 15:53:54 +0100
commit3b2d73c684501e2eb906542f5081125d4e9c485d (patch)
treeb7b469891726ba0a39dd29f1a8911a5e5bf6787f
parentd099b79fd1c4d1248a3221c9994be51bbff898e8 (diff)
implement message counting
--HG-- extra : transplant_source : %8E%83%C2%83%FA%F8X%B6%16%1D%D3X%C4o%A2%A8%28%11G%AF
-rw-r--r--cnotmuch/database.py18
-rwxr-xr-xnotmuch11
2 files changed, 29 insertions, 0 deletions
diff --git a/cnotmuch/database.py b/cnotmuch/database.py
index 8313813c..19460b33 100644
--- a/cnotmuch/database.py
+++ b/cnotmuch/database.py
@@ -329,6 +329,24 @@ class Messages(object):
nmlib.notmuch_messages_move_to_next(self._msgs)
return msg
+ def __len__(self):
+ """ Returns the number of contained messages
+
+ :note: As this iterates over the messages, we will not be able to
+ iterate over them again (as in retrieve them)!
+ """
+ if self._msgs is None:
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
+
+ i=0
+ while nmlib.notmuch_messages_valid(self._msgs):
+ nmlib.notmuch_messages_move_to_next(self._msgs)
+ i += 1
+ self._msgs = None
+ return i
+
+
+
def __del__(self):
"""Close and free the notmuch Messages"""
if self._msgs is not None:
diff --git a/notmuch b/notmuch
index 6f002aac..56f961b4 100755
--- a/notmuch
+++ b/notmuch
@@ -115,6 +115,17 @@ if __name__ == '__main__':
#TODO: handle --verbose
print "Not implemented."
+ elif sys.argv[1] == 'count':
+ db = Database()
+ if len(sys.argv) == 2:
+ #no further search term
+ querystr=''
+ else:
+ #mangle arguments wrapping terms with spaces in quotes
+ querystr = quote_query_line(sys.argv[2:])
+ logging.debug("count "+querystr)
+ print(len(Query(db,querystr).search_messages()))
+
elif sys.argv[1] == 'search-tags':
if len(sys.argv) == 2:
#no further search term