def apply(self, ui): envelope = ui.current_buffer mail = envelope.get_email() frm = decode_header(mail.get('From')) sname, saddr = email.Utils.parseaddr(frm) account = ui.accountman.get_account_by_address(saddr) if account: # attach signature file if present if account.signature: sig = os.path.expanduser(account.signature) if os.path.isfile(sig): if account.signature_filename: name = account.signature_filename else: name = None helper.attach(sig, mail, filename=name) else: ui.notify('could not locate signature: %s' % sig, priority='error') if not ui.choice('send without signature') == 'yes': return clearme = ui.notify('sending..', timeout=-1, block=False) reason = account.send_mail(mail) ui.clear_notify([clearme]) if not reason: # sucessfully send mail cmd = BufferCloseCommand(buffer=envelope) ui.apply_command(cmd) ui.notify('mail send successful') else: ui.notify('failed to send: %s' % reason, priority='error') else: ui.notify('failed to send: no account set up for %s' % saddr, priority='error')
def apply(self, ui): msg = self.mail if not msg: msg = ui.current_buffer.get_email() if self.path: files = filter(os.path.isfile, glob.glob(os.path.expanduser(self.path))) if not files: ui.notify('no matches, abort') return else: ui.notify('no files specified, abort') logging.info("attaching: %s" % files) for path in files: helper.attach(path, msg) if not self.mail: # set the envelope msg iff we got it from there ui.current_buffer.set_email(msg)