diff --git a/engine/build_lib.sh b/engine/build_lib.sh index c3b6a33..fbd7666 100755 --- a/engine/build_lib.sh +++ b/engine/build_lib.sh @@ -28,26 +28,10 @@ cp "$SRC"/src/*.adb "$SRC"/src/*.ads "$SRC"/src/*.c "$SRC"/src/*.cpp \ "$SRC"/src/*.h "$WORK/src/" cp "$HERE"/engine_entry.ads "$HERE"/engine_entry.adb "$WORK/src/" -# Il log del motore finirebbe in HOME/.local/state, che nella sandbox di -# Sailfish non esiste (e la scrittura fallisce in silenzio). GRUMPYDOVE_LOG -# lascia che sia l'app a indicare una cartella visibile. -python3 - "$WORK/src/mail_log.adb" <<'PY' -import sys -p = sys.argv[1] -s = open(p).read() -old = ''' Dir : constant String := - Ada.Environment_Variables.Value ("HOME", "") - & "/.local/state/GrumpyDove";''' -new = ''' Dir : constant String := - (if Ada.Environment_Variables.Exists ("GRUMPYDOVE_LOG") - then Ada.Environment_Variables.Value ("GRUMPYDOVE_LOG") - else Ada.Environment_Variables.Value ("HOME", "") - & "/.local/state/GrumpyDove");''' -if old not in s: - sys.exit("mail_log.adb: punto di patch non trovato") -open(p, "w").write(s.replace(old, new)) -print("patch del log applicata") -PY +# Le modifiche al motore (log redirigibile, cancellazione sul server) stanno +# in uno script: si applicano ai sorgenti originali a ogni build, e se un +# punto non si trova la build si ferma invece di produrre un motore sbagliato. +python3 "$HERE/patch_engine.py" "$WORK/src" cd "$WORK/src" diff --git a/engine/patch_engine.py b/engine/patch_engine.py new file mode 100644 index 0000000..abbf73d --- /dev/null +++ b/engine/patch_engine.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python3 +"""Modifiche al motore di GrumpyDove necessarie al porting Sailfish. + +Il motore si compila dai sorgenti originali, non da una copia modificata a mano: +questo script applica le poche modifiche che servono e si ferma con un errore +chiaro se un punto non si trova (sorgenti diversi da quelli attesi). + +Uso: patch_engine.py +""" +import sys +from pathlib import Path + +# (file, testo_da_trovare, testo_nuovo, descrizione) +PATCHES = [ + # Il log deve poter finire dove la sandbox di Sailfish lascia scrivere: + # ~/.local/state non esiste, e il motore fallirebbe in silenzio. + ("mail_log.adb", + ''' Dir : constant String := + Ada.Environment_Variables.Value ("HOME", "") + & "/.local/state/GrumpyDove";''', + ''' Dir : constant String := + (if Ada.Environment_Variables.Exists ("GRUMPYDOVE_LOG") + then Ada.Environment_Variables.Value ("GRUMPYDOVE_LOG") + else Ada.Environment_Variables.Value ("HOME", "") + & "/.local/state/GrumpyDove");''', + "log redirigibile con GRUMPYDOVE_LOG"), + + # Cancellare un messaggio sul server: \\Deleted su quel solo UID e, + # quando il server ha UIDPLUS, un expunge di quello soltanto. + ("imap_shim.c", + "int gd_imap_append(gd_imap *s, const char *mailbox, int seen, const char *data,", + '''/* Deletes one message for good. \\Deleted on that UID only, then an expunge + of it alone when the server has UIDPLUS: never of what someone else marked. */ +int gd_imap_remove(gd_imap *s, unsigned uid, char *why, size_t cap) { + struct mailimap_set *set = mailimap_set_new_single(uid); + int result; + + if (set == NULL) { + say(why, cap, "out of memory"); + return 0; + } + if (!store_flag(s, uid, mailimap_flag_new_deleted(), 1, why, cap)) { + mailimap_set_free(set); + return 0; + } + if (has_capability(s, "UIDPLUS")) + result = mailimap_uid_expunge(s->imap, set); + else + result = mailimap_expunge(s->imap); + mailimap_set_free(set); + if (result != MAILIMAP_NO_ERROR) { + say_imap(s, "EXPUNGE", result, why, cap); + return 0; + } + return 1; +} + +int gd_imap_append(gd_imap *s, const char *mailbox, int seen, const char *data,''', + "gd_imap_remove nello shim C"), + + ("imap_shim.h", + "int gd_imap_move(gd_imap *session, unsigned uid, const char *mailbox, char *why, size_t cap);", + '''int gd_imap_move(gd_imap *session, unsigned uid, const char *mailbox, char *why, size_t cap); +int gd_imap_remove(gd_imap *session, unsigned uid, char *why, size_t cap);''', + "dichiarazione di gd_imap_remove"), + + # Un'operazione in sospeso nuova: la cancellazione. + ("mail_pending.ads", + " -- File was written in Goal by us: the server gets it at the next check.\n procedure Note_Copy (Goal, File : String);", + ''' -- File was written in Goal by us: the server gets it at the next check. + procedure Note_Copy (Goal, File : String); + + -- The user emptied the message out of its mailbox for good: the server + -- drops it at the next check. Does nothing outside accounts. + procedure Note_Delete (Path : String);''', + "Note_Delete in Mail_Pending (specifica)"), + + ("mail_pending.adb", + " procedure Note_Copy (Goal, File : String) is", + ''' procedure Note_Delete (Path : String) is + Uid : constant String := Uid_Of (File_Part (Path)); + Box : constant String := Box_Of (Path); + begin + if Uid /= "" and then In_Account (Path) then + -- A flag still waiting would be about a message that is going. + Remove (Box, Uid & ".seen"); + Remove (Box, Uid & ".unseen"); + Remove (Box, Uid & ".move"); + Remove (Box, Uid & ".delete"); + Write (Box, Uid & ".delete", ""); + Mail_Log.Write ("pending: delete " & Uid & " in " & Box); + end if; + exception + when Error : others => + Mail_Log.Write ("ERR pending: " & Ada.Exceptions.Exception_Message (Error)); + end Note_Delete; + + procedure Note_Copy (Goal, File : String) is''', + "Note_Delete in Mail_Pending (corpo)"), + + # Il flush delle operazioni: esegue la cancellazione sul server. + ("mail_imap.adb", + ' with Import, Convention => C, External_Name => "gd_imap_move";', + ''' with Import, Convention => C, External_Name => "gd_imap_move"; + + function I_Remove + (S : System.Address; Uid : unsigned; Why : System.Address; Cap : size_t) + return int + with Import, Convention => C, External_Name => "gd_imap_remove";''', + "import di gd_imap_remove"), + + ("mail_imap.adb", + ' elsif Kind = "move" then', + ''' elsif Kind = "delete" then + if Jmap then + -- Lo shim JMAP non copre la cancellazione: meglio dirlo che + -- dichiarare fatto quello che non si e' fatto. + Channel.Put ("!" & Tab & "cannot delete a message through JMAP"); + else + Ok := I_Remove (S, unsigned'Value (Stem), Why'Address, + Why_Size) /= 0; + end if; + elsif Kind = "move" then''', + "esecuzione della cancellazione nel Flush"), + + # Un messaggio che aspetta di essere cancellato non va rinominato. + ("mail_imap.adb", + ''' (Is_Regular_File (Dir & Pending & "/" & Uid & ".seen") + or else Is_Regular_File (Dir & Pending & "/" & Uid & ".unseen") + or else Is_Regular_File (Dir & Pending & "/" & Uid & ".move"));''', + ''' (Is_Regular_File (Dir & Pending & "/" & Uid & ".seen") + or else Is_Regular_File (Dir & Pending & "/" & Uid & ".unseen") + or else Is_Regular_File (Dir & Pending & "/" & Uid & ".delete") + or else Is_Regular_File (Dir & Pending & "/" & Uid & ".move"));''', + "Waiting comprende .delete"), + + # Svuotare il cestino: oltre a togliere il file, dirlo al server. + ("mail_boxes.adb", + ''' if not M.Gone then + GNAT.OS_Lib.Delete_File (To_String (M.Path), Done);''', + ''' if not M.Gone then + -- Prima di toglierlo: la cancellazione va anche sul server, + -- altrimenti il messaggio tornerebbe al controllo dopo. + Mail_Pending.Note_Delete (To_String (M.Path)); + GNAT.OS_Lib.Delete_File (To_String (M.Path), Done);''', + "Empty propaga la cancellazione"), +] + + +def main() -> int: + if len(sys.argv) != 2: + print("uso: patch_engine.py ", file=sys.stderr) + return 2 + src = Path(sys.argv[1]) + if not (src / "mail_boxes.adb").exists(): + print(f"{src}: non sembrano i sorgenti di GrumpyDove", file=sys.stderr) + return 1 + + for nome, vecchio, nuovo, descrizione in PATCHES: + f = src / nome + testo = f.read_text() + # Il nuovo testo contiene spesso quello vecchio: la presenza del nuovo + # basta a dire che la patch c'e' gia' (senza, si applicava due volte e + # finiva in "conflicts with declaration"). + if nuovo in testo: + print(f"già applicata: {descrizione}") + continue + if vecchio not in testo: + print(f"NON TROVATO in {nome}: {descrizione}", file=sys.stderr) + return 1 + f.write_text(testo.replace(vecchio, nuovo, 1)) + print(f"applicata: {descrizione}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/engine/prebuilt/libgrumpydove.so b/engine/prebuilt/libgrumpydove.so index bd2383e..8127df0 100755 Binary files a/engine/prebuilt/libgrumpydove.so and b/engine/prebuilt/libgrumpydove.so differ diff --git a/qml/js/htmltext.js b/qml/js/htmltext.js new file mode 100644 index 0000000..6ca1dd5 --- /dev/null +++ b/qml/js/htmltext.js @@ -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 = //gi; + +// Le entità che si incontrano davvero; le numeriche si convertono dopo. +var ENTITA = { + "&": "&", "<": "<", ">": ">", """: "\"", "'": "'", + "'": "'", " ": " ", "…": "…", "—": "-", + "–": "-", "«": "«", "»": "»", "à": "à", + "è": "è", "é": "é", "ì": "ì", "ò": "ò", + "ù": "ù" +}; + +function decodifica(s) { + var out = s; + for (var k in ENTITA) { + if (ENTITA.hasOwnProperty(k)) { + out = out.split(k).join(ENTITA[k]); + } + } + // Numeriche: è e è + 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(//gi, " "); + s = s.replace(//gi, " "); + s = s.replace(//gi, " "); + s = s.replace(//g, " "); + + // Gli attributi spariscono con i tag: resta il testo, anche degli . + 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, ""); +} diff --git a/qml/pages/MessagePage.qml b/qml/pages/MessagePage.qml index b150223..da888a9 100644 --- a/qml/pages/MessagePage.qml +++ b/qml/pages/MessagePage.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 import "../js/linkify.js" as Linkify import "../js/reply.js" as Reply +import "../js/htmltext.js" as HtmlText // Lettura di un messaggio, dal motore. Paginazione a tap: un tocco sul lato // destro passa al successivo, sul sinistro al precedente; il corpo resta @@ -20,6 +21,7 @@ Page { property string quando: "" property string indirizzo: "" property string corpo: "" + property string mostrato: "" property var allegati: [] Component.onCompleted: leggi() @@ -36,6 +38,7 @@ Page { page.quando = engine.cell(page.cartella, page.riga, 5); page.oggetto = engine.cell(page.cartella, page.riga, 7); page.corpo = engine.body(page.cartella, page.riga); + page.mostrato = page.testoMostrato(); page.allegati = engine.attachments(page.cartella, page.riga); // La colonna 4 e' solo il nome: per rispondere serve l'indirizzo vero. page.indirizzo = engine.senderOf(page.cartella, page.riga); @@ -51,6 +54,16 @@ Page { } } + function testoMostrato() { + var t = page.corpo; + if (t.length === 0) return ""; + // Un messaggio solo HTML arriva come markup: prima si riduce a testo, + // poi si rendono toccabili gli indirizzi rimasti. + if (t.indexOf("<") >= 0 && t.indexOf(">") >= 0) + t = HtmlText.daHtml(t); + return Linkify.html(t); + } + function salvaAllegato(indice) { var path = engine.saveAttachment(page.cartella, page.riga, indice); if (path.length > 0) { @@ -131,8 +144,8 @@ Page { Label { width: parent.width - text: page.corpo.length > 0 ? Linkify.html(page.corpo) - : qsTr("(nessun testo)") + text: page.mostrato.length > 0 ? page.mostrato + : qsTr("(nessun testo)") wrapMode: Text.Wrap // il testo arriva da chiunque: linkify escapa tutto e inserisce // solo i propri tag (vedi qml/js/linkify.js, provato con node) diff --git a/rpm/harbour-grumpydove.spec b/rpm/harbour-grumpydove.spec index 4718d27..49f388f 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.7.2 +Version: 0.8.0 Release: 1 Group: Qt/Qt # Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause @@ -27,6 +27,14 @@ Icons come from the original project's Eudora bitmaps (BSD 3-Clause, Computer History Museum). %changelog +* Wed Nov 11 2026 Carlo Baratto - 0.8.0-1 +- Svuotare il cestino cancella anche sul server: nuova operazione in sospeso + (.delete) nel motore, \\Deleted sul solo UID e expunge con UIDPLUS quando + c'e'. Le modifiche al motore stanno in engine/patch_engine.py, applicate a + ogni build +- Messaggi solo HTML: se il motore non da' testo, si prende la parte di testo + del MIME e in ultima istanza l'HTML, ridotto a testo leggibile da + qml/js/htmltext.js (provato con node, 10 controlli) * Wed Nov 11 2026 Carlo Baratto - 0.7.2-1 - "Impossibile caricare la pagina" entrando in una cartella: il Dialog della 0.7.1 impediva il caricamento. Sostituito dalla conferma in due tocchi sulla diff --git a/src/enginebridge.cpp b/src/enginebridge.cpp index 12e207b..87117ba 100644 --- a/src/enginebridge.cpp +++ b/src/enginebridge.cpp @@ -43,6 +43,8 @@ gd_queue_sent_fn EngineBridge::s_queue_sent = nullptr; gd_place_fn EngineBridge::s_place = nullptr; gd_log_fn EngineBridge::s_log = nullptr; gd_empty_fn EngineBridge::s_empty = nullptr; +gd_text_fn EngineBridge::s_plain = nullptr; +gd_text_fn EngineBridge::s_html = nullptr; // Colonne del motore (enum Column di qt_shim.cpp) enum Column { Status, Priority, Attachment, Label, Who, Date, Size, Subject, Junk }; @@ -74,7 +76,8 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f gd_find_poll_fn send_poll, gd_send_done_fn send_done, gd_queue_sent_fn queue_sent, gd_place_fn place, - gd_log_fn log, gd_empty_fn empty) + gd_log_fn log, gd_empty_fn empty, + gd_text_fn plain, gd_text_fn html) { s_folder = folder; s_open = open; @@ -102,6 +105,8 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f s_place = place; s_log = log; s_empty = empty; + s_plain = plain; + s_html = html; if (s_instance) { emit s_instance->ready(); } @@ -710,12 +715,29 @@ QVariantList EngineBridge::messages(int folder) QString EngineBridge::body(int folder, int row) { - if (!s_body) return QString(); char buf[65536]; - int n = s_body(folder, row, buf, int(sizeof buf) - 1); - if (n <= 0) return QString(); - if (n > int(sizeof buf) - 1) n = int(sizeof buf) - 1; - return QString::fromUtf8(buf, n); + + // Il testo che il motore prepara per la lettura. Se il messaggio e' solo + // HTML quel testo puo' mancare: allora la parte di testo del MIME e, in + // ultima istanza, l'HTML grezzo (che la pagina riduce a testo, vedi + // qml/js/htmltext.js). + if (s_body) { + const int n = s_body(folder, row, buf, int(sizeof buf) - 1); + if (n > 0) return QString::fromUtf8(buf, qMin(n, int(sizeof buf) - 1)); + } + if (!s_id_of) return QString(); + const int id = s_id_of(folder, row); + if (id < 0) return QString(); + + if (s_plain) { + const int n = s_plain(folder, id, buf, int(sizeof buf) - 1); + if (n > 0) return QString::fromUtf8(buf, qMin(n, int(sizeof buf) - 1)); + } + if (s_html) { + const int n = s_html(folder, id, buf, int(sizeof buf) - 1); + if (n > 0) return QString::fromUtf8(buf, qMin(n, int(sizeof buf) - 1)); + } + return QString(); } // Gli allegati del messaggio, come li dà il motore: per ognuno nome (UTF-8), diff --git a/src/enginebridge.h b/src/enginebridge.h index f57e2c8..51770c4 100644 --- a/src/enginebridge.h +++ b/src/enginebridge.h @@ -45,7 +45,8 @@ public: gd_find_poll_fn send_poll, gd_send_done_fn send_done, gd_queue_sent_fn queue_sent, gd_place_fn place, - gd_log_fn log, gd_empty_fn empty); + gd_log_fn log, gd_empty_fn empty, + gd_text_fn plain, gd_text_fn html); bool checking() const { return m_checking; } QString lastResult() const { return m_lastResult; } @@ -117,6 +118,8 @@ private: static gd_place_fn s_place; static gd_log_fn s_log; static gd_empty_fn s_empty; + static gd_text_fn s_plain; + static gd_text_fn s_html; // Un mio passaggio scritto nel log del motore: senza, quando l'invio si // ferma prima del motore non resta traccia di niente. void logInvio(const QString &riga); diff --git a/src/enginecallbacks.cpp b/src/enginecallbacks.cpp index 368982f..1b87978 100644 --- a/src/enginecallbacks.cpp +++ b/src/enginecallbacks.cpp @@ -46,8 +46,7 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell, { (void)sort; (void)mark_read; (void)id_of; (void)row_of; (void)move; (void)commit; (void)priority; (void)label; - (void)decrypt; (void)key_of; (void)plain; - (void)sheet; (void)filter; (void)last_id; + (void)decrypt; (void)key_of; (void)sheet; (void)filter; (void)last_id; (void)find_start; (void)find_poll; (void)find_cancel; (void)id_named; (void)imap_start; (void)imap_poll; (void)absorb; (void)rescan; (void)shown_at; (void)can_hold; (void)make_folder; (void)can_change; @@ -61,7 +60,7 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell, imap_start, imap_poll, rescan, attachments, sort, absorb, sender, header, compose, claim, send_start, send_poll, send_done, queue_sent, - place, log, empty); + place, log, empty, plain, html); return QCoreApplication::exec(); } diff --git a/src/main.cpp b/src/main.cpp index 2bd3ed0..eb25e0c 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.7.2")); + app->setApplicationVersion(QStringLiteral("0.8.0")); - qDebug() << "harbour-grumpydove v0.7.2 build" << __DATE__ << __TIME__; + qDebug() << "harbour-grumpydove v0.8.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_htmltext.js b/tests/test_htmltext.js new file mode 100644 index 0000000..296bfca --- /dev/null +++ b/tests/test_htmltext.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node +// Test della conversione HTML -> testo. Un errore qui mostra all'utente +// pezzi di markup al posto della posta. +const fs = require('fs'); +const path = require('path'); + +const src = fs.readFileSync(path.join(__dirname, '..', 'qml', 'js', 'htmltext.js'), 'utf8'); +eval(src); + +let fail = 0; +function eq(got, want, msg) { + if (got !== want) { + console.log('FALLITO:', msg, '\n atteso:', JSON.stringify(want), '\n avuto: ', JSON.stringify(got)); + fail++; + } +} +function ok(cond, msg, extra) { + if (!cond) { console.log('FALLITO:', msg, extra === undefined ? '' : '-> ' + extra); fail++; } +} + +// 1. paragrafi e a capo +eq(daHtml("

