X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=cnotmuch%2Fdatabase.py;h=19460b339e6d9942b093c3155fa6c3575a78e432;hp=8313813ce85e67903b3ccc12809713e4718986e2;hb=3b2d73c684501e2eb906542f5081125d4e9c485d;hpb=d099b79fd1c4d1248a3221c9994be51bbff898e8 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: