Cancellazione sul server e messaggi HTML (0.8.0)

- engine/patch_engine.py applica le modifiche al motore a ogni build: log
  redirigibile, .delete in Mail_Pending, gd_imap_remove nello shim C, Empty
  che propaga la cancellazione
- body() ripiega su plain e poi su html; htmltext.js riduce l'HTML a testo
  (10 controlli node)
This commit is contained in:
Carlo Baratto committed 2026-11-11 17:07:02 +01:00
1 parent ace59213a8
commit c0f973cf6e
11 files changed
+358 -35

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
// Da HTML a testo leggibile, per i messaggi che sono solo HTML.
//
// Non si rende l'HTML (niente motore web, niente stili remoti): si tiene il
// testo, con i link ancora riconoscibili, così il linkificatore li rende
// toccabili. ES5 puro, provato con node (tests/test_htmltext.js).
// I blocchi che valgono un a capo.
var BLOCCHI = /<\/(p|div|tr|li|h[1-6]|blockquote|table|section|article)\s*>/gi;
var ACAPO = /<br\s*\/?>/gi;
// Le entità che si incontrano davvero; le numeriche si convertono dopo.
var ENTITA = {
"&amp;": "&", "&lt;": "<", "&gt;": ">", "&quot;": "\"", "&#39;": "'",
"&apos;": "'", "&nbsp;": " ", "&hellip;": "…", "&mdash;": "-",
"&ndash;": "-", "&laquo;": "«", "&raquo;": "»", "&agrave;": "à",
"&egrave;": "è", "&eacute;": "é", "&igrave;": "ì", "&ograve;": "ò",
"&ugrave;": "ù"
};
function decodifica(s) {
var out = s;
for (var k in ENTITA) {
if (ENTITA.hasOwnProperty(k)) {
out = out.split(k).join(ENTITA[k]);
}
}
// Numeriche: &#232; e &#xE8;
out = out.replace(/&#(\d+);/g, function (m, d) {
return String.fromCharCode(parseInt(d, 10));
});
out = out.replace(/&#x([0-9a-fA-F]+);/g, function (m, h) {
return String.fromCharCode(parseInt(h, 16));
});
return out;
}
function daHtml(html) {
if (!html) return "";
var s = String(html);
// Via i blocchi che non sono testo.
s = s.replace(/<script[\s\S]*?<\/script>/gi, " ");
s = s.replace(/<style[\s\S]*?<\/style>/gi, " ");
s = s.replace(/<head[\s\S]*?<\/head>/gi, " ");
s = s.replace(/<!--[\s\S]*?-->/g, " ");
// Gli attributi spariscono con i tag: resta il testo, anche degli <a>.
s = s.replace(ACAPO, "\n");
s = s.replace(BLOCCHI, "\n");
s = s.replace(/<[^>]*>/g, "");
s = decodifica(s);
// Righe vuote in eccesso e spazi ai bordi delle righe.
s = s.replace(/[ \t]+/g, " ");
s = s.replace(/ *\n */g, "\n");
s = s.replace(/\n{3,}/g, "\n\n");
return s.replace(/^\s+|\s+$/g, "");
}