diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-22 15:27:52 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-22 15:27:52 +0200 |
commit | f38554ad4c7ff918bf7792413e6599e69d30cf3a (patch) | |
tree | 8f971c3c5349166e6f2b488c7983bc868627e524 /examples/imapresource/imapserverproxy.cpp | |
parent | 1613964dd195a21eb7ff28699b76db8d41fb8408 (diff) | |
download | sink-f38554ad4c7ff918bf7792413e6599e69d30cf3a.tar.gz sink-f38554ad4c7ff918bf7792413e6599e69d30cf3a.zip |
Support for folder hierarchies
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 26 |
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 | ||
33 | using namespace Imap; | ||
34 | |||
32 | static KAsync::Job<void> runJob(KJob *job) | 35 | static 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 | ||
100 | KAsync::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 | |||
97 | KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, FetchCallback callback) | 110 | KAsync::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 | ||
157 | KAsync::Future<void> ImapServerProxy::fetchFolders(std::function<void(const QStringList &)> callback) | 170 | KAsync::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 | ||
174 | KAsync::Future<void> ImapServerProxy::fetchMessages(const QString &folder, std::function<void(const QVector<Message> &)> callback) | 187 | KAsync::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"; |