From 6f16c8f4c985ed0b31fd5998749c09a6982c3e54 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 24 Jul 2018 16:39:31 -0700 Subject: commands/globals: Convert Address to string for email.utils Email utils apparently assumes it's getting a string, and calls encode directly. This can only be hit if you have a single account configured, not with multiple accounts. Fixes #1277 --- tests/commands/global_test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py index 53556c0f..b0153a45 100644 --- a/tests/commands/global_test.py +++ b/tests/commands/global_test.py @@ -149,6 +149,30 @@ class TestComposeCommand(unittest.TestCase): 'Subject': [subject]}, cmd.envelope.headers) self.assertEqual(body, cmd.envelope.body) + @inlineCallbacks + def test_single_account_no_from(self): + # issue #1277 + envelope = self._make_envelope_mock() + del envelope.headers['From'] + account = self._make_account_mock() + account.realname = "foo" + account.address = 1 # maybe this should be a real Address? + cmd = g_commands.ComposeCommand(envelope=envelope) + + # This whole mess is required becasue ComposeCommand.apply is waaaaay + # too complicated, it needs to be split into more manageable segments. + with mock.patch('alot.commands.globals.settings.get_account_by_address', + mock.Mock(return_value=account)): + with mock.patch('alot.commands.globals.settings.get_accounts', + mock.Mock(return_value=[account])): + with mock.patch('alot.commands.globals.settings.get_addressbooks', + mock.Mock(side_effect=Stop)): + try: + yield cmd.apply(mock.Mock()) + except Stop: + pass + + class TestExternalCommand(unittest.TestCase): -- cgit v1.2.3