summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/maildirresource/maildirresource.cpp25
-rw-r--r--tests/maildirresourcetest.cpp27
2 files changed, 45 insertions, 7 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index 5a38b01..d0b663b 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -277,8 +277,27 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti
277 Akonadi2::Storage store(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); 277 Akonadi2::Storage store(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite);
278 auto synchronizationTransaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 278 auto synchronizationTransaction = store.createTransaction(Akonadi2::Storage::ReadWrite);
279 279
280 scanForRemovals(transaction, synchronizationTransaction, bufferType, [&listingPath](const QByteArray &remoteId) -> bool { 280 const auto folderLocalId = resolveRemoteId(ENTITY_TYPE_FOLDER, path, synchronizationTransaction);
281 return QFile(listingPath + QDir::separator() + remoteId).exists(); 281
282 auto exists = [&listingPath](const QByteArray &remoteId) -> bool {
283 return QFile(listingPath + "/" + remoteId).exists();
284 };
285
286 auto property = "folder";
287 Index index(bufferType + ".index." + property, transaction);
288 index.lookup(folderLocalId.toLatin1(), [&](const QByteArray &akonadiId) {
289 const auto remoteId = resolveLocalId(bufferType, akonadiId, synchronizationTransaction);
290 if (!remoteId.isEmpty()) {
291 if (!exists(remoteId.toLatin1())) {
292 Trace() << "Found a removed entity: " << akonadiId;
293 deleteEntity(akonadiId, Akonadi2::Storage::maxRevision(transaction), bufferType, [this](const QByteArray &buffer) {
294 enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::DeleteEntityCommand, buffer);
295 });
296 }
297 }
298 },
299 [property](const Index::Error &error) {
300 Warning() << "Error in index: " << error.message << property;
282 }); 301 });
283 302
284 while (entryIterator->hasNext()) { 303 while (entryIterator->hasNext()) {
@@ -300,7 +319,7 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti
300 mail.setProperty("sender", msg->from(true)->asUnicodeString()); 319 mail.setProperty("sender", msg->from(true)->asUnicodeString());
301 mail.setProperty("senderName", msg->from(true)->asUnicodeString()); 320 mail.setProperty("senderName", msg->from(true)->asUnicodeString());
302 mail.setProperty("date", msg->date(true)->dateTime()); 321 mail.setProperty("date", msg->date(true)->dateTime());
303 mail.setProperty("folder", resolveRemoteId(ENTITY_TYPE_FOLDER, path, synchronizationTransaction)); 322 mail.setProperty("folder", folderLocalId);
304 mail.setProperty("mimeMessage", filepath); 323 mail.setProperty("mimeMessage", filepath);
305 mail.setProperty("unread", !flags.testFlag(KPIM::Maildir::Seen)); 324 mail.setProperty("unread", !flags.testFlag(KPIM::Maildir::Seen));
306 mail.setProperty("important", flags.testFlag(KPIM::Maildir::Flagged)); 325 mail.setProperty("important", flags.testFlag(KPIM::Maildir::Flagged));
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index b16f883..51ea278 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -142,7 +142,7 @@ private Q_SLOTS:
142 142
143 Akonadi2::Query query; 143 Akonadi2::Query query;
144 query.resources << "org.kde.maildir.instance1"; 144 query.resources << "org.kde.maildir.instance1";
145 query.requestedProperties << "folder" << "summary"; 145 query.requestedProperties << "folder" << "subject";
146 query.propertyFilter.insert("folder", folderIdentifier); 146 query.propertyFilter.insert("folder", folderIdentifier);
147 auto mailModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); 147 auto mailModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
148 QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); 148 QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
@@ -194,18 +194,37 @@ private Q_SLOTS:
194 QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1); 194 QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1);
195 } 195 }
196 196
197 void testSyncMailMove() 197 void testReSyncMail()
198 { 198 {
199 Akonadi2::Query query; 199 Akonadi2::Query query;
200 query.resources << "org.kde.maildir.instance1"; 200 query.resources << "org.kde.maildir.instance1";
201 query.syncOnDemand = true; 201 query.syncOnDemand = true;
202 query.processAll = true; 202 query.processAll = true;
203 query.requestedProperties << "folder" << "summary"; 203 query.requestedProperties << "folder" << "subject";
204 204
205 //Ensure all local data is processed 205 //Ensure all local data is processed
206 Akonadi2::Store::synchronize(query).exec().waitForFinished(); 206 Akonadi2::Store::synchronize(query).exec().waitForFinished();
207 207
208 auto targetPath = tempDir.path() + QDir::separator() + "maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; 208 //Ensure all local data is processed
209 Akonadi2::Store::synchronize(query).exec().waitForFinished();
210
211 auto mailModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
212 QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
213 QCOMPARE(mailModel->rowCount(QModelIndex()), 2);
214 }
215
216 void testSyncMailRemoval()
217 {
218 Akonadi2::Query query;
219 query.resources << "org.kde.maildir.instance1";
220 query.syncOnDemand = true;
221 query.processAll = true;
222 query.requestedProperties << "folder" << "subject";
223
224 //Ensure all local data is processed
225 Akonadi2::Store::synchronize(query).exec().waitForFinished();
226
227 auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S";
209 QFile file(targetPath); 228 QFile file(targetPath);
210 QVERIFY(file.remove()); 229 QVERIFY(file.remove());
211 230