def apply(self, ui): envelope = ui.current_buffer.envelope # determine account to use sname, saddr = email.Utils.parseaddr(envelope.get('From')) account = settings.get_account_by_address(saddr) if account is None: if not settings.get_accounts(): ui.notify('no accounts set.', priority='error') return else: account = settings.get_accounts()[0] if account.draft_box is None: ui.notify('abort: account <%s> has no draft_box set.' % saddr, priority='error') return mail = envelope.construct_mail() # store mail locally # add Date header mail['Date'] = email.Utils.formatdate(localtime=True) path = account.store_draft_mail(crypto.email_as_string(mail)) ui.notify('draft saved successfully') # add mail to index if maildir path available if path is not None: logging.debug('adding new mail to index') ui.dbman.add_message(path, account.draft_tags) ui.apply_command(globals.FlushCommand()) ui.apply_command(commands.globals.BufferCloseCommand())
def afterwards(returnvalue): logging.debug('mail sent successfully') ui.clear_notify([clearme]) envelope.sent_time = datetime.datetime.now() ui.apply_command(commands.globals.BufferCloseCommand()) ui.notify('mail sent successfully') # store mail locally # add Date header if 'Date' not in mail: mail['Date'] = email.Utils.formatdate(localtime=True) path = account.store_sent_mail(mail) # add mail to index if maildir path available if path is not None: logging.debug('adding new mail to index') ui.dbman.add_message(path, account.sent_tags) ui.apply_command(globals.FlushCommand())
def afterwards(returnvalue): envelope.sending = False logging.debug('mail sent successfully') ui.clear_notify([clearme]) envelope.sent_time = datetime.datetime.now() ui.apply_command(commands.globals.BufferCloseCommand()) ui.notify('mail sent successfully') # store mail locally # This can raise StoreMailError path = account.store_sent_mail(mail) # add mail to index if maildir path available if path is not None: logging.debug('adding new mail to index') ui.dbman.add_message(path, account.sent_tags + envelope.tags) ui.apply_command(globals.FlushCommand())