diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-21 20:39:11 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-15 16:14:19 +0200 |
commit | 07d9eaaa97dfa63bb3ff9767c6b2e152ad8a04e0 (patch) | |
tree | ea8d32e3a213ec9562ceccb66fb24ca6b37621df /examples/imapresource/imapserverproxy.cpp | |
parent | 5f127fa687079c7180142e371c86bd6dacfb845e (diff) | |
download | sink-07d9eaaa97dfa63bb3ff9767c6b2e152ad8a04e0.tar.gz sink-07d9eaaa97dfa63bb3ff9767c6b2e152ad8a04e0.zip |
Prepare incremental syncing.
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 3406315..5fffb36 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <KIMAP/KIMAP/StoreJob> | 33 | #include <KIMAP/KIMAP/StoreJob> |
34 | #include <KIMAP/KIMAP/ExpungeJob> | 34 | #include <KIMAP/KIMAP/ExpungeJob> |
35 | #include <KIMAP/KIMAP/CapabilitiesJob> | 35 | #include <KIMAP/KIMAP/CapabilitiesJob> |
36 | #include <KIMAP/KIMAP/SearchJob> | ||
36 | 37 | ||
37 | #include <KIMAP/KIMAP/SessionUiProxy> | 38 | #include <KIMAP/KIMAP/SessionUiProxy> |
38 | #include <KCoreAddons/KJob> | 39 | #include <KCoreAddons/KJob> |
@@ -188,12 +189,14 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString | |||
188 | }); | 189 | }); |
189 | } | 190 | } |
190 | 191 | ||
191 | KAsync::Job<void> ImapServerProxy::select(const QString &mailbox) | 192 | KAsync::Job<SelectResult> ImapServerProxy::select(const QString &mailbox) |
192 | { | 193 | { |
193 | auto select = new KIMAP::SelectJob(mSession); | 194 | auto select = new KIMAP::SelectJob(mSession); |
194 | select->setMailBox(mailbox); | 195 | select->setMailBox(mailbox); |
195 | // select->setCondstoreEnabled(serverSupportsCondstore()); | 196 | select->setCondstoreEnabled(mCapabilities.contains("CONDSTORE")); |
196 | return runJob(select); | 197 | return runJob<SelectResult>(select, [select](KJob* job) -> SelectResult { |
198 | return {select->uidValidity(), select->nextUid(), select->highestModSequence()}; | ||
199 | }); | ||
197 | } | 200 | } |
198 | 201 | ||
199 | KAsync::Job<qint64> ImapServerProxy::append(const QString &mailbox, const QByteArray &content, const QList<QByteArray> &flags, const QDateTime &internalDate) | 202 | KAsync::Job<qint64> ImapServerProxy::append(const QString &mailbox, const QByteArray &content, const QList<QByteArray> &flags, const QDateTime &internalDate) |
@@ -303,6 +306,16 @@ KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::Fetch | |||
303 | return runJob(fetch); | 306 | return runJob(fetch); |
304 | } | 307 | } |
305 | 308 | ||
309 | KAsync::Job<QVector<qint64>> ImapServerProxy::search(const KIMAP::ImapSet &set) | ||
310 | { | ||
311 | auto search = new KIMAP::SearchJob(mSession); | ||
312 | search->setTerm(KIMAP::Term(KIMAP::Term::Uid, set)); | ||
313 | search->setUidBased(true); | ||
314 | return runJob<QVector<qint64>>(search, [](KJob *job) -> QVector<qint64> { | ||
315 | return static_cast<KIMAP::SearchJob*>(job)->results(); | ||
316 | }); | ||
317 | } | ||
318 | |||
306 | KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback) | 319 | KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback) |
307 | { | 320 | { |
308 | return fetch(set, scope, | 321 | return fetch(set, scope, |
@@ -320,6 +333,11 @@ KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::Fetch | |||
320 | }); | 333 | }); |
321 | } | 334 | } |
322 | 335 | ||
336 | QStringList ImapServerProxy::getCapabilities() const | ||
337 | { | ||
338 | return mCapabilities; | ||
339 | } | ||
340 | |||
323 | KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox) | 341 | KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox) |
324 | { | 342 | { |
325 | auto list = QSharedPointer<QList<qint64>>::create(); | 343 | auto list = QSharedPointer<QList<qint64>>::create(); |
@@ -351,6 +369,11 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox) | |||
351 | }); | 369 | }); |
352 | } | 370 | } |
353 | 371 | ||
372 | KAsync::Job<QVector<qint64>> ImapServerProxy::fetchUids(const QString &mailbox) | ||
373 | { | ||
374 | return select(mailbox).then<QVector<qint64>>(search(KIMAP::ImapSet(1, 0))); | ||
375 | } | ||
376 | |||
354 | KAsync::Job<void> ImapServerProxy::list(KIMAP::ListJob::Option option, const std::function<void(const QList<KIMAP::MailBoxDescriptor> &mailboxes,const QList<QList<QByteArray> > &flags)> &callback) | 377 | KAsync::Job<void> ImapServerProxy::list(KIMAP::ListJob::Option option, const std::function<void(const QList<KIMAP::MailBoxDescriptor> &mailboxes,const QList<QList<QByteArray> > &flags)> &callback) |
355 | { | 378 | { |
356 | auto listJob = new KIMAP::ListJob(mSession); | 379 | auto listJob = new KIMAP::ListJob(mSession); |
@@ -434,12 +457,19 @@ QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const | |||
434 | return folder.pathParts.join(mPersonalNamespaceSeparator); | 457 | return folder.pathParts.join(mPersonalNamespaceSeparator); |
435 | } | 458 | } |
436 | 459 | ||
437 | KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress) | 460 | KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress) |
438 | { | 461 | { |
462 | Q_UNUSED(uidNext); | ||
439 | auto time = QSharedPointer<QTime>::create(); | 463 | auto time = QSharedPointer<QTime>::create(); |
440 | time->start(); | 464 | time->start(); |
441 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 465 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
442 | return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder, time, progress]() -> KAsync::Job<void> { | 466 | return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { |
467 | |||
468 | if (selectResult.uidNext == uidNext) { | ||
469 | SinkTrace() << "Uidnext didn't change, nothing to do."; | ||
470 | return KAsync::null<void>(); | ||
471 | } | ||
472 | |||
443 | return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ | 473 | return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ |
444 | SinkTrace() << "Fetched headers"; | 474 | SinkTrace() << "Fetched headers"; |
445 | SinkTrace() << " Total: " << uidsToFetch.size(); | 475 | SinkTrace() << " Total: " << uidsToFetch.size(); |
@@ -472,3 +502,13 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::func | |||
472 | 502 | ||
473 | }); | 503 | }); |
474 | } | 504 | } |
505 | |||
506 | KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress) | ||
507 | { | ||
508 | return fetchMessages(folder, 0, callback, progress); | ||
509 | } | ||
510 | |||
511 | KAsync::Job<QVector<qint64>> ImapServerProxy::fetchUids(const Folder &folder) | ||
512 | { | ||
513 | return fetchUids(mailboxFromFolder(folder)); | ||
514 | } | ||