data/MailSelectionMutation.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "MailCache.h" | ||
| 2 | #include "MailCacheSql.h" | ||
| 3 | #include "util/MessageId.h" | ||
| 4 | #include <QFile> | ||
| 5 | #include <QScopeGuard> | ||
| 6 | #include <QSet> | ||
| 7 | #include <QSqlError> | ||
| 8 | #include <QSqlQuery> | ||
| 9 | #include <QtEndian> | ||
| 10 | |||
| 11 | 86 | MailSelectionMoveResult MailCache::enqueueSelectionMove( | |
| 12 | std::shared_ptr<const MailSelectionSnapshot> selection, | ||
| 13 | const QString &targetFolder) { | ||
| 14 | 86 | MailSelectionMoveResult result; | |
| 15 |
5/9✓ Branch 2 → 3 taken 86 times.
✓ Branch 5 → 6 taken 86 times.
✗ Branch 5 → 32 not taken.
✓ Branch 8 → 9 taken 86 times.
✗ Branch 8 → 32 not taken.
✓ Branch 10 → 11 taken 86 times.
✗ Branch 10 → 32 not taken.
✓ Branch 13 → 14 taken 86 times.
✗ Branch 13 → 32 not taken.
|
258 | if (!m_db.isOpen() || !selection || !selection->storage || selection->count <= 0 || |
| 16 |
1/2✓ Branch 16 → 17 taken 86 times.
✗ Branch 16 → 32 not taken.
|
172 | selection->accountId.isEmpty() || selection->accountId.size() > 256 || |
| 17 |
3/6✓ Branch 18 → 19 taken 86 times.
✗ Branch 18 → 32 not taken.
✓ Branch 21 → 22 taken 86 times.
✗ Branch 21 → 32 not taken.
✓ Branch 24 → 25 taken 86 times.
✗ Branch 24 → 32 not taken.
|
172 | selection->folderId <= 0 || selection->folderPath.isEmpty() || |
| 18 |
2/4✓ Branch 26 → 27 taken 86 times.
✗ Branch 26 → 32 not taken.
✓ Branch 28 → 29 taken 86 times.
✗ Branch 28 → 32 not taken.
|
258 | selection->folderPath.size() > 1024 || targetFolder.isEmpty() || |
| 19 |
5/6✓ Branch 3 → 4 taken 86 times.
✗ Branch 3 → 32 not taken.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 85 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 42 taken 85 times.
|
258 | targetFolder.size() > 1024 || targetFolder == selection->folderPath) { |
| 20 | 1 | result.error = QStringLiteral("Invalid selection move request"); | |
| 21 | 1 | return result; | |
| 22 | } | ||
| 23 |
2/2✓ Branch 44 → 45 taken 1 time.
✓ Branch 44 → 52 taken 84 times.
|
85 | if (selection->count > m_journal.maxEntries()) { |
| 24 | 1 | result.outcome = MailSelectionMoveResult::Outcome::Limited; | |
| 25 | 1 | result.error = QStringLiteral("Complete selection exceeds journal capacity"); | |
| 26 | 1 | return result; | |
| 27 | } | ||
| 28 |
2/2✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 61 taken 83 times.
|
84 | if (selection->uidValidity == 0) { |
| 29 | 1 | result.outcome = MailSelectionMoveResult::Outcome::StaleSelection; | |
| 30 | 1 | result.error = QStringLiteral("Selection mailbox identity has not been verified"); | |
| 31 | 1 | return result; | |
| 32 | } | ||
| 33 |
2/2✓ Branch 62 → 63 taken 83 times.
✓ Branch 63 → 64 taken 83 times.
|
83 | QFile input(selection->path()); |
| 34 |
7/8✓ Branch 66 → 67 taken 83 times.
✓ Branch 67 → 68 taken 83 times.
✗ Branch 67 → 71 not taken.
✓ Branch 68 → 69 taken 83 times.
✓ Branch 70 → 71 taken 1 time.
✓ Branch 70 → 72 taken 82 times.
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 81 taken 82 times.
|
83 | if (!input.open(QIODevice::ReadOnly) || input.size() != selection->count * 8) { |
| 35 | 1 | result.error = QStringLiteral("Selection snapshot is unavailable or truncated"); | |
| 36 | 1 | return result; | |
| 37 | } | ||
| 38 |
1/1✓ Branch 81 → 82 taken 82 times.
|
82 | QSqlQuery begin(m_db); |
| 39 |
3/3✓ Branch 85 → 86 taken 82 times.
✓ Branch 88 → 89 taken 1 time.
✓ Branch 88 → 95 taken 81 times.
|
82 | if (!begin.exec(QStringLiteral("BEGIN IMMEDIATE"))) { |
| 40 |
2/2✓ Branch 89 → 90 taken 1 time.
✓ Branch 90 → 91 taken 1 time.
|
1 | result.error = begin.lastError().text(); |
| 41 | 1 | return result; | |
| 42 | } | ||
| 43 | 81 | bool committed = false; | |
| 44 |
2/2✓ Branch 2 → 3 taken 19 times.
✓ Branch 2 → 4 taken 62 times.
|
162 | const auto rollback = qScopeGuard([&] { if (!committed) m_db.rollback(); }); |
| 45 |
1/1✓ Branch 96 → 97 taken 81 times.
|
81 | QSqlQuery folder(m_db); |
| 46 |
1/1✓ Branch 100 → 101 taken 81 times.
|
81 | folder.prepare(QStringLiteral("SELECT uidvalidity FROM folders WHERE id=:id AND account=:account AND path=:path")); |
| 47 |
2/2✓ Branch 106 → 107 taken 81 times.
✓ Branch 107 → 108 taken 81 times.
|
81 | folder.bindValue(":id", selection->folderId); |
| 48 |
2/2✓ Branch 113 → 114 taken 81 times.
✓ Branch 114 → 115 taken 81 times.
|
81 | folder.bindValue(":account", selection->accountId); |
| 49 |
2/2✓ Branch 120 → 121 taken 81 times.
✓ Branch 121 → 122 taken 81 times.
|
81 | folder.bindValue(":path", selection->folderPath); |
| 50 |
2/5✓ Branch 124 → 125 taken 81 times.
✗ Branch 125 → 126 not taken.
✓ Branch 125 → 132 taken 81 times.
✗ Branch 126 → 127 not taken.
✗ Branch 127 → 128 not taken.
|
81 | if (!folder.exec()) { result.error = folder.lastError().text(); return result; } |
| 51 |
11/13✓ Branch 132 → 133 taken 81 times.
✓ Branch 133 → 134 taken 79 times.
✓ Branch 133 → 138 taken 2 times.
✓ Branch 134 → 135 taken 79 times.
✓ Branch 135 → 136 taken 79 times.
✓ Branch 137 → 138 taken 1 time.
✓ Branch 137 → 139 taken 78 times.
✓ Branch 140 → 141 taken 79 times.
✓ Branch 140 → 142 taken 2 times.
✓ Branch 142 → 143 taken 3 times.
✓ Branch 142 → 150 taken 78 times.
✗ Branch 480 → 481 not taken.
✗ Branch 480 → 482 not taken.
|
81 | if (!folder.next() || folder.value(0).toLongLong() != qint64(selection->uidValidity)) { |
| 52 | 3 | result.outcome = MailSelectionMoveResult::Outcome::StaleSelection; | |
| 53 | 3 | result.error = QStringLiteral("Selection mailbox identity changed"); | |
| 54 | 3 | return result; | |
| 55 | } | ||
| 56 |
1/1✓ Branch 150 → 151 taken 78 times.
|
78 | folder.finish(); |
| 57 |
1/1✓ Branch 154 → 155 taken 78 times.
|
78 | folder.prepare(QStringLiteral("SELECT id FROM folders WHERE account=:account AND path=:path")); |
| 58 |
2/2✓ Branch 160 → 161 taken 78 times.
✓ Branch 161 → 162 taken 78 times.
|
78 | folder.bindValue(":account", selection->accountId); |
| 59 |
2/2✓ Branch 166 → 167 taken 78 times.
✓ Branch 167 → 168 taken 78 times.
|
78 | folder.bindValue(":path", targetFolder); |
| 60 |
2/5✓ Branch 170 → 171 taken 78 times.
✗ Branch 171 → 172 not taken.
✓ Branch 171 → 178 taken 78 times.
✗ Branch 172 → 173 not taken.
✗ Branch 173 → 174 not taken.
|
78 | if (!folder.exec()) { result.error = folder.lastError().text(); return result; } |
| 61 |
3/3✓ Branch 178 → 179 taken 78 times.
✓ Branch 179 → 180 taken 1 time.
✓ Branch 179 → 187 taken 77 times.
|
79 | if (!folder.next()) { result.error = QStringLiteral("Move target is not a known account folder"); return result; } |
| 62 |
1/1✓ Branch 187 → 188 taken 77 times.
|
77 | folder.finish(); |
| 63 | |||
| 64 |
1/1✓ Branch 188 → 189 taken 77 times.
|
77 | QSqlQuery header(m_db); |
| 65 | // Never materialize arbitrary header/body/label data, or an oversized ID. | ||
| 66 |
1/1✓ Branch 192 → 193 taken 77 times.
|
77 | header.prepare(QStringLiteral("SELECT CASE WHEN length(message_id)<=2048 THEN message_id END, " |
| 67 | "COALESCE(length(message_id),0) FROM headers WHERE folder_id=:folder AND uid=:uid")); | ||
| 68 |
2/2✓ Branch 198 → 199 taken 77 times.
✓ Branch 199 → 200 taken 77 times.
|
77 | header.bindValue(":folder", selection->folderId); |
| 69 |
1/1✓ Branch 202 → 203 taken 77 times.
|
77 | QSqlQuery pending(m_db); |
| 70 |
1/1✓ Branch 206 → 207 taken 77 times.
|
77 | pending.prepare(QStringLiteral("SELECT 1 FROM mutation_journal WHERE account_id=:account " |
| 71 | "AND folder_id=:folder AND uid=:uid AND kind IN (:move,:undo) " | ||
| 72 | "AND phase NOT IN (:confirmed,:failed) LIMIT 1")); | ||
| 73 |
2/2✓ Branch 212 → 213 taken 77 times.
✓ Branch 213 → 214 taken 77 times.
|
77 | pending.bindValue(":account", selection->accountId); |
| 74 |
2/2✓ Branch 219 → 220 taken 77 times.
✓ Branch 220 → 221 taken 77 times.
|
77 | pending.bindValue(":folder", selection->folderId); |
| 75 |
2/2✓ Branch 225 → 226 taken 77 times.
✓ Branch 226 → 227 taken 77 times.
|
77 | pending.bindValue(":move", static_cast<int>(MutationKind::Move)); |
| 76 |
2/2✓ Branch 231 → 232 taken 77 times.
✓ Branch 232 → 233 taken 77 times.
|
77 | pending.bindValue(":undo", static_cast<int>(MutationKind::Undo)); |
| 77 |
2/2✓ Branch 237 → 238 taken 77 times.
✓ Branch 238 → 239 taken 77 times.
|
77 | pending.bindValue(":confirmed", static_cast<int>(MutationPhase::Confirmed)); |
| 78 |
2/2✓ Branch 243 → 244 taken 77 times.
✓ Branch 244 → 245 taken 77 times.
|
77 | pending.bindValue(":failed", static_cast<int>(MutationPhase::Failed)); |
| 79 | 77 | QList<MutationRecord> records; | |
| 80 |
1/1✓ Branch 248 → 249 taken 77 times.
|
77 | records.reserve(selection->count); |
| 81 | 77 | qint64 previous = -1; | |
| 82 | 77 | qint64 bytes = 0; | |
| 83 |
2/2✓ Branch 387 → 250 taken 119 times.
✓ Branch 387 → 388 taken 64 times.
|
183 | for (qint64 offset = 0; offset < selection->count;) { |
| 84 | 119 | const qint64 count = qMin<qint64>(128, selection->count - offset); | |
| 85 |
1/1✓ Branch 252 → 253 taken 119 times.
|
119 | const auto buffer = input.read(count * 8); |
| 86 |
1/2✗ Branch 254 → 255 not taken.
✓ Branch 254 → 262 taken 119 times.
|
119 | if (buffer.size() != count * 8) { result.error = QStringLiteral("Could not read complete selection"); return result; } |
| 87 |
2/2✓ Branch 379 → 263 taken 6274 times.
✓ Branch 379 → 380 taken 106 times.
|
6380 | for (int row = 0; row < count; ++row) { |
| 88 |
1/1✓ Branch 264 → 265 taken 6274 times.
|
6274 | const auto uid = qFromLittleEndian<qint64>(buffer.constData() + row * 8); |
| 89 |
2/2✓ Branch 265 → 266 taken 1 time.
✓ Branch 265 → 273 taken 6273 times.
|
6287 | if (uid <= previous) { result.error = QStringLiteral("Selection identities are invalid or unordered"); return result; } |
| 90 | 6273 | previous = uid; | |
| 91 |
2/2✓ Branch 275 → 276 taken 6273 times.
✓ Branch 276 → 277 taken 6273 times.
|
6273 | pending.bindValue(":uid", uid); |
| 92 |
2/5✓ Branch 279 → 280 taken 6273 times.
✗ Branch 280 → 281 not taken.
✓ Branch 280 → 287 taken 6273 times.
✗ Branch 281 → 282 not taken.
✗ Branch 282 → 283 not taken.
|
6273 | if (!pending.exec()) { result.error = pending.lastError().text(); return result; } |
| 93 |
3/3✓ Branch 287 → 288 taken 6273 times.
✓ Branch 288 → 289 taken 6 times.
✓ Branch 288 → 296 taken 6267 times.
|
6273 | if (pending.next()) { |
| 94 | 6 | result.outcome = MailSelectionMoveResult::Outcome::Conflict; | |
| 95 | 6 | result.error = QStringLiteral("A selected message already has an unresolved move"); | |
| 96 | 6 | return result; | |
| 97 | } | ||
| 98 |
1/1✓ Branch 296 → 297 taken 6267 times.
|
6267 | pending.finish(); |
| 99 |
2/2✓ Branch 299 → 300 taken 6267 times.
✓ Branch 300 → 301 taken 6267 times.
|
6267 | header.bindValue(":uid", uid); |
| 100 |
2/5✓ Branch 303 → 304 taken 6267 times.
✗ Branch 304 → 305 not taken.
✓ Branch 304 → 311 taken 6267 times.
✗ Branch 305 → 306 not taken.
✗ Branch 306 → 307 not taken.
|
6267 | if (!header.exec()) { result.error = header.lastError().text(); return result; } |
| 101 |
3/3✓ Branch 311 → 312 taken 6267 times.
✓ Branch 312 → 313 taken 2 times.
✓ Branch 312 → 320 taken 6265 times.
|
6267 | if (!header.next()) { |
| 102 | 2 | result.outcome = MailSelectionMoveResult::Outcome::StaleSelection; | |
| 103 | 2 | result.error = QStringLiteral("A selected message is no longer cached"); | |
| 104 | 2 | return result; | |
| 105 | } | ||
| 106 |
2/2✓ Branch 320 → 321 taken 6265 times.
✓ Branch 321 → 322 taken 6265 times.
|
6265 | const auto storedMessageId = header.value(0).toString(); |
| 107 |
9/12✓ Branch 323 → 324 taken 6265 times.
✓ Branch 324 → 325 taken 6265 times.
✓ Branch 325 → 326 taken 6264 times.
✓ Branch 325 → 328 taken 1 time.
✓ Branch 327 → 328 taken 1 time.
✓ Branch 327 → 329 taken 6263 times.
✓ Branch 330 → 331 taken 6265 times.
✗ Branch 330 → 332 not taken.
✓ Branch 332 → 333 taken 2 times.
✓ Branch 332 → 340 taken 6263 times.
✗ Branch 594 → 595 not taken.
✗ Branch 594 → 596 not taken.
|
6265 | if (header.value(1).toLongLong() > 2048 || storedMessageId.size() > 2048) { |
| 108 | 2 | result.outcome = MailSelectionMoveResult::Outcome::Limited; | |
| 109 | 2 | result.error = QStringLiteral("Selected message metadata exceeds journal limits"); | |
| 110 | 2 | return result; | |
| 111 | } | ||
| 112 |
1/1✓ Branch 340 → 341 taken 6263 times.
|
6263 | const auto messageId = MessageId::canonicalFirst(storedMessageId); |
| 113 | 6263 | bytes += 128 + 2LL * (selection->accountId.size() + selection->folderPath.size() + | |
| 114 | 6263 | targetFolder.size() + messageId.size()); | |
| 115 |
2/2✓ Branch 348 → 349 taken 2 times.
✓ Branch 348 → 356 taken 6261 times.
|
6263 | if (bytes > m_journal.maxBytes()) { |
| 116 | 2 | result.outcome = MailSelectionMoveResult::Outcome::Limited; | |
| 117 | 2 | result.error = QStringLiteral("Complete selection exceeds journal byte capacity"); | |
| 118 | 2 | return result; | |
| 119 | } | ||
| 120 | 6261 | MutationRecord record; | |
| 121 | 12522 | record.mailId = {selection->accountId, selection->folderId, uid}; | |
| 122 | 6261 | record.folderPath = selection->folderPath; | |
| 123 | 6261 | record.kind = MutationKind::Move; | |
| 124 | 6261 | record.replayClass = MutationReplayClass::AmbiguousOperation; | |
| 125 | 6261 | record.targetFolder = targetFolder; | |
| 126 | 6261 | record.uidValidity = selection->uidValidity; | |
| 127 | 6261 | record.messageId = messageId; | |
| 128 |
1/1✓ Branch 367 → 368 taken 6261 times.
|
6261 | records.append(std::move(record)); |
| 129 | 6267 | } | |
| 130 | 106 | offset += count; | |
| 131 | 119 | } | |
| 132 |
1/1✓ Branch 388 → 389 taken 64 times.
|
64 | header.finish(); |
| 133 | 64 | bool limited = false; | |
| 134 |
1/1✓ Branch 389 → 390 taken 64 times.
|
64 | const auto tokens = m_journal.enqueueMutationsInTransaction(records, &limited); |
| 135 |
2/2✓ Branch 391 → 392 taken 2 times.
✓ Branch 391 → 397 taken 62 times.
|
64 | if (!tokens) { |
| 136 |
2/2✓ Branch 392 → 393 taken 1 time.
✓ Branch 392 → 394 taken 1 time.
|
2 | result.outcome = limited ? MailSelectionMoveResult::Outcome::Limited : MailSelectionMoveResult::Outcome::Failed; |
| 137 | 2 | result.error = m_lastError; | |
| 138 | 2 | return result; | |
| 139 | } | ||
| 140 |
2/5✓ Branch 397 → 398 taken 62 times.
✗ Branch 398 → 399 not taken.
✓ Branch 398 → 405 taken 62 times.
✗ Branch 399 → 400 not taken.
✗ Branch 400 → 401 not taken.
|
62 | if (!m_db.commit()) { result.error = m_db.lastError().text(); return result; } |
| 141 | 62 | committed = true; | |
| 142 | 62 | result.selection = std::move(selection); | |
| 143 | 62 | result.targetFolder = targetFolder; | |
| 144 |
1/1✓ Branch 410 → 411 taken 62 times.
|
62 | result.receipts.reserve(tokens->size()); |
| 145 |
2/2✓ Branch 423 → 412 taken 5017 times.
✓ Branch 423 → 424 taken 62 times.
|
5079 | for (int row = 0; row < tokens->size(); ++row) |
| 146 |
1/1✓ Branch 418 → 419 taken 5017 times.
|
15051 | result.receipts.append({tokens->at(row), records[row].mailId.uid, std::move(records[row].messageId)}); |
| 147 | 62 | result.outcome = MailSelectionMoveResult::Outcome::Journaled; | |
| 148 | 62 | return result; | |
| 149 | 16378 | } | |
| 150 | |||
| 151 | 40 | MailSelectionCancelResult MailCache::cancelQueuedSelectionMove(const MailSelectionMoveResult &action) { | |
| 152 | 40 | MailSelectionCancelResult result; | |
| 153 | 40 | const auto &selection = action.selection; | |
| 154 |
2/3✓ Branch 2 → 3 taken 40 times.
✓ Branch 4 → 5 taken 40 times.
✗ Branch 4 → 17 not taken.
|
80 | if (!m_db.isOpen() || action.outcome != MailSelectionMoveResult::Outcome::Journaled || |
| 155 |
3/6✓ Branch 6 → 7 taken 40 times.
✗ Branch 6 → 17 not taken.
✓ Branch 8 → 9 taken 40 times.
✗ Branch 8 → 17 not taken.
✓ Branch 11 → 12 taken 40 times.
✗ Branch 11 → 17 not taken.
|
40 | !selection || selection->count <= 0 || selection->count > m_journal.maxEntries() || |
| 156 |
4/8✓ Branch 3 → 4 taken 40 times.
✗ Branch 3 → 17 not taken.
✓ Branch 14 → 15 taken 40 times.
✗ Branch 14 → 17 not taken.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 40 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 40 times.
|
80 | action.receipts.size() != selection->count || selection->uidValidity == 0) { |
| 157 | ✗ | result.error = QStringLiteral("Invalid complete selection move receipt"); | |
| 158 | ✗ | return result; | |
| 159 | } | ||
| 160 |
1/1✓ Branch 27 → 28 taken 40 times.
|
40 | QSqlQuery begin(m_db); |
| 161 |
2/3✓ Branch 31 → 32 taken 40 times.
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 41 taken 40 times.
|
40 | if (!begin.exec(QStringLiteral("BEGIN IMMEDIATE"))) { |
| 162 | ✗ | result.error = begin.lastError().text(); | |
| 163 | ✗ | return result; | |
| 164 | } | ||
| 165 | 40 | bool committed = false; | |
| 166 |
2/2✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 31 times.
|
80 | const auto rollback = qScopeGuard([&] { if (!committed) m_db.rollback(); }); |
| 167 | 40 | QSet<qint64> tokens; | |
| 168 | 40 | QList<qint64> removed; // announced after the commit (S106-116) | |
| 169 | 40 | qint64 previousUid = -1; | |
| 170 |
2/2✓ Branch 117 → 45 taken 3156 times.
✓ Branch 117 → 118 taken 32 times.
|
3188 | for (const auto &receipt : action.receipts) { |
| 171 |
6/8✓ Branch 46 → 47 taken 3156 times.
✗ Branch 46 → 50 not taken.
✓ Branch 48 → 49 taken 3155 times.
✓ Branch 48 → 50 taken 1 time.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 3155 times.
✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 60 taken 3155 times.
|
3156 | if (receipt.token <= 0 || tokens.contains(receipt.token) || receipt.uid <= previousUid) { |
| 172 | 1 | result.error = QStringLiteral("Invalid or duplicate selection move receipt"); | |
| 173 | 8 | return result; | |
| 174 | } | ||
| 175 |
1/1✓ Branch 60 → 61 taken 3155 times.
|
3155 | tokens.insert(receipt.token); |
| 176 | 3155 | previousUid = receipt.uid; | |
| 177 |
1/1✓ Branch 61 → 62 taken 3155 times.
|
3155 | const auto record = m_journal.mutation(receipt.token); |
| 178 |
2/2✓ Branch 65 → 66 taken 3150 times.
✓ Branch 65 → 89 taken 3 times.
|
3153 | if (!record || record->phase != MutationPhase::Queued || |
| 179 |
1/2✓ Branch 67 → 68 taken 3150 times.
✗ Branch 67 → 89 not taken.
|
3150 | record->kind != MutationKind::Move || |
| 180 |
1/2✓ Branch 69 → 70 taken 3150 times.
✗ Branch 69 → 89 not taken.
|
3150 | record->replayClass != MutationReplayClass::AmbiguousOperation || |
| 181 |
3/4✓ Branch 75 → 76 taken 3150 times.
✗ Branch 75 → 89 not taken.
✓ Branch 93 → 94 taken 6 times.
✓ Branch 93 → 101 taken 3149 times.
|
6305 | record->mailId != MailId{selection->accountId, selection->folderId, receipt.uid} || |
| 182 |
1/2✓ Branch 79 → 80 taken 3150 times.
✗ Branch 79 → 89 not taken.
|
3150 | record->folderPath != selection->folderPath || |
| 183 |
1/2✓ Branch 82 → 83 taken 3150 times.
✗ Branch 82 → 89 not taken.
|
3150 | record->uidValidity != selection->uidValidity || |
| 184 |
7/8✓ Branch 63 → 64 taken 3153 times.
✓ Branch 63 → 89 taken 2 times.
✓ Branch 85 → 86 taken 3150 times.
✗ Branch 85 → 89 not taken.
✓ Branch 88 → 89 taken 1 time.
✓ Branch 88 → 90 taken 3149 times.
✓ Branch 91 → 92 taken 3150 times.
✓ Branch 91 → 93 taken 5 times.
|
6308 | record->targetFolder != action.targetFolder || record->messageId != receipt.messageId) { |
| 185 | 6 | result.outcome = MailSelectionCancelResult::Outcome::Conflict; | |
| 186 | 6 | result.error = QStringLiteral("The complete action is no longer queued unchanged"); | |
| 187 | 6 | return result; | |
| 188 | } | ||
| 189 | // BEGIN IMMEDIATE excludes dispatch claims until the complete action is | ||
| 190 | // removed or rolled back. No prefix can escape on a late conflict/failure. | ||
| 191 |
3/3✓ Branch 101 → 102 taken 3149 times.
✓ Branch 102 → 103 taken 1 time.
✓ Branch 102 → 110 taken 3148 times.
|
3149 | if (!m_journal.removeMutation(receipt.token, &removed)) { |
| 192 | 1 | result.error = QStringLiteral("Could not remove queued selection action"); | |
| 193 | 1 | return result; | |
| 194 | } | ||
| 195 | 3155 | } | |
| 196 |
5/5✓ Branch 118 → 119 taken 32 times.
✓ Branch 119 → 120 taken 1 time.
✓ Branch 119 → 126 taken 31 times.
✓ Branch 120 → 121 taken 1 time.
✓ Branch 121 → 122 taken 1 time.
|
32 | if (!m_db.commit()) { result.error = m_db.lastError().text(); return result; } |
| 197 | 31 | committed = true; | |
| 198 |
5/5✓ Branch 126 → 127 taken 31 times.
✓ Branch 127 → 128 taken 31 times.
✓ Branch 130 → 131 taken 2839 times.
✓ Branch 133 → 129 taken 2839 times.
✓ Branch 133 → 134 taken 31 times.
|
2870 | for (const qint64 token : removed) m_journal.announceRemoved(token); |
| 199 | 31 | result.outcome = MailSelectionCancelResult::Outcome::Cancelled; | |
| 200 | 31 | return result; | |
| 201 | 40 | } | |
| 202 | |||
| 203 | namespace { | ||
| 204 | // The selection's UIDs in snapshot order (ascending, checked). | ||
| 205 | 17 | std::optional<QList<qint64>> readSelectionUids(const MailSelectionSnapshot &selection, QString *error) { | |
| 206 |
2/2✓ Branch 2 → 3 taken 17 times.
✓ Branch 3 → 4 taken 17 times.
|
17 | QFile input(selection.path()); |
| 207 |
5/8✓ Branch 6 → 7 taken 17 times.
✓ Branch 7 → 8 taken 17 times.
✗ Branch 7 → 10 not taken.
✓ Branch 8 → 9 taken 17 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 17 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 20 taken 17 times.
|
17 | if (!input.open(QIODevice::ReadOnly) || input.size() != selection.count * 8) { |
| 208 | ✗ | *error = QStringLiteral("Selection snapshot is unavailable or truncated"); | |
| 209 | ✗ | return std::nullopt; | |
| 210 | } | ||
| 211 |
1/1✓ Branch 20 → 21 taken 17 times.
|
17 | const QByteArray bytes = input.readAll(); |
| 212 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 30 taken 17 times.
|
17 | if (bytes.size() != selection.count * 8) { |
| 213 | ✗ | *error = QStringLiteral("Could not read complete selection"); | |
| 214 | ✗ | return std::nullopt; | |
| 215 | } | ||
| 216 | 17 | QList<qint64> uids; | |
| 217 |
1/1✓ Branch 30 → 31 taken 17 times.
|
17 | uids.reserve(selection.count); |
| 218 |
2/2✓ Branch 50 → 32 taken 55 times.
✓ Branch 50 → 51 taken 17 times.
|
72 | for (qint64 row = 0; row < selection.count; ++row) { |
| 219 |
1/1✓ Branch 33 → 34 taken 55 times.
|
55 | const auto uid = qFromLittleEndian<qint64>(bytes.constData() + row * 8); |
| 220 |
5/7✓ Branch 35 → 36 taken 38 times.
✓ Branch 35 → 39 taken 17 times.
✓ Branch 36 → 37 taken 38 times.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 38 times.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 48 taken 55 times.
|
55 | if (!uids.isEmpty() && uid <= uids.last()) { |
| 221 | ✗ | *error = QStringLiteral("Selection identities are invalid or unordered"); | |
| 222 | ✗ | return std::nullopt; | |
| 223 | } | ||
| 224 |
1/1✓ Branch 48 → 49 taken 55 times.
|
55 | uids.append(uid); |
| 225 | } | ||
| 226 | 17 | return uids; | |
| 227 | 17 | } | |
| 228 | |||
| 229 | 34 | bool validStateRequest(const MailSelectionStateRequest &request) { | |
| 230 | 34 | const bool keyword = request.kind == MutationKind::Keyword; | |
| 231 |
3/8✗ Branch 7 → 8 not taken.
✓ Branch 7 → 23 taken 16 times.
✓ Branch 31 → 32 taken 16 times.
✓ Branch 31 → 33 taken 18 times.
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 66 not taken.
✗ Branch 68 → 69 not taken.
✗ Branch 68 → 70 not taken.
|
50 | const bool flagOk = (request.kind == MutationKind::Seen && request.flag == QStringLiteral("\\Seen")) || |
| 232 |
12/16✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 8 taken 18 times.
✓ Branch 8 → 9 taken 14 times.
✓ Branch 8 → 14 taken 4 times.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 23 taken 13 times.
✓ Branch 14 → 15 taken 4 times.
✓ Branch 14 → 24 taken 1 time.
✓ Branch 27 → 28 taken 14 times.
✓ Branch 27 → 29 taken 20 times.
✓ Branch 29 → 30 taken 16 times.
✓ Branch 29 → 31 taken 18 times.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
|
102 | (request.kind == MutationKind::Flagged && request.flag == QStringLiteral("\\Flagged")) || |
| 233 |
2/4✓ Branch 16 → 17 taken 4 times.
✗ Branch 16 → 24 not taken.
✓ Branch 18 → 19 taken 4 times.
✗ Branch 18 → 24 not taken.
|
4 | (keyword && !request.flag.isEmpty() && request.flag.size() <= 256 && |
| 234 |
4/5✓ Branch 21 → 22 taken 4 times.
✓ Branch 22 → 23 taken 4 times.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 14 times.
✓ Branch 25 → 27 taken 20 times.
|
38 | !request.flag.startsWith(QLatin1Char('\\'))); |
| 235 |
3/6✓ Branch 35 → 36 taken 33 times.
✗ Branch 35 → 51 not taken.
✓ Branch 37 → 38 taken 33 times.
✗ Branch 37 → 51 not taken.
✓ Branch 38 → 39 taken 33 times.
✗ Branch 38 → 51 not taken.
|
33 | return flagOk && !request.accountId.isEmpty() && request.accountId.size() <= 256 && request.folderId > 0 && |
| 236 |
7/10✓ Branch 33 → 34 taken 33 times.
✓ Branch 33 → 51 taken 1 time.
✓ Branch 40 → 41 taken 33 times.
✗ Branch 40 → 51 not taken.
✓ Branch 42 → 43 taken 33 times.
✗ Branch 42 → 51 not taken.
✓ Branch 43 → 44 taken 33 times.
✗ Branch 43 → 51 not taken.
✓ Branch 45 → 46 taken 20 times.
✓ Branch 45 → 48 taken 13 times.
|
133 | !request.folderPath.isEmpty() && request.folderPath.size() <= 1024 && request.uidValidity != 0 && |
| 237 |
2/4✓ Branch 47 → 50 taken 20 times.
✗ Branch 47 → 51 not taken.
✓ Branch 49 → 50 taken 13 times.
✗ Branch 49 → 51 not taken.
|
100 | (request.selection ? request.selection->count > 0 : !request.uids.isEmpty()); |
| 238 | } | ||
| 239 | } // namespace | ||
| 240 | |||
| 241 | 34 | MailSelectionStateResult MailCache::enqueueSelectionState(MailSelectionStateRequest request) { | |
| 242 | 34 | MailSelectionStateResult result; | |
| 243 |
8/10✓ Branch 2 → 3 taken 34 times.
✓ Branch 3 → 4 taken 34 times.
✗ Branch 3 → 8 not taken.
✓ Branch 5 → 6 taken 34 times.
✗ Branch 5 → 8 not taken.
✓ Branch 6 → 7 taken 34 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 33 times.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 18 taken 33 times.
|
34 | if (!m_db.isOpen() || !m_writeMutex || !validStateRequest(request)) { |
| 244 | 1 | result.error = QStringLiteral("Invalid selection state request"); | |
| 245 | 1 | return result; | |
| 246 | } | ||
| 247 | 33 | QList<qint64> uids = request.uids; | |
| 248 |
2/2✓ Branch 20 → 21 taken 20 times.
✓ Branch 20 → 51 taken 13 times.
|
33 | if (request.selection) { |
| 249 | // F-67 (SPRINT-104): the snapshot's mailbox identity binds the action — | ||
| 250 | // a request constructed against the CURRENT epoch must not rebase a | ||
| 251 | // selection captured under an older one onto the new UID space (the | ||
| 252 | // move path validates the same way). | ||
| 253 | 20 | const MailSelectionSnapshot &snapshot = *request.selection; | |
| 254 | 20 | if (snapshot.accountId != request.accountId || | |
| 255 |
2/2✓ Branch 24 → 25 taken 19 times.
✓ Branch 24 → 28 taken 1 time.
|
20 | snapshot.folderId != request.folderId || |
| 256 |
4/6✓ Branch 23 → 24 taken 20 times.
✗ Branch 23 → 28 not taken.
✓ Branch 26 → 27 taken 19 times.
✗ Branch 26 → 28 not taken.
✓ Branch 30 → 31 taken 3 times.
✓ Branch 30 → 38 taken 17 times.
|
59 | snapshot.folderPath != request.folderPath || |
| 257 |
2/2✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 29 taken 17 times.
|
19 | snapshot.uidValidity != request.uidValidity) { |
| 258 | 3 | result.outcome = MailSelectionStateResult::Outcome::StaleSelection; | |
| 259 | 3 | result.error = QStringLiteral("Selection mailbox identity changed"); | |
| 260 | 3 | return result; | |
| 261 | } | ||
| 262 |
1/1✓ Branch 39 → 40 taken 17 times.
|
17 | const auto read = readSelectionUids(*request.selection, &result.error); |
| 263 |
1/2✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 17 times.
|
17 | if (!read) return result; |
| 264 | 17 | uids = *read; | |
| 265 | 17 | } | |
| 266 |
2/2✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 61 taken 29 times.
|
30 | if (uids.size() > m_journal.maxEntries()) { |
| 267 | 1 | result.outcome = MailSelectionStateResult::Outcome::Limited; | |
| 268 | 1 | result.error = QStringLiteral("Complete selection exceeds journal capacity"); | |
| 269 | 1 | return result; | |
| 270 | } | ||
| 271 | 29 | const auto writeMutex = m_writeMutex; | |
| 272 | 29 | QMutexLocker publication(writeMutex.get()); | |
| 273 |
1/1✓ Branch 64 → 65 taken 29 times.
|
29 | MailCacheSql::ScopedWriteUnit unit(m_db, &result.error); |
| 274 |
1/2✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 29 times.
|
29 | if (!unit.started()) return result; |
| 275 |
1/1✓ Branch 68 → 69 taken 29 times.
|
29 | QSqlQuery folder(m_db); |
| 276 |
1/1✓ Branch 72 → 73 taken 29 times.
|
29 | folder.prepare(QStringLiteral("SELECT 1 FROM folders WHERE id=:id AND account=:account AND path=:path " |
| 277 | "AND uidvalidity=:validity")); | ||
| 278 |
2/2✓ Branch 77 → 78 taken 29 times.
✓ Branch 78 → 79 taken 29 times.
|
29 | folder.bindValue(":id", request.folderId); |
| 279 |
2/2✓ Branch 83 → 84 taken 29 times.
✓ Branch 84 → 85 taken 29 times.
|
29 | folder.bindValue(":account", request.accountId); |
| 280 |
2/2✓ Branch 89 → 90 taken 29 times.
✓ Branch 90 → 91 taken 29 times.
|
29 | folder.bindValue(":path", request.folderPath); |
| 281 |
2/2✓ Branch 95 → 96 taken 29 times.
✓ Branch 96 → 97 taken 29 times.
|
29 | folder.bindValue(":validity", request.uidValidity); |
| 282 |
2/5✓ Branch 99 → 100 taken 29 times.
✗ Branch 100 → 101 not taken.
✓ Branch 100 → 107 taken 29 times.
✗ Branch 101 → 102 not taken.
✗ Branch 102 → 103 not taken.
|
29 | if (!folder.exec()) { result.error = folder.lastError().text(); return result; } |
| 283 |
2/3✓ Branch 107 → 108 taken 29 times.
✗ Branch 108 → 109 not taken.
✓ Branch 108 → 116 taken 29 times.
|
29 | if (!folder.next()) { |
| 284 | ✗ | result.outcome = MailSelectionStateResult::Outcome::StaleSelection; | |
| 285 | ✗ | result.error = QStringLiteral("Selection mailbox identity changed"); | |
| 286 | ✗ | return result; | |
| 287 | } | ||
| 288 |
1/1✓ Branch 116 → 117 taken 29 times.
|
29 | folder.finish(); |
| 289 |
1/1✓ Branch 117 → 118 taken 29 times.
|
29 | QSqlQuery header(m_db); |
| 290 |
1/1✓ Branch 121 → 122 taken 29 times.
|
29 | header.prepare(QStringLiteral("SELECT id, flags, CASE WHEN length(message_id)<=2048 THEN message_id END " |
| 291 | "FROM headers WHERE folder_id=:folder AND uid=:uid")); | ||
| 292 |
2/2✓ Branch 126 → 127 taken 29 times.
✓ Branch 127 → 128 taken 29 times.
|
29 | header.bindValue(":folder", request.folderId); |
| 293 |
1/1✓ Branch 130 → 131 taken 29 times.
|
29 | QSqlQuery label(m_db); |
| 294 |
1/1✓ Branch 134 → 135 taken 29 times.
|
29 | label.prepare(QStringLiteral("SELECT 1 FROM mail_labels WHERE header_id=:hid AND label=:label")); |
| 295 |
2/2✓ Branch 139 → 140 taken 29 times.
✓ Branch 140 → 141 taken 29 times.
|
29 | label.bindValue(":label", request.flag); |
| 296 | 29 | const bool keyword = request.kind == MutationKind::Keyword; | |
| 297 | 29 | const bool seen = request.kind == MutationKind::Seen; | |
| 298 |
2/2✓ Branch 143 → 144 taken 14 times.
✓ Branch 143 → 145 taken 15 times.
|
29 | const quint32 bit = seen ? MailFlag::Seen : MailFlag::Flagged; |
| 299 | struct Pending { qint64 uid; qint64 headerId; quint32 flags; }; | ||
| 300 | 29 | QList<Pending> pending; | |
| 301 | 29 | QList<MutationRecord> records; | |
| 302 | 29 | QList<MailSelectionStateChange> changes; // published only after the commit | |
| 303 | 29 | qint64 bytes = 0; | |
| 304 |
4/4✓ Branch 146 → 147 taken 29 times.
✓ Branch 147 → 148 taken 29 times.
✓ Branch 238 → 149 taken 371 times.
✓ Branch 238 → 239 taken 28 times.
|
399 | for (const qint64 uid : uids) { |
| 305 |
2/2✓ Branch 152 → 153 taken 371 times.
✓ Branch 153 → 154 taken 371 times.
|
371 | header.bindValue(":uid", uid); |
| 306 |
2/5✓ Branch 156 → 157 taken 371 times.
✗ Branch 157 → 158 not taken.
✓ Branch 157 → 164 taken 371 times.
✗ Branch 158 → 159 not taken.
✗ Branch 159 → 160 not taken.
|
372 | if (!header.exec()) { result.error = header.lastError().text(); return result; } |
| 307 |
3/3✓ Branch 164 → 165 taken 371 times.
✓ Branch 165 → 166 taken 1 time.
✓ Branch 165 → 173 taken 370 times.
|
371 | if (!header.next()) { |
| 308 | // S106-118: one desired state for every message of the selection — | ||
| 309 | // like the move path, a selected message that left the cache | ||
| 310 | // refuses the whole action instead of skipping it silently. | ||
| 311 | 1 | result.outcome = MailSelectionStateResult::Outcome::StaleSelection; | |
| 312 | 1 | result.error = QStringLiteral("A selected message is no longer cached"); | |
| 313 | 1 | return result; | |
| 314 | } | ||
| 315 |
2/2✓ Branch 173 → 174 taken 370 times.
✓ Branch 174 → 175 taken 370 times.
|
370 | const qint64 headerId = header.value(0).toLongLong(); |
| 316 |
2/2✓ Branch 176 → 177 taken 370 times.
✓ Branch 177 → 178 taken 370 times.
|
370 | const quint32 flags = header.value(1).toUInt(); |
| 317 |
2/2✓ Branch 179 → 180 taken 370 times.
✓ Branch 180 → 181 taken 370 times.
|
370 | const QString messageId = header.value(2).toString(); |
| 318 |
1/1✓ Branch 182 → 183 taken 370 times.
|
370 | header.finish(); |
| 319 | 370 | bool current = false; | |
| 320 |
2/2✓ Branch 183 → 184 taken 9 times.
✓ Branch 183 → 200 taken 361 times.
|
370 | if (keyword) { |
| 321 |
2/2✓ Branch 186 → 187 taken 9 times.
✓ Branch 187 → 188 taken 9 times.
|
9 | label.bindValue(":hid", headerId); |
| 322 |
2/5✓ Branch 190 → 191 taken 9 times.
✗ Branch 191 → 192 not taken.
✓ Branch 191 → 198 taken 9 times.
✗ Branch 192 → 193 not taken.
✗ Branch 193 → 194 not taken.
|
9 | if (!label.exec()) { result.error = label.lastError().text(); return result; } |
| 323 |
1/1✓ Branch 198 → 199 taken 9 times.
|
9 | current = label.next(); |
| 324 |
1/1✓ Branch 199 → 201 taken 9 times.
|
9 | label.finish(); |
| 325 | } else { | ||
| 326 | 361 | current = (flags & bit) != 0; | |
| 327 | } | ||
| 328 |
2/2✓ Branch 201 → 202 taken 67 times.
✓ Branch 201 → 203 taken 303 times.
|
370 | if (current == request.desiredState) continue; |
| 329 | 303 | bytes += 128 + 2LL * (request.accountId.size() + request.folderPath.size() + request.flag.size() + messageId.size()); | |
| 330 |
1/2✗ Branch 208 → 209 not taken.
✓ Branch 208 → 216 taken 303 times.
|
303 | if (bytes > m_journal.maxBytes()) { |
| 331 | ✗ | result.outcome = MailSelectionStateResult::Outcome::Limited; | |
| 332 | ✗ | result.error = QStringLiteral("Complete selection exceeds journal byte capacity"); | |
| 333 | ✗ | return result; | |
| 334 | } | ||
| 335 | 303 | MutationRecord record; | |
| 336 | 303 | record.mailId = {request.accountId, request.folderId, uid}; | |
| 337 | 303 | record.folderPath = request.folderPath; | |
| 338 | 303 | record.kind = request.kind; | |
| 339 | 303 | record.replayClass = MutationReplayClass::DesiredState; | |
| 340 | 303 | record.phase = MutationPhase::Queued; | |
| 341 | 303 | record.flag = request.flag; | |
| 342 | 303 | record.desiredState = request.desiredState; | |
| 343 | 303 | record.messageId = messageId; | |
| 344 | 303 | record.uidValidity = request.uidValidity; | |
| 345 |
1/1✓ Branch 223 → 224 taken 303 times.
|
303 | records.append(std::move(record)); |
| 346 |
3/3✓ Branch 224 → 225 taken 295 times.
✓ Branch 224 → 226 taken 8 times.
✓ Branch 227 → 228 taken 303 times.
|
303 | pending.append({uid, headerId, request.desiredState ? (flags | bit) : (flags & ~bit)}); |
| 347 | 370 | } | |
| 348 |
2/2✓ Branch 240 → 241 taken 27 times.
✓ Branch 240 → 354 taken 1 time.
|
28 | if (!records.isEmpty()) { |
| 349 | 27 | bool limited = false; | |
| 350 |
1/1✓ Branch 241 → 242 taken 27 times.
|
27 | const auto tokens = m_journal.enqueueMutationsInTransaction(records, &limited); |
| 351 |
1/2✗ Branch 243 → 244 not taken.
✓ Branch 243 → 249 taken 27 times.
|
27 | if (!tokens) { |
| 352 | ✗ | result.outcome = limited ? MailSelectionStateResult::Outcome::Limited : MailSelectionStateResult::Outcome::Failed; | |
| 353 | ✗ | result.error = m_lastError; | |
| 354 | ✗ | return result; | |
| 355 | } | ||
| 356 |
1/1✓ Branch 249 → 250 taken 27 times.
|
27 | QSqlQuery write(m_db); |
| 357 |
3/3✓ Branch 250 → 251 taken 3 times.
✓ Branch 250 → 258 taken 24 times.
✓ Branch 261 → 262 taken 27 times.
|
54 | write.prepare(keyword ? (request.desiredState |
| 358 |
2/4✓ Branch 251 → 252 taken 2 times.
✓ Branch 251 → 255 taken 1 time.
✗ Branch 487 → 488 not taken.
✗ Branch 487 → 489 not taken.
|
5 | ? QStringLiteral("INSERT OR IGNORE INTO mail_labels (header_id, label) VALUES (:hid, :label)") |
| 359 |
2/4✓ Branch 267 → 268 taken 2 times.
✓ Branch 267 → 269 taken 25 times.
✗ Branch 483 → 484 not taken.
✗ Branch 483 → 485 not taken.
|
27 | : QStringLiteral("DELETE FROM mail_labels WHERE header_id = :hid AND label = :label")) |
| 360 |
4/6✓ Branch 263 → 264 taken 24 times.
✓ Branch 263 → 265 taken 3 times.
✓ Branch 265 → 266 taken 1 time.
✓ Branch 265 → 267 taken 26 times.
✗ Branch 479 → 480 not taken.
✗ Branch 479 → 481 not taken.
|
27 | : QStringLiteral("UPDATE headers SET flags = :flags WHERE id = :hid")); |
| 361 | // F-68 (SPRINT-104): a bulk Seen flip maintains the published ancestors' | ||
| 362 | // unread_descendants inside the same transaction — the flags-only fast | ||
| 363 | // path advances the thread revision without a structural rebuild, so the | ||
| 364 | // cache writer must keep the aggregate (as updateFlags does). A stale | ||
| 365 | // aggregate survived a reopen otherwise. | ||
| 366 | 27 | QList<QPair<qint64, int>> unreadDeltas; | |
| 367 |
2/2✓ Branch 330 → 270 taken 301 times.
✓ Branch 330 → 331 taken 25 times.
|
326 | for (int row = 0; row < pending.size(); ++row) { |
| 368 |
2/2✓ Branch 271 → 272 taken 301 times.
✓ Branch 276 → 277 taken 301 times.
|
602 | write.bindValue(QStringLiteral(":hid"), pending[row].headerId); |
| 369 |
3/3✓ Branch 280 → 281 taken 7 times.
✓ Branch 280 → 291 taken 294 times.
✓ Branch 286 → 287 taken 7 times.
|
315 | if (keyword) write.bindValue(QStringLiteral(":label"), request.flag); |
| 370 |
2/2✓ Branch 292 → 293 taken 294 times.
✓ Branch 297 → 298 taken 294 times.
|
588 | else write.bindValue(QStringLiteral(":flags"), pending[row].flags); |
| 371 |
5/5✓ Branch 302 → 303 taken 301 times.
✓ Branch 303 → 304 taken 2 times.
✓ Branch 303 → 310 taken 299 times.
✓ Branch 304 → 305 taken 2 times.
✓ Branch 305 → 306 taken 2 times.
|
301 | if (!write.exec()) { result.error = write.lastError().text(); return result; } |
| 372 |
3/3✓ Branch 310 → 311 taken 299 times.
✓ Branch 313 → 314 taken 299 times.
✓ Branch 314 → 315 taken 299 times.
|
299 | changes.append({pending[row].uid, tokens->at(row), pending[row].flags}); |
| 373 |
6/7✓ Branch 315 → 316 taken 25 times.
✓ Branch 315 → 319 taken 274 times.
✓ Branch 316 → 317 taken 25 times.
✓ Branch 317 → 318 taken 25 times.
✗ Branch 317 → 319 not taken.
✓ Branch 320 → 321 taken 25 times.
✓ Branch 320 → 328 taken 274 times.
|
299 | if (seen && pending[row].uid > 0) |
| 374 |
4/4✓ Branch 321 → 322 taken 25 times.
✓ Branch 322 → 323 taken 20 times.
✓ Branch 322 → 324 taken 5 times.
✓ Branch 326 → 327 taken 25 times.
|
25 | unreadDeltas.append({pending[row].uid, request.desiredState ? -1 : 1}); |
| 375 | } | ||
| 376 |
7/7✓ Branch 332 → 333 taken 11 times.
✓ Branch 332 → 336 taken 14 times.
✓ Branch 333 → 334 taken 11 times.
✓ Branch 334 → 335 taken 1 time.
✓ Branch 334 → 336 taken 10 times.
✓ Branch 337 → 338 taken 1 time.
✓ Branch 337 → 340 taken 24 times.
|
25 | if (!unreadDeltas.isEmpty() && !adjustThreadUnreadAggregates(request.folderId, unreadDeltas)) { |
| 377 | 1 | result.error = m_lastError; | |
| 378 | 1 | return result; | |
| 379 | } | ||
| 380 | 33 | } | |
| 381 |
2/3✓ Branch 354 → 355 taken 25 times.
✗ Branch 355 → 356 not taken.
✓ Branch 355 → 357 taken 25 times.
|
25 | if (!unit.commit(&result.error)) |
| 382 | ✗ | return result; | |
| 383 | // S106-117: the changes are reported only once they are committed. | ||
| 384 | 25 | result.changes = std::move(changes); | |
| 385 | 25 | result.request = std::move(request); | |
| 386 | 25 | result.outcome = MailSelectionStateResult::Outcome::Journaled; | |
| 387 | 25 | return result; | |
| 388 | 336 | } | |
| 389 |