summaryrefslogtreecommitdiff
path: root/alot/commands/globals.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-27 09:45:48 -0700
committerPatrick Totzke <patricktotzke@gmail.com>2019-05-11 17:37:57 +0100
commit7622509c0878b6b4da3def3fbc50439b8cba470c (patch)
tree91c87c912d77faca54a088296668b6091831633b /alot/commands/globals.py
parent05c7ebb517b3c2af2038a013eda46881b0b2fd44 (diff)
commands/globals split out the signature setting code
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r--alot/commands/globals.py47
1 files changed, 25 insertions, 22 deletions
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