summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-02-08 21:29:27 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-02-08 22:14:38 +0000
commit2c94f049ea2d8f5b0a9b9c3a98d9e84360e01beb (patch)
tree00eea6cf400bc48a43bee53d3d94a9447e8f4f74
parent44b85b2a1b9d35403f9c6cc6840d9c8f2547f31d (diff)
DBManager.add_message rewrite
only queue requested changes to internal write queue, let the lifting be done later in `flush`. This refactors add_message to also accept a `tags` parameter, a list of tagstrings that the message gets tagged with initially. The new interface is used in account
-rw-r--r--alot/account.py3
-rw-r--r--alot/db.py19
2 files changed, 9 insertions, 13 deletions
diff --git a/alot/account.py b/alot/account.py
index 1a405df9..abd44db5 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -134,8 +134,7 @@ class Account(object):
# I wish the mailbox module were more helpful...
path = glob.glob(os.path.join(mbx._path, '*', message_id + '*'))[0]
- message = self.dbman.add_message(path)
- message.add_tags(tags)
+ message = self.dbman.add_message(path, tags)
self.dbman.flush()
return True
diff --git a/alot/db.py b/alot/db.py
index b6521e53..b7c05d46 100644
--- a/alot/db.py
+++ b/alot/db.py
@@ -289,23 +289,20 @@ class DBManager(object):
db = Database(path=self.path, mode=mode)
return db.create_query(querystring)
- def add_message(self, path):
+ def add_message(self, path, tags=[], afterwards=None):
"""
Adds a file to the notmuch index.
:param path: path to the file
:type path: str
- :returns: the message object corresponding the added message
- :rtype: :class:`alot.message.Message`
+ :param tags: tagstrings to add
+ :type tags: list of str
+ :param afterwards: callback to trigger after adding
+ :type afterwards: callable or None
"""
- db = Database(path=self.path, mode=Database.MODE.READ_WRITE)
- try:
- message, status = db.add_message(path,
- sync_maildir_flags=True)
- except NotmuchError as e:
- raise DatabaseError(unicode(e))
-
- return Message(self, message)
+ if self.ro:
+ raise DatabaseROError()
+ self.writequeue.append(('add', afterwards, path, tags))
def remove_message(self, message):
"""