]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python/notmuch/database.py
version: bump to 0.6
[notmuch] / bindings / python / notmuch / database.py
index f141c03ef462b813be27ca58a0a8a323a1e9810c..5deb2a5dc06a62cb8d97096b376baf44812c7648 100644 (file)
@@ -100,6 +100,7 @@ class Database(object):
                 Database._std_db_path = self._get_user_default_db()
             path = Database._std_db_path
 
                 Database._std_db_path = self._get_user_default_db()
             path = Database._std_db_path
 
+        assert isinstance(path, basestring), 'Path needs to be a string or None.'
         if create == False:
             self.open(path, mode)
         else:
         if create == False:
             self.open(path, mode)
         else:
@@ -260,10 +261,10 @@ class Database(object):
         # return the Directory, init it with the absolute path
         return Directory(abs_dirpath, dir_p, self)
 
         # return the Directory, init it with the absolute path
         return Directory(abs_dirpath, dir_p, self)
 
-    def add_message(self, filename):
+    def add_message(self, filename, sync_maildir_flags=False):
         """Adds a new message to the database
 
         """Adds a new message to the database
 
-        `filename` should be a path relative to the path of the open
+        :param filename: should be a path relative to the path of the open
         database (see :meth:`get_path`), or else should be an absolute
         filename with initial components that match the path of the
         database.
         database (see :meth:`get_path`), or else should be an absolute
         filename with initial components that match the path of the
         database.
@@ -273,6 +274,13 @@ class Database(object):
         notmuch database will reference the filename, and will not copy the
         entire contents of the file.
 
         notmuch database will reference the filename, and will not copy the
         entire contents of the file.
 
+        :param sync_maildir_flags: If the message contains Maildir
+            flags, we will -depending on the notmuch configuration- sync
+            those tags to initial notmuch tags, if set to `True`. It is
+            `False` by default to remain consistent with the libnotmuch
+            API. You might want to look into the underlying method
+            :meth:`Message.maildir_flags_to_tags`.
+
         :returns: On success, we return 
 
            1) a :class:`Message` object that can be used for things
         :returns: On success, we return 
 
            1) a :class:`Message` object that can be used for things
@@ -310,11 +318,14 @@ class Database(object):
                                                   filename,
                                                   byref(msg_p))
  
                                                   filename,
                                                   byref(msg_p))
  
-        if not status in [STATUS.SUCCESS,STATUS.DUPLICATE_MESSAGE_ID]:
+        if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
             raise NotmuchError(status)
 
         #construct Message() and return
         msg = Message(msg_p, self)
             raise NotmuchError(status)
 
         #construct Message() and return
         msg = Message(msg_p, self)
+        #automatic sync initial tags from Maildir flags
+        if sync_maildir_flags:
+            msg.maildir_flags_to_tags()
         return (msg, status)
 
     def remove_message(self, filename):
         return (msg, status)
 
     def remove_message(self, filename):
@@ -358,8 +369,14 @@ class Database(object):
 
         :param msgid: The message ID
         :type msgid: string
 
         :param msgid: The message ID
         :type msgid: string
-        :returns: :class:`Message` or `None` if no message is found or if an
-                  out-of-memory situation occurs.
+        :returns: :class:`Message` or `None` if no message is found or
+                  if any xapian exception or out-of-memory situation
+                  occurs. Do note that Xapian Exceptions include
+                  "Database modified" situations, e.g. when the
+                  notmuch database has been modified by
+                  another program in the meantime. A return value of 
+                  `None` is therefore no guarantee that the message 
+                  does not exist.
         :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
                   the database was not intitialized.
         """
         :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
                   the database was not intitialized.
         """
@@ -459,7 +476,7 @@ class Query(object):
            other unexpected behavior. See above for more details.
     """
     # constants
            other unexpected behavior. See above for more details.
     """
     # constants
-    SORT = Enum(['OLDEST_FIRST','NEWEST_FIRST','MESSAGE_ID'])
+    SORT = Enum(['OLDEST_FIRST','NEWEST_FIRST','MESSAGE_ID', 'UNSORTED'])
     """Constants: Sort order in which to return results"""
 
     """notmuch_query_create"""
     """Constants: Sort order in which to return results"""
 
     """notmuch_query_create"""