summaryrefslogtreecommitdiff
path: root/alot/commands/globals.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2019-02-17 13:37:42 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2019-05-11 17:37:57 +0100
commit7df100d9ac4b81d6c6a4d214b8d00b581292f539 (patch)
tree6563492dfa2d1e954b94d392f17946f9619ea8ef /alot/commands/globals.py
parent7622509c0878b6b4da3def3fbc50439b8cba470c (diff)
commands/globals: split envelope setting code
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r--alot/commands/globals.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index 102d5a8e..f2c7407c 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -878,7 +878,28 @@ class ComposeCommand(Command):
except self.ApplyError:
return
- async def __apply(self, ui):
+ def _get_account(self, ui):
+ # find out the right account
+ sender = self.envelope.get('From')
+ name, addr = email.utils.parseaddr(sender)
+ try:
+ account = settings.get_account_by_address(addr)
+ except NoMatchingAccount:
+ msg = 'Cannot compose mail - no account found for `%s`' % addr
+ logging.error(msg)
+ ui.notify(msg, priority='error')
+ raise CommandCanceled()
+
+ if account is None:
+ accounts = settings.get_accounts()
+ if not accounts:
+ ui.notify('no accounts set.', priority='error')
+ raise self.ApplyError
+ account = accounts[0]
+
+ return account
+
+ def _set_envelope(self):
if self.envelope is None:
if self.rest:
if self.rest.startswith('mailto'):
@@ -888,6 +909,9 @@ class ComposeCommand(Command):
self.envelope.add('To', self.rest)
else:
self.envelope = Envelope()
+
+ async def __apply(self, ui):
+ self._set_envelope()
if self.template is not None:
self._get_template(ui)