diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-29 22:00:01 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-29 22:00:01 +0100 |
commit | 312702b809907866c085b92b1127129aaaf7f693 (patch) | |
tree | 8ee1294324938401f52730a57c4ec33a774d7cbb | |
parent | 8355323c285584940d81157f2596855f99996977 (diff) | |
download | sink-312702b809907866c085b92b1127129aaaf7f693.tar.gz sink-312702b809907866c085b92b1127129aaaf7f693.zip |
Stub for mail change-replay.
Not usable yet.
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 43 | ||||
-rw-r--r-- | tests/maildirresourcetest.cpp | 24 |
2 files changed, 66 insertions, 1 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 7fcf12e..c3b3047 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -98,7 +98,7 @@ QString MaildirResource::resolveLocalId(const QByteArray &bufferType, const QByt | |||
98 | Index index("localid.mapping." + bufferType, transaction); | 98 | Index index("localid.mapping." + bufferType, transaction); |
99 | QByteArray remoteId = index.lookup(localId); | 99 | QByteArray remoteId = index.lookup(localId); |
100 | if (remoteId.isEmpty()) { | 100 | if (remoteId.isEmpty()) { |
101 | Warning() << "Couldn't find the local id"; | 101 | Warning() << "Couldn't find the remote id for " << localId; |
102 | } | 102 | } |
103 | return remoteId; | 103 | return remoteId; |
104 | } | 104 | } |
@@ -405,6 +405,47 @@ KAsync::Job<void> MaildirResource::replay(const QByteArray &type, const QByteArr | |||
405 | } else { | 405 | } else { |
406 | Warning() << "Unkown operation" << operation; | 406 | Warning() << "Unkown operation" << operation; |
407 | } | 407 | } |
408 | } else if (type == ENTITY_TYPE_MAIL) { | ||
409 | Akonadi2::EntityBuffer buffer(value.data(), value.size()); | ||
410 | const Akonadi2::Entity &entity = buffer.entity(); | ||
411 | const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata()); | ||
412 | if (metadataBuffer && !metadataBuffer->replayToSource()) { | ||
413 | Trace() << "Change is coming from the source"; | ||
414 | return KAsync::null<void>(); | ||
415 | } | ||
416 | const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; | ||
417 | const auto operation = metadataBuffer ? metadataBuffer->operation() : Akonadi2::Operation_Creation; | ||
418 | if (operation == Akonadi2::Operation_Creation) { | ||
419 | const Akonadi2::ApplicationDomain::Mail mail(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mMailAdaptorFactory->createAdaptor(entity)); | ||
420 | auto parentFolder = mail.getProperty("folder").toByteArray(); | ||
421 | QByteArray parentFolderRemoteId; | ||
422 | if (!parentFolder.isEmpty()) { | ||
423 | parentFolderRemoteId = resolveLocalId(ENTITY_TYPE_FOLDER, parentFolder, synchronizationTransaction).toLatin1(); | ||
424 | } else { | ||
425 | parentFolderRemoteId = mMaildirPath.toLatin1(); | ||
426 | } | ||
427 | const auto parentFolderPath = parentFolderRemoteId; | ||
428 | KPIM::Maildir maildir(parentFolderPath, false); | ||
429 | //FIXME assemble the MIME message | ||
430 | const auto id = maildir.addEntry("foobar"); | ||
431 | Trace() << "Creating a new mail: " << id; | ||
432 | recordRemoteId(ENTITY_TYPE_MAIL, mail.identifier(), id.toUtf8(), synchronizationTransaction); | ||
433 | } else if (operation == Akonadi2::Operation_Removal) { | ||
434 | const auto uid = Akonadi2::Storage::uidFromKey(key); | ||
435 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction); | ||
436 | const Akonadi2::ApplicationDomain::Mail mail(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mMailAdaptorFactory->createAdaptor(entity)); | ||
437 | auto parentFolder = mail.getProperty("folder").toByteArray(); | ||
438 | const auto parentFolderRemoteId = resolveLocalId(ENTITY_TYPE_FOLDER, parentFolder, synchronizationTransaction); | ||
439 | const auto parentFolderPath = parentFolderRemoteId; | ||
440 | KPIM::Maildir maildir(parentFolderPath, false); | ||
441 | Trace() << "Removing a mail: " << remoteId; | ||
442 | maildir.removeEntry(remoteId); | ||
443 | removeRemoteId(ENTITY_TYPE_MAIL, uid, remoteId.toUtf8(), synchronizationTransaction); | ||
444 | } else if (operation == Akonadi2::Operation_Modification) { | ||
445 | Warning() << "Mail modifications are not implemented"; | ||
446 | } else { | ||
447 | Warning() << "Unkown operation" << operation; | ||
448 | } | ||
408 | } | 449 | } |
409 | return KAsync::null<void>(); | 450 | return KAsync::null<void>(); |
410 | } | 451 | } |
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 1e2d36b..b0bc30b 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp | |||
@@ -287,6 +287,30 @@ private Q_SLOTS: | |||
287 | QTRY_VERIFY(!QFileInfo(targetPath).exists()); | 287 | QTRY_VERIFY(!QFileInfo(targetPath).exists()); |
288 | } | 288 | } |
289 | 289 | ||
290 | void testCreateMail() | ||
291 | { | ||
292 | Akonadi2::Query query; | ||
293 | query.resources << "org.kde.maildir.instance1"; | ||
294 | query.syncOnDemand = false; | ||
295 | query.processAll = true; | ||
296 | |||
297 | //Ensure all local data is processed | ||
298 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | ||
299 | |||
300 | Akonadi2::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); | ||
301 | mail.setProperty("name", "testCreateMail"); | ||
302 | |||
303 | Akonadi2::Store::create(mail).exec().waitForFinished(); | ||
304 | |||
305 | //Ensure all local data is processed | ||
306 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | ||
307 | |||
308 | auto targetPath = tempDir.path() + "/maildir1/new"; | ||
309 | QDir dir(targetPath); | ||
310 | dir.setFilter(QDir::Files); | ||
311 | QTRY_COMPARE(dir.count(), static_cast<unsigned int>(1)); | ||
312 | } | ||
313 | |||
290 | }; | 314 | }; |
291 | 315 | ||
292 | QTEST_MAIN(MaildirResourceTest) | 316 | QTEST_MAIN(MaildirResourceTest) |