diff options
-rw-r--r-- | alot/commands/globals.py | 3 | ||||
-rw-r--r-- | tests/commands/global_test.py | 24 |
2 files changed, 26 insertions, 1 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 0f1d6e26..9ebf2859 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -818,7 +818,8 @@ class ComposeCommand(Command): accounts = settings.get_accounts() if len(accounts) == 1: a = accounts[0] - fromstring = email.utils.formataddr((a.realname, a.address)) + fromstring = email.utils.formataddr( + (a.realname, str(a.address))) self.envelope.add('From', fromstring) else: cmpl = AccountCompleter() 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): |