summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapserverproxy.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-14 10:16:33 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-15 16:14:19 +0200
commit25fdab9836b1fdd248d3d36c00a96740093cd749 (patch)
treedb9df043cadf90a7c27c43bab7217afda91db023 /examples/imapresource/imapserverproxy.cpp
parent2bfccc6301f71db5bf45977bb2955c04fa6c1605 (diff)
downloadsink-25fdab9836b1fdd248d3d36c00a96740093cd749.tar.gz
sink-25fdab9836b1fdd248d3d36c00a96740093cd749.zip
New kimap2 syntax
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r--examples/imapresource/imapserverproxy.cpp39
1 files changed, 9 insertions, 30 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 0f3524f..b14ebd2 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -257,13 +257,7 @@ KAsync::Job<void> ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::Fet
257 fetch->setSequenceSet(set); 257 fetch->setSequenceSet(set);
258 fetch->setUidBased(true); 258 fetch->setUidBased(true);
259 fetch->setScope(scope); 259 fetch->setScope(scope);
260 QObject::connect(fetch, static_cast<void(KIMAP2::FetchJob::*)(const QString &, 260 QObject::connect(fetch, &KIMAP2::FetchJob::resultReceived, callback);
261 const QMap<qint64,qint64> &,
262 const QMap<qint64,qint64> &,
263 const QMap<qint64,KIMAP2::MessageAttribute> &,
264 const QMap<qint64,KIMAP2::MessageFlags> &,
265 const QMap<qint64,KIMAP2::MessagePtr> &)>(&KIMAP2::FetchJob::headersReceived),
266 callback);
267 return runJob(fetch); 261 return runJob(fetch);
268} 262}
269 263
@@ -280,16 +274,9 @@ KAsync::Job<QVector<qint64>> ImapServerProxy::search(const KIMAP2::ImapSet &set)
280KAsync::Job<void> ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback) 274KAsync::Job<void> ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback)
281{ 275{
282 return fetch(set, scope, 276 return fetch(set, scope,
283 [callback](const QString &mailbox, 277 [callback](const KIMAP2::FetchJob::Result &result) {
284 const QMap<qint64,qint64> &uids,
285 const QMap<qint64,qint64> &sizes,
286 const QMap<qint64,KIMAP2::MessageAttribute> &attrs,
287 const QMap<qint64,KIMAP2::MessageFlags> &flags,
288 const QMap<qint64,KIMAP2::MessagePtr> &messages) {
289 QVector<Message> list; 278 QVector<Message> list;
290 for (const auto &id : uids.keys()) { 279 list << Message{result.uid, result.size, result.attributes, result.flags, result.message};
291 list << Message{uids.value(id), sizes.value(id), attrs.value(id), flags.value(id), messages.value(id)};
292 }
293 callback(list); 280 callback(list);
294 }); 281 });
295} 282}
@@ -307,22 +294,13 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox,
307 294
308 //Fetch headers of all messages 295 //Fetch headers of all messages
309 return fetch(KIMAP2::ImapSet(minUid, 0), scope, 296 return fetch(KIMAP2::ImapSet(minUid, 0), scope,
310 [list](const QString &mailbox, 297 [list](const KIMAP2::FetchJob::Result &result) {
311 const QMap<qint64,qint64> &uids,
312 const QMap<qint64,qint64> &sizes,
313 const QMap<qint64,KIMAP2::MessageAttribute> &attrs,
314 const QMap<qint64,KIMAP2::MessageFlags> &flags,
315 const QMap<qint64,KIMAP2::MessagePtr> &messages) {
316 SinkTrace() << "Received " << uids.size() << " headers from " << mailbox;
317 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
318 298
319 //TODO based on the data available here, figure out which messages to actually fetch 299 //TODO based on the data available here, figure out which messages to actually fetch
320 //(we only fetched headers and structure so far) 300 //(we only fetched headers and structure so far)
321 //We could i.e. build chunks to fetch based on the size 301 //We could i.e. build chunks to fetch based on the size
322 302
323 for (const auto &id : uids.keys()) { 303 list->append(result.uid);
324 list->append(uids.value(id));
325 }
326 }) 304 })
327 .syncThen<QList<qint64>>([list](){ 305 .syncThen<QList<qint64>>([list](){
328 return *list; 306 return *list;
@@ -416,7 +394,7 @@ QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const
416 return folder.pathParts.join(mPersonalNamespaceSeparator); 394 return folder.pathParts.join(mPersonalNamespaceSeparator);
417} 395}
418 396
419KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, qint64 changedsince, std::function<void(const QVector<Message> &)> callback) 397KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function<void(const QVector<Message> &)> callback)
420{ 398{
421 SinkTrace() << "Fetching flags " << folder.normalizedPath(); 399 SinkTrace() << "Fetching flags " << folder.normalizedPath();
422 return select(mailboxFromFolder(folder)).then<SelectResult, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<SelectResult> { 400 return select(mailboxFromFolder(folder)).then<SelectResult, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<SelectResult> {
@@ -427,13 +405,13 @@ KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, qint
427 return KAsync::value<SelectResult>(selectResult); 405 return KAsync::value<SelectResult>(selectResult);
428 } 406 }
429 407
430 SinkTrace() << "Fetching flags " << folder.normalizedPath() << selectResult.highestModSequence << changedsince; 408 SinkTrace() << "Fetching flags " << folder.normalizedPath() << set << selectResult.highestModSequence << changedsince;
431 409
432 KIMAP2::FetchJob::FetchScope scope; 410 KIMAP2::FetchJob::FetchScope scope;
433 scope.mode = KIMAP2::FetchJob::FetchScope::Flags; 411 scope.mode = KIMAP2::FetchJob::FetchScope::Flags;
434 scope.changedSince = changedsince; 412 scope.changedSince = changedsince;
435 413
436 return fetch(KIMAP2::ImapSet(1, 0), scope, callback).syncThen<SelectResult>([selectResult] { 414 return fetch(set, scope, callback).syncThen<SelectResult>([selectResult] {
437 return selectResult; 415 return selectResult;
438 }); 416 });
439 }); 417 });
@@ -451,6 +429,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui
451 return KAsync::null<void>(); 429 return KAsync::null<void>();
452 } 430 }
453 431
432 SinkTrace() << "Fetching messages from " << folder.normalizedPath() << selectResult.uidNext << uidNext;
454 return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress, folder](const QList<qint64> &uidsToFetch){ 433 return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress, folder](const QList<qint64> &uidsToFetch){
455 SinkTrace() << "Fetched headers" << folder.normalizedPath(); 434 SinkTrace() << "Fetched headers" << folder.normalizedPath();
456 SinkTrace() << " Total: " << uidsToFetch.size(); 435 SinkTrace() << " Total: " << uidsToFetch.size();