X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bindings%2Fpython%2Fnotmuch%2Fthread.py;h=9aa0e08cec90ba212fa481bfc0aac1e26c293509;hb=5d510221d17862a252955d98046508bebcd14573;hp=0dac522c5aa30a8477afd65a1fe9a9a006a5306e;hpb=76a2db3d7b92bc1a8be75f673dc384c46cf02fab;p=notmuch
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 0dac522c..9aa0e08c 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -12,22 +12,24 @@ 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
-along with notmuch. If not, see .
+along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p, c_long, c_int
-from notmuch.globals import (
+from .globals import (
nmlib,
- NullPointerError,
- NotInitializedError,
NotmuchThreadP,
NotmuchMessagesP,
NotmuchTagsP,
)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
from .messages import Messages
-from notmuch.tag import Tags
+from .tag import Tags
from datetime import date
class Thread(object):
@@ -69,7 +71,7 @@ class Thread(object):
def __init__(self, thread_p, parent=None):
"""
:param thread_p: A pointer to an internal notmuch_thread_t
- Structure. These are not publically exposed, so a user
+ Structure. These are not publicly exposed, so a user
will almost never instantiate a :class:`Thread` object
herself. They are usually handed back as a result,
e.g. when iterating through :class:`Threads`. *thread_p*
@@ -126,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.
- 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
@@ -145,6 +142,28 @@ class Thread(object):
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
@@ -226,7 +245,7 @@ class Thread(object):
The :class:`Tags` object is owned by the thread and as such, will only
be valid for as long as this :class:`Thread` is valid (e.g. until the
- query from which it derived is explicitely deleted).
+ query from which it derived is explicitly deleted).
:returns: A :class:`Tags` iterator.
:raises: :exc:`NotInitializedError` if query is not initialized
@@ -236,7 +255,7 @@ class Thread(object):
raise NotInitializedError()
tags_p = Thread._get_tags(self._thread)
- if tags_p == None:
+ if not tags_p:
raise NullPointerError()
return Tags(tags_p, self)
@@ -258,5 +277,5 @@ class Thread(object):
def __del__(self):
"""Close and free the notmuch Thread"""
- if self._thread is not None:
+ if self._thread:
self._destroy(self._thread)