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 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'examples/mailtransportresource/mailtransportresource.cpp') 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) { -- cgit v1.2.3