From 20b76fc1fd539bf95b8cb0d0ea7044718ec99972 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 6 Dec 2016 19:31:31 +0100 Subject: Move mail to sent folder after sending it --- .../mailtransportresource.cpp | 27 ++++++++++++++++++---- .../tests/mailtransporttest.cpp | 17 ++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'examples/mailtransportresource') diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 524b411..08a8748 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp @@ -23,6 +23,7 @@ #include "resourceconfig.h" #include "definitions.h" #include "inspector.h" +#include "store.h" #include #include #include @@ -81,10 +82,9 @@ public: KAsync::Job synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE { - SinkLog() << " Synchronizing"; return KAsync::start([this](KAsync::Future future) { QList toSend; - SinkLog() << " Looking for mail"; + SinkLog() << "Looking for mails to send."; store().readAll([&](const ApplicationDomain::Mail &mail) -> bool { SinkTrace() << "Found mail: " << mail.identifier(); if (!mail.getSent()) { @@ -92,13 +92,25 @@ public: } return true; }); + SinkLog() << "Found " << toSend.size() << " mails to send"; auto job = KAsync::null(); for (const auto &m : toSend) { - job = job.then(send(m, mSettings)).syncThen([this, m] { + job = job.then(send(m, mSettings)) + .then([this, m] { auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, m.identifier(), m.revision(), QSharedPointer::create()); modifiedMail.setSent(true); - modify(modifiedMail); - //TODO copy to a sent mail folder as well + + auto resource = Store::readOne(Query{}.filter(mResourceInstanceIdentifier).request()); + //Then copy the mail to the target resource + Query query; + query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::sent); + query.filter(resource.getAccount()); + return Store::fetchOne(query) + .then([this, modifiedMail](const ApplicationDomain::SinkResource &resource) -> KAsync::Job { + //First modify the mail to have the sent property set to true + modify(modifiedMail, resource.identifier(), true); + return KAsync::null(); + }); }); } job = job.syncThen([&future](const KAsync::Error &) { @@ -108,6 +120,11 @@ public: }); } + bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE + { + return false; + } + KAsync::Job replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList &changedProperties) Q_DECL_OVERRIDE { if (operation == Sink::Operation_Creation) { diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp index 410e17b..cb78603 100644 --- a/examples/mailtransportresource/tests/mailtransporttest.cpp +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp @@ -27,6 +27,7 @@ class MailtransportTest : public QObject return resource; } QByteArray mResourceInstanceIdentifier; + QByteArray mStorageResource; private slots: @@ -37,6 +38,11 @@ private slots: QVERIFY(!resource.identifier().isEmpty()); VERIFYEXEC(Store::create(resource)); mResourceInstanceIdentifier = resource.identifier(); + + auto dummyResource = ApplicationDomain::DummyResource::create("account1"); + VERIFYEXEC(Store::create(dummyResource)); + mStorageResource = dummyResource.identifier(); + QVERIFY(!mStorageResource.isEmpty()); } void cleanup() @@ -61,11 +67,12 @@ private slots: VERIFYEXEC(Store::create(mail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); VERIFYEXEC(Store::synchronize(Query().resourceFilter(mResourceInstanceIdentifier))); - VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, true))); - - auto sentMail = Store::readOne(Query(mail).request().request()); - QVERIFY(sentMail.getSent()); - QVERIFY(!sentMail.getSubject().isEmpty()); + QTest::qWait(100); + VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mStorageResource)); + auto mailInSentMailFolder = Store::readOne(Query().resourceFilter(mStorageResource).filter(true).request().request().request().request()); + //Check that the mail has been moved to the sent mail folder + QVERIFY(mailInSentMailFolder.getSent()); + QVERIFY(!mailInSentMailFolder.getSubject().isEmpty()); } //TODO test mail that fails to be sent. add a special header to the mail and have the resource fail sending. Ensure we can modify the mail to fix sending of the message. -- cgit v1.2.3