Bozze: salva in Drafts, riprendi, sostituisci per id (0.15.0)
Compose con Queue=0 scrive il messaggio senza metterlo in coda; la cartella e' Drafts (nuovo tipo 'draft' in folders()). Riprendendo una bozza il motore la sostituisce per id (Draft), non ne crea una seconda; dopo l'invio va nel cestino. Foglio di composizione estratto in foglioMessaggio(), usato da invio e bozza.
This commit is contained in:
1 parent
69f97d99b8
commit
d7549cedd0
6 files changed
+187
-22
No files matched your search
+113
-19
@@ -375,6 +375,12 @@ QString EngineBridge::headerOf(int folder, int row, const QString &name)
|
||||
return testoMotore(buf, qMin(n, int(sizeof buf) - 1)).trimmed();
|
||||
}
|
||||
|
||||
int EngineBridge::idOf(int folder, int row)
|
||||
{
|
||||
if (!s_id_of) return -1;
|
||||
return s_id_of(folder, row);
|
||||
}
|
||||
|
||||
// Una cella, come stringa UTF-8 letta dal motore.
|
||||
QString EngineBridge::cell(int folder, int row, int column)
|
||||
{
|
||||
@@ -444,6 +450,7 @@ QVariantList EngineBridge::folders()
|
||||
else if (e.nome == QLatin1String("INBOX") || e.nome == QLatin1String("In")) tipo = "in";
|
||||
else if (e.nome == QLatin1String("Sent") || e.nome == QLatin1String("Out")) tipo = "out";
|
||||
else if (e.nome == QLatin1String("Junk")) tipo = "junk";
|
||||
else if (e.nome == QLatin1String("Drafts")) tipo = "draft";
|
||||
else if (e.nome == QLatin1String("Trash")) tipo = "trash";
|
||||
|
||||
QVariantMap m;
|
||||
@@ -1045,6 +1052,110 @@ void EngineBridge::pollFiltri()
|
||||
emit ready();
|
||||
}
|
||||
|
||||
// Il foglio di composizione, nell'unico formato che Mail_Compose.Parse
|
||||
// conosce: campi "Nome: valore", riga vuota, corpo.
|
||||
QString EngineBridge::foglioMessaggio(const QString &to, const QString &cc,
|
||||
const QString &bcc, const QString &from,
|
||||
const QString &oggetto, const QString &corpo,
|
||||
const QStringList &allegati) const
|
||||
{
|
||||
QString foglio;
|
||||
foglio += QLatin1String("From: ") + from + QLatin1Char('\n');
|
||||
foglio += QLatin1String("To: ") + to.trimmed() + QLatin1Char('\n');
|
||||
if (!cc.trimmed().isEmpty())
|
||||
foglio += QLatin1String("Cc: ") + cc.trimmed() + QLatin1Char('\n');
|
||||
if (!bcc.trimmed().isEmpty())
|
||||
foglio += QLatin1String("Bcc: ") + bcc.trimmed() + QLatin1Char('\n');
|
||||
// Gli allegati: percorsi separati da punto e virgola, come li legge
|
||||
// Split_Paths di Mail_Compose. Un file che non si legge fa fallire la
|
||||
// composizione, quindi si scartano i percorsi vuoti.
|
||||
QStringList validi;
|
||||
for (int i = 0; i < allegati.size(); i++) {
|
||||
const QString p = allegati.at(i).trimmed();
|
||||
if (!p.isEmpty()) validi << p;
|
||||
}
|
||||
if (!validi.isEmpty())
|
||||
foglio += QLatin1String("Attached: ") + validi.join(QLatin1String("; "))
|
||||
+ QLatin1Char('\n');
|
||||
foglio += QLatin1String("Subject: ") + oggetto + QLatin1String("\n\n") + corpo;
|
||||
return foglio;
|
||||
}
|
||||
|
||||
// La cartella delle bozze: "Drafts" sul server; se non c'è, si ripiega su Out.
|
||||
int EngineBridge::folderDrafts()
|
||||
{
|
||||
const QVariantList tutte = folders();
|
||||
for (int i = 0; i < tutte.size(); i++) {
|
||||
const QVariantMap m = tutte.at(i).toMap();
|
||||
if (m.value(QStringLiteral("tipo")).toString() == QLatin1String("draft"))
|
||||
return m.value(QStringLiteral("folder")).toInt();
|
||||
}
|
||||
return folderOut();
|
||||
}
|
||||
|
||||
// Salvare una bozza: Queue = 0, così il messaggio non parte, e la cartella
|
||||
// di destinazione è Drafts. bozzaId >= 0 sostituisce quella ripresa.
|
||||
QString EngineBridge::salvaBozza(const QString &to, const QString &cc,
|
||||
const QString &bcc, const QString &da,
|
||||
const QString &oggetto, const QString &corpo,
|
||||
const QStringList &allegati, int bozzaId)
|
||||
{
|
||||
if (!s_compose) return tr("Il motore non è pronto");
|
||||
|
||||
const int drafts = folderDrafts();
|
||||
if (drafts < 0) {
|
||||
const QString m = tr("Manca la cartella delle bozze");
|
||||
logInvio("ERR bozza: " + m);
|
||||
return m;
|
||||
}
|
||||
|
||||
QString from = da.trimmed();
|
||||
if (from.isEmpty() && m_settings) from = m_settings->mittente().trimmed();
|
||||
|
||||
const QString foglio = foglioMessaggio(to, cc, bcc, from, oggetto, corpo,
|
||||
allegati);
|
||||
const QByteArray testo = foglio.toUtf8();
|
||||
const QByteArray nessunHtml;
|
||||
char stato[1024];
|
||||
stato[0] = '\0';
|
||||
const int id = s_compose(drafts, testo.constData(), testo.size(),
|
||||
nessunHtml.constData(), 0,
|
||||
0 /* non in coda */, 0 /* cifra */, 0 /* firma */,
|
||||
0 /* nuovo */, -1, -1, bozzaId, stato,
|
||||
int(sizeof stato) - 1);
|
||||
if (id < 0) {
|
||||
const QString m = QString::fromUtf8(stato, qMin(-id, int(sizeof stato) - 1));
|
||||
logInvio("ERR bozza: " + m);
|
||||
return m;
|
||||
}
|
||||
dropRows(drafts);
|
||||
logInvio(QString("bozza salvata: id %1 in %2").arg(id).arg(drafts));
|
||||
emit ready();
|
||||
return QString();
|
||||
}
|
||||
|
||||
// Rileggere una bozza per riprenderla: i campi del foglio e gli allegati.
|
||||
QVariantMap EngineBridge::bozza(int folder, int row)
|
||||
{
|
||||
QVariantMap m;
|
||||
m["a"] = headerOf(folder, row, QStringLiteral("To"));
|
||||
m["cc"] = headerOf(folder, row, QStringLiteral("Cc"));
|
||||
m["bcc"] = headerOf(folder, row, QStringLiteral("Bcc"));
|
||||
m["da"] = headerOf(folder, row, QStringLiteral("From"));
|
||||
m["oggetto"] = headerOf(folder, row, QStringLiteral("Subject"));
|
||||
m["corpo"] = body(folder, row);
|
||||
// I percorsi degli allegati li scrive il motore in questo header quando
|
||||
// il messaggio è una bozza (Mail_Compose.Draft_Attached).
|
||||
QStringList allegati;
|
||||
const QString attaccati =
|
||||
headerOf(folder, row, QStringLiteral("X-Grumpydove-Attached"));
|
||||
if (!attaccati.isEmpty())
|
||||
allegati = attaccati.split(QRegExp(QStringLiteral("\\s*;\\s*")),
|
||||
QString::SkipEmptyParts);
|
||||
m["allegati"] = allegati;
|
||||
return m;
|
||||
}
|
||||
|
||||
// Il giro dell'invio, come nell'originale: compose scrive il messaggio in Out
|
||||
// con il flag di coda, claim estrae quelli da mandare, send_start parla con il
|
||||
// server SMTP e send_poll riporta un messaggio per volta.
|
||||
@@ -1108,25 +1219,8 @@ QString EngineBridge::sendMessage(const QString &to, const QString &cc,
|
||||
|
||||
// Il foglio che il motore sa leggere: campi "Nome: valore", riga vuota,
|
||||
// poi il corpo (Mail_Compose.Parse).
|
||||
QString foglio;
|
||||
foglio += QLatin1String("From: ") + from + QLatin1Char('\n');
|
||||
foglio += QLatin1String("To: ") + to.trimmed() + QLatin1Char('\n');
|
||||
if (!cc.trimmed().isEmpty())
|
||||
foglio += QLatin1String("Cc: ") + cc.trimmed() + QLatin1Char('\n');
|
||||
if (!bcc.trimmed().isEmpty())
|
||||
foglio += QLatin1String("Bcc: ") + bcc.trimmed() + QLatin1Char('\n');
|
||||
// Gli allegati: percorsi separati da punto e virgola, come li legge
|
||||
// Split_Paths di Mail_Compose. Un file che non si legge fa fallire la
|
||||
// composizione, quindi si scartano i percorsi vuoti.
|
||||
QStringList validi;
|
||||
for (int i = 0; i < allegati.size(); i++) {
|
||||
const QString p = allegati.at(i).trimmed();
|
||||
if (!p.isEmpty()) validi << p;
|
||||
}
|
||||
if (!validi.isEmpty())
|
||||
foglio += QLatin1String("Attached: ") + validi.join(QLatin1String("; "))
|
||||
+ QLatin1Char('\n');
|
||||
foglio += QLatin1String("Subject: ") + oggetto + QLatin1String("\n\n") + corpo;
|
||||
const QString foglio = foglioMessaggio(to, cc, bcc, from, oggetto, corpo,
|
||||
allegati);
|
||||
|
||||
const QByteArray testo = foglio.toUtf8();
|
||||
const QByteArray nessunHtml;
|
||||
|
||||
@@ -75,6 +75,9 @@ public:
|
||||
// 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);
|
||||
// L'id interno di un messaggio: serve alle bozze, che si sostituiscono
|
||||
// per id e non per riga.
|
||||
Q_INVOKABLE int idOf(int folder, int row);
|
||||
// "non letto" non e' "stato vuoto": la regola sta in un posto solo.
|
||||
Q_INVOKABLE bool isUnread(int folder, int row);
|
||||
Q_INVOKABLE QString folderType(int folder);
|
||||
@@ -112,6 +115,13 @@ public:
|
||||
const QString &bcc, const QString &da,
|
||||
const QString &oggetto, const QString &corpo,
|
||||
const QStringList &allegati);
|
||||
// Bozze: si salvano nella cartella Drafts; bozzaId >= 0 sostituisce quella
|
||||
// che si sta riprendendo (l'id, non la riga).
|
||||
Q_INVOKABLE QString salvaBozza(const QString &to, const QString &cc,
|
||||
const QString &bcc, const QString &da,
|
||||
const QString &oggetto, const QString &corpo,
|
||||
const QStringList &allegati, int bozzaId);
|
||||
Q_INVOKABLE QVariantMap bozza(int folder, int row);
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
@@ -187,6 +197,11 @@ private:
|
||||
// Filtri: fase 1 impara dalle cartelle, fase 2 archivia i messaggi.
|
||||
void avviaFiltri(bool apprendimento);
|
||||
void pollFiltri();
|
||||
QString foglioMessaggio(const QString &to, const QString &cc,
|
||||
const QString &bcc, const QString &from,
|
||||
const QString &oggetto, const QString &corpo,
|
||||
const QStringList &allegati) const;
|
||||
int folderDrafts();
|
||||
QTimer *m_filtriTimer = nullptr;
|
||||
QString m_filtriImpara;
|
||||
QString m_filtriArchivia;
|
||||
|
||||
+2
-2
@@ -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.14.0"));
|
||||
app->setApplicationVersion(QStringLiteral("0.15.0"));
|
||||
|
||||
qDebug() << "harbour-grumpydove v0.14.0 build" << __DATE__ << __TIME__;
|
||||
qDebug() << "harbour-grumpydove v0.15.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
|
||||
|
||||
Reference in new issue
Block a user