Skip to content

Commit

Permalink
Move validation of notmuch config values to read_notmuch_config
Browse files Browse the repository at this point in the history
  • Loading branch information
lucc committed May 6, 2024
1 parent fffb427 commit 9fe0f3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions alot/db/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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:
Expand Down
23 changes: 21 additions & 2 deletions alot/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 9fe0f3e

Please sign in to comment.