Add native Winlink attachment upload, reader indicators and verified storage

This commit is contained in:
alberto committed 2026-10-17 14:33:34 +02:00
1 parent 2b00b1cbbd
commit 5fde09823b
13 files changed
+223 -20

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
import path from 'node:path';
export function attachmentSummary(bytes){const end=bytes.indexOf('\r\n\r\n');if(end<0||end>65536)return {attachmentCount:0,attachmentBytes:0};const header=bytes.subarray(0,end).toString('utf8');if(!/^MID:/mi.test(header)||!/^Body:\s*\d+\s*$/mi.test(header))return {attachmentCount:0,attachmentBytes:0};const files=[...header.matchAll(/^File:\s*(\d+)\s+[^\r\n]+\r?$/gmi)];return {attachmentCount:files.length,attachmentBytes:files.reduce((sum,f)=>sum+Number(f[1]),0)};}
export function safeName(name){return path.win32.basename(String(name).replaceAll('/','\\')).replace(/[\x00-\x1f\x7f]/g,'').slice(0,200)||'allegato.bin';}
export function mimeOf(bytes,name){if(bytes.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10])))return 'image/png';if(bytes[0]===255&&bytes[1]===216&&bytes[2]===255)return 'image/jpeg';if(/^GIF8[79]a$/.test(bytes.subarray(0,6).toString('ascii')))return 'image/gif';if(bytes.subarray(0,4).toString()==='RIFF'&&bytes.subarray(8,12).toString()==='WEBP')return 'image/webp';if(bytes.subarray(0,5).toString()==='%PDF-')return 'application/pdf';if(/\.(txt|csv|log|json|xml|html?|svg|md|7pl)$/i.test(name)&&!bytes.subarray(0,4096).includes(0))return 'text/plain';return 'application/octet-stream';}
export function b2Body(bytes){const end=bytes.indexOf('\r\n\r\n');if(end<0||end>65536)return null;const header=bytes.subarray(0,end).toString('utf8'),body=header.match(/^Body:\s*(\d+)\s*$/m);if(!body||!/^Mid:/mi.test(header))return null;const length=Number(body[1]);if(end+4+length>bytes.length)throw new Error('Corpo B2 incompleto');const data=bytes.subarray(end+4,end+4+length);try{return new TextDecoder('utf8',{fatal:true}).decode(data);}catch{return data.toString('latin1');}}