X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=cnotmuch%2Fthread.py;h=5a2505c5207e0f8262af78905a5aabcf538dd142;hp=972f426b53b080e3d20c794c7054aec1fd23c090;hb=81a041d4cbc4aefae5d5e8c6f753fd68af62c27c;hpb=2a14b523b0982a6641e45b48099e65dfe1bb4f6a diff --git a/cnotmuch/thread.py b/cnotmuch/thread.py index 972f426b..5a2505c5 100644 --- a/cnotmuch/thread.py +++ b/cnotmuch/thread.py @@ -1,6 +1,7 @@ -from ctypes import c_char_p, c_void_p, c_uint64 -from cnotmuch.globals import nmlib, STATUS, NotmuchError, Enum -from cnotmuch.tags import Tags +from ctypes import c_char_p, c_void_p, c_long +from cnotmuch.globals import nmlib, STATUS, NotmuchError +from cnotmuch.message import Messages +from cnotmuch.tag import Tags from datetime import date #------------------------------------------------------------------------------ @@ -144,11 +145,15 @@ class Thread(object): _get_subject = nmlib.notmuch_thread_get_subject _get_subject.restype = c_char_p + """notmuch_thread_get_toplevel_messages""" + _get_toplevel_messages = nmlib.notmuch_thread_get_toplevel_messages + _get_toplevel_messages.restype = c_void_p + _get_newest_date = nmlib.notmuch_thread_get_newest_date - _get_newest_date.restype = c_uint64 + _get_newest_date.restype = c_long _get_oldest_date = nmlib.notmuch_thread_get_oldest_date - _get_oldest_date.restype = c_uint64 + _get_oldest_date.restype = c_long """notmuch_thread_get_tags""" _get_tags = nmlib.notmuch_thread_get_tags @@ -203,7 +208,34 @@ class Thread(object): return nmlib.notmuch_thread_get_total_messages(self._thread) - ###TODO: notmuch_messages_t * notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread); + def get_toplevel_messages(self): + """Returns a :class:`Messages` iterator for the top-level messages in + 'thread' + + This iterator will not necessarily iterate over all of the messages + in the thread. It will only iterate over the messages in the thread + which are not replies to other messages in the thread. + + To iterate over all messages in the thread, the caller will need to + iterate over the result of :meth:`Message.get_replies` for each + top-level message (and do that recursively for the resulting + messages, etc.). + + :returns: :class:`Messages` + :exception: :exc:`NotmuchError` + + * STATUS.NOT_INITIALIZED if query is not inited + * STATUS.NULL_POINTER if search_messages failed + """ + if self._thread is None: + raise NotmuchError(STATUS.NOT_INITIALIZED) + + msgs_p = Thread._get_toplevel_messages(self._thread) + + if msgs_p is None: + NotmuchError(STATUS.NULL_POINTER) + + return Messages(msgs_p,self) def get_matched_messages(self): """Returns the number of messages in 'thread' that matched the query