+
+#------------------------------------------------------------------------------
+class Message(object):
+ """Wrapper around notmuch_message_t"""
+
+ """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_tags (notmuch_message_t *message)"""
+ _get_tags = nmlib.notmuch_message_get_tags
+ _get_tags.restype = c_void_p
+
+ def __init__(self, msg_p, parent=None):
+ """
+ msg_p is a pointer to an notmuch_message_t Structure. If it is None,
+ we will raise an NotmuchError(STATUS.NULL_POINTER).
+
+ Is a 'parent' object is passed which this message is derived from,
+ we save a reference to it, so we can automatically delete the parent
+ object once all derived objects are dead.
+ """
+ if msg_p is None:
+ NotmuchError(STATUS.NULL_POINTER)
+ self._msg = msg_p
+ self._parent = parent
+ print "Inited Message derived from %s" %(str(parent))
+
+
+ def get_message_id(self):
+ """ return the msg id
+
+ Raises NotmuchError(STATUS.NOT_INITIALIZED) if not inited
+ """
+ if self._msg is None:
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
+ return Message._get_message_id(self._msg)
+
+
+ def get_filename(self):
+ """ return the msg filename
+
+ Raises NotmuchError(STATUS.NOT_INITIALIZED) if not inited
+ """
+ if self._msg is None:
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
+ return Message._get_filename(self._msg)
+
+ def get_tags(self):
+ """ return the msg tags
+
+ Raises NotmuchError(STATUS.NOT_INITIALIZED) if not inited
+ Raises NotmuchError(STATUS.NULL_POINTER) on error.
+ """
+ if self._msg is None:
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
+
+ tags_p = Message._get_tags(self._msg)
+ if tags_p == None:
+ raise NotmuchError(STATUS.NULL_POINTER)
+ return Tags(tags_p, self)
+
+ def __del__(self):
+ """Close and free the notmuch Message"""
+ if self._msg is not None:
+ print("Freeing the Message now")
+ nmlib.notmuch_message_destroy (self._msg)