summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-05-13 12:14:40 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-05-13 12:14:40 +0100
commit0375b095f16d20f7034f5932e022ec6c1ce6cd7a (patch)
treed7183e881b51046f6d0a387cffcf11a949939042 /alot
parent05812e255b0f40c4693114e26e1e57a4e3b8d5fc (diff)
add envelope commands 'sign' and 'unsign'
besides the already present togglesign.
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/envelope.py59
1 files changed, 45 insertions, 14 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index 0280b303..e734a690 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -133,7 +133,8 @@ class SendCommand(Command):
else:
account = settings.get_accounts()[0]
- clearme = ui.notify('constructing mail (GPG, attachments)...', timeout=-1)
+ clearme = ui.notify(u'constructing mail (GPG, attachments)\u2026',
+ timeout=-1)
try:
mail = envelope.construct_mail()
@@ -332,26 +333,56 @@ class ToggleHeaderCommand(Command):
ui.current_buffer.toggle_all_headers()
-@registerCommand(MODE, 'togglesign', arguments=[
- (['keyid'], {'nargs':argparse.REMAINDER, 'help':'which key id to use'})])
-class ToggleSignCommand(Command):
+@registerCommand(MODE, 'sign', forced={'action': 'sign'}, arguments=[
+ (['keyid'], {'nargs':argparse.REMAINDER, 'help':'which key id to use'})],
+ help='mark mail to be signed before sending')
+@registerCommand(MODE, 'unsign', forced={'action': 'unsign'},
+ help='mark mail not to be signed before sending')
+@registerCommand(MODE, 'togglesign', forced={'action': 'toggle'}, arguments=[
+ (['keyid'], {'nargs':argparse.REMAINDER, 'help':'which key id to use'})],
+ help='toggle sign status')
+class SignCommand(Command):
"""toggle signing this email"""
- def __init__(self, keyid, **kwargs):
+ def __init__(self, action=None, keyid=None, **kwargs):
"""
+ :param action: whether to sign/unsign/toggle
+ :type action: str
:param keyid: which key id to use
:type keyid: str
"""
+ self.action = action
self.keyid = keyid
Command.__init__(self, **kwargs)
def apply(self, ui):
- if len(self.keyid) > 0:
- keyid = str(' '.join(self.keyid))
- try:
- key = crypto.CryptoContext().get_key(keyid)
- except GPGProblem, e:
- ui.notify(e.message, priority='error')
- return
- ui.current_buffer.envelope.sign_key = key
- ui.current_buffer.envelope.sign = not ui.current_buffer.envelope.sign
+ sign = None
+ key = None
+ envelope = ui.current_buffer.envelope
+ # sign status
+ if self.action == 'sign':
+ sign = True
+ elif self.action == 'unsign':
+ sign = False
+ elif self.action == 'toggle':
+ sign = not envelope.sign
+ envelope.sign = sign
+
+ # try to find key if hint given as parameter
+ if self.action in ['sign', 'toggle']:
+ if len(self.keyid) > 0:
+ keyid = str(' '.join(self.keyid))
+ try:
+ key = crypto.CryptoContext().get_key(keyid)
+ if key == None:
+ envelope.sign = False
+ ui.notify('no key found using hint "%s"' % keyid,
+ priority='error')
+ return
+ except GPGProblem, e:
+ envelope.sign = False
+ ui.notify(e.message, priority='error')
+ return
+ envelope.sign_key = key
+
+ # reload buffer
ui.current_buffer.rebuild()