]> git.cworth.org Git - notmuch/blobdiff - cnotmuch/database.py
implement Message.get_thread_id()
[notmuch] / cnotmuch / database.py
index 6a74f5d58014eaafeaef4e79b4d0d936b0d77442..0ae24ec245b53f8bbbb191739f6271e806fb6b95 100644 (file)
@@ -252,7 +252,7 @@ class Query(object):
 
 
     """notmuch_query_count_messages"""
-    _count_messages = _nmlib.notmuch_query_count_messages
+    _count_messages = nmlib.notmuch_query_count_messages
     _count_messages.restype = c_uint
 
     def __init__(self, db, querystr):
@@ -336,9 +336,10 @@ class Query(object):
         """Estimate the number of messages matching the query
 
         This function performs a search and returns Xapian's best
-        guess as to the number of matching messages. It is somewhat
-        faster than performing :meth:`search_messages` and counting
-        the result with `len()`. Technically, it wraps the underlying
+        guess as to the number of matching messages. It is much faster
+        than performing :meth:`search_messages` and counting the
+        result with `len()` (although it always returned the same
+        result in my tests). Technically, it wraps the underlying
         *notmuch_query_count_messages* function.
 
         :returns: :class:`Messages`
@@ -619,10 +620,15 @@ class Message(object):
     """notmuch_message_get_filename (notmuch_message_t *message)"""
     _get_filename = nmlib.notmuch_message_get_filename
     _get_filename.restype = c_char_p 
+
     """notmuch_message_get_message_id (notmuch_message_t *message)"""
     _get_message_id = nmlib.notmuch_message_get_message_id
     _get_message_id.restype = c_char_p 
 
+    """notmuch_message_get_thread_id"""
+    _get_thread_id = nmlib.notmuch_message_get_thread_id
+    _get_thread_id.restype = c_char_p
+
     """notmuch_message_get_tags (notmuch_message_t *message)"""
     _get_tags = nmlib.notmuch_message_get_tags
     _get_tags.restype = c_void_p
@@ -652,7 +658,7 @@ class Message(object):
 
 
     def get_message_id(self):
-        """Return the message ID
+        """Returns the message ID
         
         :returns: String with a message ID
         :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message 
@@ -662,6 +668,24 @@ class Message(object):
             raise NotmuchError(STATUS.NOT_INITIALIZED)
         return Message._get_message_id(self._msg)
 
+    def get_thread_id(self):
+        """Returns the thread ID
+
+        The returned string belongs to 'message' will only be valid for as 
+        long as the message is valid.
+
+        This function will not return None since Notmuch ensures that every
+        message belongs to a single thread.
+
+        :returns: String with a thread ID
+        :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message 
+                    is not initialized.
+        """
+        if self._msg is None:
+            raise NotmuchError(STATUS.NOT_INITIALIZED)
+
+        return Message._get_thread_id (self._msg);
+
     def get_date(self):
         """Returns time_t of the message date