]> git.notmuchmail.org Git - notmuch/commitdiff
Implement Message().get|set_flag()
authorSebastian Spaeth <sebastian@sspaeth.de>
Thu, 25 Mar 2010 07:39:21 +0000 (08:39 +0100)
committerSebastian Spaeth <sebastian@sspaeth.de>
Thu, 25 Mar 2010 07:39:21 +0000 (08:39 +0100)
These were the last 2 missing methods from the Message object, which should be feature complete now.

cnotmuch/database.py
cnotmuch/message.py
cnotmuch/notmuch.py
docs/source/index.rst

index 321b9611ac2cf83af5a752040c87afba5087944a..e540bb3ce46dcb2670dcad31b5c11373145ee089 100644 (file)
@@ -1,4 +1,4 @@
-import ctypes, os
+import os
 from ctypes import c_int, c_char_p, c_void_p, c_uint, byref
 from cnotmuch.globals import nmlib, STATUS, NotmuchError, Enum
 from cnotmuch.thread import Threads
 from ctypes import c_int, c_char_p, c_void_p, c_uint, byref
 from cnotmuch.globals import nmlib, STATUS, NotmuchError, Enum
 from cnotmuch.thread import Threads
@@ -451,6 +451,10 @@ class Query(object):
         The returned threads are owned by the query and as such, will only be 
         valid until the Query is deleted.
 
         The returned threads are owned by the query and as such, will only be 
         valid until the Query is deleted.
 
+        The method sets :attr:`Message.FLAG`\.MATCH for those messages that
+        match the query. The method :meth:`Message.get_flag` allows us
+        to get the value of this flag.
+
         Technically, it wraps the underlying
         *notmuch_query_search_threads* function.
 
         Technically, it wraps the underlying
         *notmuch_query_search_threads* function.
 
index 3ff3e7f158fab4c66951d1ac42c718747df026b5..4ed480285f6c90f02893ffc36f38fbb145f86c7a 100644 (file)
@@ -1,6 +1,6 @@
-from ctypes import c_char_p, c_void_p, c_long
+from ctypes import c_char_p, c_void_p, c_long, c_bool
 from datetime import date
 from datetime import date
-from cnotmuch.globals import nmlib, STATUS, NotmuchError
+from cnotmuch.globals import nmlib, STATUS, NotmuchError, Enum
 from cnotmuch.tag import Tags
 #------------------------------------------------------------------------------
 class Messages(object):
 from cnotmuch.tag import Tags
 #------------------------------------------------------------------------------
 class Messages(object):
@@ -166,6 +166,10 @@ class Message(object):
     _get_filename = nmlib.notmuch_message_get_filename
     _get_filename.restype = c_char_p 
 
     _get_filename = nmlib.notmuch_message_get_filename
     _get_filename.restype = c_char_p 
 
+    """notmuch_message_get_flag"""
+    _get_flag = nmlib.notmuch_message_get_flag
+    _get_flag.restype = c_bool
+
     """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_message_id (notmuch_message_t *message)"""
     _get_message_id = nmlib.notmuch_message_get_message_id
     _get_message_id.restype = c_char_p 
@@ -188,6 +192,9 @@ class Message(object):
     _get_header = nmlib.notmuch_message_get_header
     _get_header.restype = c_char_p
 
     _get_header = nmlib.notmuch_message_get_header
     _get_header.restype = c_char_p
 
+    #Constants: Flags that can be set/get with set_flag
+    FLAG = Enum(['MATCH'])
+
     def __init__(self, msg_p, parent=None):
         """
         :param msg_p: A pointer to an internal notmuch_message_t
     def __init__(self, msg_p, parent=None):
         """
         :param msg_p: A pointer to an internal notmuch_message_t
@@ -315,6 +322,38 @@ class Message(object):
             raise NotmuchError(STATUS.NOT_INITIALIZED)
         return Message._get_filename(self._msg)
 
             raise NotmuchError(STATUS.NOT_INITIALIZED)
         return Message._get_filename(self._msg)
 
+    def get_flag(self, flag):
+        """Checks whether a specific flag is set for this message
+
+        The method :meth:`Query.search_threads` sets
+        *Message.FLAG.MATCH* for those messages that match the
+        query. This method allows us to get the value of this flag.
+
+        :param flag: One of the :attr:`Message.FLAG` values (currently only 
+                     *Message.FLAG.MATCH*
+        :returns: A bool, indicating whether the flag is set.
+        :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_flag(self._msg, flag)
+
+    def set_flag(self, flag, value):
+        """Sets/Unsets a specific flag for this message
+
+        :param flag: One of the :attr:`Message.FLAG` values (currently only 
+                     *Message.FLAG.MATCH*
+        :param value: A bool indicating whether to set or unset the flag.
+
+        :returns: Nothing
+        :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message 
+              is not initialized.
+        """
+        if self._msg is None:
+            raise NotmuchError(STATUS.NOT_INITIALIZED)
+        nmlib.notmuch_message_set_flag(self._msg, flag, value)
+
     def get_tags(self):
         """Returns the message tags
 
     def get_tags(self):
         """Returns the message tags
 
index 306940e95105c6fc149503eb84d545d63ee0003c..019da2afc37052f45d529bba79f4482021fb806c 100644 (file)
@@ -33,8 +33,8 @@
 
 """
 from database import Database, Query
 
 """
 from database import Database, Query
-from message import Messages
-from thread import Threads
+from message import Messages, Message
+from thread import Threads, Thread
 from tag import Tags
 from cnotmuch.globals import nmlib, STATUS, NotmuchError
 __LICENSE__="GPL v3+"
 from tag import Tags
 from cnotmuch.globals import nmlib, STATUS, NotmuchError
 __LICENSE__="GPL v3+"
index 4a6c574bdc85a8e1952be76f29b16d8fc8f7b5b2..89b8d6c1029bffc77e8a7a2ad68fa8023633c934 100644 (file)
@@ -140,7 +140,15 @@ More information on specific topics can be found on the following pages:
 
    .. automethod:: get_filename
 
 
    .. automethod:: get_filename
 
-   .. automethod:: get_flag
+   .. attribute:: FLAG
+
+        FLAG.MATCH 
+          This flag is automatically set by a
+         Query.search_threads on those messages that match the
+         query. This allows us to distinguish matches from the rest
+         of the messages in that thread.
+
+  .. automethod:: get_flag
 
    .. automethod:: set_flag
    
 
    .. automethod:: set_flag