import { Command } from '@cliffy/command/mod.ts' import { Contact } from '../src/contact.ts' import { send } from '../src/send.ts' import { Mail } from '../types.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('-t, --template ', 'HTML template from config', { default: 'message' }) .arguments(' ') .action( async ({ from, cc, cci, attachments }, 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 mail: Mail = { from: fromContact, to: [Contact.fromString(to)], subject, body, options: { cc: cc?.map(Contact.fromString) ?? [], cci: cci?.map(Contact.fromString) ?? [], attachments: attachments ?? [], }, } await send(mail) }, )