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 /examples/maildirresource/maildirresource.cpp | |
parent | 8355323c285584940d81157f2596855f99996977 (diff) | |
download | sink-312702b809907866c085b92b1127129aaaf7f693.tar.gz sink-312702b809907866c085b92b1127129aaaf7f693.zip |
Stub for mail change-replay.
Not usable yet.
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 43 |
1 files changed, 42 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 | } |