From 25fdab9836b1fdd248d3d36c00a96740093cd749 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 14 Sep 2016 10:16:33 +0200 Subject: New kimap2 syntax --- examples/imapresource/imapresource.cpp | 15 ++++++--- examples/imapresource/imapserverproxy.cpp | 39 +++++----------------- examples/imapresource/imapserverproxy.h | 13 +++----- .../imapresource/tests/imapserverproxytest.cpp | 24 +++---------- 4 files changed, 28 insertions(+), 63 deletions(-) (limited to 'examples') diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 8422b49..c26dc39 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -220,10 +220,9 @@ public: auto capabilities = imap->getCapabilities(); bool canDoIncrementalRemovals = false; return KAsync::start([=]() { + auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(); - // auto changedsince = QSharedPointer::create(0); - //FIXME this should generate a compiletime error - return imap->fetchFlags(folder, changedsince, [this, folder](const QVector &messages) { + return imap->fetchFlags(folder, KIMAP2::ImapSet(1, qMax(uidNext, qint64(1))), changedsince, [this, folder](const QVector &messages) { // synchronizeMails(folder.normalizedPath(), messages); const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folder.normalizedPath().toUtf8()); for (const auto &message : messages) { @@ -266,11 +265,17 @@ public: } synchronizeMails(folder.normalizedPath(), messages); }, - [](int progress, int total) { - SinkTrace() << "Progress: " << progress << " out of " << total; + [this, maxUid, folder](int progress, int total) { + SinkLog() << "Progress: " << progress << " out of " << total; + //commit every 10 messages + if ((progress % 10) == 0) { + commit(); + } }) .syncThen([this, maxUid, folder]() { syncStore().writeValue(folder.normalizedPath().toUtf8() + "uidnext", QByteArray::number(*maxUid)); + SinkLog() << "UIDMAX: " << *maxUid << folder.normalizedPath(); + commit(); }); }); 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 ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::Fet fetch->setSequenceSet(set); fetch->setUidBased(true); fetch->setScope(scope); - QObject::connect(fetch, static_cast &, - const QMap &, - const QMap &, - const QMap &, - const QMap &)>(&KIMAP2::FetchJob::headersReceived), - callback); + QObject::connect(fetch, &KIMAP2::FetchJob::resultReceived, callback); return runJob(fetch); } @@ -280,16 +274,9 @@ KAsync::Job> ImapServerProxy::search(const KIMAP2::ImapSet &set) KAsync::Job ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function &)> &callback) { return fetch(set, scope, - [callback](const QString &mailbox, - const QMap &uids, - const QMap &sizes, - const QMap &attrs, - const QMap &flags, - const QMap &messages) { + [callback](const KIMAP2::FetchJob::Result &result) { QVector list; - for (const auto &id : uids.keys()) { - list << Message{uids.value(id), sizes.value(id), attrs.value(id), flags.value(id), messages.value(id)}; - } + list << Message{result.uid, result.size, result.attributes, result.flags, result.message}; callback(list); }); } @@ -307,22 +294,13 @@ KAsync::Job> ImapServerProxy::fetchHeaders(const QString &mailbox, //Fetch headers of all messages return fetch(KIMAP2::ImapSet(minUid, 0), scope, - [list](const QString &mailbox, - const QMap &uids, - const QMap &sizes, - const QMap &attrs, - const QMap &flags, - const QMap &messages) { - SinkTrace() << "Received " << uids.size() << " headers from " << mailbox; - SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); + [list](const KIMAP2::FetchJob::Result &result) { //TODO based on the data available here, figure out which messages to actually fetch //(we only fetched headers and structure so far) //We could i.e. build chunks to fetch based on the size - for (const auto &id : uids.keys()) { - list->append(uids.value(id)); - } + list->append(result.uid); }) .syncThen>([list](){ return *list; @@ -416,7 +394,7 @@ QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const return folder.pathParts.join(mPersonalNamespaceSeparator); } -KAsync::Job ImapServerProxy::fetchFlags(const Folder &folder, qint64 changedsince, std::function &)> callback) +KAsync::Job ImapServerProxy::fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function &)> callback) { SinkTrace() << "Fetching flags " << folder.normalizedPath(); return select(mailboxFromFolder(folder)).then([=](const SelectResult &selectResult) -> KAsync::Job { @@ -427,13 +405,13 @@ KAsync::Job ImapServerProxy::fetchFlags(const Folder &folder, qint return KAsync::value(selectResult); } - SinkTrace() << "Fetching flags " << folder.normalizedPath() << selectResult.highestModSequence << changedsince; + SinkTrace() << "Fetching flags " << folder.normalizedPath() << set << selectResult.highestModSequence << changedsince; KIMAP2::FetchJob::FetchScope scope; scope.mode = KIMAP2::FetchJob::FetchScope::Flags; scope.changedSince = changedsince; - return fetch(KIMAP2::ImapSet(1, 0), scope, callback).syncThen([selectResult] { + return fetch(set, scope, callback).syncThen([selectResult] { return selectResult; }); }); @@ -451,6 +429,7 @@ KAsync::Job ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui return KAsync::null(); } + SinkTrace() << "Fetching messages from " << folder.normalizedPath() << selectResult.uidNext << uidNext; return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then>([this, callback, time, progress, folder](const QList &uidsToFetch){ SinkTrace() << "Fetched headers" << folder.normalizedPath(); SinkTrace() << " Total: " << uidsToFetch.size(); diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index ff87d47..e0e87d4 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h @@ -51,8 +51,8 @@ namespace FolderFlags struct Message { qint64 uid; qint64 size; - QPair attributes; - QList flags; + KIMAP2::MessageAttributes attributes; + KIMAP2::MessageFlags flags; KMime::Message::Ptr msg; }; @@ -111,12 +111,7 @@ public: KAsync::Job copy(const KIMAP2::ImapSet &set, const QString &newMailbox); KAsync::Job> search(const KIMAP2::ImapSet &set); - typedef std::function &, - const QMap &, - const QMap &, - const QMap &, - const QMap &)> FetchCallback; + typedef std::function FetchCallback; KAsync::Job fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, FetchCallback callback); KAsync::Job fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function &)> &callback); @@ -138,7 +133,7 @@ public: KAsync::Job fetchFolders(std::function &)> callback); KAsync::Job fetchMessages(const Folder &folder, std::function &)> callback, std::function progress = std::function()); KAsync::Job fetchMessages(const Folder &folder, qint64 uidNext, std::function &)> callback, std::function progress = std::function()); - KAsync::Job fetchFlags(const Folder &folder, qint64 changedsince, std::function &)> callback); + KAsync::Job fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function &)> callback); KAsync::Job> fetchUids(const Folder &folder); private: diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index 21c2248..1bd5982 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp @@ -12,7 +12,7 @@ using namespace Imap; -SINK_DEBUG_AREA("imapserverproxytest") +// SINK_DEBUG_AREA("imapserverproxytest") /** */ @@ -77,15 +77,8 @@ private slots: scope.mode = KIMAP2::FetchJob::FetchScope::Headers; int count = 0; auto job = imap.select("INBOX.test").then(imap.fetch(KIMAP2::ImapSet::fromImapSequenceSet("1:*"), scope, - [&count](const QString &mailbox, - const QMap &uids, - const QMap &sizes, - const QMap &attrs, - const QMap &flags, - const QMap &messages) { - SinkTrace() << "Received " << uids.size() << " messages from " << mailbox; - SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); - count += uids.size(); + [&count](const KIMAP2::FetchJob::Result &) { + count++; })); VERIFYEXEC(job); @@ -102,15 +95,8 @@ private slots: scope.mode = KIMAP2::FetchJob::FetchScope::Headers; int count = 0; auto job = imap.select("INBOX.test").then(imap.fetch(KIMAP2::ImapSet::fromImapSequenceSet("1:*"), scope, - [&count](const QString &mailbox, - const QMap &uids, - const QMap &sizes, - const QMap &attrs, - const QMap &flags, - const QMap &messages) { - SinkTrace() << "Received " << uids.size() << " messages from " << mailbox; - SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); - count += uids.size(); + [&count](const KIMAP2::FetchJob::Result &) { + count++; })); VERIFYEXEC(job); -- cgit v1.2.3