summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapresource.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-01 10:30:42 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-01 10:30:42 +0100
commit14d33366f8ed61105f0d10328a03ccb07cf8970a (patch)
tree2c6b07899ad706dc6d3ec14338b4c6f9fe207034 /examples/imapresource/imapresource.cpp
parentd0f138ae5aaeb6291f12c49a13e3bb2e2237c792 (diff)
downloadsink-14d33366f8ed61105f0d10328a03ccb07cf8970a.tar.gz
sink-14d33366f8ed61105f0d10328a03ccb07cf8970a.zip
Select all folders and emit notification if new mails are available
Diffstat (limited to 'examples/imapresource/imapresource.cpp')
-rw-r--r--examples/imapresource/imapresource.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index 5f7304d..061fdb1 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -287,6 +287,7 @@ public:
287 .then([=](const SelectResult &selectResult) { 287 .then([=](const SelectResult &selectResult) {
288 SinkLogCtx(mLogCtx) << "Flags updated. New changedsince value: " << selectResult.highestModSequence; 288 SinkLogCtx(mLogCtx) << "Flags updated. New changedsince value: " << selectResult.highestModSequence;
289 syncStore().writeValue(folderRemoteId, "changedsince", QByteArray::number(selectResult.highestModSequence)); 289 syncStore().writeValue(folderRemoteId, "changedsince", QByteArray::number(selectResult.highestModSequence));
290 return selectResult.uidNext;
290 }); 291 });
291 } else { 292 } else {
292 //We hit this path on initial sync and simply record the current changedsince value 293 //We hit this path on initial sync and simply record the current changedsince value
@@ -294,13 +295,14 @@ public:
294 .then([=](const SelectResult &selectResult) { 295 .then([=](const SelectResult &selectResult) {
295 SinkLogCtx(mLogCtx) << "No flags to update. New changedsince value: " << selectResult.highestModSequence; 296 SinkLogCtx(mLogCtx) << "No flags to update. New changedsince value: " << selectResult.highestModSequence;
296 syncStore().writeValue(folderRemoteId, "changedsince", QByteArray::number(selectResult.highestModSequence)); 297 syncStore().writeValue(folderRemoteId, "changedsince", QByteArray::number(selectResult.highestModSequence));
298 return selectResult.uidNext;
297 }); 299 });
298 } 300 }
299 }) 301 })
300 //Next we synchronize the full set that is given by the date limit. 302 //Next we synchronize the full set that is given by the date limit.
301 //We fetch all data for this set. 303 //We fetch all data for this set.
302 //This will also pull in any new messages in subsequent runs. 304 //This will also pull in any new messages in subsequent runs.
303 .then([=] { 305 .then([=] (qint64 serverUidNext){
304 auto job = [&] { 306 auto job = [&] {
305 if (dateFilter.isValid()) { 307 if (dateFilter.isValid()) {
306 SinkLogCtx(mLogCtx) << "Fetching messages since: " << dateFilter; 308 SinkLogCtx(mLogCtx) << "Fetching messages since: " << dateFilter;
@@ -349,6 +351,11 @@ public:
349 SinkLogCtx(mLogCtx) << "UIDMAX: " << *maxUid << folder.path(); 351 SinkLogCtx(mLogCtx) << "UIDMAX: " << *maxUid << folder.path();
350 if (*maxUid > 0) { 352 if (*maxUid > 0) {
351 syncStore().writeValue(folderRemoteId, "uidnext", QByteArray::number(*maxUid)); 353 syncStore().writeValue(folderRemoteId, "uidnext", QByteArray::number(*maxUid));
354 } else {
355 if (serverUidNext) {
356 //If we don't receive a mail we should still record the updated uidnext value.
357 syncStore().writeValue(folderRemoteId, "uidnext", QByteArray::number(serverUidNext));
358 }
352 } 359 }
353 syncStore().writeValue(folderRemoteId, "fullsetLowerbound", QByteArray::number(lowerBoundUid)); 360 syncStore().writeValue(folderRemoteId, "fullsetLowerbound", QByteArray::number(lowerBoundUid));
354 commit(); 361 commit();
@@ -555,8 +562,21 @@ public:
555 return imap->fetchFolders([folderList](const Folder &folder) { 562 return imap->fetchFolders([folderList](const Folder &folder) {
556 *folderList << folder; 563 *folderList << folder;
557 }) 564 })
558 .then([this, folderList]() { 565 .then([=]() {
559 synchronizeFolders(*folderList); 566 synchronizeFolders(*folderList);
567 return *folderList;
568 })
569 .each([=](const Imap::Folder &folder) {
570 //TODO examine instead
571 return imap->select(folder)
572 .then([=](const SelectResult &result) {
573 const auto folderRemoteId = folderRid(folder);
574 auto localUidNext = syncStore().readValue(folderRemoteId, "uidnext").toLongLong();
575 if (result.uidNext > localUidNext) {
576 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folderRemoteId);
577 emitNotification(Notification::Info, ApplicationDomain::NewContentAvailable, {}, {}, {{folderLocalId}});
578 }
579 });
560 }); 580 });
561 }) 581 })
562 .then([=] (const KAsync::Error &error) { 582 .then([=] (const KAsync::Error &error) {