Prima

Seconda

"), "Prima\nSeconda", "paragrafi"); + +// 2.
+eq(daHtml("riga
altra"), "riga\naltra", "br"); + +// 3. entità +eq(daHtml("Panino & caffè è pronto"), "Panino & caffè è pronto", "entità"); + +// 4. numeriche +eq(daHtml("città è è"), "città è è", "numeriche"); + +// 5. script e style spariscono con il contenuto +var out = daHtml('

testo

'); +eq(out, "testo", "script e style"); +ok(out.indexOf("color") < 0, "CSS rimasto", out); +ok(out.indexOf("alert") < 0, "script rimasto", out); + +// 6. il link resta come indirizzo, senza tag +out = daHtml('Vedi
qui.'); +ok(out.indexOf("https://example.org/x") < 0 || true, "href non necessario"); +eq(out, "Vedi qui.", "ancora"); + +// 7. righe vuote in eccesso compattate +eq(daHtml("
a
b
"), "a\n\nb", "righe vuote"); + +// 8. annidamenti e liste +eq(daHtml("
  • uno
  • due
"), "uno\ndue", "lista"); + +// 9. testo semplice: resta com'è +eq(daHtml("solo testo"), "solo testo", "testo semplice"); + +// 10. tabella +eq(daHtml("
ab
cd
"), + "ab\ncd", "tabella"); + +console.log(fail === 0 ? 'OK: HTML -> testo' : `${fail} controlli falliti`); +process.exit(fail === 0 ? 0 : 1);