diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 19:31:31 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 19:31:31 +0100 |
commit | 20b76fc1fd539bf95b8cb0d0ea7044718ec99972 (patch) | |
tree | 03da4339c8879e4d45e0c5a903b6bfb410c4bf31 /examples/mailtransportresource/mailtransportresource.cpp | |
parent | 62c7b07c0d62f8f03e22556bf62ed90d267c6d2e (diff) | |
download | sink-20b76fc1fd539bf95b8cb0d0ea7044718ec99972.tar.gz sink-20b76fc1fd539bf95b8cb0d0ea7044718ec99972.zip |
Move mail to sent folder after sending it
Diffstat (limited to 'examples/mailtransportresource/mailtransportresource.cpp')
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
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 @@ | |||
23 | #include "resourceconfig.h" | 23 | #include "resourceconfig.h" |
24 | #include "definitions.h" | 24 | #include "definitions.h" |
25 | #include "inspector.h" | 25 | #include "inspector.h" |
26 | #include "store.h" | ||
26 | #include <QDir> | 27 | #include <QDir> |
27 | #include <QFileInfo> | 28 | #include <QFileInfo> |
28 | #include <QSettings> | 29 | #include <QSettings> |
@@ -81,10 +82,9 @@ public: | |||
81 | 82 | ||
82 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 83 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
83 | { | 84 | { |
84 | SinkLog() << " Synchronizing"; | ||
85 | return KAsync::start<void>([this](KAsync::Future<void> future) { | 85 | return KAsync::start<void>([this](KAsync::Future<void> future) { |
86 | QList<ApplicationDomain::Mail> toSend; | 86 | QList<ApplicationDomain::Mail> toSend; |
87 | SinkLog() << " Looking for mail"; | 87 | SinkLog() << "Looking for mails to send."; |
88 | store().readAll<ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) -> bool { | 88 | store().readAll<ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) -> bool { |
89 | SinkTrace() << "Found mail: " << mail.identifier(); | 89 | SinkTrace() << "Found mail: " << mail.identifier(); |
90 | if (!mail.getSent()) { | 90 | if (!mail.getSent()) { |
@@ -92,13 +92,25 @@ public: | |||
92 | } | 92 | } |
93 | return true; | 93 | return true; |
94 | }); | 94 | }); |
95 | SinkLog() << "Found " << toSend.size() << " mails to send"; | ||
95 | auto job = KAsync::null<void>(); | 96 | auto job = KAsync::null<void>(); |
96 | for (const auto &m : toSend) { | 97 | for (const auto &m : toSend) { |
97 | job = job.then(send(m, mSettings)).syncThen<void>([this, m] { | 98 | job = job.then(send(m, mSettings)) |
99 | .then<void>([this, m] { | ||
98 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, m.identifier(), m.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 100 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, m.identifier(), m.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
99 | modifiedMail.setSent(true); | 101 | modifiedMail.setSent(true); |
100 | modify(modifiedMail); | 102 | |
101 | //TODO copy to a sent mail folder as well | 103 | auto resource = Store::readOne<ApplicationDomain::SinkResource>(Query{}.filter(mResourceInstanceIdentifier).request<ApplicationDomain::SinkResource::Account>()); |
104 | //Then copy the mail to the target resource | ||
105 | Query query; | ||
106 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::sent); | ||
107 | query.filter<ApplicationDomain::SinkResource::Account>(resource.getAccount()); | ||
108 | return Store::fetchOne<ApplicationDomain::SinkResource>(query) | ||
109 | .then<void, ApplicationDomain::SinkResource>([this, modifiedMail](const ApplicationDomain::SinkResource &resource) -> KAsync::Job<void> { | ||
110 | //First modify the mail to have the sent property set to true | ||
111 | modify(modifiedMail, resource.identifier(), true); | ||
112 | return KAsync::null<void>(); | ||
113 | }); | ||
102 | }); | 114 | }); |
103 | } | 115 | } |
104 | job = job.syncThen<void>([&future](const KAsync::Error &) { | 116 | job = job.syncThen<void>([&future](const KAsync::Error &) { |
@@ -108,6 +120,11 @@ public: | |||
108 | }); | 120 | }); |
109 | } | 121 | } |
110 | 122 | ||
123 | bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE | ||
124 | { | ||
125 | return false; | ||
126 | } | ||
127 | |||
111 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE | 128 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE |
112 | { | 129 | { |
113 | if (operation == Sink::Operation_Creation) { | 130 | if (operation == Sink::Operation_Creation) { |