summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-08-15 21:51:56 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-08-15 21:51:56 +0100
commita53ad0baa345adb97042a8fee4dc609127164edc (patch)
treed39f0980bcc607e1b359290290b3b97239168f23
parenta2648f2480fe779802fd268c4d800955b1830d3c (diff)
parent354fa0d47bdb31637eccfc63c2e80ce3a0a6d583 (diff)
Merge branch '0.3.2-feature-avoid-dbl-send-497'
-rw-r--r--alot/commands/envelope.py18
-rw-r--r--alot/db/envelope.py1
2 files changed, 17 insertions, 2 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index b4c5604d..de731325 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -118,6 +118,10 @@ class SendCommand(Command):
def apply(self, ui):
currentbuffer = ui.current_buffer # needed to close later
envelope = currentbuffer.envelope
+
+ # This is to warn the user before re-sending
+ # an already sent message in case the envelope buffer
+ # was not closed because it was the last remaining buffer.
if envelope.sent_time:
warning = 'A modified version of ' * envelope.modified_since_sent
warning += 'this message has been sent at %s.' % envelope.sent_time
@@ -125,6 +129,14 @@ class SendCommand(Command):
if (yield ui.choice(warning, cancel='no',
msg_position='left')) == 'no':
return
+
+ # don't do anything if another SendCommand is in the middle of sending
+ # the message and we were triggered accidentally
+ if envelope.sending:
+ msg = 'sending this message already!'
+ logging.debug(msg)
+ return
+
frm = envelope.get('From')
sname, saddr = email.Utils.parseaddr(frm)
@@ -155,6 +167,7 @@ class SendCommand(Command):
clearme = ui.notify('sending..', timeout=-1)
def afterwards(returnvalue):
+ envelope.sending = False
logging.debug('mail sent successfully')
ui.clear_notify([clearme])
envelope.sent_time = datetime.datetime.now()
@@ -170,11 +183,13 @@ class SendCommand(Command):
ui.apply_command(globals.FlushCommand())
def errb(failure):
+ envelope.sending = False
ui.clear_notify([clearme])
failure.trap(SendingMailFailed)
errmsg = 'failed to send: %s' % failure.value
ui.notify(errmsg, priority='error')
+ envelope.sending = True
d = account.send_mail(mail)
d.addCallback(afterwards)
d.addErrback(errb)
@@ -185,8 +200,7 @@ class SendCommand(Command):
(['--spawn'], {'action': BooleanAction, 'default':None,
'help':'spawn editor in new terminal'}),
(['--refocus'], {'action': BooleanAction, 'default':True,
- 'help':'refocus envelope after editing'}),
-])
+ 'help':'refocus envelope after editing'})])
class EditCommand(Command):
"""edit mail"""
def __init__(self, envelope=None, spawn=None, refocus=True, **kwargs):
diff --git a/alot/db/envelope.py b/alot/db/envelope.py
index 04621ab4..d8cf9faf 100644
--- a/alot/db/envelope.py
+++ b/alot/db/envelope.py
@@ -57,6 +57,7 @@ class Envelope(object):
self.encrypt = encrypt
self.sent_time = None
self.modified_since_sent = False
+ self.sending = False # used as semaphore to avoid accidental double sendout
def __str__(self):
return "Envelope (%s)\n%s" % (self.headers, self.body)