summaryrefslogtreecommitdiff
path: root/alot/commands/envelope.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-02-02 21:43:40 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-02-02 22:27:33 +0000
commitfbcec8a2828522a62c1c07877c3448d7a2a011eb (patch)
treeb724c5c64f426c462089a186f0f4d105aaa66ed5 /alot/commands/envelope.py
parente4baf73beca49b694bbaada217eee846bef9d64f (diff)
use asyncronous call to sendmail
in account.send_mail and use call/errbacks in envelope accordingly
Diffstat (limited to 'alot/commands/envelope.py')
-rw-r--r--alot/commands/envelope.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index af26b1ed..3dcc19f8 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -125,28 +125,28 @@ class SendCommand(Command):
# send
clearme = ui.notify('sending..', timeout=-1)
+ mail = envelope.construct_mail()
def afterwards(returnvalue):
+ logging.debug('mail sent successfully')
ui.clear_notify([clearme])
- if returnvalue == 'success': # successfully send mail
- envelope.sent_time = datetime.datetime.now()
- ui.apply_command(commands.globals.BufferCloseCommand())
- ui.notify('mail send successfully')
- else:
- ui.notify('failed to send: %s' % returnvalue,
- priority='error')
-
- def thread_code():
- mail = envelope.construct_mail()
- try:
- account.send_mail(mail)
- except SendingMailFailed as e:
- return unicode(e)
- else:
- return 'success'
+ envelope.sent_time = datetime.datetime.now()
+ ui.apply_command(commands.globals.BufferCloseCommand())
+ ui.notify('mail sent successfully')
+ # add mail to index
+ logging.debug('adding new mail to index')
+ account.store_sent_mail(mail)
+
+ def errb(failure):
+ ui.clear_notify([clearme])
+ failure.trap(SendingMailFailed)
+ errmsg = 'failed to send: %s' % failure.value
+ ui.notify(errmsg, priority='error')
- d = threads.deferToThread(thread_code)
+ d = account.send_mail(mail)
d.addCallback(afterwards)
+ d.addErrback(errb)
+ logging.debug('added errbacks,callbacks')
@registerCommand(MODE, 'edit')