From 2f0605ded80cd4c216b8cbaaf228e98811207744 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 1 Feb 2016 13:14:14 +0100 Subject: Ensure maildir flagchanges work completely --- examples/maildirresource/libmaildir/maildir.cpp | 2 +- examples/maildirresource/libmaildir/maildir.h | 2 +- examples/maildirresource/maildirresource.cpp | 12 +++ tests/maildirresourcetest.cpp | 97 +++++++++++++++---------- 4 files changed, 74 insertions(+), 39 deletions(-) diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp index 3d4630f..f8ca606 100644 --- a/examples/maildirresource/libmaildir/maildir.cpp +++ b/examples/maildirresource/libmaildir/maildir.cpp @@ -560,7 +560,7 @@ QDateTime Maildir::lastModified(const QString& key) const return info.lastModified(); } -QByteArray Maildir::readEntryHeadersFromFile(const QString& file) const +QByteArray Maildir::readEntryHeadersFromFile(const QString& file) { QByteArray result; diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h index a89a832..42d53e6 100644 --- a/examples/maildirresource/libmaildir/maildir.h +++ b/examples/maildirresource/libmaildir/maildir.h @@ -184,7 +184,7 @@ public: * Return the contents of the headers section of the file the maildir with the given @p file, that * is a full path to the file. You can get it by using findRealKey(key) . */ - QByteArray readEntryHeadersFromFile( const QString& file ) const; + static QByteArray readEntryHeadersFromFile( const QString& file ); /** * Return the contents of the headers section of the file the maildir with the given @p key. diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 33883a7..922eb5a 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -311,6 +311,18 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray } return KAsync::null(); } + if (property == "subject") { + const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); + + KMime::Message *msg = new KMime::Message; + msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(remoteId))); + msg->parse(); + + if (msg->subject(true)->asUnicodeString() != expectedValue.toString()) { + return KAsync::error(1, "Subject not as expected."); + } + return KAsync::null(); + } } if (inspectionType == Sink::Resources::Inspection::ExistenceInspectionType) { const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 6ad6ca6..85c329e 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -307,26 +307,26 @@ private Q_SLOTS: Store::flushMessageQueue(query.resources).exec().waitForFinished(); auto result = Store::fetchOne( - Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") + Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") + ) + .then, Folder>([query](const Folder &folder) { + return Store::fetchAll( + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") ) - .then, Folder>([query](const Folder &folder) { - return Store::fetchAll( - Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") - ) - .then, QList >([query](const QList &mails) { - //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE - if (mails.size() != 1) { - return KAsync::error(1, "Wrong number of mails."); - } - auto mail = mails.first(); - - return Store::remove(*mail) - .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already - .then(Resources::inspect(Resources::Inspection::ExistenceInspection(*mail, false))); - }) - .then([](){}); + .then, QList >([query](const QList &mails) { + //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE + if (mails.size() != 1) { + return KAsync::error(1, "Wrong number of mails."); + } + auto mail = mails.first(); + + return Store::remove(*mail) + .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already + .then(Resources::inspect(Resources::Inspection::ExistenceInspection(*mail, false))); }) - .exec(); + .then([](){}); + }) + .exec(); result.waitForFinished(); QVERIFY(!result.errorCode()); } @@ -340,31 +340,54 @@ private Q_SLOTS: Store::synchronize(query).exec().waitForFinished(); Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Folder f; + auto result = Store::fetchOne( - Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") + Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") + ) + .then, Folder>([query, &f](const Folder &folder) { + f = folder; + return Store::fetchAll( + Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") ) - .then, Folder>([query](const Folder &folder) { Trace() << "Found a folder" << folder.identifier(); - return Store::fetchAll( - Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") - ) - .then, QList >([query](const QList &mails) { - //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE - if (mails.size() != 1) { - return KAsync::error(1, "Wrong number of mails."); - } - auto mail = mails.first(); - mail->setProperty("unread", true); - auto inspectionCommand = Resources::Inspection::PropertyInspection(*mail, "unread", true); - return Store::modify(*mail) - .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already - .then(Resources::inspect(inspectionCommand)); - }) - .then([](){}); + .then, QList >([query](const QList &mails) { + //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE + if (mails.size() != 1) { + return KAsync::error(1, "Wrong number of mails."); + } + auto mail = mails.first(); + mail->setProperty("unread", true); + return Store::modify(*mail) + .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already + .then(Resources::inspect(Resources::Inspection::PropertyInspection(*mail, "unread", true))) + .then(Resources::inspect(Resources::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject")))); }) - .exec(); + .then([](){}); + }) + .exec(); result.waitForFinished(); QVERIFY(!result.errorCode()); + + auto result2 = Store::fetchAll( + Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") + ) + .then, QList >([query](const QList &mails) { + //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE + if (mails.size() != 1) { + qWarning() << "Wrong number of mails"; + return KAsync::error(1, "Wrong number of mails."); + } + auto mail = mails.first(); + if (mail->getProperty("subject").toString().isEmpty()) { + qWarning() << "Wrong subject"; + return KAsync::error(1, "Wrong subject."); + } + return KAsync::null(); + }) + .exec(); + result2.waitForFinished(); + QVERIFY(!result2.errorCode()); } }; -- cgit v1.2.3