9 import notmuch2._base as base
10 import notmuch2._config as config
11 import notmuch2._capi as capi
12 import notmuch2._errors as errors
13 import notmuch2._message as message
14 import notmuch2._query as querymod
15 import notmuch2._tags as tags
18 __all__ = ['Database', 'AtomicContext', 'DbRevision', 'IndexOptions']
21 def _config_pathname():
22 """Return the path of the configuration file.
26 cfgfname = os.getenv('NOTMUCH_CONFIG', '~/.notmuch-config')
27 return pathlib.Path(os.path.expanduser(cfgfname))
30 class Mode(enum.Enum):
31 READ_ONLY = capi.lib.NOTMUCH_DATABASE_MODE_READ_ONLY
32 READ_WRITE = capi.lib.NOTMUCH_DATABASE_MODE_READ_WRITE
34 class ConfigFile(enum.Enum):
36 SEARCH = capi.ffi.NULL
38 class QuerySortOrder(enum.Enum):
39 OLDEST_FIRST = capi.lib.NOTMUCH_SORT_OLDEST_FIRST
40 NEWEST_FIRST = capi.lib.NOTMUCH_SORT_NEWEST_FIRST
41 MESSAGE_ID = capi.lib.NOTMUCH_SORT_MESSAGE_ID
42 UNSORTED = capi.lib.NOTMUCH_SORT_UNSORTED
45 class QueryExclude(enum.Enum):
46 TRUE = capi.lib.NOTMUCH_EXCLUDE_TRUE
47 FLAG = capi.lib.NOTMUCH_EXCLUDE_FLAG
48 FALSE = capi.lib.NOTMUCH_EXCLUDE_FALSE
49 ALL = capi.lib.NOTMUCH_EXCLUDE_ALL
52 class DecryptionPolicy(enum.Enum):
53 FALSE = capi.lib.NOTMUCH_DECRYPT_FALSE
54 TRUE = capi.lib.NOTMUCH_DECRYPT_TRUE
55 AUTO = capi.lib.NOTMUCH_DECRYPT_AUTO
56 NOSTASH = capi.lib.NOTMUCH_DECRYPT_NOSTASH
59 class Database(base.NotmuchObject):
60 """Toplevel access to notmuch.
62 A :class:`Database` can be opened read-only or read-write.
63 Modifications are not atomic by default, use :meth:`begin_atomic`
64 for atomic updates. If the underlying database has been modified
65 outside of this class a :exc:`XapianError` will be raised and the
66 instance must be closed and a new one created.
68 You can use an instance of this class as a context-manager.
70 :cvar MODE: The mode a database can be opened with, an enumeration
71 of ``READ_ONLY`` and ``READ_WRITE``
72 :cvar SORT: The sort order for search results, ``OLDEST_FIRST``,
73 ``NEWEST_FIRST``, ``MESSAGE_ID`` or ``UNSORTED``.
74 :cvar EXCLUDE: Which messages to exclude from queries, ``TRUE``,
75 ``FLAG``, ``FALSE`` or ``ALL``. See the query documentation
77 :cvar CONFIG: Control loading of config file. Enumeration of
78 ``EMPTY`` (don't load a config file), and ``SEARCH`` (search as
79 in :ref:`config_search`)
80 :cvar AddedMessage: A namedtuple ``(msg, dup)`` used by
81 :meth:`add` as return value.
82 :cvar STR_MODE_MAP: A map mapping strings to :attr:`MODE` items.
83 This is used to implement the ``ro`` and ``rw`` string
86 :ivar closed: Boolean indicating if the database is closed or
89 :param path: The directory of where the database is stored. If
90 ``None`` the location will be searched according to
92 :type path: str, bytes, os.PathLike or pathlib.Path
93 :param mode: The mode to open the database in. One of
94 :attr:`MODE.READ_ONLY` OR :attr:`MODE.READ_WRITE`. For
95 convenience you can also use the strings ``ro`` for
96 :attr:`MODE.READ_ONLY` and ``rw`` for :attr:`MODE.READ_WRITE`.
97 :type mode: :attr:`MODE` or str.
99 :param config: Where to load the configuration from, if any.
100 :type config: :attr:`CONFIG.EMPTY`, :attr:`CONFIG.SEARCH`, str, bytes, os.PathLike, pathlib.Path
101 :raises KeyError: if an unknown mode string is used.
102 :raises OSError: or subclasses if the configuration file can not
104 :raises configparser.Error: or subclasses if the configuration
105 file can not be parsed.
106 :raises NotmuchError: or subclasses for other failures.
110 SORT = QuerySortOrder
111 EXCLUDE = QueryExclude
113 AddedMessage = collections.namedtuple('AddedMessage', ['msg', 'dup'])
114 _db_p = base.MemoryPointer()
116 'ro': MODE.READ_ONLY,
117 'rw': MODE.READ_WRITE,
121 def _cfg_path_encode(path):
122 if isinstance(path,ConfigFile):
126 elif not hasattr(os, 'PathLike') and isinstance(path, pathlib.Path):
129 path = os.fsencode(path)
133 def _db_path_encode(path):
136 elif not hasattr(os, 'PathLike') and isinstance(path, pathlib.Path):
139 path = os.fsencode(path)
142 def __init__(self, path=None, mode=MODE.READ_ONLY, config=CONFIG.SEARCH):
143 if isinstance(mode, str):
144 mode = self.STR_MODE_MAP[mode]
147 db_pp = capi.ffi.new('notmuch_database_t **')
148 cmsg = capi.ffi.new('char**')
149 ret = capi.lib.notmuch_database_open_with_config(self._db_path_encode(path),
151 self._cfg_path_encode(config),
155 msg = capi.ffi.string(cmsg[0]).decode(errors='replace')
156 capi.lib.free(cmsg[0])
159 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
160 raise errors.NotmuchError(ret, msg)
161 self._db_p = db_pp[0]
165 def create(cls, path=None, config=ConfigFile.EMPTY):
166 """Create and open database in READ_WRITE mode.
168 This is creates a new notmuch database and returns an opened
169 instance in :attr:`MODE.READ_WRITE` mode.
171 :param path: The directory of where the database is stored.
172 If ``None`` the location will be read searched by the
173 notmuch library (see notmuch(3)::notmuch_open_with_config).
174 :type path: str, bytes or os.PathLike
176 :param config: The pathname of the notmuch configuration file.
177 :type config: :attr:`CONFIG.EMPTY`, :attr:`CONFIG.SEARCH`, str, bytes, os.PathLike, pathlib.Path
179 :raises OSError: or subclasses if the configuration file can not
181 :raises configparser.Error: or subclasses if the configuration
182 file can not be parsed.
183 :raises NotmuchError: if the config file does not have the
184 database.path setting.
185 :raises FileError: if the database already exists.
187 :returns: The newly created instance.
190 db_pp = capi.ffi.new('notmuch_database_t **')
191 cmsg = capi.ffi.new('char**')
192 ret = capi.lib.notmuch_database_create_with_config(cls._db_path_encode(path),
193 cls._cfg_path_encode(config),
197 msg = capi.ffi.string(cmsg[0]).decode(errors='replace')
198 capi.lib.free(cmsg[0])
201 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
202 raise errors.NotmuchError(ret, msg)
204 # Now close the db and let __init__ open it. Inefficient but
205 # creating is not a hot loop while this allows us to have a
207 ret = capi.lib.notmuch_database_destroy(db_pp[0])
208 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
209 raise errors.NotmuchError(ret)
210 return cls(path, cls.MODE.READ_WRITE, config=config)
213 def default_path(cfg_path=None):
214 """Return the path of the user's default database.
216 This reads the user's configuration file and returns the
217 default path of the database.
219 :param cfg_path: The pathname of the notmuch configuration file.
220 If not specified tries to use the pathname provided in the
221 :envvar:`NOTMUCH_CONFIG` environment variable and falls back
222 to :file:`~/.notmuch-config`.
223 :type cfg_path: str, bytes, os.PathLike or pathlib.Path.
225 :returns: The path of the database, which does not necessarily
228 :raises OSError: or subclasses if the configuration file can not
230 :raises configparser.Error: or subclasses if the configuration
231 file can not be parsed.
232 :raises NotmuchError: if the config file does not have the
233 database.path setting.
236 Use the ``config`` parameter to :meth:`__init__` or :meth:`__create__` instead.
239 cfg_path = _config_pathname()
240 if not hasattr(os, 'PathLike') and isinstance(cfg_path, pathlib.Path):
241 cfg_path = bytes(cfg_path)
242 parser = configparser.ConfigParser()
243 with open(cfg_path) as fp:
246 return pathlib.Path(parser.get('database', 'path'))
247 except configparser.Error:
248 raise errors.NotmuchError(
249 'No database.path setting in {}'.format(cfg_path))
258 except errors.ObjectDestroyedError:
265 ret = capi.lib.notmuch_database_destroy(self._db_p)
266 except errors.ObjectDestroyedError:
267 ret = capi.lib.NOTMUCH_STATUS_SUCCESS
270 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
271 raise errors.NotmuchError(ret)
274 """Close the notmuch database.
276 Once closed most operations will fail. This can still be
277 useful however to explicitly close a database which is opened
278 read-write as this would otherwise stop other processes from
279 reading the database while it is open.
281 :raises ObjectDestroyedError: if used after destroyed.
283 ret = capi.lib.notmuch_database_close(self._db_p)
284 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
285 raise errors.NotmuchError(ret)
288 def reopen(self, mode=None):
289 """Reopen an opened notmuch database.
291 :param mode: Mode to reopen the database with. When None, the previously
292 active mode is preserved.
293 :type mode: :attr:`MODE`, str, or None.
295 This is useful e.g. for:
296 - switching the mode between read-only and read-write
297 - recovering from OperationInvalidatedError
299 if isinstance(mode, str):
301 mode = self.STR_MODE_MAP[mode]
303 raise ValueError('Invalid mode: %s' % mode)
305 mode = mode or self.mode
308 ret = capi.lib.notmuch_database_reopen(self._db_p, mode.value)
309 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
310 raise errors.NotmuchError(ret)
315 def __exit__(self, exc_type, exc_value, traceback):
320 """The pathname of the notmuch database.
322 This is returned as a :class:`pathlib.Path` instance.
324 :raises ObjectDestroyedError: if used after destroyed.
327 return self._cache_path
328 except AttributeError:
329 ret = capi.lib.notmuch_database_get_path(self._db_p)
330 self._cache_path = pathlib.Path(os.fsdecode(capi.ffi.string(ret)))
331 return self._cache_path
335 """The database format version.
337 This is a positive integer.
339 :raises ObjectDestroyedError: if used after destroyed.
342 return self._cache_version
343 except AttributeError:
344 ret = capi.lib.notmuch_database_get_version(self._db_p)
345 self._cache_version = ret
349 def needs_upgrade(self):
350 """Whether the database should be upgraded.
352 If *True* the database can be upgraded using :meth:`upgrade`.
353 Not doing so may result in some operations raising
354 :exc:`UpgradeRequiredError`.
356 A read-only database will never be upgradable.
358 :raises ObjectDestroyedError: if used after destroyed.
360 ret = capi.lib.notmuch_database_needs_upgrade(self._db_p)
363 def upgrade(self, progress_cb=None):
364 """Upgrade the database to the latest version.
366 Upgrade the database, optionally with a progress callback
367 which should be a callable which will be called with a
368 floating point number in the range of [0.0 .. 1.0].
370 raise NotImplementedError
373 """Return a context manager to perform atomic operations.
375 The returned context manager can be used to perform atomic
376 operations on the database.
378 .. note:: Unlike a traditional RDBMS transaction this does
379 not imply durability, it only ensures the changes are
380 performed atomically.
382 :raises ObjectDestroyedError: if used after destroyed.
384 ctx = AtomicContext(self, '_db_p')
388 """The currently committed revision in the database.
390 Returned as a ``(revision, uuid)`` namedtuple.
392 :raises ObjectDestroyedError: if used after destroyed.
394 raw_uuid = capi.ffi.new('char**')
395 rev = capi.lib.notmuch_database_get_revision(self._db_p, raw_uuid)
396 return DbRevision(rev, capi.ffi.string(raw_uuid[0]))
398 def get_directory(self, path):
399 raise NotImplementedError
401 def default_indexopts(self):
402 """Returns default index options for the database.
404 :raises ObjectDestroyedError: if used after destroyed.
406 :returns: :class:`IndexOptions`.
408 opts = capi.lib.notmuch_database_get_default_indexopts(self._db_p)
409 return IndexOptions(self, opts)
411 def add(self, filename, *, sync_flags=False, indexopts=None):
412 """Add a message to the database.
414 Add a new message to the notmuch database. The message is
415 referred to by the pathname of the maildir file. If the
416 message ID of the new message already exists in the database,
417 this adds ``pathname`` to the list of list of files for the
420 :param filename: The path of the file containing the message.
421 :type filename: str, bytes, os.PathLike or pathlib.Path.
422 :param sync_flags: Whether to sync the known maildir flags to
423 notmuch tags. See :meth:`Message.flags_to_tags` for
425 :type sync_flags: bool
426 :param indexopts: The indexing options, see
427 :meth:`default_indexopts`. Leave as `None` to use the
428 default options configured in the database.
429 :type indexopts: :class:`IndexOptions` or `None`
431 :returns: A tuple where the first item is the newly inserted
432 messages as a :class:`Message` instance, and the second
433 item is a boolean indicating if the message inserted was a
434 duplicate. This is the namedtuple ``AddedMessage(msg,
436 :rtype: Database.AddedMessage
438 If an exception is raised, no message was added.
440 :raises XapianError: A Xapian exception occurred.
441 :raises FileError: The file referred to by ``pathname`` could
443 :raises FileNotEmailError: The file referred to by
444 ``pathname`` is not recognised as an email message.
445 :raises ReadOnlyDatabaseError: The database is opened in
447 :raises UpgradeRequiredError: The database must be upgraded
449 :raises ObjectDestroyedError: if used after destroyed.
451 if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
452 filename = bytes(filename)
453 msg_pp = capi.ffi.new('notmuch_message_t **')
454 opts_p = indexopts._opts_p if indexopts else capi.ffi.NULL
455 ret = capi.lib.notmuch_database_index_file(
456 self._db_p, os.fsencode(filename), opts_p, msg_pp)
457 ok = [capi.lib.NOTMUCH_STATUS_SUCCESS,
458 capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID]
460 raise errors.NotmuchError(ret)
461 msg = message.Message(self, msg_pp[0], db=self)
463 msg.tags.from_maildir_flags()
464 return self.AddedMessage(
465 msg, ret == capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
467 def remove(self, filename):
468 """Remove a message from the notmuch database.
470 Removing a message which is not in the database is just a
471 silent nop-operation.
473 :param filename: The pathname of the file containing the
474 message to be removed.
475 :type filename: str, bytes, os.PathLike or pathlib.Path.
477 :returns: True if the message is still in the database. This
478 can happen when multiple files contain the same message ID.
479 The true/false distinction is fairly arbitrary, but think
480 of it as ``dup = db.remove_message(name); if dup: ...``.
483 :raises XapianError: A Xapian exception occurred.
484 :raises ReadOnlyDatabaseError: The database is opened in
486 :raises UpgradeRequiredError: The database must be upgraded
488 :raises ObjectDestroyedError: if used after destroyed.
490 if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
491 filename = bytes(filename)
492 ret = capi.lib.notmuch_database_remove_message(self._db_p,
493 os.fsencode(filename))
494 ok = [capi.lib.NOTMUCH_STATUS_SUCCESS,
495 capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID]
497 raise errors.NotmuchError(ret)
498 if ret == capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
503 def find(self, msgid):
504 """Return the message matching the given message ID.
506 If a message with the given message ID is found a
507 :class:`Message` instance is returned. Otherwise a
508 :exc:`LookupError` is raised.
510 :param msgid: The message ID to look for.
513 :returns: The message instance.
516 :raises LookupError: If no message was found.
517 :raises OutOfMemoryError: When there is no memory to allocate
518 the message instance.
519 :raises XapianError: A Xapian exception occurred.
520 :raises ObjectDestroyedError: if used after destroyed.
522 msg_pp = capi.ffi.new('notmuch_message_t **')
523 ret = capi.lib.notmuch_database_find_message(self._db_p,
524 msgid.encode(), msg_pp)
525 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
526 raise errors.NotmuchError(ret)
528 if msg_p == capi.ffi.NULL:
530 msg = message.Message(self, msg_p, db=self)
533 def get(self, filename):
534 """Return the :class:`Message` given a pathname.
536 If a message with the given pathname exists in the database
537 return the :class:`Message` instance for the message.
538 Otherwise raise a :exc:`LookupError` exception.
540 :param filename: The pathname of the message.
541 :type filename: str, bytes, os.PathLike or pathlib.Path
543 :returns: The message instance.
546 :raises LookupError: If no message was found. This is also
547 a subclass of :exc:`KeyError`.
548 :raises OutOfMemoryError: When there is no memory to allocate
549 the message instance.
550 :raises XapianError: A Xapian exception occurred.
551 :raises ObjectDestroyedError: if used after destroyed.
553 if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
554 filename = bytes(filename)
555 msg_pp = capi.ffi.new('notmuch_message_t **')
556 ret = capi.lib.notmuch_database_find_message_by_filename(
557 self._db_p, os.fsencode(filename), msg_pp)
558 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
559 raise errors.NotmuchError(ret)
561 if msg_p == capi.ffi.NULL:
563 msg = message.Message(self, msg_p, db=self)
568 """Return an immutable set with all tags used in this database.
570 This returns an immutable set-like object implementing the
571 collections.abc.Set Abstract Base Class. Due to the
572 underlying libnotmuch implementation some operations have
573 different performance characteristics then plain set objects.
574 Mainly any lookup operation is O(n) rather then O(1).
576 Normal usage treats tags as UTF-8 encoded unicode strings so
577 they are exposed to Python as normal unicode string objects.
578 If you need to handle tags stored in libnotmuch which are not
579 valid unicode do check the :class:`ImmutableTagSet` docs for
582 :rtype: ImmutableTagSet
584 :raises ObjectDestroyedError: if used after destroyed.
587 ref = self._cached_tagset
588 except AttributeError:
593 tagset = tags.ImmutableTagSet(
594 self, '_db_p', capi.lib.notmuch_database_get_all_tags)
595 self._cached_tagset = weakref.ref(tagset)
600 """Return a mutable mapping with the settings stored in this database.
602 This returns an mutable dict-like object implementing the
603 collections.abc.MutableMapping Abstract Base Class.
607 :raises ObjectDestroyedError: if used after destroyed.
610 ref = self._cached_config
611 except AttributeError:
612 config_mapping = None
614 config_mapping = ref()
615 if config_mapping is None:
616 config_mapping = config.ConfigMapping(self, '_db_p')
617 self._cached_config = weakref.ref(config_mapping)
618 return config_mapping
620 def _create_query(self, query, *,
621 omit_excluded=EXCLUDE.TRUE,
622 sort=SORT.UNSORTED, # Check this default
624 """Create an internal query object.
626 :raises OutOfMemoryError: if no memory is available to
629 if isinstance(query, str):
630 query = query.encode('utf-8')
631 query_p = capi.lib.notmuch_query_create(self._db_p, query)
632 if query_p == capi.ffi.NULL:
633 raise errors.OutOfMemoryError()
634 capi.lib.notmuch_query_set_omit_excluded(query_p, omit_excluded.value)
635 capi.lib.notmuch_query_set_sort(query_p, sort.value)
636 if exclude_tags is not None:
637 for tag in exclude_tags:
638 if isinstance(tag, str):
639 tag = tag.encode('utf-8')
640 capi.lib.notmuch_query_add_tag_exclude(query_p, tag)
641 return querymod.Query(self, query_p)
643 def messages(self, query, *,
644 omit_excluded=EXCLUDE.TRUE,
645 sort=SORT.UNSORTED, # Check this default
647 """Search the database for messages.
649 :returns: An iterator over the messages found.
652 :raises OutOfMemoryError: if no memory is available to
654 :raises ObjectDestroyedError: if used after destroyed.
656 query = self._create_query(query,
657 omit_excluded=omit_excluded,
659 exclude_tags=exclude_tags)
660 return query.messages()
662 def count_messages(self, query, *,
663 omit_excluded=EXCLUDE.TRUE,
664 sort=SORT.UNSORTED, # Check this default
666 """Search the database for messages.
668 :returns: An iterator over the messages found.
671 :raises ObjectDestroyedError: if used after destroyed.
673 query = self._create_query(query,
674 omit_excluded=omit_excluded,
676 exclude_tags=exclude_tags)
677 return query.count_messages()
679 def threads(self, query, *,
680 omit_excluded=EXCLUDE.TRUE,
681 sort=SORT.UNSORTED, # Check this default
683 query = self._create_query(query,
684 omit_excluded=omit_excluded,
686 exclude_tags=exclude_tags)
687 return query.threads()
689 def count_threads(self, query, *,
690 omit_excluded=EXCLUDE.TRUE,
691 sort=SORT.UNSORTED, # Check this default
693 query = self._create_query(query,
694 omit_excluded=omit_excluded,
696 exclude_tags=exclude_tags)
697 return query.count_threads()
699 def status_string(self):
700 raise NotImplementedError
703 return 'Database(path={self.path}, mode={self.mode})'.format(self=self)
707 """Context manager for atomic support.
709 This supports the notmuch_database_begin_atomic and
710 notmuch_database_end_atomic API calls. The object can not be
711 directly instantiated by the user, only via ``Database.atomic``.
712 It does keep a reference to the :class:`Database` instance to keep
715 :raises XapianError: When this is raised at enter time the atomic
716 section is not active. When it is raised at exit time the
717 atomic section is still active and you may need to try using
719 :raises ObjectDestroyedError: if used after destroyed.
722 def __init__(self, db, ptr_name):
724 self._ptr = lambda: getattr(db, ptr_name)
725 self._exit_fn = lambda: None
732 return self.parent.alive
738 ret = capi.lib.notmuch_database_begin_atomic(self._ptr())
739 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
740 raise errors.NotmuchError(ret)
741 self._exit_fn = self._end_atomic
744 def _end_atomic(self):
745 ret = capi.lib.notmuch_database_end_atomic(self._ptr())
746 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
747 raise errors.NotmuchError(ret)
749 def __exit__(self, exc_type, exc_value, traceback):
753 """Force ending the atomic section.
755 This can only be called once __exit__ has been called. It
756 will attempt to close the atomic section (again). This is
757 useful if the original exit raised an exception and the atomic
758 section is still open. But things are pretty ugly by now.
760 :raises XapianError: If exiting fails, the atomic section is
762 :raises UnbalancedAtomicError: If the database was currently
763 not in an atomic section.
764 :raises ObjectDestroyedError: if used after destroyed.
766 ret = capi.lib.notmuch_database_end_atomic(self._ptr())
767 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
768 raise errors.NotmuchError(ret)
771 """Abort the transaction.
773 Aborting a transaction will not commit any of the changes, but
774 will also implicitly close the database.
776 self._exit_fn = lambda: None
780 @functools.total_ordering
782 """A database revision.
784 The database revision number increases monotonically with each
785 commit to the database. Which means user-visible changes can be
786 ordered. This object is sortable with other revisions. It
787 carries the UUID of the database to ensure it is only ever
788 compared with revisions from the same database.
791 def __init__(self, rev, uuid):
797 """The revision number, a positive integer."""
802 """The UUID of the database, consider this opaque."""
805 def __eq__(self, other):
806 if isinstance(other, self.__class__):
807 if self.uuid != other.uuid:
809 return self.rev == other.rev
811 return NotImplemented
813 def __lt__(self, other):
814 if self.__class__ is other.__class__:
815 if self.uuid != other.uuid:
817 return self.rev < other.rev
819 return NotImplemented
822 return 'DbRevision(rev={self.rev}, uuid={self.uuid})'.format(self=self)
825 class IndexOptions(base.NotmuchObject):
828 This represents the indexing options which can be used to index a
829 message. See :meth:`Database.default_indexopts` to create an
830 instance of this. It can be used e.g. when indexing a new message
831 using :meth:`Database.add`.
833 _opts_p = base.MemoryPointer()
835 def __init__(self, parent, opts_p):
836 self._parent = parent
837 self._opts_p = opts_p
841 if not self._parent.alive:
845 except errors.ObjectDestroyedError:
852 capi.lib.notmuch_indexopts_destroy(self._opts_p)
856 def decrypt_policy(self):
857 """The decryption policy.
859 This is an enum from the :class:`DecryptionPolicy`. See the
860 `index.decrypt` section in :any:`notmuch-config(1)` for details
861 on the options. **Do not set this to
862 :attr:`DecryptionPolicy.TRUE`** without considering the
863 security of your index.
865 You can change this policy by assigning a new
866 :class:`DecryptionPolicy` to this property.
868 :raises ObjectDestroyedError: if used after destroyed.
870 :returns: A :class:`DecryptionPolicy` enum instance.
872 raw = capi.lib.notmuch_indexopts_get_decrypt_policy(self._opts_p)
873 return DecryptionPolicy(raw)
875 @decrypt_policy.setter
876 def decrypt_policy(self, val):
877 ret = capi.lib.notmuch_indexopts_set_decrypt_policy(
878 self._opts_p, val.value)
879 if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
880 raise errors.NotmuchError(ret, msg)