diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-08-30 00:35:03 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-15 16:14:19 +0200 |
commit | 4cd598035dcc297ad3a3af16fb5eda218c018a16 (patch) | |
tree | 1f2101c284d5aa0fdcba525f64ac18c2652df10f | |
parent | 8a0a4de6c51d5ef23ae86655a63536bd8386c575 (diff) | |
download | sink-4cd598035dcc297ad3a3af16fb5eda218c018a16.tar.gz sink-4cd598035dcc297ad3a3af16fb5eda218c018a16.zip |
Flag updates
-rw-r--r-- | examples/imapresource/imapresource.cpp | 19 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 29 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 1 | ||||
-rw-r--r-- | examples/imapresource/tests/imapmailsynctest.cpp | 8 | ||||
-rw-r--r-- | examples/maildirresource/tests/maildirmailsynctest.cpp | 7 | ||||
-rw-r--r-- | tests/mailsynctest.cpp | 38 | ||||
-rw-r--r-- | tests/mailsynctest.h | 2 |
7 files changed, 97 insertions, 7 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index aad7887..3a7be2d 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -219,8 +219,23 @@ public: | |||
219 | SinkLog() << "Synchronizing mails" << folder.normalizedPath(); | 219 | SinkLog() << "Synchronizing mails" << folder.normalizedPath(); |
220 | auto capabilities = imap->getCapabilities(); | 220 | auto capabilities = imap->getCapabilities(); |
221 | bool canDoIncrementalRemovals = false; | 221 | bool canDoIncrementalRemovals = false; |
222 | return KAsync::syncStart<void>([=]() { | 222 | return KAsync::start<void>([=]() { |
223 | //TODO update flags | 223 | const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(); |
224 | // auto changedsince = QSharedPointer<qint64>::create(0); | ||
225 | //FIXME this should generate a compiletime error | ||
226 | return imap->fetchFlags(folder, changedsince, [this, folder](const QVector<Message> &messages) { | ||
227 | // synchronizeMails(folder.normalizedPath(), messages); | ||
228 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folder.normalizedPath().toUtf8()); | ||
229 | for (const auto &message : messages) { | ||
230 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); | ||
231 | |||
232 | |||
233 | auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); | ||
234 | mail.setUnread(!message.flags.contains(Imap::Flags::Seen)); | ||
235 | mail.setImportant(message.flags.contains(Imap::Flags::Flagged)); | ||
236 | createOrModify(ENTITY_TYPE_MAIL, remoteId, mail); | ||
237 | } | ||
238 | }); | ||
224 | }) | 239 | }) |
225 | .then<void>([=]() { | 240 | .then<void>([=]() { |
226 | //TODO Remove what's no longer existing | 241 | //TODO Remove what's no longer existing |
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 25cbc57..4ce413a 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -416,6 +416,27 @@ QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const | |||
416 | return folder.pathParts.join(mPersonalNamespaceSeparator); | 416 | return folder.pathParts.join(mPersonalNamespaceSeparator); |
417 | } | 417 | } |
418 | 418 | ||
419 | KAsync::Job<void> ImapServerProxy::fetchFlags(const Folder &folder, qint64 changedsince, std::function<void(const QVector<Message> &)> callback) | ||
420 | { | ||
421 | SinkTrace() << "Fetching flags " << folder.normalizedPath(); | ||
422 | return select(mailboxFromFolder(folder)).then<void, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<void> { | ||
423 | SinkTrace() << "Modeseq " << folder.normalizedPath() << selectResult.highestModSequence << changedsince; | ||
424 | |||
425 | if (selectResult.highestModSequence == static_cast<quint64>(changedsince)) { | ||
426 | SinkTrace()<< folder.normalizedPath() << "Changedsince didn't change, nothing to do."; | ||
427 | return KAsync::null<void>(); | ||
428 | } | ||
429 | |||
430 | SinkTrace() << "Fetching flags " << folder.normalizedPath() << selectResult.highestModSequence << changedsince; | ||
431 | |||
432 | KIMAP2::FetchJob::FetchScope scope; | ||
433 | scope.mode = KIMAP2::FetchJob::FetchScope::Flags; | ||
434 | scope.changedSince = changedsince; | ||
435 | |||
436 | return fetch(KIMAP2::ImapSet(1, 0), scope, callback); | ||
437 | }); | ||
438 | } | ||
439 | |||
419 | KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress) | 440 | KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress) |
420 | { | 441 | { |
421 | auto time = QSharedPointer<QTime>::create(); | 442 | auto time = QSharedPointer<QTime>::create(); |
@@ -423,14 +444,14 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui | |||
423 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 444 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
424 | return select(mailboxFromFolder(folder)).then<void, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { | 445 | return select(mailboxFromFolder(folder)).then<void, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { |
425 | 446 | ||
426 | SinkLog() << "UIDNEXT " << selectResult.uidNext << uidNext; | 447 | SinkTrace() << "UIDNEXT " << folder.normalizedPath() << selectResult.uidNext << uidNext; |
427 | if (selectResult.uidNext == (uidNext + 1)) { | 448 | if (selectResult.uidNext == (uidNext + 1)) { |
428 | SinkTrace() << "Uidnext didn't change, nothing to do."; | 449 | SinkTrace()<< folder.normalizedPath() << "Uidnext didn't change, nothing to do."; |
429 | return KAsync::null<void>(); | 450 | return KAsync::null<void>(); |
430 | } | 451 | } |
431 | 452 | ||
432 | return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ | 453 | return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress, folder](const QList<qint64> &uidsToFetch){ |
433 | SinkTrace() << "Fetched headers"; | 454 | SinkTrace() << "Fetched headers" << folder.normalizedPath(); |
434 | SinkTrace() << " Total: " << uidsToFetch.size(); | 455 | SinkTrace() << " Total: " << uidsToFetch.size(); |
435 | SinkTrace() << " Uids to fetch: " << uidsToFetch; | 456 | SinkTrace() << " Uids to fetch: " << uidsToFetch; |
436 | SinkTrace() << " Took: " << Sink::Log::TraceTime(time->elapsed()); | 457 | SinkTrace() << " Took: " << Sink::Log::TraceTime(time->elapsed()); |
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 9adce3d..83efc38 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -138,6 +138,7 @@ public: | |||
138 | KAsync::Job<void> fetchFolders(std::function<void(const QVector<Folder> &)> callback); | 138 | KAsync::Job<void> fetchFolders(std::function<void(const QVector<Folder> &)> callback); |
139 | KAsync::Job<void> fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>()); | 139 | KAsync::Job<void> fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>()); |
140 | KAsync::Job<void> fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>()); | 140 | KAsync::Job<void> fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>()); |
141 | KAsync::Job<void> fetchFlags(const Folder &folder, qint64 changedsince, std::function<void(const QVector<Message> &)> callback); | ||
141 | KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); | 142 | KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); |
142 | 143 | ||
143 | private: | 144 | private: |
diff --git a/examples/imapresource/tests/imapmailsynctest.cpp b/examples/imapresource/tests/imapmailsynctest.cpp index fcc659d..f908412 100644 --- a/examples/imapresource/tests/imapmailsynctest.cpp +++ b/examples/imapresource/tests/imapmailsynctest.cpp | |||
@@ -104,6 +104,14 @@ protected: | |||
104 | VERIFYEXEC(imap.login("doe", "doe")); | 104 | VERIFYEXEC(imap.login("doe", "doe")); |
105 | VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'), messages)); | 105 | VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'), messages)); |
106 | } | 106 | } |
107 | |||
108 | void markAsImportant(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE | ||
109 | { | ||
110 | Imap::ImapServerProxy imap("localhost", 993); | ||
111 | VERIFYEXEC(imap.login("doe", "doe")); | ||
112 | VERIFYEXEC(imap.select("INBOX." + folderPath.join('.'))); | ||
113 | VERIFYEXEC(imap.addFlags(KIMAP2::ImapSet::fromImapSequenceSet(messageIdentifier), QByteArrayList() << Imap::Flags::Flagged)); | ||
114 | } | ||
107 | }; | 115 | }; |
108 | 116 | ||
109 | QTEST_MAIN(ImapMailSyncTest) | 117 | QTEST_MAIN(ImapMailSyncTest) |
diff --git a/examples/maildirresource/tests/maildirmailsynctest.cpp b/examples/maildirresource/tests/maildirmailsynctest.cpp index 444fb42..f2cf3e0 100644 --- a/examples/maildirresource/tests/maildirmailsynctest.cpp +++ b/examples/maildirresource/tests/maildirmailsynctest.cpp | |||
@@ -125,6 +125,13 @@ protected: | |||
125 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); | 125 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); |
126 | maildir.removeEntry(messageIdentifier); | 126 | maildir.removeEntry(messageIdentifier); |
127 | } | 127 | } |
128 | |||
129 | void markAsImportant(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE | ||
130 | { | ||
131 | auto rootPath = tempDir.path() + "/maildir1/"; | ||
132 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); | ||
133 | maildir.changeEntryFlags(messageIdentifier, KPIM::Maildir::Flagged); | ||
134 | } | ||
128 | }; | 135 | }; |
129 | 136 | ||
130 | QTEST_MAIN(MaildirMailSyncTest) | 137 | QTEST_MAIN(MaildirMailSyncTest) |
diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 9c57f0a..8260978 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp | |||
@@ -344,7 +344,43 @@ void MailSyncTest::testFetchNewRemovedMessages() | |||
344 | } | 344 | } |
345 | } | 345 | } |
346 | 346 | ||
347 | //TODO test flag sync | 347 | void MailSyncTest::testFlagChange() |
348 | { | ||
349 | Sink::Query query; | ||
350 | query.resources << mResourceInstanceIdentifier; | ||
351 | query.request<Mail::Subject>().request<Mail::Important>(); | ||
352 | |||
353 | auto msg = KMime::Message::Ptr::create(); | ||
354 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); | ||
355 | msg->assemble(); | ||
356 | auto messageIdentifier = createMessage(QStringList() << "test", msg->encodedContent(true)); | ||
357 | |||
358 | Store::synchronize(query).exec().waitForFinished(); | ||
359 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
360 | |||
361 | { | ||
362 | auto job = Store::fetchAll<Mail>(query).syncThen<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
363 | QCOMPARE(mails.size(), 2); | ||
364 | QVERIFY(!mails.at(1)->getImportant()); | ||
365 | }); | ||
366 | VERIFYEXEC(job); | ||
367 | } | ||
368 | |||
369 | markAsImportant(QStringList() << "test", messageIdentifier); | ||
370 | |||
371 | // Ensure all local data is processed | ||
372 | VERIFYEXEC(Store::synchronize(query)); | ||
373 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
374 | |||
375 | { | ||
376 | auto job = Store::fetchAll<Mail>(query).syncThen<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
377 | QCOMPARE(mails.size(), 2); | ||
378 | QVERIFY(mails.at(1)->getImportant()); | ||
379 | }); | ||
380 | VERIFYEXEC(job); | ||
381 | } | ||
382 | |||
383 | } | ||
348 | 384 | ||
349 | void MailSyncTest::testFailingSync() | 385 | void MailSyncTest::testFailingSync() |
350 | { | 386 | { |
diff --git a/tests/mailsynctest.h b/tests/mailsynctest.h index 31d3f03..94643f6 100644 --- a/tests/mailsynctest.h +++ b/tests/mailsynctest.h | |||
@@ -50,6 +50,7 @@ protected: | |||
50 | virtual void removeFolder(const QStringList &folderPath) = 0; | 50 | virtual void removeFolder(const QStringList &folderPath) = 0; |
51 | virtual QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) = 0; | 51 | virtual QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) = 0; |
52 | virtual void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) = 0; | 52 | virtual void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) = 0; |
53 | virtual void markAsImportant(const QStringList &folderPath, const QByteArray &messageIdentifier) = 0; | ||
53 | 54 | ||
54 | private slots: | 55 | private slots: |
55 | void initTestCase(); | 56 | void initTestCase(); |
@@ -66,6 +67,7 @@ private slots: | |||
66 | void testListMails(); | 67 | void testListMails(); |
67 | void testResyncMails(); | 68 | void testResyncMails(); |
68 | void testFetchNewRemovedMessages(); | 69 | void testFetchNewRemovedMessages(); |
70 | void testFlagChange(); | ||
69 | 71 | ||
70 | void testFailingSync(); | 72 | void testFailingSync(); |
71 | }; | 73 | }; |