From 07d9eaaa97dfa63bb3ff9767c6b2e152ad8a04e0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 21 Jul 2016 20:39:11 +0200 Subject: Prepare incremental syncing. --- examples/imapresource/imapresource.cpp | 67 +++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 26 deletions(-) (limited to 'examples/imapresource/imapresource.cpp') diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 24fd426..3ad80f9 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -211,14 +211,49 @@ public: SinkLog() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; } + KAsync::Job synchronizeFolder(QSharedPointer imap, const Imap::Folder &folder) + { + QSet uids; + SinkLog() << "Synchronizing mails" << folder.normalizedPath(); + auto capabilities = imap->getCapabilities(); + bool canDoIncrementalRemovals = false; + return KAsync::start([=]() { + //TODO update flags + }) + .then>([=]() { + //TODO Remove what's no longer existing + if (canDoIncrementalRemovals) { + } else { + return imap->fetchUids(folder).then>([this, folder](const QVector &uids) { + SinkTrace() << "Syncing removals"; + synchronizeRemovals(folder.normalizedPath(), uids.toList().toSet()); + commit(); + }).then([](){}); + } + return KAsync::null(); + }) + .then>([this, folder, imap]() { + auto uidNext = 0; + return imap->fetchMessages(folder, uidNext, [this, folder](const QVector &messages) { + SinkTrace() << "Got mail"; + synchronizeMails(folder.normalizedPath(), messages); + }, + [](int progress, int total) { + SinkTrace() << "Progress: " << progress << " out of " << total; + }); + }); + + + } + KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE { SinkLog() << " Synchronizing"; return KAsync::start([this](KAsync::Future future) { SinkTrace() << "Connecting to:" << mServer << mPort; SinkTrace() << "as:" << mUser; - ImapServerProxy imap(mServer, mPort); - auto loginFuture = imap.login(mUser, mPassword).exec(); + auto imap = QSharedPointer::create(mServer, mPort); + auto loginFuture = imap->login(mUser, mPassword).exec(); loginFuture.waitForFinished(); if (loginFuture.errorCode()) { SinkWarning() << "Login failed."; @@ -229,7 +264,7 @@ public: } QVector folderList; - auto folderFuture = imap.fetchFolders([this, &imap, &folderList](const QVector &folders) { + auto folderFuture = imap->fetchFolders([this, &imap, &folderList](const QVector &folders) { synchronizeFolders(folders); commit(); folderList << folders; @@ -248,27 +283,7 @@ public: if (folder.noselect) { continue; } - QSet uids; - SinkLog() << "Synchronizing mails" << folder.normalizedPath(); - auto messagesFuture = imap.fetchMessages(folder, [this, folder, &uids](const QVector &messages) { - for (const auto &msg : messages) { - uids << msg.uid; - } - synchronizeMails(folder.normalizedPath(), messages); - }, - [](int progress, int total) { - SinkTrace() << "Progress: " << progress << " out of " << total; - }).exec(); - messagesFuture.waitForFinished(); - commit(); - if (messagesFuture.errorCode()) { - SinkWarning() << "Folder sync failed: " << folder.normalizedPath(); - continue; - } - //Remove what there is to remove - synchronizeRemovals(folder.normalizedPath(), uids); - commit(); - SinkTrace() << "Folder synchronized: " << folder.normalizedPath(); + synchronizeFolder(imap, folder).exec().waitForFinished(); } future.setFinished(); }); @@ -541,7 +556,7 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in SinkTrace() << "Connecting to:" << mServer << mPort; SinkTrace() << "as:" << mUser; auto inspectionJob = imap->login(mUser, mPassword) - .then(imap->select(folderRemoteId)) + .then(imap->select(folderRemoteId).then([](){})) .then(imap->fetch(set, scope, [imap, messageByUid](const QVector &messages) { for (const auto &m : messages) { messageByUid->insert(m.uid, m); @@ -604,7 +619,7 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in auto imap = QSharedPointer::create(mServer, mPort); auto messageByUid = QSharedPointer>::create(); auto inspectionJob = imap->login(mUser, mPassword) - .then(imap->select(remoteId)) + .then(imap->select(remoteId).then([](){})) .then(imap->fetch(set, scope, [=](const QVector &messages) { for (const auto &m : messages) { messageByUid->insert(m.uid, m); -- cgit v1.2.3