import {ownCall} from './config.mjs'; export function mailDirection(m,call){const sender=String(m.fromAddress||m.from||'').replace(/^RMS[/:]/i,'').trim().toUpperCase();const own=ownCall(sender,call)||ownCall(m.from,call);return own?'outgoing':'incoming';} export function mailFolder(m,call){if(mailDirection(m,call)==='incoming')return 'inbox';return ['F','D'].includes(m.status)?'sent':'queue';} export function cmsStatus(log){const lines=log.split(/\r?\n/).filter(l=>/[|<>]RMS\s+/.test(l)&&!/;PR:|;PQ:|;FW:/.test(l));const start=lines.findLastIndex(l=>/Connecting to BBS RMS/.test(l));if(start<0)return {state:'idle',at:null,text:'Nessuna sessione rilevata oggi'};const part=lines.slice(start),last=part.at(-1);const done=part.some(l=>/[<>]RMS\s+FQ\s*$/.test(l));const failed=part.some(l=>/Protocol Error|Failure with|Authentication failed|Connection failed|Invalid password/i.test(l));const ended=part.some(l=>/RMS Disconnected/.test(l));return {state:done?'complete':failed?'error':ended?'ended':'running',at:last.slice(0,15),text:done?'Sincronizzazione completata':failed?'Errore nella sessione CMS':ended?'Sessione CMS conclusa':'Sincronizzazione in corso'};}