Skip to content

Commit

Permalink
Merge pull request #1278 from dcbaker/fix-1277
Browse files Browse the repository at this point in the history
commands/globals: Convert Address to string for email.utils
  • Loading branch information
dcbaker committed Jul 25, 2018
2 parents 4cba47a + 6f16c8f commit ce7bda0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ def apply(self, ui):
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()
Expand Down
24 changes: 24 additions & 0 deletions tests/commands/global_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ def test_decode_template_on_loading(self):
'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):

Expand Down

0 comments on commit ce7bda0

Please sign in to comment.