summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-18 09:08:53 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-07-26 10:36:16 -0700
commit065bb9a1077181ee305cdd857dbe2d492850f937 (patch)
tree4ff637718a20da880a7b3a0f477a5810ab045a12 /alot
parent0bbf12232e86da57ce24703ff0ea82780dc27e31 (diff)
command/envelope: Don't use a deferred, use await
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/envelope.py49
1 files changed, 20 insertions, 29 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index 1c13044c..b06bb92d 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -10,8 +10,7 @@ import os
import re
import tempfile
import textwrap
-
-from twisted.internet.defer import ensureDeferred
+import traceback
from . import Command, registerCommand
from . import globals
@@ -232,8 +231,25 @@ class SendCommand(Command):
return
logging.debug("ACCOUNT: \"%s\"" % account.address)
- # define callback
- def afterwards(_):
+ # send out
+ clearme = ui.notify('sending..', timeout=-1)
+ if self.envelope is not None:
+ self.envelope.sending = True
+ try:
+ await account.send_mail(self.mail)
+ except SendingMailFailed as e:
+ if self.envelope is not None:
+ self.envelope.sending = False
+ ui.clear_notify([clearme])
+ logging.error(traceback.format_exc())
+ errmsg = 'failed to send: {}'.format(e)
+ ui.notify(errmsg, priority='error', block=True)
+ except StoreMailError as e:
+ ui.clear_notify([clearme])
+ logging.error(traceback.format_exc())
+ errmsg = 'could not store mail: {}'.format(e)
+ ui.notify(errmsg, priority='error', block=True)
+ else:
initial_tags = []
if self.envelope is not None:
self.envelope.sending = False
@@ -261,31 +277,6 @@ class SendCommand(Command):
ui.dbman.add_message(path, account.sent_tags + initial_tags)
ui.apply_command(globals.FlushCommand())
- # define errback
- def send_errb(failure):
- if self.envelope is not None:
- self.envelope.sending = False
- ui.clear_notify([clearme])
- failure.trap(SendingMailFailed)
- logging.error(failure.getTraceback())
- errmsg = 'failed to send: %s' % failure.value
- ui.notify(errmsg, priority='error', block=True)
-
- def store_errb(failure):
- failure.trap(StoreMailError)
- logging.error(failure.getTraceback())
- errmsg = 'could not store mail: %s' % failure.value
- ui.notify(errmsg, priority='error', block=True)
-
- # send out
- clearme = ui.notify('sending..', timeout=-1)
- if self.envelope is not None:
- self.envelope.sending = True
- d = ensureDeferred(account.send_mail(self.mail))
- d.addCallback(afterwards)
- d.addErrback(send_errb)
- d.addErrback(store_errb)
-
@registerCommand(MODE, 'edit', arguments=[
(['--spawn'], {'action': cargparse.BooleanAction, 'default': None,