summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapserverproxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r--examples/imapresource/imapserverproxy.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 9630096..836a9bc 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -23,12 +23,15 @@
23#include <KIMAP/KIMAP/LoginJob> 23#include <KIMAP/KIMAP/LoginJob>
24#include <KIMAP/KIMAP/SelectJob> 24#include <KIMAP/KIMAP/SelectJob>
25#include <KIMAP/KIMAP/AppendJob> 25#include <KIMAP/KIMAP/AppendJob>
26#include <KIMAP/KIMAP/CreateJob>
26 27
27#include <KIMAP/KIMAP/SessionUiProxy> 28#include <KIMAP/KIMAP/SessionUiProxy>
28#include <KCoreAddons/KJob> 29#include <KCoreAddons/KJob>
29 30
30#include "log.h" 31#include "log.h"
31 32
33using namespace Imap;
34
32static KAsync::Job<void> runJob(KJob *job) 35static KAsync::Job<void> runJob(KJob *job)
33{ 36{
34 return KAsync::start<void>([job](KAsync::Future<void> &future) { 37 return KAsync::start<void>([job](KAsync::Future<void> &future) {
@@ -94,6 +97,16 @@ KAsync::Job<void> ImapServerProxy::append(const QString &mailbox, const QByteArr
94 return runJob(append); 97 return runJob(append);
95} 98}
96 99
100KAsync::Job<void> ImapServerProxy::create(const QString &mailbox)
101{
102 if (mSession->state() == KIMAP::Session::State::Disconnected) {
103 return KAsync::error<void>(1, "Not connected");
104 }
105 auto create = new KIMAP::CreateJob(mSession);
106 create->setMailBox(mailbox);
107 return runJob(create);
108}
109
97KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, FetchCallback callback) 110KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, FetchCallback callback)
98{ 111{
99 if (mSession->state() == KIMAP::Session::State::Disconnected) { 112 if (mSession->state() == KIMAP::Session::State::Disconnected) {
@@ -154,14 +167,14 @@ KAsync::Job<void> ImapServerProxy::list(KIMAP::ListJob::Option option, const std
154 return runJob(listJob); 167 return runJob(listJob);
155} 168}
156 169
157KAsync::Future<void> ImapServerProxy::fetchFolders(std::function<void(const QStringList &)> callback) 170KAsync::Future<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback)
158{ 171{
159 Trace() << "Fetching folders"; 172 Trace() << "Fetching folders";
160 auto job = login("doe", "doe").then<void>(list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ 173 auto job = login("doe", "doe").then<void>(list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){
161 QStringList list; 174 QVector<Folder> list;
162 for (const auto &mailbox : mailboxes) { 175 for (const auto &mailbox : mailboxes) {
163 Trace() << "Found mailbox: " << mailbox.name; 176 Trace() << "Found mailbox: " << mailbox.name;
164 list << mailbox.name; 177 list << Folder{mailbox.name.split(mailbox.separator)};
165 } 178 }
166 callback(list); 179 callback(list);
167 }), 180 }),
@@ -171,10 +184,11 @@ KAsync::Future<void> ImapServerProxy::fetchFolders(std::function<void(const QStr
171 return job.exec(); 184 return job.exec();
172} 185}
173 186
174KAsync::Future<void> ImapServerProxy::fetchMessages(const QString &folder, std::function<void(const QVector<Message> &)> callback) 187KAsync::Future<void> ImapServerProxy::fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback)
175{ 188{
176 auto job = login("doe", "doe").then<void>(select(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> { 189 //TODO use the right separator
177 return fetchHeaders(folder).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){ 190 auto job = login("doe", "doe").then<void>(select(folder.pathParts.join('.'))).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> {
191 return fetchHeaders(folder.pathParts.join('.')).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){
178 Trace() << "Uids to fetch: " << uidsToFetch; 192 Trace() << "Uids to fetch: " << uidsToFetch;
179 if (uidsToFetch.isEmpty()) { 193 if (uidsToFetch.isEmpty()) {
180 Trace() << "Nothing to fetch"; 194 Trace() << "Nothing to fetch";