From 7622509c0878b6b4da3def3fbc50439b8cba470c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 27 Jul 2018 09:45:48 -0700 Subject: commands/globals split out the signature setting code --- alot/commands/globals.py | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'alot/commands/globals.py') diff --git a/alot/commands/globals.py b/alot/commands/globals.py index fd71fc67..102d5a8e 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -848,6 +848,30 @@ class ComposeCommand(Command): if self.envelope.account is None: self.envelope.account = account + async def _set_signature(self, ui, account): + if not self.omit_signature and account.signature: + logging.debug('has signature') + sig = os.path.expanduser(account.signature) + if os.path.isfile(sig): + logging.debug('is file') + if account.signature_as_attachment: + name = account.signature_filename or None + self.envelope.attach(sig, filename=name) + logging.debug('attached') + else: + with open(sig, 'rb') as f: + sigcontent = f.read() + mimetype = helper.guess_mimetype(sigcontent) + if mimetype.startswith('text'): + sigcontent = helper.try_decode(sigcontent) + self.envelope.body += '\n' + sigcontent + else: + ui.notify('could not locate signature: %s' % sig, + priority='error') + if (await ui.choice('send without signature?', 'yes', + 'no')) == 'no': + raise self.ApplyError + async def apply(self, ui): try: await self.__apply(ui) @@ -889,28 +913,7 @@ class ComposeCommand(Command): await self._set_sender(self,ui) # add signature - if not self.omit_signature and account.signature: - logging.debug('has signature') - sig = os.path.expanduser(account.signature) - if os.path.isfile(sig): - logging.debug('is file') - if account.signature_as_attachment: - name = account.signature_filename or None - self.envelope.attach(sig, filename=name) - logging.debug('attached') - else: - with open(sig, 'rb') as f: - sigcontent = f.read() - mimetype = helper.guess_mimetype(sigcontent) - if mimetype.startswith('text'): - sigcontent = helper.try_decode(sigcontent) - self.envelope.body += '\n' + sigcontent - else: - ui.notify('could not locate signature: %s' % sig, - priority='error') - if (await ui.choice('send without signature?', 'yes', - 'no')) == 'no': - return + await self._set_signature(ui, account) # Figure out whether we should GPG sign messages by default # and look up key if so -- cgit v1.2.3