diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 2 | ||||
-rw-r--r-- | examples/imapresource/imapresource.cpp | 74 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 35 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 18 | ||||
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 7 |
5 files changed, 59 insertions, 77 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 0f7463f..221e20d 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -113,7 +113,7 @@ class DummySynchronizer : public Sink::Synchronizer { | |||
113 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | 113 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE |
114 | { | 114 | { |
115 | SinkLog() << " Synchronizing with the source"; | 115 | SinkLog() << " Synchronizing with the source"; |
116 | return KAsync::start<void>([this]() { | 116 | return KAsync::syncStart<void>([this]() { |
117 | synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) { | 117 | synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) { |
118 | return createEvent(ridBuffer, data); | 118 | return createEvent(ridBuffer, data); |
119 | }); | 119 | }); |
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index e199ea1..f78376a 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -56,6 +56,8 @@ | |||
56 | 56 | ||
57 | SINK_DEBUG_AREA("imapresource") | 57 | SINK_DEBUG_AREA("imapresource") |
58 | 58 | ||
59 | Q_DECLARE_METATYPE(QSharedPointer<Imap::ImapServerProxy>) | ||
60 | |||
59 | using namespace Imap; | 61 | using namespace Imap; |
60 | using namespace Sink; | 62 | using namespace Sink; |
61 | 63 | ||
@@ -217,22 +219,22 @@ public: | |||
217 | SinkLog() << "Synchronizing mails" << folder.normalizedPath(); | 219 | SinkLog() << "Synchronizing mails" << folder.normalizedPath(); |
218 | auto capabilities = imap->getCapabilities(); | 220 | auto capabilities = imap->getCapabilities(); |
219 | bool canDoIncrementalRemovals = false; | 221 | bool canDoIncrementalRemovals = false; |
220 | return KAsync::start<void>([=]() { | 222 | return KAsync::syncStart<void>([=]() { |
221 | //TODO update flags | 223 | //TODO update flags |
222 | }) | 224 | }) |
223 | .then<void, KAsync::Job<void>>([=]() { | 225 | .then<void>([=]() { |
224 | //TODO Remove what's no longer existing | 226 | //TODO Remove what's no longer existing |
225 | if (canDoIncrementalRemovals) { | 227 | if (canDoIncrementalRemovals) { |
226 | } else { | 228 | } else { |
227 | return imap->fetchUids(folder).then<void, QVector<qint64>>([this, folder](const QVector<qint64> &uids) { | 229 | return imap->fetchUids(folder).syncThen<void, QVector<qint64>>([this, folder](const QVector<qint64> &uids) { |
228 | SinkTrace() << "Syncing removals"; | 230 | SinkTrace() << "Syncing removals"; |
229 | synchronizeRemovals(folder.normalizedPath(), uids.toList().toSet()); | 231 | synchronizeRemovals(folder.normalizedPath(), uids.toList().toSet()); |
230 | commit(); | 232 | commit(); |
231 | }).then<void>([](){}); | 233 | }); |
232 | } | 234 | } |
233 | return KAsync::null<void>(); | 235 | return KAsync::null<void>(); |
234 | }) | 236 | }) |
235 | .then<void, KAsync::Job<void>>([this, folder, imap]() { | 237 | .then<void>([this, folder, imap]() { |
236 | SinkTrace() << "About to fetch mail"; | 238 | SinkTrace() << "About to fetch mail"; |
237 | const auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); | 239 | const auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); |
238 | auto maxUid = QSharedPointer<qint64>::create(0); | 240 | auto maxUid = QSharedPointer<qint64>::create(0); |
@@ -248,7 +250,7 @@ public: | |||
248 | [](int progress, int total) { | 250 | [](int progress, int total) { |
249 | SinkTrace() << "Progress: " << progress << " out of " << total; | 251 | SinkTrace() << "Progress: " << progress << " out of " << total; |
250 | }) | 252 | }) |
251 | .then<void>([this, maxUid, folder]() { | 253 | .syncThen<void>([this, maxUid, folder]() { |
252 | syncStore().writeValue(folder.normalizedPath().toUtf8() + "uidnext", QByteArray::number(*maxUid)); | 254 | syncStore().writeValue(folder.normalizedPath().toUtf8() + "uidnext", QByteArray::number(*maxUid)); |
253 | }); | 255 | }); |
254 | }); | 256 | }); |
@@ -330,15 +332,12 @@ public: | |||
330 | flags << Imap::Flags::Flagged; | 332 | flags << Imap::Flags::Flagged; |
331 | } | 333 | } |
332 | QDateTime internalDate = mail.getDate(); | 334 | QDateTime internalDate = mail.getDate(); |
333 | auto rid = QSharedPointer<QByteArray>::create(); | ||
334 | return login.then(imap->append(mailbox, content, flags, internalDate)) | 335 | return login.then(imap->append(mailbox, content, flags, internalDate)) |
335 | .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { | 336 | .addToContext(imap) |
337 | .syncThen<QByteArray, qint64>([mail](qint64 uid) { | ||
336 | const auto remoteId = assembleMailRid(mail, uid); | 338 | const auto remoteId = assembleMailRid(mail, uid); |
337 | //FIXME this get's called after the final error handler? WTF? | ||
338 | SinkTrace() << "Finished creating a new mail: " << remoteId; | 339 | SinkTrace() << "Finished creating a new mail: " << remoteId; |
339 | *rid = remoteId; | 340 | return remoteId; |
340 | }).then<QByteArray>([rid, imap]() { //FIXME fix KJob so we don't need this extra clause | ||
341 | return *rid; | ||
342 | }); | 341 | }); |
343 | } else if (operation == Sink::Operation_Removal) { | 342 | } else if (operation == Sink::Operation_Removal) { |
344 | const auto folderId = folderIdFromMailRid(oldRemoteId); | 343 | const auto folderId = folderIdFromMailRid(oldRemoteId); |
@@ -348,7 +347,7 @@ public: | |||
348 | KIMAP::ImapSet set; | 347 | KIMAP::ImapSet set; |
349 | set.add(uid); | 348 | set.add(uid); |
350 | return login.then(imap->remove(mailbox, set)) | 349 | return login.then(imap->remove(mailbox, set)) |
351 | .then<QByteArray>([imap, oldRemoteId]() { | 350 | .syncThen<QByteArray>([imap, oldRemoteId] { |
352 | SinkTrace() << "Finished removing a mail: " << oldRemoteId; | 351 | SinkTrace() << "Finished removing a mail: " << oldRemoteId; |
353 | return QByteArray(); | 352 | return QByteArray(); |
354 | }); | 353 | }); |
@@ -374,29 +373,24 @@ public: | |||
374 | const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); | 373 | const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); |
375 | QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); | 374 | QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); |
376 | QDateTime internalDate = mail.getDate(); | 375 | QDateTime internalDate = mail.getDate(); |
377 | auto rid = QSharedPointer<QByteArray>::create(); | ||
378 | KIMAP::ImapSet set; | 376 | KIMAP::ImapSet set; |
379 | set.add(uid); | 377 | set.add(uid); |
380 | return login.then(imap->append(mailbox, content, flags, internalDate)) | 378 | return login.then(imap->append(mailbox, content, flags, internalDate)) |
381 | .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { | 379 | .addToContext(imap) |
380 | .then<QByteArray, qint64>([=](qint64 uid) { | ||
382 | const auto remoteId = assembleMailRid(mail, uid); | 381 | const auto remoteId = assembleMailRid(mail, uid); |
383 | SinkTrace() << "Finished creating a modified mail: " << remoteId; | 382 | SinkTrace() << "Finished creating a modified mail: " << remoteId; |
384 | *rid = remoteId; | 383 | return imap->remove(oldMailbox, set).then(KAsync::value(remoteId)); |
385 | }) | ||
386 | .then(imap->remove(oldMailbox, set)) | ||
387 | .then<QByteArray>([rid, imap]() { | ||
388 | return *rid; | ||
389 | }); | 384 | }); |
390 | } else { | 385 | } else { |
391 | SinkTrace() << "Updating flags only."; | 386 | SinkTrace() << "Updating flags only."; |
392 | KIMAP::ImapSet set; | 387 | KIMAP::ImapSet set; |
393 | set.add(uid); | 388 | set.add(uid); |
394 | return login.then(imap->select(mailbox)) | 389 | return login.then(imap->select(mailbox)) |
390 | .addToContext(imap) | ||
395 | .then(imap->storeFlags(set, flags)) | 391 | .then(imap->storeFlags(set, flags)) |
396 | .then<void>([imap, mailbox]() { | 392 | .syncThen<QByteArray>([=] { |
397 | SinkTrace() << "Finished modifying mail"; | 393 | SinkTrace() << "Finished modifying mail"; |
398 | }) | ||
399 | .then<QByteArray>([oldRemoteId, imap]() { | ||
400 | return oldRemoteId; | 394 | return oldRemoteId; |
401 | }); | 395 | }); |
402 | } | 396 | } |
@@ -416,13 +410,13 @@ public: | |||
416 | SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName(); | 410 | SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName(); |
417 | auto rid = QSharedPointer<QByteArray>::create(); | 411 | auto rid = QSharedPointer<QByteArray>::create(); |
418 | auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName())) | 412 | auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName())) |
419 | .then<void, QString>([imap, rid](const QString &createdFolder) { | 413 | .syncThen<void, QString>([imap, rid](const QString &createdFolder) { |
420 | SinkTrace() << "Finished creating a new folder: " << createdFolder; | 414 | SinkTrace() << "Finished creating a new folder: " << createdFolder; |
421 | *rid = createdFolder.toUtf8(); | 415 | *rid = createdFolder.toUtf8(); |
422 | }); | 416 | }); |
423 | if (folder.getSpecialPurpose().isEmpty()) { | 417 | if (folder.getSpecialPurpose().isEmpty()) { |
424 | return createFolder | 418 | return createFolder |
425 | .then<QByteArray>([rid](){ | 419 | .syncThen<QByteArray>([rid](){ |
426 | return *rid; | 420 | return *rid; |
427 | }); | 421 | }); |
428 | } else { //We try to merge special purpose folders first | 422 | } else { //We try to merge special purpose folders first |
@@ -435,7 +429,7 @@ public: | |||
435 | }; | 429 | }; |
436 | } | 430 | } |
437 | })) | 431 | })) |
438 | .then<void, KAsync::Job<void>>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> { | 432 | .then<void>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> { |
439 | for (const auto &purpose : folder.getSpecialPurpose()) { | 433 | for (const auto &purpose : folder.getSpecialPurpose()) { |
440 | if (specialPurposeFolders->contains(purpose)) { | 434 | if (specialPurposeFolders->contains(purpose)) { |
441 | auto f = specialPurposeFolders->value(purpose); | 435 | auto f = specialPurposeFolders->value(purpose); |
@@ -446,13 +440,13 @@ public: | |||
446 | } | 440 | } |
447 | SinkTrace() << "No match found for merging, creating a new folder"; | 441 | SinkTrace() << "No match found for merging, creating a new folder"; |
448 | return imap->createSubfolder(parentFolder, folder.getName()) | 442 | return imap->createSubfolder(parentFolder, folder.getName()) |
449 | .then<void, QString>([imap, rid](const QString &createdFolder) { | 443 | .syncThen<void, QString>([imap, rid](const QString &createdFolder) { |
450 | SinkTrace() << "Finished creating a new folder: " << createdFolder; | 444 | SinkTrace() << "Finished creating a new folder: " << createdFolder; |
451 | *rid = createdFolder.toUtf8(); | 445 | *rid = createdFolder.toUtf8(); |
452 | }); | 446 | }); |
453 | 447 | ||
454 | }) | 448 | }) |
455 | .then<QByteArray>([rid](){ | 449 | .syncThen<QByteArray>([rid](){ |
456 | return *rid; | 450 | return *rid; |
457 | }); | 451 | }); |
458 | return mergeJob; | 452 | return mergeJob; |
@@ -460,7 +454,7 @@ public: | |||
460 | } else if (operation == Sink::Operation_Removal) { | 454 | } else if (operation == Sink::Operation_Removal) { |
461 | SinkTrace() << "Removing a folder: " << oldRemoteId; | 455 | SinkTrace() << "Removing a folder: " << oldRemoteId; |
462 | return login.then<void>(imap->remove(oldRemoteId)) | 456 | return login.then<void>(imap->remove(oldRemoteId)) |
463 | .then<QByteArray>([oldRemoteId, imap]() { | 457 | .syncThen<QByteArray>([oldRemoteId, imap]() { |
464 | SinkTrace() << "Finished removing a folder: " << oldRemoteId; | 458 | SinkTrace() << "Finished removing a folder: " << oldRemoteId; |
465 | return QByteArray(); | 459 | return QByteArray(); |
466 | }); | 460 | }); |
@@ -468,11 +462,11 @@ public: | |||
468 | SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName(); | 462 | SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName(); |
469 | auto rid = QSharedPointer<QByteArray>::create(); | 463 | auto rid = QSharedPointer<QByteArray>::create(); |
470 | return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName())) | 464 | return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName())) |
471 | .then<void, QString>([imap, rid](const QString &createdFolder) { | 465 | .syncThen<void, QString>([imap, rid](const QString &createdFolder) { |
472 | SinkTrace() << "Finished renaming a folder: " << createdFolder; | 466 | SinkTrace() << "Finished renaming a folder: " << createdFolder; |
473 | *rid = createdFolder.toUtf8(); | 467 | *rid = createdFolder.toUtf8(); |
474 | }) | 468 | }) |
475 | .then<QByteArray>([rid](){ | 469 | .syncThen<QByteArray>([rid](){ |
476 | return *rid; | 470 | return *rid; |
477 | }); | 471 | }); |
478 | } | 472 | } |
@@ -566,7 +560,8 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
566 | SinkTrace() << "Connecting to:" << mServer << mPort; | 560 | SinkTrace() << "Connecting to:" << mServer << mPort; |
567 | SinkTrace() << "as:" << mUser; | 561 | SinkTrace() << "as:" << mUser; |
568 | auto inspectionJob = imap->login(mUser, mPassword) | 562 | auto inspectionJob = imap->login(mUser, mPassword) |
569 | .then<void>(imap->select(folderRemoteId).then<void>([](){})) | 563 | .then<Imap::SelectResult>(imap->select(folderRemoteId)) |
564 | .syncThen<void, Imap::SelectResult>([](Imap::SelectResult){}) | ||
570 | .then<void>(imap->fetch(set, scope, [imap, messageByUid](const QVector<Imap::Message> &messages) { | 565 | .then<void>(imap->fetch(set, scope, [imap, messageByUid](const QVector<Imap::Message> &messages) { |
571 | for (const auto &m : messages) { | 566 | for (const auto &m : messages) { |
572 | messageByUid->insert(m.uid, m); | 567 | messageByUid->insert(m.uid, m); |
@@ -575,7 +570,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
575 | 570 | ||
576 | if (inspectionType == Sink::ResourceControl::Inspection::PropertyInspectionType) { | 571 | if (inspectionType == Sink::ResourceControl::Inspection::PropertyInspectionType) { |
577 | if (property == "unread") { | 572 | if (property == "unread") { |
578 | return inspectionJob.then<void, KAsync::Job<void>>([=]() { | 573 | return inspectionJob.then<void>([=]() { |
579 | auto msg = messageByUid->value(uid); | 574 | auto msg = messageByUid->value(uid); |
580 | if (expectedValue.toBool() && msg.flags.contains(Imap::Flags::Seen)) { | 575 | if (expectedValue.toBool() && msg.flags.contains(Imap::Flags::Seen)) { |
581 | return KAsync::error<void>(1, "Expected unread but couldn't find it."); | 576 | return KAsync::error<void>(1, "Expected unread but couldn't find it."); |
@@ -587,7 +582,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
587 | }); | 582 | }); |
588 | } | 583 | } |
589 | if (property == "subject") { | 584 | if (property == "subject") { |
590 | return inspectionJob.then<void, KAsync::Job<void>>([=]() { | 585 | return inspectionJob.then<void>([=]() { |
591 | auto msg = messageByUid->value(uid); | 586 | auto msg = messageByUid->value(uid); |
592 | if (msg.msg->subject(true)->asUnicodeString() != expectedValue.toString()) { | 587 | if (msg.msg->subject(true)->asUnicodeString() != expectedValue.toString()) { |
593 | return KAsync::error<void>(1, "Subject not as expected: " + msg.msg->subject(true)->asUnicodeString()); | 588 | return KAsync::error<void>(1, "Subject not as expected: " + msg.msg->subject(true)->asUnicodeString()); |
@@ -597,7 +592,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
597 | } | 592 | } |
598 | } | 593 | } |
599 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { | 594 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { |
600 | return inspectionJob.then<void, KAsync::Job<void>>([=]() { | 595 | return inspectionJob.then<void>([=]() { |
601 | if (!messageByUid->contains(uid)) { | 596 | if (!messageByUid->contains(uid)) { |
602 | SinkWarning() << "Existing messages are: " << messageByUid->keys(); | 597 | SinkWarning() << "Existing messages are: " << messageByUid->keys(); |
603 | SinkWarning() << "We're looking for: " << uid; | 598 | SinkWarning() << "We're looking for: " << uid; |
@@ -628,20 +623,19 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
628 | scope.mode = KIMAP::FetchJob::FetchScope::Headers; | 623 | scope.mode = KIMAP::FetchJob::FetchScope::Headers; |
629 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 624 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); |
630 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); | 625 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); |
631 | auto inspectionJob = imap->login(mUser, mPassword) | 626 | return imap->login(mUser, mPassword) |
632 | .then<void>(imap->select(remoteId).then<void>([](){})) | 627 | .then<void>(imap->select(remoteId).syncThen<void>([](){})) |
633 | .then<void>(imap->fetch(set, scope, [=](const QVector<Imap::Message> &messages) { | 628 | .then<void>(imap->fetch(set, scope, [=](const QVector<Imap::Message> &messages) { |
634 | for (const auto &m : messages) { | 629 | for (const auto &m : messages) { |
635 | messageByUid->insert(m.uid, m); | 630 | messageByUid->insert(m.uid, m); |
636 | } | 631 | } |
637 | })) | 632 | })) |
638 | .then<void, KAsync::Job<void>>([imap, messageByUid, expectedCount]() { | 633 | .then<void>([imap, messageByUid, expectedCount]() { |
639 | if (messageByUid->size() != expectedCount) { | 634 | if (messageByUid->size() != expectedCount) { |
640 | return KAsync::error<void>(1, QString("Wrong number of messages on the server; found %1 instead of %2.").arg(messageByUid->size()).arg(expectedCount)); | 635 | return KAsync::error<void>(1, QString("Wrong number of messages on the server; found %1 instead of %2.").arg(messageByUid->size()).arg(expectedCount)); |
641 | } | 636 | } |
642 | return KAsync::null<void>(); | 637 | return KAsync::null<void>(); |
643 | }); | 638 | }); |
644 | return inspectionJob; | ||
645 | } | 639 | } |
646 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { | 640 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { |
647 | auto folderByPath = QSharedPointer<QSet<QString>>::create(); | 641 | auto folderByPath = QSharedPointer<QSet<QString>>::create(); |
@@ -655,7 +649,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
655 | *folderByName << f.pathParts.last(); | 649 | *folderByName << f.pathParts.last(); |
656 | } | 650 | } |
657 | })) | 651 | })) |
658 | .then<void, KAsync::Job<void>>([this, folderByName, folderByPath, folder, remoteId, imap]() { | 652 | .then<void>([this, folderByName, folderByPath, folder, remoteId, imap]() { |
659 | if (!folderByName->contains(folder.getName())) { | 653 | if (!folderByName->contains(folder.getName())) { |
660 | SinkWarning() << "Existing folders are: " << *folderByPath; | 654 | SinkWarning() << "Existing folders are: " << *folderByPath; |
661 | SinkWarning() << "We're looking for: " << folder.getName(); | 655 | SinkWarning() << "We're looking for: " << folder.getName(); |
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index a3d8d16..94367d8 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -161,7 +161,7 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString | |||
161 | auto namespaceJob = new KIMAP::NamespaceJob(mSession); | 161 | auto namespaceJob = new KIMAP::NamespaceJob(mSession); |
162 | 162 | ||
163 | //FIXME The ping is only required because the login job doesn't fail after the configured timeout | 163 | //FIXME The ping is only required because the login job doesn't fail after the configured timeout |
164 | return ping().then(runJob(loginJob)).then(runJob(capabilitiesJob)).then<void>([this](){ | 164 | return ping().then(runJob(loginJob)).then(runJob(capabilitiesJob)).syncThen<void>([this](){ |
165 | SinkTrace() << "Supported capabilities: " << mCapabilities; | 165 | SinkTrace() << "Supported capabilities: " << mCapabilities; |
166 | QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; | 166 | QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; |
167 | for (const auto &requiredExtension : requiredExtensions) { | 167 | for (const auto &requiredExtension : requiredExtensions) { |
@@ -170,7 +170,7 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString | |||
170 | //TODO fail the job | 170 | //TODO fail the job |
171 | } | 171 | } |
172 | } | 172 | } |
173 | }).then(runJob(namespaceJob)).then<void>([this, namespaceJob](){ | 173 | }).then(runJob(namespaceJob)).syncThen<void>([this, namespaceJob] { |
174 | for (const auto &ns :namespaceJob->personalNamespaces()) { | 174 | for (const auto &ns :namespaceJob->personalNamespaces()) { |
175 | mPersonalNamespaces << ns.name; | 175 | mPersonalNamespaces << ns.name; |
176 | mPersonalNamespaceSeparator = ns.separator; | 176 | mPersonalNamespaceSeparator = ns.separator; |
@@ -363,7 +363,7 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox, | |||
363 | list->append(uids.value(id)); | 363 | list->append(uids.value(id)); |
364 | } | 364 | } |
365 | }) | 365 | }) |
366 | .then<QList<qint64>>([list](){ | 366 | .syncThen<QList<qint64>>([list](){ |
367 | return *list; | 367 | return *list; |
368 | }); | 368 | }); |
369 | } | 369 | } |
@@ -402,35 +402,34 @@ KAsync::Job<void> ImapServerProxy::move(const QString &mailbox, const KIMAP::Ima | |||
402 | 402 | ||
403 | KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailbox, const QString &folderName) | 403 | KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailbox, const QString &folderName) |
404 | { | 404 | { |
405 | auto folder = QSharedPointer<QString>::create(); | 405 | return KAsync::start<QString>([this, parentMailbox, folderName]() { |
406 | return KAsync::start<void, KAsync::Job<void>>([this, parentMailbox, folderName, folder]() { | ||
407 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 406 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
407 | auto folder = QSharedPointer<QString>::create(); | ||
408 | if (parentMailbox.isEmpty()) { | 408 | if (parentMailbox.isEmpty()) { |
409 | *folder = mPersonalNamespaces.toList().first() + folderName; | 409 | *folder = mPersonalNamespaces.toList().first() + folderName; |
410 | } else { | 410 | } else { |
411 | *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; | 411 | *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; |
412 | } | 412 | } |
413 | SinkTrace() << "Creating subfolder: " << *folder; | 413 | SinkTrace() << "Creating subfolder: " << *folder; |
414 | return create(*folder); | 414 | return create(*folder) |
415 | }) | 415 | .syncThen<QString>([=]() { |
416 | .then<QString>([=]() { | 416 | return *folder; |
417 | return *folder; | 417 | }); |
418 | }); | 418 | }); |
419 | } | 419 | } |
420 | 420 | ||
421 | KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox, const QString &newName) | 421 | KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox, const QString &newName) |
422 | { | 422 | { |
423 | auto folder = QSharedPointer<QString>::create(); | 423 | return KAsync::start<QString>([this, oldMailbox, newName] { |
424 | return KAsync::start<void, KAsync::Job<void>>([this, oldMailbox, newName, folder]() { | ||
425 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 424 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
426 | auto parts = oldMailbox.split(mPersonalNamespaceSeparator); | 425 | auto parts = oldMailbox.split(mPersonalNamespaceSeparator); |
427 | parts.removeLast(); | 426 | parts.removeLast(); |
428 | *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; | 427 | auto folder = QSharedPointer<QString>::create(parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName); |
429 | SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder; | 428 | SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder; |
430 | return rename(oldMailbox, *folder); | 429 | return rename(oldMailbox, *folder) |
431 | }) | 430 | .syncThen<QString>([=]() { |
432 | .then<QString>([=]() { | 431 | return *folder; |
433 | return *folder; | 432 | }); |
434 | }); | 433 | }); |
435 | } | 434 | } |
436 | 435 | ||
@@ -461,7 +460,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui | |||
461 | auto time = QSharedPointer<QTime>::create(); | 460 | auto time = QSharedPointer<QTime>::create(); |
462 | time->start(); | 461 | time->start(); |
463 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 462 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
464 | return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { | 463 | return select(mailboxFromFolder(folder)).then<void, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { |
465 | 464 | ||
466 | SinkLog() << "UIDNEXT " << selectResult.uidNext << uidNext; | 465 | SinkLog() << "UIDNEXT " << selectResult.uidNext << uidNext; |
467 | if (selectResult.uidNext == (uidNext + 1)) { | 466 | if (selectResult.uidNext == (uidNext + 1)) { |
@@ -469,7 +468,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui | |||
469 | return KAsync::null<void>(); | 468 | return KAsync::null<void>(); |
470 | } | 469 | } |
471 | 470 | ||
472 | return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ | 471 | return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ |
473 | SinkTrace() << "Fetched headers"; | 472 | SinkTrace() << "Fetched headers"; |
474 | SinkTrace() << " Total: " << uidsToFetch.size(); | 473 | SinkTrace() << " Total: " << uidsToFetch.size(); |
475 | SinkTrace() << " Uids to fetch: " << uidsToFetch; | 474 | SinkTrace() << " Uids to fetch: " << uidsToFetch; |
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 392b422..e69d822 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -367,7 +367,7 @@ public: | |||
367 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | 367 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE |
368 | { | 368 | { |
369 | SinkLog() << " Synchronizing"; | 369 | SinkLog() << " Synchronizing"; |
370 | return KAsync::start<void, KAsync::Job<void> >([this]() { | 370 | return KAsync::start<void>([this]() { |
371 | KPIM::Maildir maildir(mMaildirPath, true); | 371 | KPIM::Maildir maildir(mMaildirPath, true); |
372 | if (!maildir.isValid(false)) { | 372 | if (!maildir.isValid(false)) { |
373 | return KAsync::error<void>(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath); | 373 | return KAsync::error<void>(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath); |
@@ -402,18 +402,14 @@ public: | |||
402 | if (operation == Sink::Operation_Creation) { | 402 | if (operation == Sink::Operation_Creation) { |
403 | const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); | 403 | const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); |
404 | SinkTrace() << "Mail created: " << remoteId; | 404 | SinkTrace() << "Mail created: " << remoteId; |
405 | return KAsync::start<QByteArray>([=]() -> QByteArray { | 405 | return KAsync::value(remoteId.toUtf8()); |
406 | return remoteId.toUtf8(); | ||
407 | }); | ||
408 | } else if (operation == Sink::Operation_Removal) { | 406 | } else if (operation == Sink::Operation_Removal) { |
409 | SinkTrace() << "Removing a mail: " << oldRemoteId; | 407 | SinkTrace() << "Removing a mail: " << oldRemoteId; |
410 | return KAsync::null<QByteArray>(); | 408 | return KAsync::null<QByteArray>(); |
411 | } else if (operation == Sink::Operation_Modification) { | 409 | } else if (operation == Sink::Operation_Modification) { |
412 | SinkTrace() << "Modifying a mail: " << oldRemoteId; | 410 | SinkTrace() << "Modifying a mail: " << oldRemoteId; |
413 | const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); | 411 | const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); |
414 | return KAsync::start<QByteArray>([=]() -> QByteArray { | 412 | return KAsync::value(remoteId.toUtf8()); |
415 | return remoteId.toUtf8(); | ||
416 | }); | ||
417 | } | 413 | } |
418 | return KAsync::null<QByteArray>(); | 414 | return KAsync::null<QByteArray>(); |
419 | } | 415 | } |
@@ -427,9 +423,7 @@ public: | |||
427 | SinkTrace() << "Creating a new folder: " << path; | 423 | SinkTrace() << "Creating a new folder: " << path; |
428 | KPIM::Maildir maildir(path, false); | 424 | KPIM::Maildir maildir(path, false); |
429 | maildir.create(); | 425 | maildir.create(); |
430 | return KAsync::start<QByteArray>([=]() -> QByteArray { | 426 | return KAsync::value(path.toUtf8()); |
431 | return path.toUtf8(); | ||
432 | }); | ||
433 | } else if (operation == Sink::Operation_Removal) { | 427 | } else if (operation == Sink::Operation_Removal) { |
434 | const auto path = oldRemoteId; | 428 | const auto path = oldRemoteId; |
435 | SinkTrace() << "Removing a folder: " << path; | 429 | SinkTrace() << "Removing a folder: " << path; |
@@ -438,9 +432,7 @@ public: | |||
438 | return KAsync::null<QByteArray>(); | 432 | return KAsync::null<QByteArray>(); |
439 | } else if (operation == Sink::Operation_Modification) { | 433 | } else if (operation == Sink::Operation_Modification) { |
440 | SinkWarning() << "Folder modifications are not implemented"; | 434 | SinkWarning() << "Folder modifications are not implemented"; |
441 | return KAsync::start<QByteArray>([=]() -> QByteArray { | 435 | return KAsync::value(oldRemoteId); |
442 | return oldRemoteId; | ||
443 | }); | ||
444 | } | 436 | } |
445 | return KAsync::null<QByteArray>(); | 437 | return KAsync::null<QByteArray>(); |
446 | } | 438 | } |
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index a729d4d..be4e4e0 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -124,17 +124,14 @@ public: | |||
124 | }); | 124 | }); |
125 | auto job = KAsync::null<void>(); | 125 | auto job = KAsync::null<void>(); |
126 | for (const auto &m : toSend) { | 126 | for (const auto &m : toSend) { |
127 | job = job.then(send(m, mSettings)).then<void>([this, m]() { | 127 | job = job.then(send(m, mSettings)).syncThen<void>([this, m] { |
128 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, m.identifier(), m.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 128 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, m.identifier(), m.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
129 | modifiedMail.setSent(true); | 129 | modifiedMail.setSent(true); |
130 | modify(modifiedMail); | 130 | modify(modifiedMail); |
131 | //TODO copy to a sent mail folder as well | 131 | //TODO copy to a sent mail folder as well |
132 | }); | 132 | }); |
133 | } | 133 | } |
134 | job = job.then<void>([&future]() { | 134 | job = job.syncThen<void>([&future](const KAsync::Error &) { |
135 | future.setFinished(); | ||
136 | }, | ||
137 | [&future](int errorCode, const QString &errorString) { | ||
138 | future.setFinished(); | 135 | future.setFinished(); |
139 | }); | 136 | }); |
140 | job.exec(); | 137 | job.exec(); |