diff --git a/alot/db/manager.py b/alot/db/manager.py index 6d950ef74..4980a996c 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -51,9 +51,7 @@ def exclude_tags(self): if exclude_tags is not None: return exclude_tags - exclude_tags = settings.get_notmuch_setting('search', 'exclude_tags') - if exclude_tags: - return [t for t in exclude_tags.split(';') if t] + return settings.get_notmuch_setting('search', 'exclude_tags') def flush(self): """ @@ -72,7 +70,7 @@ def flush(self): raise DatabaseROError() if self.writequeue: # read notmuch's config regarding imap flag synchronization - sync = settings.get_notmuch_setting('maildir', 'synchronize_flags') == 'true' + sync = settings.get_notmuch_setting('maildir', 'synchronize_flags') # go through writequeue entries while self.writequeue: diff --git a/alot/settings/utils.py b/alot/settings/utils.py index 7b106b122..ae5ee46f8 100644 --- a/alot/settings/utils.py +++ b/alot/settings/utils.py @@ -93,13 +93,15 @@ def read_notmuch_config(path): The configuration value for a key under a section can be accessed with ``config[section][key]``. - The returned value is a dict ``config`` with + The returned value is a dict ``config`` with some values converted to + special python types. These are the values that alot is known to use. All + other values in the returned dict are just strings. :param path: path to the configuration file, which is passed as argument to the --config option of notmuch. :type path: str :raises: :class:`~alot.settings.errors.ConfigError` - :rtype: `dict` + :rtype: dict """ cmd = ['notmuch', '--config', path, 'config', 'list'] out, err, code = call_cmd(cmd) @@ -112,6 +114,23 @@ def read_notmuch_config(path): for line in out.splitlines(): left_hand, right_hand = line.split("=", maxsplit=1) section, key = left_hand.split(".", maxsplit=1) + if section == "maildir" and key == "synchronize_flags": + if right_hand == "true": + right_hand = True + elif right_hand == "false": + right_hand = False + else: + raise ConfigError( + f"Bad value for maildir.synchronize_flags: {right_hand}") + if section == "search" and key == "exclude_tags": + try: + if right_hand: + right_hand = [t for t in right_hand.split(';') if t] + else: + right_hand = None + except: + raise ConfigError( + "Can not split search.exclude_tags into a list: {right_hand}") config.setdefault(section, {})[key] = right_hand return config