]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python/notmuch/thread.py
Merge branch 'release'
[notmuch] / bindings / python / notmuch / thread.py
index a759c90974d267d44277e789d99e1f5bc5f2f68f..cc151f7e2142eb4bbce751157e2a659497d647aa 100644 (file)
@@ -12,13 +12,13 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with notmuch.  If not, see <http://www.gnu.org/licenses/>.
+along with notmuch.  If not, see <https://www.gnu.org/licenses/>.
 
 
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
 """
 
 from ctypes import c_char_p, c_long, c_int
 """
 
 from ctypes import c_char_p, c_long, c_int
-from notmuch.globals import (
+from .globals import (
     nmlib,
     NotmuchThreadP,
     NotmuchMessagesP,
     nmlib,
     NotmuchThreadP,
     NotmuchMessagesP,
@@ -29,7 +29,7 @@ from .errors import (
     NotInitializedError,
 )
 from .messages import Messages
     NotInitializedError,
 )
 from .messages import Messages
-from notmuch.tag import Tags
+from .tag import Tags
 from datetime import date
 
 class Thread(object):
 from datetime import date
 
 class Thread(object):
@@ -128,11 +128,6 @@ class Thread(object):
            in the thread. It will only iterate over the messages in the thread
            which are not replies to other messages in the thread.
 
            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`
         :raises: :exc:`NotInitializedError` if query is not initialized
         :raises: :exc:`NullPointerError` if search_messages failed
         :returns: :class:`Messages`
         :raises: :exc:`NotInitializedError` if query is not initialized
         :raises: :exc:`NullPointerError` if search_messages failed
@@ -147,6 +142,28 @@ class Thread(object):
 
         return Messages(msgs_p, self)
 
 
         return Messages(msgs_p, self)
 
+    """notmuch_thread_get_messages"""
+    _get_messages = nmlib.notmuch_thread_get_messages
+    _get_messages.argtypes = [NotmuchThreadP]
+    _get_messages.restype = NotmuchMessagesP
+
+    def get_messages(self):
+        """Returns a :class:`Messages` iterator for all messages in 'thread'
+
+        :returns: :class:`Messages`
+        :raises: :exc:`NotInitializedError` if query is not initialized
+        :raises: :exc:`NullPointerError` if get_messages failed
+        """
+        if not self._thread:
+            raise NotInitializedError()
+
+        msgs_p = Thread._get_messages(self._thread)
+
+        if not msgs_p:
+            raise NullPointerError()
+
+        return Messages(msgs_p, self)
+
     _get_matched_messages = nmlib.notmuch_thread_get_matched_messages
     _get_matched_messages.argtypes = [NotmuchThreadP]
     _get_matched_messages.restype = c_int
     _get_matched_messages = nmlib.notmuch_thread_get_matched_messages
     _get_matched_messages.argtypes = [NotmuchThreadP]
     _get_matched_messages.restype = c_int
@@ -238,7 +255,7 @@ class Thread(object):
             raise NotInitializedError()
 
         tags_p = Thread._get_tags(self._thread)
             raise NotInitializedError()
 
         tags_p = Thread._get_tags(self._thread)
-        if tags_p == None:
+        if not tags_p:
             raise NullPointerError()
         return Tags(tags_p, self)
 
             raise NullPointerError()
         return Tags(tags_p, self)
 
@@ -260,5 +277,5 @@ class Thread(object):
 
     def __del__(self):
         """Close and free the notmuch Thread"""
 
     def __del__(self):
         """Close and free the notmuch Thread"""
-        if self._thread is not None:
+        if self._thread:
             self._destroy(self._thread)
             self._destroy(self._thread)