presentation/MailOutboxSender.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "MailOutboxSender.h" | ||
| 2 | #include "ComposeLog.h" | ||
| 3 | |||
| 4 | #include <QEventLoop> | ||
| 5 | #include <QLocale> | ||
| 6 | #include <QLoggingCategory> | ||
| 7 | #include <QPointer> | ||
| 8 | #include <QTimeZone> | ||
| 9 | |||
| 10 | |||
| 11 | 805 | MailOutboxSender::MailOutboxSender(MailOutboxStore &store, Deps deps, QObject *parent) | |
| 12 |
1/1✓ Branch 5 → 6 taken 805 times.
|
805 | : QObject(parent), m_store(store), m_deps(std::move(deps)) { |
| 13 |
1/1✓ Branch 7 → 8 taken 805 times.
|
805 | m_timer.setSingleShot(true); |
| 14 |
1/1✓ Branch 8 → 9 taken 805 times.
|
805 | connect(&m_timer, &QTimer::timeout, this, &MailOutboxSender::processDue); |
| 15 | 805 | } | |
| 16 | |||
| 17 | 176 | QDateTime MailOutboxSender::now() const { | |
| 18 |
2/2✓ Branch 3 → 4 taken 61 times.
✓ Branch 3 → 5 taken 115 times.
|
176 | return m_deps.now ? m_deps.now() : QDateTime::currentDateTimeUtc(); |
| 19 | } | ||
| 20 | |||
| 21 | 20 | QByteArray MailOutboxSender::withDate(const QByteArray &message, const QDateTime &when) { | |
| 22 |
1/1✓ Branch 2 → 3 taken 20 times.
|
20 | const QDateTime utc = when.toUTC(); |
| 23 |
4/4✓ Branch 3 → 4 taken 20 times.
✓ Branch 7 → 8 taken 20 times.
✓ Branch 8 → 9 taken 20 times.
✓ Branch 9 → 10 taken 20 times.
|
60 | const QByteArray date = "Date: " + QLocale(QLocale::C).toString(utc, QStringLiteral("ddd, dd MMM yyyy HH:mm:ss")).toUtf8() + |
| 24 |
1/1✓ Branch 10 → 11 taken 20 times.
|
20 | " +0000"; |
| 25 | 20 | const qsizetype headerEnd = message.indexOf("\r\n\r\n"); | |
| 26 |
2/2✓ Branch 21 → 22 taken 19 times.
✓ Branch 21 → 32 taken 1 time.
|
20 | if (message.startsWith("Date: ")) { |
| 27 | 19 | const qsizetype end = message.indexOf("\r\n"); | |
| 28 |
5/8✓ Branch 24 → 25 taken 19 times.
✗ Branch 24 → 32 not taken.
✓ Branch 25 → 26 taken 19 times.
✗ Branch 25 → 27 not taken.
✓ Branch 26 → 27 taken 19 times.
✗ Branch 26 → 32 not taken.
✓ Branch 27 → 28 taken 19 times.
✓ Branch 28 → 29 taken 19 times.
|
19 | if (end > 0 && (headerEnd < 0 || end <= headerEnd)) return date + message.mid(end); |
| 29 | } | ||
| 30 |
2/2✓ Branch 32 → 33 taken 1 time.
✓ Branch 33 → 34 taken 1 time.
|
1 | return date + "\r\n" + message; |
| 31 | 20 | } | |
| 32 | |||
| 33 | 18 | QString MailOutboxSender::classify(const TransmitResult &result) { | |
| 34 |
1/1✓ Branch 2 → 3 taken 18 times.
|
18 | const QString error = result.error.toLower(); |
| 35 |
3/6✓ Branch 4 → 5 taken 16 times.
✗ Branch 4 → 31 not taken.
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 31 not taken.
✓ Branch 6 → 7 taken 16 times.
✗ Branch 6 → 31 not taken.
|
16 | if (result.code == 535 || result.code == 530 || result.code == 534 || result.code == 538 || |
| 36 |
4/6✓ Branch 8 → 9 taken 16 times.
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 31 not taken.
✓ Branch 11 → 12 taken 16 times.
✓ Branch 12 → 13 taken 16 times.
✗ Branch 12 → 31 not taken.
|
16 | error.contains(QLatin1String("authentication")) || error.contains(QLatin1String("auth ")) || |
| 37 |
6/6✓ Branch 14 → 15 taken 16 times.
✓ Branch 15 → 16 taken 9 times.
✓ Branch 15 → 31 taken 7 times.
✓ Branch 17 → 18 taken 9 times.
✓ Branch 18 → 19 taken 8 times.
✓ Branch 18 → 31 taken 1 time.
|
16 | error.contains(QLatin1String("password")) || error.contains(QLatin1String("certificate")) || |
| 38 |
4/6✓ Branch 20 → 21 taken 8 times.
✓ Branch 21 → 22 taken 8 times.
✗ Branch 21 → 31 not taken.
✓ Branch 23 → 24 taken 8 times.
✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 31 not taken.
|
8 | error.contains(QLatin1String("tls")) || error.contains(QLatin1String("starttls")) || |
| 39 |
8/10✓ Branch 3 → 4 taken 16 times.
✓ Branch 3 → 31 taken 2 times.
✓ Branch 26 → 27 taken 8 times.
✓ Branch 27 → 28 taken 8 times.
✗ Branch 27 → 31 not taken.
✓ Branch 29 → 30 taken 8 times.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 8 times.
✓ Branch 33 → 34 taken 10 times.
✓ Branch 33 → 39 taken 8 times.
|
34 | error.contains(QLatin1String("not encrypted")) || error.contains(QLatin1String("not configured"))) |
| 40 | 10 | return QStringLiteral("account"); | |
| 41 |
4/4✓ Branch 39 → 40 taken 7 times.
✓ Branch 39 → 46 taken 1 time.
✓ Branch 40 → 41 taken 4 times.
✓ Branch 40 → 46 taken 3 times.
|
12 | if (result.code >= 400 && result.code < 500) return QStringLiteral("network"); |
| 42 |
2/2✓ Branch 46 → 47 taken 1 time.
✓ Branch 46 → 52 taken 3 times.
|
5 | if (result.code == 0) return QStringLiteral("network"); |
| 43 |
2/3✓ Branch 53 → 54 taken 3 times.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 60 taken 3 times.
|
3 | if (error.startsWith(QLatin1String("recipient"))) return QStringLiteral("recipients"); |
| 44 | 3 | return QStringLiteral("message"); | |
| 45 | 18 | } | |
| 46 | |||
| 47 | 20 | QDateTime MailOutboxSender::nextRetry(const QDateTime &now, int attempts) { | |
| 48 | static const int minutes[] = {1, 2, 5, 10, 30}; | ||
| 49 |
1/1✓ Branch 2 → 3 taken 20 times.
|
20 | const int index = qBound(0, attempts - 1, 5); |
| 50 |
1/2✓ Branch 3 → 4 taken 20 times.
✗ Branch 3 → 5 not taken.
|
20 | return now.addSecs(60LL * (index < 5 ? minutes[index] : 60)); |
| 51 | } | ||
| 52 | |||
| 53 | 2 | void MailOutboxSender::start() { | |
| 54 | // MailJD stopped while a message was being handed over: before anything | ||
| 55 | // is sent again, the Sent folder tells whether the server took it. | ||
| 56 |
5/5✓ Branch 2 → 3 taken 2 times.
✓ Branch 3 → 4 taken 2 times.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 35 → 6 taken 2 times.
✓ Branch 35 → 36 taken 2 times.
|
4 | for (const OutboxEntry &entry : m_store.interrupted()) { |
| 57 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 25 taken 2 times.
|
2 | if (!m_deps.sentContains) { |
| 58 | ✗ | m_store.recordFailure(entry.id, QStringLiteral("interrupted"), | |
| 59 | ✗ | tr("MailJD stopped while sending — check whether it arrived."), QStringLiteral("failed")); | |
| 60 | ✗ | continue; | |
| 61 | } | ||
| 62 |
1/1✓ Branch 25 → 26 taken 2 times.
|
2 | QPointer<MailOutboxSender> self(this); |
| 63 | 2 | const qint64 id = entry.id; | |
| 64 |
2/4✓ Branch 27 → 28 taken 2 times.
✓ Branch 28 → 29 taken 2 times.
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
|
2 | m_deps.sentContains(entry, [self, id](bool found) { |
| 65 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 2 times.
|
2 | if (!self) return; |
| 66 |
4/4✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 14 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 10 → 11 taken 1 time.
|
2 | if (found) self->m_store.markSent(id, self->now(), {}); |
| 67 |
1/1✓ Branch 23 → 24 taken 1 time.
|
3 | else self->m_store.recordFailure(id, QStringLiteral("interrupted"), |
| 68 |
1/1✓ Branch 19 → 20 taken 1 time.
|
2 | tr("MailJD stopped while sending — check whether it arrived."), |
| 69 | 2 | QStringLiteral("failed")); | |
| 70 | 2 | emit self->changed(); | |
| 71 | }); | ||
| 72 | 4 | } | |
| 73 | 2 | scheduleNext(); | |
| 74 | 2 | } | |
| 75 | |||
| 76 | 46 | qint64 MailOutboxSender::enqueue(const OutboxEntry &entry) { | |
| 77 | 46 | const qint64 id = m_store.enqueue(entry); | |
| 78 |
1/2✓ Branch 3 → 4 taken 46 times.
✗ Branch 3 → 22 not taken.
|
46 | if (id > 0) { |
| 79 |
2/10✓ Branch 4 → 5 taken 46 times.
✗ Branch 8 → 9 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 19 → 6 not taken.
✓ Branch 19 → 20 taken 46 times.
|
46 | qCInfo(lcCompose) << "outbox enqueue" << id << "state" << entry.state << "bytes" << entry.mime.size(); |
| 80 | 46 | emit changed(); | |
| 81 | 46 | scheduleNext(); | |
| 82 | } | ||
| 83 | 46 | return id; | |
| 84 | } | ||
| 85 | |||
| 86 | 7 | std::optional<OutboxEntry> MailOutboxSender::takeBack(qint64 id) { | |
| 87 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 7 times.
|
7 | if (m_inFlight.contains(id)) return std::nullopt; |
| 88 |
1/1✓ Branch 5 → 6 taken 7 times.
|
7 | auto entry = m_store.find(id); |
| 89 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 7 times.
|
7 | if (!entry) return std::nullopt; |
| 90 | 7 | const QStringList editable{QStringLiteral("undo"), QStringLiteral("scheduled"), QStringLiteral("queued"), | |
| 91 |
2/4✓ Branch 29 → 30 taken 42 times.
✓ Branch 29 → 31 taken 7 times.
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 52 not taken.
|
49 | QStringLiteral("retry"), QStringLiteral("waiting"), QStringLiteral("failed")}; |
| 92 |
1/2✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 7 times.
|
7 | if (!editable.contains(entry->state)) return std::nullopt; |
| 93 |
1/1✓ Branch 41 → 42 taken 7 times.
|
7 | m_store.remove(id); |
| 94 |
1/1✓ Branch 42 → 43 taken 7 times.
|
7 | emit changed(); |
| 95 |
1/1✓ Branch 43 → 44 taken 7 times.
|
7 | scheduleNext(); |
| 96 | 7 | return entry; | |
| 97 | 56 | } | |
| 98 | |||
| 99 | 11 | bool MailOutboxSender::sendNow(qint64 id) { | |
| 100 |
1/1✓ Branch 2 → 3 taken 11 times.
|
11 | const auto entry = m_store.find(id); |
| 101 |
6/8✓ Branch 4 → 5 taken 10 times.
✓ Branch 4 → 13 taken 1 time.
✓ Branch 8 → 9 taken 10 times.
✗ Branch 8 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 10 times.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 17 taken 10 times.
|
11 | if (!entry || entry->state == QLatin1String("sending") || entry->state == QLatin1String("sent")) return false; |
| 102 |
2/2✓ Branch 17 → 18 taken 10 times.
✓ Branch 21 → 22 taken 10 times.
|
20 | m_store.setState(id, QStringLiteral("queued"), now()); |
| 103 |
1/1✓ Branch 25 → 26 taken 10 times.
|
10 | emit changed(); |
| 104 | // *Send now* is the user's explicit request: it tries at once, also when | ||
| 105 | // the network is believed to be down (the detection can be wrong). | ||
| 106 |
5/8✓ Branch 26 → 27 taken 10 times.
✓ Branch 28 → 29 taken 10 times.
✗ Branch 28 → 32 not taken.
✓ Branch 30 → 31 taken 10 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 10 times.
✗ Branch 33 → 36 not taken.
✓ Branch 35 → 36 taken 10 times.
|
10 | if (const auto queued = m_store.find(id); queued && !m_inFlight.contains(id)) transmit(*queued); |
| 107 |
1/1✓ Branch 37 → 38 taken 10 times.
|
10 | scheduleNext(); |
| 108 | 10 | return true; | |
| 109 | 11 | } | |
| 110 | |||
| 111 | ✗ | bool MailOutboxSender::reschedule(qint64 id, const QDateTime &due) { | |
| 112 | ✗ | const auto entry = m_store.find(id); | |
| 113 | ✗ | if (!entry || entry->invitation || !due.isValid() || m_inFlight.contains(id)) return false; | |
| 114 | ✗ | m_store.setState(id, QStringLiteral("scheduled"), due.toUTC()); | |
| 115 | ✗ | emit changed(); | |
| 116 | ✗ | scheduleNext(); | |
| 117 | ✗ | return true; | |
| 118 | ✗ | } | |
| 119 | |||
| 120 | 1 | bool MailOutboxSender::resendToRefused(qint64 id) { | |
| 121 |
1/1✓ Branch 2 → 3 taken 1 time.
|
1 | const auto entry = m_store.find(id); |
| 122 |
3/6✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 8 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 1 time.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 1 time.
|
1 | if (!entry || entry->refused.isEmpty()) return false; |
| 123 |
1/1✓ Branch 13 → 14 taken 1 time.
|
1 | m_store.setRecipients(id, entry->refused); |
| 124 |
2/2✓ Branch 14 → 15 taken 1 time.
✓ Branch 18 → 19 taken 1 time.
|
2 | m_store.setState(id, QStringLiteral("queued"), now()); |
| 125 |
1/1✓ Branch 22 → 23 taken 1 time.
|
1 | emit changed(); |
| 126 | // *Send now* is the user's explicit request: it tries at once, also when | ||
| 127 | // the network is believed to be down (the detection can be wrong). | ||
| 128 |
5/8✓ Branch 23 → 24 taken 1 time.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 29 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 33 not taken.
✓ Branch 32 → 33 taken 1 time.
|
1 | if (const auto queued = m_store.find(id); queued && !m_inFlight.contains(id)) transmit(*queued); |
| 129 |
1/1✓ Branch 34 → 35 taken 1 time.
|
1 | scheduleNext(); |
| 130 | 1 | return true; | |
| 131 | 1 | } | |
| 132 | |||
| 133 | 10 | void MailOutboxSender::accountChanged(const QString &accountId) { | |
| 134 | 10 | bool any = false; | |
| 135 |
5/5✓ Branch 2 → 3 taken 10 times.
✓ Branch 3 → 4 taken 10 times.
✓ Branch 4 → 5 taken 10 times.
✓ Branch 27 → 6 taken 1 time.
✓ Branch 27 → 28 taken 10 times.
|
11 | for (const OutboxEntry &entry : m_store.entries()) { |
| 136 |
3/6✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 12 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1 time.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 1 time.
|
1 | if (entry.accountId != accountId || entry.state != QLatin1String("waiting")) continue; |
| 137 |
2/2✓ Branch 16 → 17 taken 1 time.
✓ Branch 20 → 21 taken 1 time.
|
2 | m_store.setState(entry.id, QStringLiteral("queued"), now()); |
| 138 | 1 | any = true; | |
| 139 | 10 | } | |
| 140 |
2/2✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 9 times.
|
10 | if (any) { |
| 141 | 1 | emit changed(); | |
| 142 | 1 | processDue(); | |
| 143 | } | ||
| 144 | 10 | } | |
| 145 | |||
| 146 | 2 | void MailOutboxSender::networkAvailable() { | |
| 147 |
5/5✓ Branch 2 → 3 taken 2 times.
✓ Branch 3 → 4 taken 2 times.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 27 → 6 taken 1 time.
✓ Branch 27 → 28 taken 2 times.
|
3 | for (const OutboxEntry &entry : m_store.entries()) |
| 148 |
3/6✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 14 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 25 not taken.
|
1 | if (entry.state == QLatin1String("retry") && entry.errorClass == QLatin1String("network")) |
| 149 |
2/2✓ Branch 16 → 17 taken 1 time.
✓ Branch 20 → 21 taken 1 time.
|
4 | m_store.setState(entry.id, QStringLiteral("retry"), now()); |
| 150 | 2 | processDue(); | |
| 151 | 2 | } | |
| 152 | |||
| 153 | 795 | void MailOutboxSender::flushUndoWindow(int timeoutMs) { | |
| 154 | 795 | bool any = false; | |
| 155 |
5/5✓ Branch 2 → 3 taken 795 times.
✓ Branch 3 → 4 taken 795 times.
✓ Branch 4 → 5 taken 795 times.
✓ Branch 22 → 6 taken 31 times.
✓ Branch 22 → 23 taken 795 times.
|
826 | for (const OutboxEntry &entry : m_store.entries()) { |
| 156 |
2/2✓ Branch 9 → 10 taken 17 times.
✓ Branch 9 → 11 taken 14 times.
|
31 | if (entry.state != QLatin1String("undo")) continue; |
| 157 |
2/2✓ Branch 11 → 12 taken 14 times.
✓ Branch 15 → 16 taken 14 times.
|
28 | m_store.setState(entry.id, QStringLiteral("queued"), now()); |
| 158 | 14 | any = true; | |
| 159 | 795 | } | |
| 160 |
2/2✓ Branch 24 → 25 taken 781 times.
✓ Branch 24 → 26 taken 14 times.
|
809 | if (!any) return; |
| 161 |
1/1✓ Branch 26 → 27 taken 14 times.
|
14 | processDue(); |
| 162 |
1/2✓ Branch 28 → 29 taken 14 times.
✗ Branch 28 → 30 not taken.
|
14 | if (m_inFlight.isEmpty()) return; |
| 163 | ✗ | QEventLoop loop; | |
| 164 | ✗ | QTimer guard; | |
| 165 | ✗ | guard.setSingleShot(true); | |
| 166 | ✗ | connect(&guard, &QTimer::timeout, &loop, &QEventLoop::quit); | |
| 167 | ✗ | connect(this, &MailOutboxSender::changed, &loop, [this, &loop] { | |
| 168 | ✗ | if (m_inFlight.isEmpty()) loop.quit(); | |
| 169 | ✗ | }); | |
| 170 | ✗ | guard.start(timeoutMs); | |
| 171 | ✗ | loop.exec(); | |
| 172 | ✗ | } | |
| 173 | |||
| 174 | 116 | void MailOutboxSender::scheduleNext() { | |
| 175 | 116 | QDateTime next; | |
| 176 |
5/5✓ Branch 3 → 4 taken 116 times.
✓ Branch 4 → 5 taken 116 times.
✓ Branch 5 → 6 taken 116 times.
✓ Branch 53 → 7 taken 116 times.
✓ Branch 53 → 54 taken 116 times.
|
232 | for (const OutboxEntry &entry : m_store.entries()) { |
| 177 | 116 | const QStringList timed{QStringLiteral("undo"), QStringLiteral("scheduled"), QStringLiteral("queued"), | |
| 178 |
2/4✓ Branch 22 → 23 taken 464 times.
✓ Branch 22 → 24 taken 116 times.
✗ Branch 73 → 74 not taken.
✗ Branch 73 → 75 not taken.
|
580 | QStringLiteral("retry")}; |
| 179 |
5/6✓ Branch 29 → 30 taken 80 times.
✓ Branch 29 → 32 taken 36 times.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 80 times.
✓ Branch 34 → 35 taken 36 times.
✓ Branch 34 → 36 taken 80 times.
|
116 | if (!timed.contains(entry.state) || m_inFlight.contains(entry.id)) continue; |
| 180 |
7/8✓ Branch 36 → 37 taken 80 times.
✓ Branch 37 → 38 taken 10 times.
✓ Branch 37 → 41 taken 70 times.
✓ Branch 38 → 39 taken 10 times.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 42 taken 10 times.
✓ Branch 43 → 44 taken 70 times.
✓ Branch 43 → 45 taken 10 times.
|
80 | if (!next.isValid() || entry.due < next) next = entry.due; |
| 181 | 232 | } | |
| 182 |
3/3✓ Branch 55 → 56 taken 116 times.
✓ Branch 56 → 57 taken 46 times.
✓ Branch 56 → 59 taken 70 times.
|
116 | if (!next.isValid()) { |
| 183 |
1/1✓ Branch 57 → 58 taken 46 times.
|
46 | m_timer.stop(); |
| 184 | 46 | return; | |
| 185 | } | ||
| 186 |
2/2✓ Branch 59 → 60 taken 70 times.
✓ Branch 60 → 61 taken 70 times.
|
70 | const qint64 delay = qMax<qint64>(0, now().msecsTo(next)); |
| 187 |
1/1✓ Branch 64 → 65 taken 70 times.
|
70 | m_timer.start(int(qMin<qint64>(delay, 60 * 60 * 1000))); |
| 188 | 696 | } | |
| 189 | |||
| 190 | 30 | void MailOutboxSender::processDue() { | |
| 191 |
3/4✓ Branch 3 → 4 taken 30 times.
✗ Branch 3 → 6 not taken.
✓ Branch 5 → 6 taken 13 times.
✓ Branch 5 → 7 taken 17 times.
|
30 | const bool online = !m_deps.online || m_deps.online(); |
| 192 |
6/6✓ Branch 8 → 9 taken 30 times.
✓ Branch 9 → 10 taken 30 times.
✓ Branch 11 → 12 taken 30 times.
✓ Branch 12 → 13 taken 30 times.
✓ Branch 56 → 14 taken 26 times.
✓ Branch 56 → 57 taken 30 times.
|
56 | for (const OutboxEntry &due : m_store.due(now())) { |
| 193 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 26 times.
|
26 | if (m_inFlight.contains(due.id)) continue; |
| 194 |
2/2✓ Branch 18 → 19 taken 17 times.
✓ Branch 18 → 47 taken 9 times.
|
26 | if (!online) { |
| 195 |
2/6✗ Branch 21 → 22 not taken.
✓ Branch 21 → 25 taken 17 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✓ Branch 27 → 28 taken 17 times.
✗ Branch 27 → 46 not taken.
|
17 | if (due.state != QLatin1String("retry") || due.errorClass != QLatin1String("network")) { |
| 196 |
2/2✓ Branch 33 → 34 taken 17 times.
✓ Branch 37 → 38 taken 17 times.
|
34 | m_store.recordFailure(due.id, QStringLiteral("network"), tr("Waiting for the network"), QStringLiteral("retry"), |
| 197 |
2/2✓ Branch 28 → 29 taken 17 times.
✓ Branch 29 → 30 taken 17 times.
|
34 | nextRetry(now(), due.attempts + 1)); |
| 198 |
1/1✓ Branch 45 → 46 taken 17 times.
|
17 | emit changed(); |
| 199 | } | ||
| 200 | 17 | continue; | |
| 201 | } | ||
| 202 |
3/4✓ Branch 47 → 48 taken 9 times.
✓ Branch 49 → 50 taken 9 times.
✗ Branch 49 → 52 not taken.
✓ Branch 51 → 52 taken 9 times.
|
9 | if (const auto entry = m_store.find(due.id)) transmit(*entry); |
| 203 | 30 | } | |
| 204 | 30 | scheduleNext(); | |
| 205 | 30 | } | |
| 206 | |||
| 207 | 20 | void MailOutboxSender::transmit(const OutboxEntry &entry) { | |
| 208 |
6/9✓ Branch 3 → 4 taken 9 times.
✓ Branch 3 → 9 taken 11 times.
✓ Branch 5 → 6 taken 9 times.
✗ Branch 5 → 9 not taken.
✓ Branch 6 → 7 taken 9 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 9 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 20 times.
|
20 | if (m_deps.serverDelivers && m_deps.deliverByServer && m_deps.serverDelivers(entry)) { |
| 209 | ✗ | deliverByServer(entry); | |
| 210 | ✗ | return; | |
| 211 | } | ||
| 212 |
3/6✓ Branch 14 → 15 taken 20 times.
✗ Branch 14 → 17 not taken.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 20 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 20 times.
|
20 | if (!m_deps.resolveAccount || !m_deps.transmit) return; |
| 213 |
1/1✓ Branch 21 → 22 taken 20 times.
|
20 | m_inFlight.insert(entry.id); |
| 214 |
1/1✓ Branch 26 → 27 taken 20 times.
|
40 | m_store.setState(entry.id, QStringLiteral("sending")); |
| 215 |
1/1✓ Branch 30 → 31 taken 20 times.
|
20 | emit changed(); |
| 216 |
1/1✓ Branch 31 → 32 taken 20 times.
|
20 | const QDateTime sentAt = now(); |
| 217 |
1/1✓ Branch 32 → 33 taken 20 times.
|
20 | const QByteArray bytes = withDate(entry.mime, sentAt); |
| 218 |
1/1✓ Branch 33 → 34 taken 20 times.
|
20 | QPointer<MailOutboxSender> self(this); |
| 219 |
2/6✓ Branch 37 → 38 taken 20 times.
✓ Branch 38 → 39 taken 20 times.
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 66 not taken.
|
20 | m_deps.resolveAccount(entry.accountId, [self, entry, bytes](std::optional<AccountConfig> account) { |
| 220 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 20 times.
|
20 | if (!self) return; |
| 221 |
3/6✓ Branch 6 → 7 taken 20 times.
✗ Branch 6 → 10 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 20 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 20 taken 20 times.
|
20 | if (!account || account->smtp.host.isEmpty()) { |
| 222 | ✗ | TransmitResult missing; | |
| 223 | ✗ | missing.error = tr("The account is not configured for sending."); | |
| 224 | ✗ | self->finish(entry, missing, bytes); | |
| 225 | ✗ | return; | |
| 226 | ✗ | } | |
| 227 |
1/1✓ Branch 26 → 27 taken 20 times.
|
40 | self->m_deps.transmit(*account, entry.envelopeFrom, entry.recipients, bytes, |
| 228 |
1/5✓ Branch 24 → 25 taken 20 times.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
|
40 | [self, entry, bytes](const TransmitResult &result) { |
| 229 |
1/2✓ Branch 3 → 4 taken 20 times.
✗ Branch 3 → 6 not taken.
|
20 | if (self) self->finish(entry, result, bytes); |
| 230 | 20 | }); | |
| 231 | }); | ||
| 232 | 20 | } | |
| 233 | |||
| 234 | ✗ | void MailOutboxSender::deliverByServer(const OutboxEntry &entry) { | |
| 235 | ✗ | m_store.setState(entry.id, QStringLiteral("sending")); | |
| 236 | ✗ | const bool delivered = m_deps.deliverByServer(entry); | |
| 237 | ✗ | qCInfo(lcCompose) << "outbox invitation handed to the calendar server" << entry.id << delivered; | |
| 238 | ✗ | if (delivered) { | |
| 239 | ✗ | m_store.remove(entry.id); | |
| 240 | ✗ | emit transmitted(entry.id, entry.summaryTo, false); | |
| 241 | } else { | ||
| 242 | ✗ | m_store.recordFailure(entry.id, QStringLiteral("message"), tr("The calendar did not take the invitation."), | |
| 243 | ✗ | QStringLiteral("failed")); | |
| 244 | ✗ | emit failedEntry(entry.id, QStringLiteral("message"), tr("The calendar did not take the invitation.")); | |
| 245 | } | ||
| 246 | ✗ | emit changed(); | |
| 247 | ✗ | scheduleNext(); | |
| 248 | ✗ | } | |
| 249 | |||
| 250 | 20 | void MailOutboxSender::finish(const OutboxEntry &entry, const TransmitResult &result, const QByteArray &sentBytes) { | |
| 251 |
1/1✓ Branch 2 → 3 taken 20 times.
|
20 | m_inFlight.remove(entry.id); |
| 252 |
2/2✓ Branch 3 → 4 taken 8 times.
✓ Branch 3 → 103 taken 12 times.
|
20 | if (result.ok) { |
| 253 |
1/5✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 8 times.
✗ Branch 7 → 8 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 13 not taken.
|
8 | const bool late = entry.state == QLatin1String("scheduled") && entry.due.isValid() && |
| 254 |
1/8✗ Branch 9 → 10 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 8 times.
✗ Branch 170 → 171 not taken.
✗ Branch 170 → 172 not taken.
|
8 | entry.due.secsTo(now()) > 15 * 60; |
| 255 |
2/2✓ Branch 16 → 17 taken 8 times.
✓ Branch 17 → 18 taken 8 times.
|
8 | m_store.markSent(entry.id, now(), sentBytes); |
| 256 |
3/3✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 22 taken 7 times.
✓ Branch 21 → 22 taken 1 time.
|
8 | if (!result.refused.isEmpty()) m_store.recordPartial(entry.id, result.refused, result.refusalReply); |
| 257 |
2/3✓ Branch 23 → 24 taken 8 times.
✗ Branch 23 → 25 not taken.
✓ Branch 24 → 25 taken 8 times.
|
8 | if (m_deps.flagOriginal) m_deps.flagOriginal(entry); |
| 258 |
1/3✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 8 times.
✗ Branch 27 → 28 not taken.
|
8 | if (m_deps.afterTransmit) m_deps.afterTransmit(entry, sentBytes); |
| 259 | 8 | QByteArray copy = sentBytes; | |
| 260 |
6/7✓ Branch 30 → 31 taken 8 times.
✗ Branch 30 → 46 not taken.
✓ Branch 34 → 35 taken 8 times.
✓ Branch 35 → 36 taken 8 times.
✓ Branch 36 → 37 taken 8 times.
✓ Branch 37 → 38 taken 8 times.
✓ Branch 38 → 39 taken 8 times.
|
16 | if (!entry.bcc.isEmpty()) copy.prepend("Bcc: " + entry.bcc.join(QStringLiteral(",\r\n ")).toUtf8() + "\r\n"); |
| 261 |
4/5✓ Branch 47 → 48 taken 8 times.
✗ Branch 47 → 51 not taken.
✓ Branch 48 → 49 taken 8 times.
✓ Branch 49 → 50 taken 7 times.
✓ Branch 49 → 51 taken 1 time.
|
8 | const bool stored = m_deps.storeSentCopy && m_deps.storeSentCopy(entry, copy); |
| 262 |
2/2✓ Branch 53 → 54 taken 7 times.
✓ Branch 53 → 57 taken 1 time.
|
8 | if (result.refused.isEmpty()) { |
| 263 |
3/3✓ Branch 54 → 55 taken 6 times.
✓ Branch 54 → 56 taken 1 time.
✓ Branch 55 → 57 taken 6 times.
|
7 | if (stored) m_store.remove(entry.id); |
| 264 |
1/1✓ Branch 56 → 57 taken 1 time.
|
1 | else m_store.setCopyPending(entry.id, true); |
| 265 | } | ||
| 266 |
2/10✓ Branch 57 → 58 taken 8 times.
✗ Branch 61 → 62 not taken.
✗ Branch 62 → 63 not taken.
✗ Branch 63 → 64 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 66 → 67 not taken.
✗ Branch 67 → 68 not taken.
✗ Branch 68 → 69 not taken.
✗ Branch 72 → 59 not taken.
✓ Branch 72 → 73 taken 8 times.
|
8 | qCInfo(lcCompose) << "outbox sent" << entry.id << "refused" << result.refused.size() << "late" << late; |
| 267 |
1/1✓ Branch 73 → 74 taken 8 times.
|
8 | emit transmitted(entry.id, entry.summaryTo, late); |
| 268 |
2/2✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 99 taken 7 times.
|
8 | if (!result.refused.isEmpty()) { |
| 269 |
1/1✓ Branch 79 → 80 taken 1 time.
|
2 | emit failedEntry(entry.id, QStringLiteral("recipients"), result.refusalReply); |
| 270 |
1/2✗ Branch 83 → 84 not taken.
✓ Branch 83 → 99 taken 1 time.
|
1 | if (m_deps.notify) |
| 271 | ✗ | m_deps.notify(tr("Not every recipient got your mail"), | |
| 272 | ✗ | tr("%1 refused: %2").arg(result.refused.join(QStringLiteral(", ")), result.refusalReply)); | |
| 273 | } | ||
| 274 |
1/1✓ Branch 99 → 100 taken 8 times.
|
8 | emit changed(); |
| 275 |
1/1✓ Branch 100 → 101 taken 8 times.
|
8 | scheduleNext(); |
| 276 | 8 | return; | |
| 277 | 8 | } | |
| 278 |
1/1✓ Branch 103 → 104 taken 12 times.
|
12 | const QString errorClass = classify(result); |
| 279 |
2/10✓ Branch 104 → 105 taken 12 times.
✗ Branch 108 → 109 not taken.
✗ Branch 109 → 110 not taken.
✗ Branch 110 → 111 not taken.
✗ Branch 111 → 112 not taken.
✗ Branch 112 → 113 not taken.
✗ Branch 113 → 114 not taken.
✗ Branch 114 → 115 not taken.
✗ Branch 118 → 106 not taken.
✓ Branch 118 → 119 taken 12 times.
|
12 | qCInfo(lcCompose) << "outbox failure" << entry.id << "class" << errorClass << "code" << result.code; |
| 280 |
2/2✓ Branch 121 → 122 taken 3 times.
✓ Branch 121 → 133 taken 9 times.
|
12 | if (errorClass == QLatin1String("network")) { |
| 281 |
3/3✓ Branch 122 → 123 taken 3 times.
✓ Branch 123 → 124 taken 3 times.
✓ Branch 127 → 128 taken 3 times.
|
6 | m_store.recordFailure(entry.id, errorClass, result.error, QStringLiteral("retry"), nextRetry(now(), entry.attempts + 1)); |
| 282 |
2/2✓ Branch 135 → 136 taken 8 times.
✓ Branch 135 → 150 taken 1 time.
|
9 | } else if (errorClass == QLatin1String("account")) { |
| 283 |
1/1✓ Branch 140 → 141 taken 8 times.
|
16 | m_store.recordFailure(entry.id, errorClass, result.error, QStringLiteral("waiting")); |
| 284 |
4/4✓ Branch 145 → 146 taken 7 times.
✓ Branch 145 → 164 taken 1 time.
✓ Branch 146 → 147 taken 7 times.
✓ Branch 147 → 148 taken 7 times.
|
8 | if (m_deps.notify) m_deps.notify(tr("Can't send: the server refused the account"), result.error); |
| 285 | } else { | ||
| 286 |
1/1✓ Branch 154 → 155 taken 1 time.
|
2 | m_store.recordFailure(entry.id, errorClass, result.error, QStringLiteral("failed")); |
| 287 |
1/4✗ Branch 159 → 160 not taken.
✓ Branch 159 → 164 taken 1 time.
✗ Branch 160 → 161 not taken.
✗ Branch 161 → 162 not taken.
|
1 | if (m_deps.notify) m_deps.notify(tr("A message could not be sent"), result.error); |
| 288 | } | ||
| 289 |
1/1✓ Branch 164 → 165 taken 12 times.
|
12 | emit failedEntry(entry.id, errorClass, result.error); |
| 290 |
1/1✓ Branch 165 → 166 taken 12 times.
|
12 | emit changed(); |
| 291 |
1/1✓ Branch 166 → 167 taken 12 times.
|
12 | scheduleNext(); |
| 292 | 12 | } | |
| 293 |