From 6e443d5ad73cc2beed0ea45294221b0af89eadd6 Mon Sep 17 00:00:00 2001 From: "Bjarni R. Einarsson" Date: Sat, 8 Aug 2015 11:26:00 +0100 Subject: [PATCH] Provide basic notifications for sending progress, fixes #735 --- mailpile/plugins/compose.py | 18 ++++++++++++++++-- .../default/html/jsapi/global/notifications.js | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mailpile/plugins/compose.py b/mailpile/plugins/compose.py index 8c8be4f02..acbe0def8 100644 --- a/mailpile/plugins/compose.py +++ b/mailpile/plugins/compose.py @@ -902,7 +902,8 @@ def command(self, emails=None): # FIXME: Also fatal, when the SMTP server REJECTS the mail except: # We want to try that again! - message = _('Failed to send %s') % email + subject = email.get_msg_info(config.index.MSG_SUBJECT) + message = _('Failed to send message: %s') % subject for ev in events: ev.flags = Event.INCOMPLETE ev.message = message @@ -1032,14 +1033,27 @@ def command(self): if not idx: return self._error(_('The index is not ready yet')) + # Collect a list of messages from the outbox messages = [] for tag in cfg.get_tags(type='outbox'): search = ['in:%s' % tag._key] for msg_idx_pos in idx.search(self.session, search, order='flat-index').as_set(): messages.append('=%s' % b36(msg_idx_pos)) + + # Messages no longer in the outbox get their events canceled... + if cfg.event_log: + events = cfg.event_log.incomplete(source='.plugins.compose.Sendit') + for ev in events: + if ('mid' in ev.data and + ('=%s' % ev.data['mid']) not in messages): + ev.flags = ev.COMPLETE + ev.message = _('Sending cancelled.') + cfg.event_log.log_event(ev) + + # Send all the mail! if messages: - self.args = tuple(messages) + self.args = tuple(set(messages)) return Sendit.command(self) else: return self._success(_('The outbox is empty')) diff --git a/mailpile/www/default/html/jsapi/global/notifications.js b/mailpile/www/default/html/jsapi/global/notifications.js index 49e6f60cf..dfba4a2b2 100644 --- a/mailpile/www/default/html/jsapi/global/notifications.js +++ b/mailpile/www/default/html/jsapi/global/notifications.js @@ -187,3 +187,12 @@ EventLog.subscribe('.*mail_source.*', function(ev) { Mailpile.notification(ev); } }); +EventLog.subscribe('.*compose.Sendit', function(ev) { + if (ev.data.delivered == ev.data.recipients) { + ev.icon = 'icon-outbox'; + } + else if (ev.data.last_error) { + ev.icon = 'icon-signature-unknown'; + } + Mailpile.notification(ev); +});