summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/imapresource/imapresource.cpp66
1 files changed, 33 insertions, 33 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index c608b04..25d905b 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -260,7 +260,7 @@ public:
260 //Next we synchronize the full set that is given by the date limit. 260 //Next we synchronize the full set that is given by the date limit.
261 //We fetch all data for this set. 261 //We fetch all data for this set.
262 //This will also pull in any new messages in subsequent runs. 262 //This will also pull in any new messages in subsequent runs.
263 .then<void>([=]() { 263 .then([=] {
264 auto job = [&] { 264 auto job = [&] {
265 SinkLogCtx(mLogCtx) << "Fetching messages since: " << dateFilter; 265 SinkLogCtx(mLogCtx) << "Fetching messages since: " << dateFilter;
266 if (dateFilter.isValid()) { 266 if (dateFilter.isValid()) {
@@ -269,7 +269,7 @@ public:
269 return imap->fetchUids(imap->mailboxFromFolder(folder)); 269 return imap->fetchUids(imap->mailboxFromFolder(folder));
270 } 270 }
271 }(); 271 }();
272 return job.then<void, QVector<qint64>>([=](const QVector<qint64> &uidsToFetch) { 272 return job.then([=](const QVector<qint64> &uidsToFetch) {
273 SinkTraceCtx(mLogCtx) << "Received result set " << uidsToFetch; 273 SinkTraceCtx(mLogCtx) << "Received result set " << uidsToFetch;
274 SinkTraceCtx(mLogCtx) << "About to fetch mail" << folder.path(); 274 SinkTraceCtx(mLogCtx) << "About to fetch mail" << folder.path();
275 const auto uidNext = syncStore().readValue(folderRemoteId, "uidnext").toLongLong(); 275 const auto uidNext = syncStore().readValue(folderRemoteId, "uidnext").toLongLong();
@@ -303,7 +303,7 @@ public:
303 commit(); 303 commit();
304 } 304 }
305 }) 305 })
306 .then([=]() { 306 .then([=] {
307 SinkLogCtx(mLogCtx) << "UIDMAX: " << *maxUid << folder.path(); 307 SinkLogCtx(mLogCtx) << "UIDMAX: " << *maxUid << folder.path();
308 if (*maxUid > 0) { 308 if (*maxUid > 0) {
309 syncStore().writeValue(folderRemoteId, "uidnext", QByteArray::number(*maxUid)); 309 syncStore().writeValue(folderRemoteId, "uidnext", QByteArray::number(*maxUid));
@@ -321,7 +321,7 @@ public:
321 SinkLogCtx(mLogCtx) << "Fetching headers until: " << fullsetLowerbound; 321 SinkLogCtx(mLogCtx) << "Fetching headers until: " << fullsetLowerbound;
322 322
323 return imap->fetchUids(imap->mailboxFromFolder(folder)) 323 return imap->fetchUids(imap->mailboxFromFolder(folder))
324 .then<void, QVector<qint64>>([=] (const QVector<qint64> &uids) { 324 .then([=] (const QVector<qint64> &uids) {
325 //sort in reverse order and remove everything greater than fullsetLowerbound 325 //sort in reverse order and remove everything greater than fullsetLowerbound
326 QVector<qint64> toFetch = uids; 326 QVector<qint64> toFetch = uids;
327 qSort(toFetch.begin(), toFetch.end(), qGreater<qint64>()); 327 qSort(toFetch.begin(), toFetch.end(), qGreater<qint64>());
@@ -345,7 +345,7 @@ public:
345 } 345 }
346 }); 346 });
347 }) 347 })
348 .then([=]() { 348 .then([=] {
349 SinkLogCtx(mLogCtx) << "Headers fetched: " << folder.path(); 349 SinkLogCtx(mLogCtx) << "Headers fetched: " << folder.path();
350 syncStore().writeValue(folderRemoteId, "headersFetched", "true"); 350 syncStore().writeValue(folderRemoteId, "headersFetched", "true");
351 commit(); 351 commit();
@@ -357,7 +357,7 @@ public:
357 return KAsync::null(); 357 return KAsync::null();
358 }) 358 })
359 //Finally remove messages that are no longer existing on the server. 359 //Finally remove messages that are no longer existing on the server.
360 .then<void>([=]() { 360 .then([=] {
361 //TODO do an examine with QRESYNC and remove VANISHED messages if supported instead 361 //TODO do an examine with QRESYNC and remove VANISHED messages if supported instead
362 return imap->fetchUids(folder).then([=](const QVector<qint64> &uids) { 362 return imap->fetchUids(folder).then([=](const QVector<qint64> &uids) {
363 SinkTraceCtx(mLogCtx) << "Syncing removals: " << folder.path(); 363 SinkTraceCtx(mLogCtx) << "Syncing removals: " << folder.path();
@@ -425,7 +425,7 @@ public:
425 .onError([](const KAsync::Error &error) { 425 .onError([](const KAsync::Error &error) {
426 SinkWarning() << "Folder list sync failed."; 426 SinkWarning() << "Folder list sync failed.";
427 }) 427 })
428 .then([folderList]() { return *folderList; } ); 428 .then([folderList] { return *folderList; } );
429 } 429 }
430 } 430 }
431 431
@@ -434,7 +434,7 @@ public:
434 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); 434 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort);
435 if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { 435 if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) {
436 return login(imap) 436 return login(imap)
437 .then<void>([=]() { 437 .then([=] {
438 auto folderList = QSharedPointer<QVector<Folder>>::create(); 438 auto folderList = QSharedPointer<QVector<Folder>>::create();
439 return imap->fetchFolders([folderList](const Folder &folder) { 439 return imap->fetchFolders([folderList](const Folder &folder) {
440 *folderList << folder; 440 *folderList << folder;
@@ -443,7 +443,7 @@ public:
443 synchronizeFolders(*folderList); 443 synchronizeFolders(*folderList);
444 }); 444 });
445 }) 445 })
446 .then<void>([=] (const KAsync::Error &error) { 446 .then([=] (const KAsync::Error &error) {
447 if (error) { 447 if (error) {
448 SinkWarning() << "Error during folder sync: " << error.errorMessage; 448 SinkWarning() << "Error during folder sync: " << error.errorMessage;
449 } 449 }
@@ -460,7 +460,7 @@ public:
460 //if we have no folder filter: 460 //if we have no folder filter:
461 //* fetch list of folders from server directly and sync (because we have no guarantee that the folder sync was already processed by the pipeline). 461 //* fetch list of folders from server directly and sync (because we have no guarantee that the folder sync was already processed by the pipeline).
462 return login(imap) 462 return login(imap)
463 .then<void>([=] () -> KAsync::Job<void> { 463 .then([=] {
464 if (!query.ids().isEmpty()) { 464 if (!query.ids().isEmpty()) {
465 //If we have mail id's simply fetch the full payload of those mails 465 //If we have mail id's simply fetch the full payload of those mails
466 QVector<qint64> toFetch; 466 QVector<qint64> toFetch;
@@ -495,7 +495,7 @@ public:
495 bool syncHeaders = query.hasFilter<ApplicationDomain::Mail::Folder>(); 495 bool syncHeaders = query.hasFilter<ApplicationDomain::Mail::Folder>();
496 //FIXME If we were able to to flush in between we could just query the local store for the folder list. 496 //FIXME If we were able to to flush in between we could just query the local store for the folder list.
497 return getFolderList(imap, query) 497 return getFolderList(imap, query)
498 .then<void, QVector<Folder>>([=] (const QVector<Folder> &folders) { 498 .then([=] (const QVector<Folder> &folders) {
499 //Synchronize folders 499 //Synchronize folders
500 return KAsync::value(folders) 500 return KAsync::value(folders)
501 .serialEach<void>([=](const Folder &folder) { 501 .serialEach<void>([=](const Folder &folder) {
@@ -514,7 +514,7 @@ public:
514 }); 514 });
515 } 515 }
516 }) 516 })
517 .then<void>([=] (const KAsync::Error &error) { 517 .then([=] (const KAsync::Error &error) {
518 if (error) { 518 if (error) {
519 SinkWarning() << "Error during sync: " << error.errorMessage; 519 SinkWarning() << "Error during sync: " << error.errorMessage;
520 } 520 }
@@ -574,7 +574,7 @@ public:
574 set.add(uid); 574 set.add(uid);
575 job = login.then(imap->append(mailbox, content, flags, internalDate)) 575 job = login.then(imap->append(mailbox, content, flags, internalDate))
576 .addToContext(imap) 576 .addToContext(imap)
577 .then<QByteArray, qint64>([=](qint64 uid) { 577 .then([=](qint64 uid) {
578 const auto remoteId = assembleMailRid(mail, uid); 578 const auto remoteId = assembleMailRid(mail, uid);
579 SinkTrace() << "Finished creating a modified mail: " << remoteId; 579 SinkTrace() << "Finished creating a modified mail: " << remoteId;
580 return imap->remove(oldMailbox, set).then(KAsync::value(remoteId)); 580 return imap->remove(oldMailbox, set).then(KAsync::value(remoteId));
@@ -593,14 +593,14 @@ public:
593 } 593 }
594 } 594 }
595 return job 595 return job
596 .then<QByteArray, QByteArray>([=] (const KAsync::Error &error, const QByteArray &remoteId) { 596 .then([=] (const KAsync::Error &error, const QByteArray &remoteId) {
597 if (error) { 597 if (error) {
598 SinkWarning() << "Error during changereplay: " << error.errorMessage; 598 SinkWarning() << "Error during changereplay: " << error.errorMessage;
599 return imap->logout() 599 return imap->logout()
600 .then<QByteArray>(KAsync::error<QByteArray>(error)); 600 .then(KAsync::error<QByteArray>(error));
601 } 601 }
602 return imap->logout() 602 return imap->logout()
603 .then<QByteArray>(KAsync::value(remoteId)); 603 .then(KAsync::value(remoteId));
604 }); 604 });
605 } 605 }
606 606
@@ -615,7 +615,7 @@ public:
615 } 615 }
616 SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName(); 616 SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName();
617 auto rid = QSharedPointer<QByteArray>::create(); 617 auto rid = QSharedPointer<QByteArray>::create();
618 auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName())) 618 auto createFolder = login.then(imap->createSubfolder(parentFolder, folder.getName()))
619 .then([imap, rid](const QString &createdFolder) { 619 .then([imap, rid](const QString &createdFolder) {
620 SinkTrace() << "Finished creating a new folder: " << createdFolder; 620 SinkTrace() << "Finished creating a new folder: " << createdFolder;
621 *rid = createdFolder.toUtf8(); 621 *rid = createdFolder.toUtf8();
@@ -628,12 +628,12 @@ public:
628 } else { //We try to merge special purpose folders first 628 } else { //We try to merge special purpose folders first
629 auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create(); 629 auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create();
630 auto mergeJob = imap->login(mUser, mPassword) 630 auto mergeJob = imap->login(mUser, mPassword)
631 .then<void>(imap->fetchFolders([=](const Imap::Folder &folder) { 631 .then(imap->fetchFolders([=](const Imap::Folder &folder) {
632 if (SpecialPurpose::isSpecialPurposeFolderName(folder.name())) { 632 if (SpecialPurpose::isSpecialPurposeFolderName(folder.name())) {
633 specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.name()), folder.path()); 633 specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.name()), folder.path());
634 }; 634 };
635 })) 635 }))
636 .then<void>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> { 636 .then([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> {
637 for (const auto &purpose : folder.getSpecialPurpose()) { 637 for (const auto &purpose : folder.getSpecialPurpose()) {
638 if (specialPurposeFolders->contains(purpose)) { 638 if (specialPurposeFolders->contains(purpose)) {
639 auto f = specialPurposeFolders->value(purpose); 639 auto f = specialPurposeFolders->value(purpose);
@@ -657,20 +657,20 @@ public:
657 } 657 }
658 } else if (operation == Sink::Operation_Removal) { 658 } else if (operation == Sink::Operation_Removal) {
659 SinkTrace() << "Removing a folder: " << oldRemoteId; 659 SinkTrace() << "Removing a folder: " << oldRemoteId;
660 return login.then<void>(imap->remove(oldRemoteId)) 660 return login.then(imap->remove(oldRemoteId))
661 .then([oldRemoteId, imap]() { 661 .then([oldRemoteId, imap] {
662 SinkTrace() << "Finished removing a folder: " << oldRemoteId; 662 SinkTrace() << "Finished removing a folder: " << oldRemoteId;
663 return QByteArray(); 663 return QByteArray();
664 }); 664 });
665 } else if (operation == Sink::Operation_Modification) { 665 } else if (operation == Sink::Operation_Modification) {
666 SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName(); 666 SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName();
667 auto rid = QSharedPointer<QByteArray>::create(); 667 auto rid = QSharedPointer<QByteArray>::create();
668 return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName())) 668 return login.then(imap->renameSubfolder(oldRemoteId, folder.getName()))
669 .then([imap, rid](const QString &createdFolder) { 669 .then([imap, rid](const QString &createdFolder) {
670 SinkTrace() << "Finished renaming a folder: " << createdFolder; 670 SinkTrace() << "Finished renaming a folder: " << createdFolder;
671 *rid = createdFolder.toUtf8(); 671 *rid = createdFolder.toUtf8();
672 }) 672 })
673 .then([rid](){ 673 .then([rid] {
674 return *rid; 674 return *rid;
675 }); 675 });
676 } 676 }
@@ -730,15 +730,15 @@ protected:
730 SinkTrace() << "Connecting to:" << mServer << mPort; 730 SinkTrace() << "Connecting to:" << mServer << mPort;
731 SinkTrace() << "as:" << mUser; 731 SinkTrace() << "as:" << mUser;
732 auto inspectionJob = imap->login(mUser, mPassword) 732 auto inspectionJob = imap->login(mUser, mPassword)
733 .then<Imap::SelectResult>(imap->select(folderRemoteId)) 733 .then(imap->select(folderRemoteId))
734 .then([](Imap::SelectResult){}) 734 .then([](Imap::SelectResult){})
735 .then<void>(imap->fetch(set, scope, [imap, messageByUid](const Imap::Message &message) { 735 .then(imap->fetch(set, scope, [imap, messageByUid](const Imap::Message &message) {
736 messageByUid->insert(message.uid, message); 736 messageByUid->insert(message.uid, message);
737 })); 737 }));
738 738
739 if (inspectionType == Sink::ResourceControl::Inspection::PropertyInspectionType) { 739 if (inspectionType == Sink::ResourceControl::Inspection::PropertyInspectionType) {
740 if (property == "unread") { 740 if (property == "unread") {
741 return inspectionJob.then<void>([=]() { 741 return inspectionJob.then([=] {
742 auto msg = messageByUid->value(uid); 742 auto msg = messageByUid->value(uid);
743 if (expectedValue.toBool() && msg.flags.contains(Imap::Flags::Seen)) { 743 if (expectedValue.toBool() && msg.flags.contains(Imap::Flags::Seen)) {
744 return KAsync::error<void>(1, "Expected unread but couldn't find it."); 744 return KAsync::error<void>(1, "Expected unread but couldn't find it.");
@@ -750,7 +750,7 @@ protected:
750 }); 750 });
751 } 751 }
752 if (property == "subject") { 752 if (property == "subject") {
753 return inspectionJob.then<void>([=]() { 753 return inspectionJob.then([=] {
754 auto msg = messageByUid->value(uid); 754 auto msg = messageByUid->value(uid);
755 if (msg.msg->subject(true)->asUnicodeString() != expectedValue.toString()) { 755 if (msg.msg->subject(true)->asUnicodeString() != expectedValue.toString()) {
756 return KAsync::error<void>(1, "Subject not as expected: " + msg.msg->subject(true)->asUnicodeString()); 756 return KAsync::error<void>(1, "Subject not as expected: " + msg.msg->subject(true)->asUnicodeString());
@@ -760,7 +760,7 @@ protected:
760 } 760 }
761 } 761 }
762 if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { 762 if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) {
763 return inspectionJob.then<void>([=]() { 763 return inspectionJob.then([=] {
764 if (!messageByUid->contains(uid)) { 764 if (!messageByUid->contains(uid)) {
765 SinkWarning() << "Existing messages are: " << messageByUid->keys(); 765 SinkWarning() << "Existing messages are: " << messageByUid->keys();
766 SinkWarning() << "We're looking for: " << uid; 766 SinkWarning() << "We're looking for: " << uid;
@@ -792,11 +792,11 @@ protected:
792 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); 792 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort);
793 auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); 793 auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create();
794 return imap->login(mUser, mPassword) 794 return imap->login(mUser, mPassword)
795 .then<void>(imap->select(remoteId).then([](){})) 795 .then(imap->select(remoteId))
796 .then<void>(imap->fetch(set, scope, [=](const Imap::Message message) { 796 .then(imap->fetch(set, scope, [=](const Imap::Message message) {
797 messageByUid->insert(message.uid, message); 797 messageByUid->insert(message.uid, message);
798 })) 798 }))
799 .then<void>([imap, messageByUid, expectedCount]() { 799 .then([imap, messageByUid, expectedCount] {
800 if (messageByUid->size() != expectedCount) { 800 if (messageByUid->size() != expectedCount) {
801 return KAsync::error<void>(1, QString("Wrong number of messages on the server; found %1 instead of %2.").arg(messageByUid->size()).arg(expectedCount)); 801 return KAsync::error<void>(1, QString("Wrong number of messages on the server; found %1 instead of %2.").arg(messageByUid->size()).arg(expectedCount));
802 } 802 }
@@ -809,11 +809,11 @@ protected:
809 809
810 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); 810 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort);
811 auto inspectionJob = imap->login(mUser, mPassword) 811 auto inspectionJob = imap->login(mUser, mPassword)
812 .then<void>(imap->fetchFolders([=](const Imap::Folder &f) { 812 .then(imap->fetchFolders([=](const Imap::Folder &f) {
813 *folderByPath << f.path(); 813 *folderByPath << f.path();
814 *folderByName << f.name(); 814 *folderByName << f.name();
815 })) 815 }))
816 .then<void>([this, folderByName, folderByPath, folder, remoteId, imap]() { 816 .then([this, folderByName, folderByPath, folder, remoteId, imap] {
817 if (!folderByName->contains(folder.getName())) { 817 if (!folderByName->contains(folder.getName())) {
818 SinkWarning() << "Existing folders are: " << *folderByPath; 818 SinkWarning() << "Existing folders are: " << *folderByPath;
819 SinkWarning() << "We're looking for: " << folder.getName(); 819 SinkWarning() << "We're looking for: " << folder.getName();