diff --git a/qml/js/linkify.js b/qml/js/linkify.js new file mode 100644 index 0000000..6a4c3f2 --- /dev/null +++ b/qml/js/linkify.js @@ -0,0 +1,45 @@ +// Trasforma il testo di un messaggio in HTML con i link attivi. +// +// Il testo arriva da chiunque: prima si escapa tutto, poi si inseriscono i +// propri tag. Una sola passata riconosce URL e indirizzi, così un link non +// finisce dentro l'href di un altro. ES5 puro: si prova con node. + +var RE = /(https?:\/\/[^\s<>"']+)|([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})/g; + +function escapeHtml(s) { + return s.replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """); +} + +// La punteggiatura che chiude una frase non fa parte dell'indirizzo. +function trimTail(url) { + var m = url.match(/[.,;:!?)\]]+$/); + if (!m) return [url, ""]; + return [url.substring(0, url.length - m[0].length), m[0]]; +} + +function html(text) { + if (!text) return ""; + var out = ""; + var last = 0; + var m; + RE.lastIndex = 0; + while ((m = RE.exec(text)) !== null) { + out += escapeHtml(text.substring(last, m.index)); + var token = m[0]; + var tail = ""; + if (m[1]) { // URL: la coda di punteggiatura resta fuori + var t = trimTail(token); + token = t[0]; + tail = t[1]; + } + var href = m[1] ? token : ("mailto:" + token); + out += '' + escapeHtml(token) + ''; + out += escapeHtml(tail); + last = m.index + m[0].length; + } + out += escapeHtml(text.substring(last)); + return out.replace(/\n/g, "
"); +} diff --git a/qml/pages/MessagePage.qml b/qml/pages/MessagePage.qml index 06c7fc8..0d480c1 100644 --- a/qml/pages/MessagePage.qml +++ b/qml/pages/MessagePage.qml @@ -1,5 +1,6 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import "../js/linkify.js" as Linkify // Lettura di un messaggio, dal motore. Paginazione a tap: un tocco sul lato // destro passa al successivo, sul sinistro al precedente; il corpo resta @@ -118,12 +119,16 @@ Page { Label { width: parent.width - text: page.corpo.length > 0 ? page.corpo : qsTr("(nessun testo)") + text: page.corpo.length > 0 ? Linkify.html(page.corpo) + : qsTr("(nessun testo)") wrapMode: Text.Wrap - textFormat: Text.PlainText + // il testo arriva da chiunque: linkify escapa tutto e inserisce + // solo i propri tag (vedi qml/js/linkify.js, provato con node) + textFormat: Text.RichText font.pixelSize: Theme.fontSizeSmall color: Theme.primaryColor bottomPadding: Theme.paddingLarge + onLinkActivated: Qt.openUrlExternally(link) } // Allegati: un tocco li salva in Download e li apre con l'app diff --git a/rpm/harbour-grumpydove.spec b/rpm/harbour-grumpydove.spec index 01dcfc9..4c1b6e4 100644 --- a/rpm/harbour-grumpydove.spec +++ b/rpm/harbour-grumpydove.spec @@ -1,6 +1,6 @@ Name: harbour-grumpydove Summary: Eudora-style mail interface, mobile prototype -Version: 0.4.5 +Version: 0.5.0 Release: 1 Group: Qt/Qt # Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause @@ -27,6 +27,11 @@ Icons come from the original project's Eudora bitmaps (BSD 3-Clause, Computer History Museum). %changelog +* Wed Nov 11 2026 Carlo Baratto - 0.5.0-1 +- Link nel corpo dei messaggi: URL e indirizzi diventano apribili (browser e + client di posta). Il testo e' escapato prima di inserire i tag, cosi' un + messaggio non puo' iniettare HTML; la punteggiatura finale resta fuori dal + link. Logica in qml/js/linkify.js, provata con node (tests/test_linkify.js) * Wed Nov 11 2026 Carlo Baratto - 0.4.5-1 - Fix: la posta veniva riscaricata da capo a ogni controllo. Dopo lo scarico mancava absorb, la chiamata con cui la vista prende i file nuovi diff --git a/src/main.cpp b/src/main.cpp index a0e2c27..4713283 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,9 +24,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) app->setOrganizationName(QStringLiteral("harbour")); app->setApplicationName(QStringLiteral("grumpydove")); - app->setApplicationVersion(QStringLiteral("0.4.5")); + app->setApplicationVersion(QStringLiteral("0.5.0")); - qDebug() << "harbour-grumpydove v0.4.5 build" << __DATE__ << __TIME__; + qDebug() << "harbour-grumpydove v0.5.0 build" << __DATE__ << __TIME__; // La sandbox di Sailfish (SailJail) non lascia vedere ~/Mail, ma il motore // legge il percorso del Maildir da GRUMPYDOVE_MAIL: si punta alla cartella diff --git a/tests/test_linkify.js b/tests/test_linkify.js new file mode 100644 index 0000000..91c58e7 --- /dev/null +++ b/tests/test_linkify.js @@ -0,0 +1,56 @@ +#!/usr/bin/env node +// Test del linkificatore: quello che arriva dal mittente non deve mai +// diventare HTML attivo, e i link devono essere quelli giusti. +const fs = require('fs'); +const path = require('path'); + +const src = fs.readFileSync(path.join(__dirname, '..', 'qml', 'js', 'linkify.js'), 'utf8'); +eval(src); + +let fail = 0; +function check(cond, msg, extra) { + if (!cond) { console.log('FALLITO:', msg, extra === undefined ? '' : '-> ' + extra); fail++; } +} + +// 1. un URL semplice diventa un link +let out = html("Vedi https://example.org/pagina per i dettagli"); +check(out.indexOf('https://example.org/pagina') >= 0, + 'URL non linkificato', out); + +// 2. la punteggiatura finale resta fuori dal link +out = html("Scrivi a https://example.org/x. Poi altro."); +check(out.indexOf('href="https://example.org/x"') >= 0, 'punto finale dentro l\'URL', out); +check(out.indexOf('.') >= 0, 'punto finale non fuori dal link', out); + +// 3. indirizzo email +out = html("scrivi a mario.rossi@example.it, grazie"); +check(out.indexOf('href="mailto:mario.rossi@example.it"') >= 0, 'email non linkificata', out); + +// 4. HTML nel testo: mai attivo +out = html(""); +check(out.indexOf('= 0, 'escape mancante', out); + +// 5. le virgolette nel testo non rompono l'attributo +out = html('un "ciao" e https://example.org/a?b=1&c=2'); +check(out.indexOf('"ciao"') >= 0, 'virgolette non esplicate', out); +check(out.indexOf('&c=2') >= 0, 'ampersand non esplicato nell\'href', out); + +// 6. a capo conservati +out = html("prima\nseconda"); +check(out.indexOf('
') >= 0, 'a capo persi', out); + +// 7. testo senza link: nessun tag +out = html("solo testo, niente da aprire"); +check(out.indexOf('