diff options
-rw-r--r-- | alot/commands/envelope.py | 19 | ||||
-rw-r--r-- | alot/db/manager.py | 10 | ||||
-rw-r--r-- | alot/db/utils.py | 9 | ||||
-rwxr-xr-x | alot/init.py | 4 |
4 files changed, 36 insertions, 6 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 0480cf0c..63ad22a4 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -21,6 +21,7 @@ from alot.commands import globals from alot.helper import string_decode from alot.settings import settings from alot.utils.booleanaction import BooleanAction +from alot.db.errors import DatabaseError MODE = 'envelope' @@ -130,14 +131,24 @@ class SaveCommand(Command): # add Date header mail['Date'] = email.Utils.formatdate(localtime=True) path = account.store_draft_mail(crypto.email_as_string(mail)) - ui.notify('draft saved successfully') + + msg = 'draft saved successfully' # add mail to index if maildir path available if path is not None: + ui.notify(msg + ' to %s' % path) logging.debug('adding new mail to index') - ui.dbman.add_message(path, account.draft_tags) - ui.apply_command(globals.FlushCommand()) - ui.apply_command(commands.globals.BufferCloseCommand()) + try: + ui.dbman.add_message(path, account.draft_tags) + ui.apply_command(globals.FlushCommand()) + ui.apply_command(commands.globals.BufferCloseCommand()) + except DatabaseError as e: + logging.error(e.message) + ui.notify('could not index message:\n%s' % e.message, + priority='error', + block=True) + else: + ui.apply_command(commands.globals.BufferCloseCommand()) @registerCommand(MODE, 'send') diff --git a/alot/db/manager.py b/alot/db/manager.py index b3d31694..5450b788 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -21,6 +21,8 @@ from errors import DatabaseLockedError from errors import DatabaseROError from errors import NonexistantObjectError from alot.db import DB_ENC +from alot.db.utils import is_subdir_of + class FillPipeProcess(multiprocessing.Process): @@ -418,7 +420,13 @@ class DBManager(object): """ if self.ro: raise DatabaseROError() - self.writequeue.append(('add', afterwards, path, tags)) + if not is_subdir_of(path,self.path): + msg = 'message path %s ' % path + msg += ' is not below notmuchs ' + msg += 'root path (%s)' % self.path + raise DatabaseError(msg) + else: + self.writequeue.append(('add', afterwards, path, tags)) def remove_message(self, message, afterwards=None): """ diff --git a/alot/db/utils.py b/alot/db/utils.py index 45ee0db8..db8de0de 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -390,3 +390,12 @@ def encode_header(key, value): else: value = Header(value) return value + +def is_subdir_of(subpath, superpath): + #make both absolute + superpath = os.path.realpath(superpath) + subpath = os.path.realpath(subpath) + + #return true, if the common prefix of both is equal to directory + #e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b + return os.path.commonprefix([subpath, superpath]) == superpath diff --git a/alot/init.py b/alot/init.py index af6cf1b1..45ae1590 100755 --- a/alot/init.py +++ b/alot/init.py @@ -163,7 +163,9 @@ def main(): settings.set('colourmode', args['colour-mode']) # get ourselves a database manager - dbman = DBManager(path=args['mailindex-path'], ro=args['read-only']) + indexpath = settings.get_notmuch_setting('database', 'path') + indexpath = args['mailindex-path'] or indexpath + dbman = DBManager(path=indexpath, ro=args['read-only']) # determine what to do try: |