class Message(base.NotmuchObject):
- """An email message stored in the notmuch database.
+ """An email message stored in the notmuch database retrieved via a query.
This should not be directly created, instead it will be returned
by calling methods on :class:`Database`. A message keeps a
@property
def alive(self):
- if not self._parent.alive:
- return False
- try:
- self._msg_p
- except errors.ObjectDestroyedError:
- return False
- else:
- return True
-
- def __del__(self):
- self._destroy()
+ return self._parent.alive
def _destroy(self):
- if self.alive:
- capi.lib.notmuch_message_destroy(self._msg_p)
- self._msg_p = None
+ pass
@property
def messageid(self):
bytes() on it will return the original bytes used to create
it.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_get_message_id(self._msg_p)
return base.BinString(capi.ffi.string(ret))
bytes() on it will return the original bytes used to create
it.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_get_thread_id(self._msg_p)
return base.BinString(capi.ffi.string(ret))
If multiple files in the database contain the same message ID
this will be just one of the files, chosen at random.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_get_filename(self._msg_p)
return pathlib.Path(os.fsdecode(capi.ffi.string(ret)))
See :attr:`path` for details, this is the same but does return
the path as a bytes object which is faster but less convenient.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_get_filename(self._msg_p)
return capi.ffi.string(ret)
:returns: Iterator yielding :class:`pathlib.Path` instances.
:rtype: iter
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
fnames_p = capi.lib.notmuch_message_get_filenames(self._msg_p)
return PathIter(self, fnames_p)
:returns: Iterator yielding :class:`bytes` instances.
:rtype: iter
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
fnames_p = capi.lib.notmuch_message_get_filenames(self._msg_p)
return FilenamesIter(self, fnames_p)
:attr:`messageid` and :attr:`threadid` attributes are valid
for it.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_get_flag(
self._msg_p, capi.lib.NOTMUCH_MESSAGE_FLAG_GHOST)
these messages to be flagged, which results in this property
being set to *True*.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_get_flag(
self._msg_p, capi.lib.NOTMUCH_MESSAGE_FLAG_EXCLUDED)
message's header, you can get the original header value with
:meth:`header`.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
return capi.lib.notmuch_message_get_date(self._msg_p)
:raises LookupError: if the header is not present.
:raises NullPointerError: For unexpected notmuch errors.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
# The returned is supposedly guaranteed to be UTF-8. Header
# names must be ASCII as per RFC x822.
:raises ReadOnlyDatabaseError: When manipulating tags on a
database opened in read-only mode.
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
try:
ref = self._cached_tagset
:raises UnbalancedFreezeThawError: if you somehow managed to
call __exit__ of this context manager more than once. Why
did you do that?
- :raises ObjectDestroyedError: if used after destoryed.
+ :raises ObjectDestroyedError: if used after destroyed.
"""
ret = capi.lib.notmuch_message_freeze(self._msg_p)
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
if isinstance(other, self.__class__):
return self.messageid == other.messageid
+class StandaloneMessage(Message):
+ """An email message stored in the notmuch database.
+
+ This subclass of Message is used for messages that are retrieved from the
+ database directly and are not owned by a query.
+ """
+ @property
+ def alive(self):
+ if not self._parent.alive:
+ return False
+ try:
+ self._msg_p
+ except errors.ObjectDestroyedError:
+ return False
+ else:
+ return True
+
+ def __del__(self):
+ self._destroy()
+
+ def _destroy(self):
+ if self.alive:
+ capi.lib.notmuch_message_destroy(self._msg_p)
+ self._msg_p = None
class FilenamesIter(base.NotmuchIter):
"""Iterator for binary filenames objects."""