diff options
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 70f6ae5..9280bdc 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "facadefactory.h" | 35 | #include "facadefactory.h" |
36 | #include "indexupdater.h" | 36 | #include "indexupdater.h" |
37 | #include "libmaildir/maildir.h" | 37 | #include "libmaildir/maildir.h" |
38 | #include "inspection.h" | ||
38 | #include <QDate> | 39 | #include <QDate> |
39 | #include <QUuid> | 40 | #include <QUuid> |
40 | #include <QDir> | 41 | #include <QDir> |
@@ -292,6 +293,35 @@ void MaildirResource::removeFromDisk(const QByteArray &instanceIdentifier) | |||
292 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); | 293 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); |
293 | } | 294 | } |
294 | 295 | ||
296 | KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | ||
297 | { | ||
298 | auto synchronizationStore = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadOnly); | ||
299 | auto synchronizationTransaction = synchronizationStore->createTransaction(Akonadi2::Storage::ReadOnly); | ||
300 | Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | ||
301 | if (domainType == ENTITY_TYPE_MAIL) { | ||
302 | if (inspectionType == Akonadi2::Resources::Inspection::PropertyInspectionType) { | ||
303 | if (property == "unread") { | ||
304 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); | ||
305 | const auto flags = KPIM::Maildir::readEntryFlags(remoteId.split('/').last()); | ||
306 | if (expectedValue.toBool() && !(flags & KPIM::Maildir::Seen)) { | ||
307 | return KAsync::error<void>(1, "Expected seen but couldn't find it."); | ||
308 | } | ||
309 | if (!expectedValue.toBool() && (flags & KPIM::Maildir::Seen)) { | ||
310 | return KAsync::error<void>(1, "Expected seen but couldn't find it."); | ||
311 | } | ||
312 | return KAsync::null<void>(); | ||
313 | } | ||
314 | } | ||
315 | if (inspectionType == Akonadi2::Resources::Inspection::ExistenceInspectionType) { | ||
316 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); | ||
317 | if (QFileInfo(remoteId).exists() != expectedValue.toBool()) { | ||
318 | return KAsync::error<void>(1, "Wrong file existence: " + remoteId); | ||
319 | } | ||
320 | } | ||
321 | } | ||
322 | return KAsync::null<void>(); | ||
323 | } | ||
324 | |||
295 | MaildirResourceFactory::MaildirResourceFactory(QObject *parent) | 325 | MaildirResourceFactory::MaildirResourceFactory(QObject *parent) |
296 | : Akonadi2::ResourceFactory(parent) | 326 | : Akonadi2::ResourceFactory(parent) |
297 | { | 327 | { |