Invio dei messaggi (0.6.0)
compose -> claim -> send_start -> send_poll, poi queue_sent per la copia in Sent. Il foglio e' To/Cc/Bcc/Subject, riga vuota, corpo (Mail_Compose.Parse); la riga SMTP viene da AccountSettings::smtpLine. ComposePage ha Cc, il pulsante Invia e gli esiti.
This commit is contained in:
1 parent
ce0f9bfa66
commit
79eee96199
6 files changed
+238
-20
No files matched your search
+153
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QHash>
|
||||
@@ -33,6 +34,12 @@ gd_sort_fn EngineBridge::s_sort = nullptr;
|
||||
gd_absorb_fn EngineBridge::s_absorb = nullptr;
|
||||
gd_text_fn EngineBridge::s_sender = nullptr;
|
||||
gd_header_fn EngineBridge::s_header = nullptr;
|
||||
gd_compose_fn EngineBridge::s_compose = nullptr;
|
||||
gd_claim_fn EngineBridge::s_claim = nullptr;
|
||||
gd_send_start_fn EngineBridge::s_send_start = nullptr;
|
||||
gd_find_poll_fn EngineBridge::s_send_poll = nullptr;
|
||||
gd_send_done_fn EngineBridge::s_send_done = nullptr;
|
||||
gd_queue_sent_fn EngineBridge::s_queue_sent = nullptr;
|
||||
|
||||
// Colonne del motore (enum Column di qt_shim.cpp)
|
||||
enum Column { Status, Priority, Attachment, Label, Who, Date, Size, Subject, Junk };
|
||||
@@ -58,7 +65,12 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||
gd_rescan_fn rescan, gd_text_fn attachments,
|
||||
gd_sort_fn sort, gd_absorb_fn absorb,
|
||||
gd_text_fn sender, gd_header_fn header)
|
||||
gd_text_fn sender, gd_header_fn header,
|
||||
gd_compose_fn compose, gd_claim_fn claim,
|
||||
gd_send_start_fn send_start,
|
||||
gd_find_poll_fn send_poll,
|
||||
gd_send_done_fn send_done,
|
||||
gd_queue_sent_fn queue_sent)
|
||||
{
|
||||
s_folder = folder;
|
||||
s_open = open;
|
||||
@@ -77,6 +89,12 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
||||
s_absorb = absorb;
|
||||
s_sender = sender;
|
||||
s_header = header;
|
||||
s_compose = compose;
|
||||
s_claim = claim;
|
||||
s_send_start = send_start;
|
||||
s_send_poll = send_poll;
|
||||
s_send_done = send_done;
|
||||
s_queue_sent = queue_sent;
|
||||
if (s_instance) {
|
||||
emit s_instance->ready();
|
||||
}
|
||||
@@ -341,6 +359,140 @@ QString EngineBridge::folderType(int folder)
|
||||
return QString();
|
||||
}
|
||||
|
||||
// Una cartella per nome: serve per trovare la coda di invio ("Out").
|
||||
int EngineBridge::folderNamed(const QString &nome)
|
||||
{
|
||||
const QVariantList elenco = folders();
|
||||
for (int i = 0; i < elenco.size(); i++) {
|
||||
const QVariantMap m = elenco.at(i).toMap();
|
||||
if (m.value("nome").toString().compare(nome, Qt::CaseInsensitive) == 0)
|
||||
return m.value("folder").toInt();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 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.
|
||||
QString EngineBridge::sendMessage(const QString &to, const QString &cc,
|
||||
const QString &bcc, const QString &oggetto,
|
||||
const QString &corpo)
|
||||
{
|
||||
if (!s_compose || !s_claim || !s_send_start || !s_send_poll)
|
||||
return tr("Il motore non è pronto");
|
||||
|
||||
const int out = folderNamed(QStringLiteral("Out"));
|
||||
if (out < 0)
|
||||
return tr("Manca la cartella «Out», la coda di invio");
|
||||
|
||||
const QString config = m_settings ? m_settings->smtpLine() : QString();
|
||||
if (config.isEmpty())
|
||||
return tr("SMTP non configurato: controlla l'account");
|
||||
|
||||
if (to.trimmed().isEmpty())
|
||||
return tr("Manca il destinatario");
|
||||
|
||||
// Il foglio che il motore sa leggere: campi "Nome: valore", riga vuota,
|
||||
// poi il corpo (Mail_Compose.Parse).
|
||||
QString foglio;
|
||||
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');
|
||||
foglio += QLatin1String("Subject: ") + oggetto + QLatin1String("\n\n") + corpo;
|
||||
|
||||
const QByteArray testo = foglio.toUtf8();
|
||||
const QByteArray nessunHtml;
|
||||
char stato[1024];
|
||||
stato[0] = '\0';
|
||||
const int salvato = s_compose(out, testo.constData(), testo.size(),
|
||||
nessunHtml.constData(), 0,
|
||||
1 /* in coda */, 0 /* cifra */, 0 /* firma */,
|
||||
0 /* nessun originale */, -1, -1, -1,
|
||||
stato, int(sizeof stato) - 1);
|
||||
if (salvato < 0) {
|
||||
const QString motivo = QString::fromUtf8(stato).trimmed();
|
||||
return motivo.isEmpty() ? tr("Il motore ha rifiutato il messaggio") : motivo;
|
||||
}
|
||||
|
||||
QByteArray coda(1 << 20, '\0');
|
||||
const int usati = s_claim(out, coda.data(), coda.size());
|
||||
if (usati <= 0)
|
||||
return tr("Niente in coda da mandare");
|
||||
coda.truncate(usati);
|
||||
|
||||
// Il nome della personalità serve alla copia in Sent sul server.
|
||||
QString persona = m_settings->persona().isEmpty() ? m_settings->user()
|
||||
: m_settings->persona();
|
||||
persona.replace(QRegularExpression(QStringLiteral("[^A-Za-z0-9._-]")),
|
||||
QStringLiteral("-"));
|
||||
|
||||
m_sendFolder = out;
|
||||
m_sendOk = 0;
|
||||
m_sendKo = 0;
|
||||
m_sendEsito.clear();
|
||||
m_sendPersona = persona;
|
||||
|
||||
if (!m_sendTimer) {
|
||||
m_sendTimer = new QTimer(this);
|
||||
m_sendTimer->setInterval(200);
|
||||
connect(m_sendTimer, &QTimer::timeout, this, &EngineBridge::pollSend);
|
||||
}
|
||||
const QByteArray cfg = config.toUtf8();
|
||||
s_send_start(cfg.constData(), cfg.size(), coda.constData(), coda.size());
|
||||
m_sendTimer->start();
|
||||
return QString();
|
||||
}
|
||||
|
||||
void EngineBridge::pollSend()
|
||||
{
|
||||
if (!s_send_poll) {
|
||||
if (m_sendTimer) m_sendTimer->stop();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray buffer(64 * 1024, '\0');
|
||||
int ancora = 0;
|
||||
const int letti = s_send_poll(buffer.data(), buffer.size(), &ancora);
|
||||
const QList<QByteArray> righe = buffer.left(letti).split('\n');
|
||||
for (int i = 0; i < righe.size(); i++) {
|
||||
const QByteArray riga = righe.at(i);
|
||||
if (riga.isEmpty()) continue;
|
||||
if (riga.at(0) == '!') {
|
||||
m_sendEsito = QString::fromUtf8(riga.mid(2)).trimmed();
|
||||
continue;
|
||||
}
|
||||
const QList<QByteArray> celle = riga.split('\t');
|
||||
if (celle.size() < 2) continue;
|
||||
const int id = celle.at(1).toInt();
|
||||
const bool inviato = riga.at(0) == '+';
|
||||
if (inviato) {
|
||||
++m_sendOk;
|
||||
// La copia che resta sul server: la mette lui nel Sent della
|
||||
// personalità, se la conosce.
|
||||
if (s_queue_sent && !m_sendPersona.isEmpty()) {
|
||||
const QByteArray p = m_sendPersona.toUtf8();
|
||||
s_queue_sent(m_sendFolder, id, p.constData(), p.size());
|
||||
}
|
||||
} else {
|
||||
++m_sendKo;
|
||||
m_sendEsito = celle.size() > 2 ? QString::fromUtf8(celle.at(2)).trimmed()
|
||||
: tr("invio non riuscito");
|
||||
}
|
||||
if (s_send_done) s_send_done(m_sendFolder, id, inviato ? 1 : 0);
|
||||
}
|
||||
|
||||
if (ancora) return;
|
||||
|
||||
m_sendTimer->stop();
|
||||
if (s_absorb) s_absorb(m_sendFolder);
|
||||
dropAllRows(); // Out e Sent sono cambiate
|
||||
if (s_rescan) s_rescan();
|
||||
emit sendFinished(m_sendOk, m_sendKo, m_sendEsito);
|
||||
QTimer::singleShot(0, this, [this] { emit ready(); });
|
||||
}
|
||||
|
||||
// Legge una cartella dal motore una volta sola e la tiene: una chiamata per
|
||||
// campo per riga, quindi rileggerla a ogni apertura era il costo vero.
|
||||
void EngineBridge::buildRows(int folder)
|
||||
|
||||
+26
-1
@@ -39,7 +39,12 @@ public:
|
||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||
gd_rescan_fn rescan, gd_text_fn attachments,
|
||||
gd_sort_fn sort, gd_absorb_fn absorb,
|
||||
gd_text_fn sender, gd_header_fn header);
|
||||
gd_text_fn sender, gd_header_fn header,
|
||||
gd_compose_fn compose, gd_claim_fn claim,
|
||||
gd_send_start_fn send_start,
|
||||
gd_find_poll_fn send_poll,
|
||||
gd_send_done_fn send_done,
|
||||
gd_queue_sent_fn queue_sent);
|
||||
|
||||
bool checking() const { return m_checking; }
|
||||
QString lastResult() const { return m_lastResult; }
|
||||
@@ -60,9 +65,15 @@ public:
|
||||
// "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);
|
||||
Q_INVOKABLE int folderNamed(const QString &nome);
|
||||
// Manda un messaggio: stringa vuota se e' partito, altrimenti il motivo.
|
||||
Q_INVOKABLE QString sendMessage(const QString &to, const QString &cc,
|
||||
const QString &bcc, const QString &oggetto,
|
||||
const QString &corpo);
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
void sendFinished(int inviati, int falliti, const QString &esito);
|
||||
void checkingChanged();
|
||||
void mailChecked();
|
||||
// a ogni riga di avanzamento che il motore manda durante il controllo
|
||||
@@ -90,6 +101,20 @@ private:
|
||||
static gd_absorb_fn s_absorb;
|
||||
static gd_text_fn s_sender;
|
||||
static gd_header_fn s_header;
|
||||
static gd_compose_fn s_compose;
|
||||
static gd_claim_fn s_claim;
|
||||
static gd_send_start_fn s_send_start;
|
||||
static gd_find_poll_fn s_send_poll;
|
||||
static gd_send_done_fn s_send_done;
|
||||
static gd_queue_sent_fn s_queue_sent;
|
||||
|
||||
void pollSend();
|
||||
QTimer *m_sendTimer = nullptr;
|
||||
int m_sendFolder = -1;
|
||||
int m_sendOk = 0;
|
||||
int m_sendKo = 0;
|
||||
QString m_sendEsito;
|
||||
QString m_sendPersona;
|
||||
|
||||
AccountSettings *m_settings;
|
||||
QTimer *m_poll;
|
||||
|
||||
@@ -47,9 +47,8 @@ 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)empty; (void)log; (void)priority; (void)label;
|
||||
(void)decrypt; (void)key_of; (void)plain;
|
||||
(void)sheet; (void)compose; (void)filter; (void)last_id;
|
||||
(void)sheet; (void)filter; (void)last_id;
|
||||
(void)find_start; (void)find_poll; (void)find_cancel; (void)id_named;
|
||||
(void)claim; (void)send_done; (void)send_start; (void)send_poll;
|
||||
(void)imap_start; (void)imap_poll; (void)absorb; (void)rescan;
|
||||
(void)shown_at; (void)can_hold; (void)make_folder; (void)can_change;
|
||||
(void)change_folder; (void)forget; (void)has_box; (void)place;
|
||||
@@ -60,7 +59,8 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
|
||||
EngineBridge::keepCallbacks(folder, open, cell, body, unread,
|
||||
mark_read, id_of, move, commit,
|
||||
imap_start, imap_poll, rescan, attachments, sort,
|
||||
absorb, sender, header);
|
||||
absorb, sender, header, compose, claim,
|
||||
send_start, send_poll, send_done, queue_sent);
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
||||
|
||||
+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.5.4"));
|
||||
app->setApplicationVersion(QStringLiteral("0.6.0"));
|
||||
|
||||
qDebug() << "harbour-grumpydove v0.5.4 build" << __DATE__ << __TIME__;
|
||||
qDebug() << "harbour-grumpydove v0.6.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