import {parseMessages,decode} from './bpq.mjs';
async function killAsSysop(id,item,bpq){
const status=await bpq('/Mail/Status'),key=status.match(/href=\/Mail\/Msgs\?([^\s>]+)/)?.[1];if(!key)throw Error('Sessione amministrativa BPQ non disponibile');
const html=await bpq('/Mail/MsgDetails?'+key,{method:'POST',body:String(id)});
if(!new RegExp('Message\\s+'+id+'(?!\\d)').test(html))throw Error('BPQ non ha confermato il messaggio da cancellare');
const fields={};for(const match of html.matchAll(/]*>/gi)){
const name=match[0].match(/\bname=(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i),value=match[0].match(/\bvalue=(?:"([^"]*)"|'([^']*)'|([^\s>]*))/i);
if(name&&value)fields[name[1]??name[2]??name[3]]=decode(value[1]??value[2]??value[3]);
}
const names=['From','To','BID','EFROM','VIA','Title'];
if(names.some(name=>!(name in fields)||/[|\r\n\0]/.test(fields[name])))throw Error('Metadati BPQ non verificabili: cancellazione interrotta');
const typeBlock=html.match(/