const escape=value=>String(value??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); const line=value=>String(value??'').replace(/[\r\n]+/g,' ').slice(0,240); const variants={ 'jarvis-application':{title:'Recruitment Register',intro:'An update about your DuneRealms recruitment application.',action:'View the recruitment record'}, 'political-event':{title:'Election Register',intro:'An update from the official DuneRealms election register.',action:'Open the election register'}, 'mail-report':{title:'Reported mail',intro:'A user has reported an internal message. Review the report and original message before creating a Legal ticket.',action:'Review reported mail'}, 'ticket-submitted':{title:'Ticket submitted',intro:'Your ticket has been submitted. You can follow its progress and reply in the Support Centre.',action:'View your ticket'}, 'new-ticket-alert':{title:'New ticket alert',intro:'A new ticket is waiting for your team. Open the staff ticket desk to review it.',action:'Open staff ticket'}, 'mailbox-ready':{title:'Your internal inbox is ready',intro:'Your DuneRealms internal inbox is ready. Open your account centre to read messages and manage your mail settings.',action:'Open Internal Mail'}, 'forwarding-updated':{title:'Mail forwarding updated',intro:'Your internal mail forwarding settings have changed. A copy of forwarded messages stays in your internal inbox.',action:'Review mail settings'} }; export function automatedMailTemplate(kind,{ticketId='',subject='',department='',recipientName='',message='',url}={}){ const variant=variants[kind];if(!variant)throw Error('Unknown automatic email template'); const target=new URL(url);if(target.protocol!=='https:'||!['cp.dunerealms.com','support.dunerealms.com'].includes(target.hostname)||target.username||target.password)throw Error('Unsupported email action link'); const title=variant.title,reference=line(ticketId),summary=line(subject),dept=line(department),greeting=recipientName?'Hello '+line(recipientName)+',':'Hello,'; const details=[reference&&['Ticket',reference],summary&&['Subject',summary],dept&&['Department',dept]].filter(Boolean); const text=[greeting,'',title,'',variant.intro,...details.map(([k,v])=>k+': '+v),'',String(message||'').slice(0,4000),'',variant.action+': '+target.href,'','For support, visit https://support.dunerealms.com/ and submit a ticket.','DuneRealms · The Caravan Dispatch'].join('\n'); const rows=details.map(([k,v])=>`${escape(k)}${escape(v)}`).join(''); const html=`${escape(title)}
DuneRealms

THE CARAVAN DISPATCH

${escape(title)}

${escape(greeting)}

${escape(variant.intro)}

${message?'

'+escape(String(message).slice(0,4000))+'

':''}${rows?`${rows}
`:''}
${escape(variant.action)}

If the button does not open, use:
${escape(target.href)}

DuneRealms SupportDuneRealms
For support, visit our support site and submit a ticket.
`; return {subject:title+(reference?' · '+reference:''),text,html}; }