diff options
-rw-r--r-- | alot/account.py | 11 | ||||
-rw-r--r-- | alot/commands/envelope.py | 6 | ||||
-rw-r--r-- | alot/commands/globals.py | 5 | ||||
-rw-r--r-- | alot/commands/utils.py | 2 | ||||
-rw-r--r-- | alot/settings/manager.py | 6 | ||||
-rw-r--r-- | tests/commands/envelope_test.py | 22 | ||||
-rw-r--r-- | tests/settings/manager_test.py | 20 |
7 files changed, 31 insertions, 41 deletions
diff --git a/alot/account.py b/alot/account.py index 116c3417..f4a360a4 100644 --- a/alot/account.py +++ b/alot/account.py @@ -250,12 +250,6 @@ class Account(object): u'^' + str(self.alias_regexp) + u'$', flags=0 if case_sensitive_username else re.IGNORECASE) - - def get_addresses(self): - """return all email addresses connected to this account, in order of - their importance""" - return [self.address] + self.aliases - def matches_address(self, address): """returns whether this account knows about an email address @@ -267,9 +261,8 @@ class Account(object): for alias in self.aliases: if alias == address: return True - if self._alias_regexp is not None: - if self._alias_regexp.match(address): - return True + if self._alias_regexp and self._alias_regexp.match(address): + return True return False @staticmethod diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 2aa15475..737a596f 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -258,8 +258,8 @@ class SendCommand(Command): address = msg.get('Resent-From', False) or msg.get('From', '') logging.debug("FROM: \"%s\"" % address) try: - account = settings.get_account_by_address(address, - return_default=True) + account = settings.account_matching_address(address, + return_default=True) except NoMatchingAccount: ui.notify('no accounts set', priority='error') return @@ -543,7 +543,7 @@ class SignCommand(Command): else: if envelope.account is None: try: - envelope.account = settings.get_account_by_address( + envelope.account = settings.account_matching_address( envelope['From']) except NoMatchingAccount: envelope.sign = False diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 8c91ffe5..a3435742 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -860,9 +860,10 @@ class ComposeCommand(Command): # try to find the account again if account is None: try: - account = settings.get_account_by_address(fromaddress) + account = settings.account_matching_address(fromaddress) except NoMatchingAccount: - msg = 'Cannot compose mail - no account found for `%s`' % fromaddress + msg = 'Cannot compose mail - ' \ + 'no account found for `%s`' % fromaddress logging.error(msg) ui.notify(msg, priority='error') raise CommandCanceled() diff --git a/alot/commands/utils.py b/alot/commands/utils.py index 14ca78af..57c52d35 100644 --- a/alot/commands/utils.py +++ b/alot/commands/utils.py @@ -47,7 +47,7 @@ async def update_keys(ui, envelope, block_error=False, signed_only=False): if 'From' in envelope.headers: try: if envelope.account is None: - envelope.account = settings.get_account_by_address( + envelope.account = settings.account_matching_address( envelope['From']) acc = envelope.account if acc.encrypt_to_self: diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 87ae14c7..4b97c611 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -464,7 +464,7 @@ class SettingsManager(object): """ return self._accounts - def get_account_by_address(self, address, return_default=False): + def account_matching_address(self, address, return_default=False): """returns :class:`Account` for a given email address (str) :param str address: address to look up. A realname part will be ignored. @@ -491,10 +491,6 @@ class SettingsManager(object): """returns addresses of known accounts without its aliases""" return [a.address for a in self._accounts] - def get_addresses(self): - """returns addresses of known accounts including all their aliases""" - return list(self._accountmap.keys()) - def get_addressbooks(self, order=None, append_remaining=True): """returns list of all defined :class:`AddressBook` objects""" order = order or [] diff --git a/tests/commands/envelope_test.py b/tests/commands/envelope_test.py index b09cddaa..76aa7e88 100644 --- a/tests/commands/envelope_test.py +++ b/tests/commands/envelope_test.py @@ -186,7 +186,7 @@ class TestSignCommand(unittest.TestCase): self.assertEqual(env.sign_key, mock.sentinel.default) ui.notify.assert_called_once() - @mock.patch('alot.commands.envelope.settings.get_account_by_address', + @mock.patch('alot.commands.envelope.settings.account_matching_address', mock.Mock(side_effect=NoMatchingAccount)) def test_apply_no_keyid_nomatchingaccount(self): """If there is a nokeyid and no account can be found to match the From, @@ -359,28 +359,28 @@ class TestSendCommand(unittest.TestCase): pass @utilities.async_test - async def test_get_account_by_address_with_str(self): + async def test_account_matching_address_with_str(self): cmd = envelope.SendCommand(mail=self.mail) account = mock.Mock(wraps=self.MockedAccount()) with mock.patch( - 'alot.commands.envelope.settings.get_account_by_address', - mock.Mock(return_value=account)) as get_account_by_address: + 'alot.commands.envelope.settings.account_matching_address', + mock.Mock(return_value=account)) as account_matching_address: await cmd.apply(mock.Mock()) - get_account_by_address.assert_called_once_with('foo@example.com', - return_default=True) + account_matching_address.assert_called_once_with('foo@example.com', + return_default=True) # check that the apply did run through till the end. account.send_mail.assert_called_once_with(self.mail) @utilities.async_test - async def test_get_account_by_address_with_email_message(self): + async def test_account_matching_address_with_email_message(self): mail = email.message_from_string(self.mail) cmd = envelope.SendCommand(mail=mail) account = mock.Mock(wraps=self.MockedAccount()) with mock.patch( - 'alot.commands.envelope.settings.get_account_by_address', - mock.Mock(return_value=account)) as get_account_by_address: + 'alot.commands.envelope.settings.account_matching_address', + mock.Mock(return_value=account)) as account_matching_address: await cmd.apply(mock.Mock()) - get_account_by_address.assert_called_once_with('foo@example.com', - return_default=True) + account_matching_address.assert_called_once_with('foo@example.com', + return_default=True) # check that the apply did run through till the end. account.send_mail.assert_called_once_with(mail) diff --git a/tests/settings/manager_test.py b/tests/settings/manager_test.py index e82d5f27..21439403 100644 --- a/tests/settings/manager_test.py +++ b/tests/settings/manager_test.py @@ -188,7 +188,7 @@ class TestSettingsManagerExpandEnvironment(unittest.TestCase): class TestSettingsManagerGetAccountByAddress(utilities.TestCaseClassCleanup): - """Test the get_account_by_address helper.""" + """Test the account_matching_address helper.""" @classmethod def setUpClass(cls): @@ -216,17 +216,17 @@ class TestSettingsManagerGetAccountByAddress(utilities.TestCaseClassCleanup): cls.manager.read_config(f.name) def test_exists_addr(self): - acc = self.manager.get_account_by_address(u'that_guy@example.com') + acc = self.manager.account_matching_address(u'that_guy@example.com') self.assertEqual(acc.realname, 'That Guy') def test_doesnt_exist_return_default(self): - acc = self.manager.get_account_by_address(u'doesntexist@example.com', - return_default=True) + acc = self.manager.account_matching_address(u'doesntexist@example.com', + return_default=True) self.assertEqual(acc.realname, 'That Guy') def test_doesnt_exist_raise(self): with self.assertRaises(NoMatchingAccount): - self.manager.get_account_by_address(u'doesntexist@example.com') + self.manager.account_matching_address(u'doesntexist@example.com') def test_doesnt_exist_no_default(self): with tempfile.NamedTemporaryFile() as f: @@ -234,11 +234,11 @@ class TestSettingsManagerGetAccountByAddress(utilities.TestCaseClassCleanup): settings = SettingsManager() settings.read_config(f.name) with self.assertRaises(NoMatchingAccount): - settings.get_account_by_address('that_guy@example.com', - return_default=True) + settings.account_matching_address('that_guy@example.com', + return_default=True) def test_real_name_will_be_stripped_before_matching(self): - acc = self.manager.get_account_by_address( + acc = self.manager.account_matching_address( 'That Guy <a_dude@example.com>') self.assertEqual(acc.realname, 'A Dude') @@ -249,6 +249,6 @@ class TestSettingsManagerGetAccountByAddress(utilities.TestCaseClassCleanup): considered the same. Among servers that do this gmail, yahoo, fastmail, anything running Exchange (i.e., most large corporations), and others. """ - acc1 = self.manager.get_account_by_address('That_guy@example.com') - acc2 = self.manager.get_account_by_address('that_guy@example.com') + acc1 = self.manager.account_matching_address('That_guy@example.com') + acc2 = self.manager.account_matching_address('that_guy@example.com') self.assertIs(acc1, acc2) |