Rispondi con l'indirizzo vero, rispondi a tutti (0.5.2)
- EngineBridge::senderOf/headerOf: il motore da' il mittente come Nome<TAB>indirizzo, gli header come valore grezzo - Restare sulla colonna 4 (solo nome) lasciava il campo A vuoto - qml/js/reply.js: estrazione indirizzi, dedupe, esclusione del proprio indirizzo; tests/test_reply.js (8 controlli)
This commit is contained in:
1 parent
a7b760f0bf
commit
355c059247
8 files changed
+169
-8
No files matched your search
@@ -0,0 +1,49 @@
|
|||||||
|
// Indirizzi per le risposte.
|
||||||
|
//
|
||||||
|
// Gli header contengono forme come "Mario Rossi <mario@example.it>, altra@x.it":
|
||||||
|
// qui si tengono solo gli indirizzi veri, si tolgono i doppioni e si esclude
|
||||||
|
// chi scrive. ES5 puro, provato con node (tests/test_reply.js).
|
||||||
|
|
||||||
|
// Gli indirizzi dentro un valore di header: fra <...> se c'e', altrimenti il
|
||||||
|
// pezzo stesso se somiglia a un indirizzo.
|
||||||
|
function estrai(valore) {
|
||||||
|
var out = [];
|
||||||
|
if (!valore) return out;
|
||||||
|
var pezzi = String(valore).split(",");
|
||||||
|
for (var i = 0; i < pezzi.length; i++) {
|
||||||
|
var p = pezzi[i].replace(/^\s+|\s+$/g, "");
|
||||||
|
if (!p) continue;
|
||||||
|
var m = p.match(/<([^<>]+)>/);
|
||||||
|
var a = (m ? m[1] : p).replace(/^\s+|\s+$/g, "");
|
||||||
|
if (a.indexOf("@") > 0) out.push(a);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unisci(liste, me) {
|
||||||
|
var out = [];
|
||||||
|
var visti = {};
|
||||||
|
var miei = {};
|
||||||
|
estrai(me).forEach(function (a) { miei[a.toLowerCase()] = true; });
|
||||||
|
|
||||||
|
for (var l = 0; l < liste.length; l++) {
|
||||||
|
var pezzi = estrai(liste[l]);
|
||||||
|
for (var i = 0; i < pezzi.length; i++) {
|
||||||
|
var k = pezzi[i].toLowerCase();
|
||||||
|
if (visti[k] || miei[k]) continue; // doppione o sono io
|
||||||
|
visti[k] = true;
|
||||||
|
out.push(pezzi[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rispondi: solo chi ha scritto.
|
||||||
|
function rispondi(from) {
|
||||||
|
return estrai(from).join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rispondi a tutti: mittente, destinatari e copie, senza me e senza doppioni.
|
||||||
|
function rispondiATutti(from, to, cc, me) {
|
||||||
|
return unisci([from, to, cc], me);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
import "../js/linkify.js" as Linkify
|
import "../js/linkify.js" as Linkify
|
||||||
|
import "../js/reply.js" as Reply
|
||||||
|
|
||||||
// Lettura di un messaggio, dal motore. Paginazione a tap: un tocco sul lato
|
// Lettura di un messaggio, dal motore. Paginazione a tap: un tocco sul lato
|
||||||
// destro passa al successivo, sul sinistro al precedente; il corpo resta
|
// destro passa al successivo, sul sinistro al precedente; il corpo resta
|
||||||
@@ -36,6 +37,8 @@ Page {
|
|||||||
page.oggetto = engine.cell(page.cartella, page.riga, 7);
|
page.oggetto = engine.cell(page.cartella, page.riga, 7);
|
||||||
page.corpo = engine.body(page.cartella, page.riga);
|
page.corpo = engine.body(page.cartella, page.riga);
|
||||||
page.allegati = engine.attachments(page.cartella, page.riga);
|
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);
|
||||||
page.totale = engine.messages(page.cartella).length;
|
page.totale = engine.messages(page.cartella).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,8 +183,25 @@ Page {
|
|||||||
PullDownMenu {
|
PullDownMenu {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Rispondi")
|
text: qsTr("Rispondi")
|
||||||
|
onClicked: {
|
||||||
|
const a = Reply.rispondi(page.indirizzo);
|
||||||
|
if (a === "") {
|
||||||
|
avviso.text = qsTr("Indirizzo del mittente non disponibile");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
||||||
|
{ destinatario: a,
|
||||||
|
oggetto: "Re: " + page.oggetto });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: qsTr("Rispondi a tutti")
|
||||||
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
||||||
{ destinatario: page.indirizzo,
|
{ destinatario: Reply.rispondiATutti(
|
||||||
|
page.indirizzo,
|
||||||
|
engine.headerOf(page.cartella, page.riga, "to"),
|
||||||
|
engine.headerOf(page.cartella, page.riga, "cc"),
|
||||||
|
account.persona),
|
||||||
oggetto: "Re: " + page.oggetto })
|
oggetto: "Re: " + page.oggetto })
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Name: harbour-grumpydove
|
Name: harbour-grumpydove
|
||||||
Summary: Eudora-style mail interface, mobile prototype
|
Summary: Eudora-style mail interface, mobile prototype
|
||||||
Version: 0.5.1
|
Version: 0.5.2
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: Qt/Qt
|
Group: Qt/Qt
|
||||||
# Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause
|
# 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).
|
Computer History Museum).
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.5.2-1
|
||||||
|
- Rispondi prendeva un destinatario vuoto: ora legge l'indirizzo del mittente
|
||||||
|
dal motore (la colonna 4 e' solo il nome) e lo mette in "A"
|
||||||
|
- Rispondi a tutti: mittente piu' destinatari e copie, senza me e senza
|
||||||
|
doppioni (qml/js/reply.js, provato con node: tests/test_reply.js)
|
||||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.5.1-1
|
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.5.1-1
|
||||||
- Le cartelle lette restano in memoria: aprire la lista o tornare indietro non
|
- Le cartelle lette restano in memoria: aprire la lista o tornare indietro non
|
||||||
richiede piu' al motore una chiamata per campo per ogni messaggio. La copia
|
richiede piu' al motore una chiamata per campo per ogni messaggio. La copia
|
||||||
|
|||||||
+36
-1
@@ -31,6 +31,8 @@ gd_rescan_fn EngineBridge::s_rescan = nullptr;
|
|||||||
gd_text_fn EngineBridge::s_attachments = nullptr;
|
gd_text_fn EngineBridge::s_attachments = nullptr;
|
||||||
gd_sort_fn EngineBridge::s_sort = nullptr;
|
gd_sort_fn EngineBridge::s_sort = nullptr;
|
||||||
gd_absorb_fn EngineBridge::s_absorb = nullptr;
|
gd_absorb_fn EngineBridge::s_absorb = nullptr;
|
||||||
|
gd_text_fn EngineBridge::s_sender = nullptr;
|
||||||
|
gd_header_fn EngineBridge::s_header = nullptr;
|
||||||
|
|
||||||
// Colonne del motore (enum Column di qt_shim.cpp)
|
// Colonne del motore (enum Column di qt_shim.cpp)
|
||||||
enum Column { Status, Priority, Attachment, Label, Who, Date, Size, Subject, Junk };
|
enum Column { Status, Priority, Attachment, Label, Who, Date, Size, Subject, Junk };
|
||||||
@@ -55,7 +57,8 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
|||||||
gd_move_fn move, gd_commit_fn commit,
|
gd_move_fn move, gd_commit_fn commit,
|
||||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||||
gd_rescan_fn rescan, gd_text_fn attachments,
|
gd_rescan_fn rescan, gd_text_fn attachments,
|
||||||
gd_sort_fn sort, gd_absorb_fn absorb)
|
gd_sort_fn sort, gd_absorb_fn absorb,
|
||||||
|
gd_text_fn sender, gd_header_fn header)
|
||||||
{
|
{
|
||||||
s_folder = folder;
|
s_folder = folder;
|
||||||
s_open = open;
|
s_open = open;
|
||||||
@@ -72,6 +75,8 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
|||||||
s_attachments = attachments;
|
s_attachments = attachments;
|
||||||
s_sort = sort;
|
s_sort = sort;
|
||||||
s_absorb = absorb;
|
s_absorb = absorb;
|
||||||
|
s_sender = sender;
|
||||||
|
s_header = header;
|
||||||
if (s_instance) {
|
if (s_instance) {
|
||||||
emit s_instance->ready();
|
emit s_instance->ready();
|
||||||
}
|
}
|
||||||
@@ -195,6 +200,36 @@ bool EngineBridge::moveToTrash(int folder, int row)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// L'indirizzo di chi ha scritto: il motore da' "Nome\tindirizzo".
|
||||||
|
QString EngineBridge::senderOf(int folder, int row)
|
||||||
|
{
|
||||||
|
if (!s_sender || !s_id_of) return QString();
|
||||||
|
const int id = s_id_of(folder, row);
|
||||||
|
if (id < 0) return QString();
|
||||||
|
char buf[1024];
|
||||||
|
const int n = s_sender(folder, id, buf, int(sizeof buf) - 1);
|
||||||
|
if (n <= 0) return QString();
|
||||||
|
buf[qMin(n, int(sizeof buf) - 1)] = '\0';
|
||||||
|
const QString tutto = QString::fromUtf8(buf);
|
||||||
|
const int tab = tutto.indexOf(QLatin1Char('\t'));
|
||||||
|
const QString indirizzo = tab >= 0 ? tutto.mid(tab + 1) : tutto;
|
||||||
|
return indirizzo.trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un header del messaggio, come lo da' il motore ("to", "cc", ...).
|
||||||
|
QString EngineBridge::headerOf(int folder, int row, const QString &name)
|
||||||
|
{
|
||||||
|
if (!s_header || !s_id_of) return QString();
|
||||||
|
const int id = s_id_of(folder, row);
|
||||||
|
if (id < 0) return QString();
|
||||||
|
char buf[4096];
|
||||||
|
const int n = s_header(folder, id, name.toUtf8().constData(), buf,
|
||||||
|
int(sizeof buf) - 1);
|
||||||
|
if (n <= 0) return QString();
|
||||||
|
buf[qMin(n, int(sizeof buf) - 1)] = '\0';
|
||||||
|
return QString::fromUtf8(buf).trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
// Una cella, come stringa UTF-8 letta dal motore.
|
// Una cella, come stringa UTF-8 letta dal motore.
|
||||||
QString EngineBridge::cell(int folder, int row, int column)
|
QString EngineBridge::cell(int folder, int row, int column)
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-1
@@ -38,7 +38,8 @@ public:
|
|||||||
gd_move_fn move, gd_commit_fn commit,
|
gd_move_fn move, gd_commit_fn commit,
|
||||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||||
gd_rescan_fn rescan, gd_text_fn attachments,
|
gd_rescan_fn rescan, gd_text_fn attachments,
|
||||||
gd_sort_fn sort, gd_absorb_fn absorb);
|
gd_sort_fn sort, gd_absorb_fn absorb,
|
||||||
|
gd_text_fn sender, gd_header_fn header);
|
||||||
|
|
||||||
bool checking() const { return m_checking; }
|
bool checking() const { return m_checking; }
|
||||||
QString lastResult() const { return m_lastResult; }
|
QString lastResult() const { return m_lastResult; }
|
||||||
@@ -53,6 +54,9 @@ public:
|
|||||||
Q_INVOKABLE void checkMail();
|
Q_INVOKABLE void checkMail();
|
||||||
Q_INVOKABLE QVariantList attachments(int folder, int row);
|
Q_INVOKABLE QVariantList attachments(int folder, int row);
|
||||||
Q_INVOKABLE QString saveAttachment(int folder, int row, int index);
|
Q_INVOKABLE QString saveAttachment(int folder, int row, int index);
|
||||||
|
// Per rispondere serve l'indirizzo, non solo il nome che sta in colonna.
|
||||||
|
Q_INVOKABLE QString senderOf(int folder, int row);
|
||||||
|
Q_INVOKABLE QString headerOf(int folder, int row, const QString &name);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ready();
|
void ready();
|
||||||
@@ -81,6 +85,8 @@ private:
|
|||||||
static gd_text_fn s_attachments;
|
static gd_text_fn s_attachments;
|
||||||
static gd_sort_fn s_sort;
|
static gd_sort_fn s_sort;
|
||||||
static gd_absorb_fn s_absorb;
|
static gd_absorb_fn s_absorb;
|
||||||
|
static gd_text_fn s_sender;
|
||||||
|
static gd_header_fn s_header;
|
||||||
|
|
||||||
AccountSettings *m_settings;
|
AccountSettings *m_settings;
|
||||||
QTimer *m_poll;
|
QTimer *m_poll;
|
||||||
|
|||||||
@@ -46,7 +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)sort; (void)mark_read; (void)id_of; (void)row_of; (void)move;
|
||||||
(void)commit; (void)empty; (void)log; (void)priority; (void)label;
|
(void)commit; (void)empty; (void)log; (void)priority; (void)label;
|
||||||
(void)decrypt; (void)sender; (void)key_of; (void)header; (void)plain;
|
(void)decrypt; (void)key_of; (void)plain;
|
||||||
(void)sheet; (void)compose; (void)filter; (void)last_id;
|
(void)sheet; (void)compose; (void)filter; (void)last_id;
|
||||||
(void)find_start; (void)find_poll; (void)find_cancel; (void)id_named;
|
(void)find_start; (void)find_poll; (void)find_cancel; (void)id_named;
|
||||||
(void)claim; (void)send_done; (void)send_start; (void)send_poll;
|
(void)claim; (void)send_done; (void)send_start; (void)send_poll;
|
||||||
@@ -60,7 +60,7 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
|
|||||||
EngineBridge::keepCallbacks(folder, open, cell, body, unread,
|
EngineBridge::keepCallbacks(folder, open, cell, body, unread,
|
||||||
mark_read, id_of, move, commit,
|
mark_read, id_of, move, commit,
|
||||||
imap_start, imap_poll, rescan, attachments, sort,
|
imap_start, imap_poll, rescan, attachments, sort,
|
||||||
absorb);
|
absorb, sender, header);
|
||||||
return QCoreApplication::exec();
|
return QCoreApplication::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -24,9 +24,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
|||||||
|
|
||||||
app->setOrganizationName(QStringLiteral("harbour"));
|
app->setOrganizationName(QStringLiteral("harbour"));
|
||||||
app->setApplicationName(QStringLiteral("grumpydove"));
|
app->setApplicationName(QStringLiteral("grumpydove"));
|
||||||
app->setApplicationVersion(QStringLiteral("0.5.1"));
|
app->setApplicationVersion(QStringLiteral("0.5.2"));
|
||||||
|
|
||||||
qDebug() << "harbour-grumpydove v0.5.1 build" << __DATE__ << __TIME__;
|
qDebug() << "harbour-grumpydove v0.5.2 build" << __DATE__ << __TIME__;
|
||||||
|
|
||||||
// La sandbox di Sailfish (SailJail) non lascia vedere ~/Mail, ma il motore
|
// La sandbox di Sailfish (SailJail) non lascia vedere ~/Mail, ma il motore
|
||||||
// legge il percorso del Maildir da GRUMPYDOVE_MAIL: si punta alla cartella
|
// legge il percorso del Maildir da GRUMPYDOVE_MAIL: si punta alla cartella
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Test degli indirizzi di risposta: un errore qui manda la posta a chi non
|
||||||
|
// deve, quindi i casi scomodi si provano prima.
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const src = fs.readFileSync(path.join(__dirname, '..', 'qml', 'js', 'reply.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++; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. il mittente si estrae anche con il nome davanti
|
||||||
|
eq(rispondi("Mario Rossi <mario@example.it>"), "mario@example.it", "nome + indirizzo");
|
||||||
|
|
||||||
|
// 2. mittente nudo
|
||||||
|
eq(rispondi("mario@example.it"), "mario@example.it", "indirizzo nudo");
|
||||||
|
|
||||||
|
// 3. rispondi a tutti: mittente, to e cc
|
||||||
|
eq(rispondiATutti("Mario <mario@example.it>",
|
||||||
|
"Anna <anna@example.it>, io@example.it",
|
||||||
|
"capo@example.it",
|
||||||
|
"io@example.it"),
|
||||||
|
"mario@example.it, anna@example.it, capo@example.it", "tutti, senza me");
|
||||||
|
|
||||||
|
// 4. doppioni tolti (anche con maiuscole diverse)
|
||||||
|
eq(rispondiATutti("a@x.it", "A@X.IT, b@x.it", "", ""), "a@x.it, b@x.it", "doppioni");
|
||||||
|
|
||||||
|
// 5. senza to e cc resta solo il mittente
|
||||||
|
eq(rispondiATutti("a@x.it", "", "", "io@x.it"), "a@x.it", "solo mittente");
|
||||||
|
|
||||||
|
// 6. se il mittente sono io, la lista resta vuota
|
||||||
|
eq(rispondiATutti("io@x.it", "b@x.it", "", "io@x.it"), "b@x.it", "io mittente");
|
||||||
|
|
||||||
|
// 7. valori sporchi non producono indirizzi inventati
|
||||||
|
eq(estrai("undisclosed-recipients:;").length, 0, "nessun indirizzo");
|
||||||
|
eq(estrai("<> , , mario@x.it").length, 1, "solo quello valido");
|
||||||
|
|
||||||
|
// 8. piu' indirizzi con virgola e punto e virgola misti
|
||||||
|
eq(rispondiATutti("a@x.it", "b@x.it, c@x.it", "d@x.it", ""),
|
||||||
|
"a@x.it, b@x.it, c@x.it, d@x.it", "quattro indirizzi");
|
||||||
|
|
||||||
|
console.log(fail === 0 ? 'OK: indirizzi di risposta' : `${fail} controlli falliti`);
|
||||||
|
process.exit(fail === 0 ? 0 : 1);
|
||||||
Reference in new issue
Block a user