2 This file is part of notmuch.
4 Notmuch is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation, either version 3 of the License, or (at your
7 option) any later version.
9 Notmuch is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with notmuch. If not, see <http://www.gnu.org/licenses/>.
17 Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
21 from ctypes import c_int, c_char_p, c_void_p, c_uint, c_long, byref
22 from notmuch.globals import nmlib, STATUS, NotmuchError, Enum
23 from notmuch.thread import Threads
24 from notmuch.message import Messages, Message
25 from notmuch.tag import Tags
28 class Database(object):
29 """Represents a notmuch database (wraps notmuch_database_t)
31 .. note:: Do remember that as soon as we tear down this object,
32 all underlying derived objects such as queries, threads,
33 messages, tags etc will be freed by the underlying library
34 as well. Accessing these objects will lead to segfaults and
35 other unexpected behavior. See above for more details.
38 """Class attribute to cache user's default database"""
40 MODE = Enum(['READ_ONLY', 'READ_WRITE'])
41 """Constants: Mode in which to open the database"""
43 """notmuch_database_get_directory"""
44 _get_directory = nmlib.notmuch_database_get_directory
45 _get_directory.restype = c_void_p
47 """notmuch_database_get_path"""
48 _get_path = nmlib.notmuch_database_get_path
49 _get_path.restype = c_char_p
51 """notmuch_database_get_version"""
52 _get_version = nmlib.notmuch_database_get_version
53 _get_version.restype = c_uint
55 """notmuch_database_open"""
56 _open = nmlib.notmuch_database_open
57 _open.restype = c_void_p
59 """notmuch_database_upgrade"""
60 _upgrade = nmlib.notmuch_database_upgrade
61 _upgrade.argtypes = [c_void_p, c_void_p, c_void_p]
63 """ notmuch_database_find_message"""
64 _find_message = nmlib.notmuch_database_find_message
65 _find_message.restype = c_void_p
67 """notmuch_database_get_all_tags"""
68 _get_all_tags = nmlib.notmuch_database_get_all_tags
69 _get_all_tags.restype = c_void_p
71 """notmuch_database_create"""
72 _create = nmlib.notmuch_database_create
73 _create.restype = c_void_p
75 def __init__(self, path=None, create=False, mode=0):
76 """If *path* is `None`, we will try to read a users notmuch
77 configuration and use his configured database. The location of the
78 configuration file can be specified through the environment variable
79 *NOTMUCH_CONFIG*, falling back to the default `~/.notmuch-config`.
81 If *create* is `True`, the database will always be created in
82 :attr:`MODE`.READ_WRITE mode. Default mode for opening is READ_ONLY.
84 :param path: Directory to open/create the database in (see
85 above for behavior if `None`)
86 :type path: `str` or `None`
87 :param create: Pass `False` to open an existing, `True` to create a new
90 :param mode: Mode to open a database in. Is always
91 :attr:`MODE`.READ_WRITE when creating a new one.
92 :type mode: :attr:`MODE`
94 :exception: :exc:`NotmuchError` in case of failure.
98 # no path specified. use a user's default database
99 if Database._std_db_path is None:
100 #the following line throws a NotmuchError if it fails
101 Database._std_db_path = self._get_user_default_db()
102 path = Database._std_db_path
104 assert isinstance(path, basestring), 'Path must be a string or None.'
106 self.open(path, mode)
110 def _verify_initialized_db(self):
111 """Raises a NotmuchError in case self._db is still None"""
113 raise NotmuchError(STATUS.NOT_INITIALIZED)
115 def create(self, path):
116 """Creates a new notmuch database
118 This function is used by __init__() and usually does not need
119 to be called directly. It wraps the underlying
120 *notmuch_database_create* function and creates a new notmuch
121 database at *path*. It will always return a database in :attr:`MODE`
122 .READ_WRITE mode as creating an empty database for
123 reading only does not make a great deal of sense.
125 :param path: A directory in which we should create the database.
128 :exception: :exc:`NotmuchError` in case of any failure
129 (after printing an error message on stderr).
131 if self._db is not None:
132 raise NotmuchError(message="Cannot create db, this Database() "
133 "already has an open one.")
135 res = Database._create(path, Database.MODE.READ_WRITE)
139 message="Could not create the specified database")
142 def open(self, path, mode=0):
143 """Opens an existing database
145 This function is used by __init__() and usually does not need
146 to be called directly. It wraps the underlying
147 *notmuch_database_open* function.
149 :param status: Open the database in read-only or read-write mode
150 :type status: :attr:`MODE`
152 :exception: Raises :exc:`NotmuchError` in case
153 of any failure (after printing an error message on stderr).
156 res = Database._open(path, mode)
160 message="Could not open the specified database")
164 """Returns the file path of an open database
166 Wraps *notmuch_database_get_path*."""
167 # Raise a NotmuchError if not initialized
168 self._verify_initialized_db()
170 return Database._get_path(self._db)
172 def get_version(self):
173 """Returns the database format version
175 :returns: The database version as positive integer
176 :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
177 the database was not intitialized.
179 # Raise a NotmuchError if not initialized
180 self._verify_initialized_db()
182 return Database._get_version(self._db)
184 def needs_upgrade(self):
185 """Does this database need to be upgraded before writing to it?
187 If this function returns `True` then no functions that modify the
188 database (:meth:`add_message`,
189 :meth:`Message.add_tag`, :meth:`Directory.set_mtime`,
190 etc.) will work unless :meth:`upgrade` is called successfully first.
192 :returns: `True` or `False`
193 :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
194 the database was not intitialized.
196 # Raise a NotmuchError if not initialized
197 self._verify_initialized_db()
199 return nmlib.notmuch_database_needs_upgrade(self._db)
202 """Upgrades the current database
204 After opening a database in read-write mode, the client should
205 check if an upgrade is needed (notmuch_database_needs_upgrade) and
206 if so, upgrade with this function before making any modifications.
208 NOT IMPLEMENTED: The optional progress_notify callback can be
209 used by the caller to provide progress indication to the
210 user. If non-NULL it will be called periodically with
211 'progress' as a floating-point value in the range of [0.0..1.0]
212 indicating the progress made so far in the upgrade process.
214 :TODO: catch exceptions, document return values and etc...
216 # Raise a NotmuchError if not initialized
217 self._verify_initialized_db()
219 status = Database._upgrade(self._db, None, None)
220 #TODO: catch exceptions, document return values and etc
223 def get_directory(self, path):
224 """Returns a :class:`Directory` of path,
225 (creating it if it does not exist(?))
227 .. warning:: This call needs a writeable database in
228 Database.MODE.READ_WRITE mode. The underlying library will exit the
229 program if this method is used on a read-only database!
231 :param path: A str containing the path relative to the path of database
232 (see :meth:`get_path`), or else should be an absolute path
233 with initial components that match the path of 'database'.
234 :returns: :class:`Directory` or raises an exception.
235 :exception: :exc:`NotmuchError`
237 STATUS.NOT_INITIALIZED
238 If the database was not intitialized.
241 If path is not relative database or absolute with initial
242 components same as database.
245 # Raise a NotmuchError if not initialized
246 self._verify_initialized_db()
248 # sanity checking if path is valid, and make path absolute
249 if path[0] == os.sep:
250 # we got an absolute path
251 if not path.startswith(self.get_path()):
252 # but its initial components are not equal to the db path
253 raise NotmuchError(STATUS.FILE_ERROR,
254 message="Database().get_directory() called "
255 "with a wrong absolute path.")
258 #we got a relative path, make it absolute
259 abs_dirpath = os.path.abspath(os.path.join(self.get_path(), path))
261 dir_p = Database._get_directory(self._db, path)
263 # return the Directory, init it with the absolute path
264 return Directory(abs_dirpath, dir_p, self)
266 def add_message(self, filename, sync_maildir_flags=False):
267 """Adds a new message to the database
269 :param filename: should be a path relative to the path of the open
270 database (see :meth:`get_path`), or else should be an absolute
271 filename with initial components that match the path of the
274 The file should be a single mail message (not a multi-message mbox)
275 that is expected to remain at its current location, since the
276 notmuch database will reference the filename, and will not copy the
277 entire contents of the file.
279 :param sync_maildir_flags: If the message contains Maildir
280 flags, we will -depending on the notmuch configuration- sync
281 those tags to initial notmuch tags, if set to `True`. It is
282 `False` by default to remain consistent with the libnotmuch
283 API. You might want to look into the underlying method
284 :meth:`Message.maildir_flags_to_tags`.
286 :returns: On success, we return
288 1) a :class:`Message` object that can be used for things
289 such as adding tags to the just-added message.
290 2) one of the following STATUS values:
293 Message successfully added to database.
294 STATUS.DUPLICATE_MESSAGE_ID
295 Message has the same message ID as another message already
296 in the database. The new filename was successfully added
297 to the message in the database.
299 :rtype: 2-tuple(:class:`Message`, STATUS)
301 :exception: Raises a :exc:`NotmuchError` with the following meaning.
302 If such an exception occurs, nothing was added to the database.
305 An error occurred trying to open the file, (such as
306 permission denied, or file not found, etc.).
307 STATUS.FILE_NOT_EMAIL
308 The contents of filename don't look like an email
310 STATUS.READ_ONLY_DATABASE
311 Database was opened in read-only mode so no message can
313 STATUS.NOT_INITIALIZED
314 The database has not been initialized.
316 # Raise a NotmuchError if not initialized
317 self._verify_initialized_db()
320 status = nmlib.notmuch_database_add_message(self._db,
324 if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
325 raise NotmuchError(status)
327 #construct Message() and return
328 msg = Message(msg_p, self)
329 #automatic sync initial tags from Maildir flags
330 if sync_maildir_flags:
331 msg.maildir_flags_to_tags()
334 def remove_message(self, filename):
335 """Removes a message from the given notmuch database
337 Note that only this particular filename association is removed from
338 the database. If the same message (as determined by the message ID)
339 is still available via other filenames, then the message will
340 persist in the database for those filenames. When the last filename
341 is removed for a particular message, the database content for that
342 message will be entirely removed.
344 :returns: A STATUS value with the following meaning:
347 The last filename was removed and the message was removed
349 STATUS.DUPLICATE_MESSAGE_ID
350 This filename was removed but the message persists in the
351 database with at least one other filename.
353 :exception: Raises a :exc:`NotmuchError` with the following meaning.
354 If such an exception occurs, nothing was removed from the
357 STATUS.READ_ONLY_DATABASE
358 Database was opened in read-only mode so no message can be
360 STATUS.NOT_INITIALIZED
361 The database has not been initialized.
363 # Raise a NotmuchError if not initialized
364 self._verify_initialized_db()
366 return nmlib.notmuch_database_remove_message(self._db,
369 def find_message(self, msgid):
370 """Returns a :class:`Message` as identified by its message ID
372 Wraps the underlying *notmuch_database_find_message* function.
374 :param msgid: The message ID
376 :returns: :class:`Message` or `None` if no message is found or
377 if any xapian exception or out-of-memory situation
378 occurs. Do note that Xapian Exceptions include
379 "Database modified" situations, e.g. when the
380 notmuch database has been modified by
381 another program in the meantime. A return value of
382 `None` is therefore no guarantee that the message
384 :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
385 the database was not intitialized.
387 # Raise a NotmuchError if not initialized
388 self._verify_initialized_db()
390 msg_p = Database._find_message(self._db, msgid)
393 return Message(msg_p, self)
395 def get_all_tags(self):
396 """Returns :class:`Tags` with a list of all tags found in the database
398 :returns: :class:`Tags`
399 :execption: :exc:`NotmuchError` with STATUS.NULL_POINTER on error
401 # Raise a NotmuchError if not initialized
402 self._verify_initialized_db()
404 tags_p = Database._get_all_tags(self._db)
406 raise NotmuchError(STATUS.NULL_POINTER)
407 return Tags(tags_p, self)
409 def create_query(self, querystring):
410 """Returns a :class:`Query` derived from this database
412 This is a shorthand method for doing::
415 # Automatically frees the Database() when 'q' is deleted
417 q = Database(dbpath).create_query('from:"Biene Maja"')
419 # long version, which is functionally equivalent but will keep the
420 # Database in the 'db' variable around after we delete 'q':
422 db = Database(dbpath)
423 q = Query(db,'from:"Biene Maja"')
425 This function is a python extension and not in the underlying C API.
427 # Raise a NotmuchError if not initialized
428 self._verify_initialized_db()
430 return Query(self, querystring)
433 return "'Notmuch DB " + self.get_path() + "'"
436 """Close and free the notmuch database if needed"""
437 if self._db is not None:
438 nmlib.notmuch_database_close(self._db)
440 def _get_user_default_db(self):
441 """ Reads a user's notmuch config and returns his db location
443 Throws a NotmuchError if it cannot find it"""
444 from ConfigParser import SafeConfigParser
445 config = SafeConfigParser()
446 conf_f = os.getenv('NOTMUCH_CONFIG',
447 os.path.expanduser('~/.notmuch-config'))
449 if not config.has_option('database', 'path'):
450 raise NotmuchError(message="No DB path specified"
451 " and no user default found")
452 return config.get('database', 'path')
456 """Property returning a pointer to `notmuch_database_t` or `None`
458 This should normally not be needed by a user (and is not yet
459 guaranteed to remain stable in future versions).
465 """Represents a search query on an opened :class:`Database`.
467 A query selects and filters a subset of messages from the notmuch
468 database we derive from.
470 Query() provides an instance attribute :attr:`sort`, which
471 contains the sort order (if specified via :meth:`set_sort`) or
474 Technically, it wraps the underlying *notmuch_query_t* struct.
476 .. note:: Do remember that as soon as we tear down this object,
477 all underlying derived objects such as threads,
478 messages, tags etc will be freed by the underlying library
479 as well. Accessing these objects will lead to segfaults and
480 other unexpected behavior. See above for more details.
483 SORT = Enum(['OLDEST_FIRST', 'NEWEST_FIRST', 'MESSAGE_ID', 'UNSORTED'])
484 """Constants: Sort order in which to return results"""
486 """notmuch_query_create"""
487 _create = nmlib.notmuch_query_create
488 _create.restype = c_void_p
490 """notmuch_query_search_threads"""
491 _search_threads = nmlib.notmuch_query_search_threads
492 _search_threads.restype = c_void_p
494 """notmuch_query_search_messages"""
495 _search_messages = nmlib.notmuch_query_search_messages
496 _search_messages.restype = c_void_p
498 """notmuch_query_count_messages"""
499 _count_messages = nmlib.notmuch_query_count_messages
500 _count_messages.restype = c_uint
502 def __init__(self, db, querystr):
504 :param db: An open database which we derive the Query from.
505 :type db: :class:`Database`
506 :param querystr: The query string for the message.
507 :type querystr: utf-8 encoded str or unicode
512 self.create(db, querystr)
514 def create(self, db, querystr):
515 """Creates a new query derived from a Database
517 This function is utilized by __init__() and usually does not need to
520 :param db: Database to create the query from.
521 :type db: :class:`Database`
522 :param querystr: The query string
523 :type querystr: utf-8 encoded str or unicode
525 :exception: :exc:`NotmuchError`
527 * STATUS.NOT_INITIALIZED if db is not inited
528 * STATUS.NULL_POINTER if the query creation failed
532 raise NotmuchError(STATUS.NOT_INITIALIZED)
533 # create reference to parent db to keep it alive
535 if isinstance(querystr, unicode):
536 # xapian takes utf-8 encoded byte arrays
537 querystr = querystr.encode('utf-8')
538 # create query, return None if too little mem available
539 query_p = Query._create(db.db_p, querystr)
541 NotmuchError(STATUS.NULL_POINTER)
542 self._query = query_p
544 def set_sort(self, sort):
545 """Set the sort order future results will be delivered in
547 Wraps the underlying *notmuch_query_set_sort* function.
549 :param sort: Sort order (see :attr:`Query.SORT`)
551 :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if query has not
554 if self._query is None:
555 raise NotmuchError(STATUS.NOT_INITIALIZED)
558 nmlib.notmuch_query_set_sort(self._query, sort)
560 def search_threads(self):
561 """Execute a query for threads
563 Execute a query for threads, returning a :class:`Threads` iterator.
564 The returned threads are owned by the query and as such, will only be
565 valid until the Query is deleted.
567 The method sets :attr:`Message.FLAG`\.MATCH for those messages that
568 match the query. The method :meth:`Message.get_flag` allows us
569 to get the value of this flag.
571 Technically, it wraps the underlying
572 *notmuch_query_search_threads* function.
574 :returns: :class:`Threads`
575 :exception: :exc:`NotmuchError`
577 * STATUS.NOT_INITIALIZED if query is not inited
578 * STATUS.NULL_POINTER if search_threads failed
580 if self._query is None:
581 raise NotmuchError(STATUS.NOT_INITIALIZED)
583 threads_p = Query._search_threads(self._query)
585 if threads_p is None:
586 raise NotmuchError(STATUS.NULL_POINTER)
588 return Threads(threads_p, self)
590 def search_messages(self):
591 """Filter messages according to the query and return
592 :class:`Messages` in the defined sort order
594 Technically, it wraps the underlying
595 *notmuch_query_search_messages* function.
597 :returns: :class:`Messages`
598 :exception: :exc:`NotmuchError`
600 * STATUS.NOT_INITIALIZED if query is not inited
601 * STATUS.NULL_POINTER if search_messages failed
603 if self._query is None:
604 raise NotmuchError(STATUS.NOT_INITIALIZED)
606 msgs_p = Query._search_messages(self._query)
609 NotmuchError(STATUS.NULL_POINTER)
611 return Messages(msgs_p, self)
613 def count_messages(self):
614 """Estimate the number of messages matching the query
616 This function performs a search and returns Xapian's best
617 guess as to the number of matching messages. It is much faster
618 than performing :meth:`search_messages` and counting the
619 result with `len()` (although it always returned the same
620 result in my tests). Technically, it wraps the underlying
621 *notmuch_query_count_messages* function.
623 :returns: :class:`Messages`
624 :exception: :exc:`NotmuchError`
626 * STATUS.NOT_INITIALIZED if query is not inited
628 if self._query is None:
629 raise NotmuchError(STATUS.NOT_INITIALIZED)
631 return Query._count_messages(self._query)
634 """Close and free the Query"""
635 if self._query is not None:
636 nmlib.notmuch_query_destroy(self._query)
639 class Directory(object):
640 """Represents a directory entry in the notmuch directory
642 Modifying attributes of this object will modify the
643 database, not the real directory attributes.
645 The Directory object is usually derived from another object
646 e.g. via :meth:`Database.get_directory`, and will automatically be
647 become invalid whenever that parent is deleted. You should
648 therefore initialized this object handing it a reference to the
649 parent, preventing the parent from automatically being garbage
653 """notmuch_directory_get_mtime"""
654 _get_mtime = nmlib.notmuch_directory_get_mtime
655 _get_mtime.restype = c_long
657 """notmuch_directory_set_mtime"""
658 _set_mtime = nmlib.notmuch_directory_set_mtime
659 _set_mtime.argtypes = [c_char_p, c_long]
661 """notmuch_directory_get_child_files"""
662 _get_child_files = nmlib.notmuch_directory_get_child_files
663 _get_child_files.restype = c_void_p
665 """notmuch_directory_get_child_directories"""
666 _get_child_directories = nmlib.notmuch_directory_get_child_directories
667 _get_child_directories.restype = c_void_p
669 def _verify_dir_initialized(self):
670 """Raises a NotmuchError(STATUS.NOT_INITIALIZED) if dir_p is None"""
671 if self._dir_p is None:
672 raise NotmuchError(STATUS.NOT_INITIALIZED)
674 def __init__(self, path, dir_p, parent):
676 :param path: The absolute path of the directory object.
677 :param dir_p: The pointer to an internal notmuch_directory_t object.
678 :param parent: The object this Directory is derived from
679 (usually a :class:`Database`). We do not directly use
680 this, but store a reference to it as long as
681 this Directory object lives. This keeps the
686 self._parent = parent
688 def set_mtime(self, mtime):
689 """Sets the mtime value of this directory in the database
691 The intention is for the caller to use the mtime to allow efficient
692 identification of new messages to be added to the database. The
693 recommended usage is as follows:
695 * Read the mtime of a directory from the filesystem
697 * Call :meth:`Database.add_message` for all mail files in
700 * Call notmuch_directory_set_mtime with the mtime read from the
701 filesystem. Then, when wanting to check for updates to the
702 directory in the future, the client can call :meth:`get_mtime`
703 and know that it only needs to add files if the mtime of the
704 directory and files are newer than the stored timestamp.
706 .. note:: :meth:`get_mtime` function does not allow the caller
707 to distinguish a timestamp of 0 from a non-existent
708 timestamp. So don't store a timestamp of 0 unless you are
709 comfortable with that.
711 :param mtime: A (time_t) timestamp
712 :returns: Nothing on success, raising an exception on failure.
713 :exception: :exc:`NotmuchError`:
715 STATUS.XAPIAN_EXCEPTION
716 A Xapian exception occurred, mtime not stored.
717 STATUS.READ_ONLY_DATABASE
718 Database was opened in read-only mode so directory
719 mtime cannot be modified.
720 STATUS.NOT_INITIALIZED
721 The directory has not been initialized
723 #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if the dir_p is None
724 self._verify_dir_initialized()
726 #TODO: make sure, we convert the mtime parameter to a 'c_long'
727 status = Directory._set_mtime(self._dir_p, mtime)
730 if status == STATUS.SUCCESS:
732 #fail with Exception otherwise
733 raise NotmuchError(status)
736 """Gets the mtime value of this directory in the database
738 Retrieves a previously stored mtime for this directory.
740 :param mtime: A (time_t) timestamp
741 :returns: Nothing on success, raising an exception on failure.
742 :exception: :exc:`NotmuchError`:
744 STATUS.NOT_INITIALIZED
745 The directory has not been initialized
747 #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self.dir_p is None
748 self._verify_dir_initialized()
750 return Directory._get_mtime(self._dir_p)
752 # Make mtime attribute a property of Directory()
753 mtime = property(get_mtime, set_mtime, doc="""Property that allows getting
754 and setting of the Directory *mtime* (read-write)
756 See :meth:`get_mtime` and :meth:`set_mtime` for usage and
757 possible exceptions.""")
759 def get_child_files(self):
760 """Gets a Filenames iterator listing all the filenames of
761 messages in the database within the given directory.
763 The returned filenames will be the basename-entries only (not
766 #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self._dir_p is None
767 self._verify_dir_initialized()
769 files_p = Directory._get_child_files(self._dir_p)
770 return Filenames(files_p, self)
772 def get_child_directories(self):
773 """Gets a :class:`Filenames` iterator listing all the filenames of
774 sub-directories in the database within the given directory
776 The returned filenames will be the basename-entries only (not
779 #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self._dir_p is None
780 self._verify_dir_initialized()
782 files_p = Directory._get_child_directories(self._dir_p)
783 return Filenames(files_p, self)
787 """Returns the absolute path of this Directory (read-only)"""
791 """Object representation"""
792 return "<notmuch Directory object '%s'>" % self._path
795 """Close and free the Directory"""
796 if self._dir_p is not None:
797 nmlib.notmuch_directory_destroy(self._dir_p)
800 class Filenames(object):
801 """An iterator over File- or Directory names stored in the database"""
803 #notmuch_filenames_get
804 _get = nmlib.notmuch_filenames_get
805 _get.restype = c_char_p
807 def __init__(self, files_p, parent):
809 :param files_p: The pointer to an internal notmuch_filenames_t object.
810 :param parent: The object this Directory is derived from
811 (usually a Directory()). We do not directly use
812 this, but store a reference to it as long as
813 this Directory object lives. This keeps the
816 self._files_p = files_p
817 self._parent = parent
820 """ Make Filenames an iterator """
824 if self._files_p is None:
825 raise NotmuchError(STATUS.NOT_INITIALIZED)
827 if not nmlib.notmuch_filenames_valid(self._files_p):
831 file = Filenames._get(self._files_p)
832 nmlib.notmuch_filenames_move_to_next(self._files_p)
836 """len(:class:`Filenames`) returns the number of contained files
838 .. note:: As this iterates over the files, we will not be able to
839 iterate over them again! So this will fail::
842 files = Database().get_directory('').get_child_files()
843 if len(files) > 0: #this 'exhausts' msgs
844 # next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!!
845 for file in files: print file
847 if self._files_p is None:
848 raise NotmuchError(STATUS.NOT_INITIALIZED)
851 while nmlib.notmuch_filenames_valid(self._files_p):
852 nmlib.notmuch_filenames_move_to_next(self._files_p)
858 """Close and free Filenames"""
859 if self._files_p is not None:
860 nmlib.notmuch_filenames_destroy(self._files_p)