import { Command } from '@cliffy/command/mod.ts' import { format } from '../src/format.ts' import { Contact } from '../src/contact.ts' // import { send } from '../src/send.ts' import { send } from '../src/transporter.ts' export const cmd = new Command() .name('send') .description('Send a mail.') .option( '-f, --from ', 'From mail account or short name from config.', { default: '!me' }, ) .option('--cc ', 'Copy carbon.', { collect: true }) .option('--cci ', 'Copy carbon invisible.', { collect: true, }) .option('-a, --attachments ', 'Attachments.', { collect: true }) .option('--content-type ', 'Mail body Content-Type.', { default: 'text/html; charset=utf-8', }) //.option('-t, --template ', 'HTML template from config', { default: 'basic' }) .arguments(' ') .action( async ({ from, cc, cci, attachments, contentType }, to, subject, body) => { const fromContact: Contact = await (async () => { if (from === '!me') { const whoami = new Deno.Command('whoami', { stderr: 'inherit', }) const { stdout } = await whoami.output() const rawName = new TextDecoder().decode(stdout).trim() const name = encodeURIComponent(rawName) return { name: `${name} de Cohabit`, address: `_${name}_@cohabit.fr`, } } if (from.startsWith('!')) { //@ts-ignore try expand return expand(from.slice(1)) } return Contact.fromString(from) })() const toContact = Contact.fromString(to) const mail = format(fromContact, toContact, subject, body, { cc: cc?.map(Contact.fromString) ?? [], cci: cci?.map(Contact.fromString) ?? [], attachments: attachments ?? [], contentType, }) await send(mail) }, ) if (import.meta.main) { if (Deno.args.length) { cmd.parse(Deno.args) } else { cmd.showHelp() } }