diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-07-27 14:26:24 -0700 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2019-05-11 17:37:57 +0100 |
commit | 7ed4acf47be826315e605902c560db35085f9516 (patch) | |
tree | f6048882b0f09744e35abe43e56e0aaf7a0d1b5e /alot/commands/globals.py | |
parent | 018d3f0eea4f698a2e3f3aad313b26982e8b0099 (diff) |
commands/globals: Split code for setting a missing To header
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r-- | alot/commands/globals.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 7c167caa..29bc3cd3 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -921,6 +921,23 @@ class ComposeCommand(Command): logging.warning(msg) ui.notify(msg, priority='error') + async def _set_to(self, ui, account): + if 'To' not in self.envelope.headers: + allbooks = not settings.get('complete_matching_abook_only') + logging.debug(allbooks) + abooks = settings.get_addressbooks(order=[account], + append_remaining=allbooks) + logging.debug(abooks) + completer = ContactsCompleter(abooks) + to = await ui.prompt('To', completer=completer, + history=ui.recipienthistory) + if to is None: + raise CommandCanceled() + + to = to.strip(' \t\n,') + ui.recipienthistory.append(to) + self.envelope.add('To', to) + async def __apply(self, ui): self._set_envelope() if self.template is not None: @@ -955,21 +972,7 @@ class ComposeCommand(Command): self._set_gpg_sign(ui, account) # get missing To header - if 'To' not in self.envelope.headers: - allbooks = not settings.get('complete_matching_abook_only') - logging.debug(allbooks) - abooks = settings.get_addressbooks(order=[account], - append_remaining=allbooks) - logging.debug(abooks) - completer = ContactsCompleter(abooks) - to = await ui.prompt('To', completer=completer, - history=ui.recipienthistory) - if to is None: - raise CommandCanceled() - - to = to.strip(' \t\n,') - ui.recipienthistory.append(to) - self.envelope.add('To', to) + await self._set_to(ui, account) if settings.get('ask_subject') and \ 'Subject' not in self.envelope.headers: |