diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2017-07-27 15:04:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-27 15:04:26 -0700 |
commit | 78d069ea38277721e31b621daf8df0d8b8174041 (patch) | |
tree | 41c287cf4aa1d52a2c52b804c41f5643465da8fc /alot/settings | |
parent | 054eab33e52bd9687a4b567e9ea369d447cc33ee (diff) | |
parent | 084e37cc9b5148d75f88936a353d5249824a4b60 (diff) |
Merge pull request #1089 from dcbaker/submit/sign-without-hint
commands/envelope: Fall back to account for signing key
Diffstat (limited to 'alot/settings')
-rw-r--r-- | alot/settings/errors.py | 5 | ||||
-rw-r--r-- | alot/settings/manager.py | 26 |
2 files changed, 22 insertions, 9 deletions
diff --git a/alot/settings/errors.py b/alot/settings/errors.py index 606f78e1..baf794ff 100644 --- a/alot/settings/errors.py +++ b/alot/settings/errors.py @@ -6,3 +6,8 @@ class ConfigError(Exception): """could not parse user config""" pass + + +class NoMatchingAccount(ConfigError): + """No account matching requirements found.""" + pass diff --git a/alot/settings/manager.py b/alot/settings/manager.py index ab68659e..796f98a5 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -17,7 +17,7 @@ from ..addressbook.external import ExternalAddressbook from ..helper import pretty_datetime, string_decode from ..utils import configobj as checks -from .errors import ConfigError +from .errors import ConfigError, NoMatchingAccount from .utils import read_config from .utils import resolve_att from .theme import Theme @@ -430,19 +430,27 @@ class SettingsManager(object): """ return self._accounts - def get_account_by_address(self, address): - """ - returns :class:`Account` for a given email address (str) + def get_account_by_address(self, address, return_default=False): + """returns :class:`Account` for a given email address (str) - :param address: address to look up - :type address: string - :rtype: :class:`Account` or None + :param str address: address to look up + :param bool return_default: If True and no address can be found, then + the default account wil be returned + :rtype: :class:`Account` + :raises ~alot.settings.errors.NoMatchingAccount: If no account can be + found. Thsi includes if return_default is True and there are no + accounts defined. """ - for myad in self.get_addresses(): if myad == address: return self._accountmap[myad] - return None + if return_default: + try: + return self.get_accounts()[0] + except IndexError: + # Fall through + pass + raise NoMatchingAccount def get_main_addresses(self): """returns addresses of known accounts without its aliases""" |