summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapresource.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-23 17:05:10 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-23 17:25:25 +0100
commit03fd475039b418f2f16b2890554fb59403d708dd (patch)
tree1db5b8d8aa4d5f30ed2881bb68a3044aab25011b /examples/imapresource/imapresource.cpp
parent48c0f01320981319a9ac0f34a7ce117325bfbc13 (diff)
downloadsink-03fd475039b418f2f16b2890554fb59403d708dd.tar.gz
sink-03fd475039b418f2f16b2890554fb59403d708dd.zip
Track uidvalidity to detect changes behind our back.
Diffstat (limited to 'examples/imapresource/imapresource.cpp')
-rw-r--r--examples/imapresource/imapresource.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index 6607578..e8bc903 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -246,10 +246,23 @@ public:
246 SinkWarningCtx(mLogCtx) << "Invalid folder " << folderRemoteId << folder.path(); 246 SinkWarningCtx(mLogCtx) << "Invalid folder " << folderRemoteId << folder.path();
247 return KAsync::error<void>("Invalid folder"); 247 return KAsync::error<void>("Invalid folder");
248 } 248 }
249 // auto capabilities = imap->getCapabilities();
250 249
251 //First we fetch flag changes for all messages. Since we don't know which messages are locally available we just get everything and only apply to what we have. 250 //Start by checking if UIDVALIDITY is still correct
252 return KAsync::start<void>([=]() { 251 return KAsync::start([=] {
252 bool ok = false;
253 const auto uidvalidity = syncStore().readValue(folderRemoteId, "uidvalidity").toLongLong(&ok);
254 return imap->select(folder)
255 .then([=](const SelectResult &selectResult) {
256 SinkLogCtx(mLogCtx) << "Checking UIDVALIDITY. Local" << uidvalidity << "remote " << selectResult.uidValidity;
257 if (ok && selectResult.uidValidity != uidvalidity) {
258 SinkWarningCtx(mLogCtx) << "UIDVALIDITY changed " << selectResult.uidValidity << uidvalidity;
259 syncStore().removePrefix(folderRemoteId);
260 }
261 syncStore().writeValue(folderRemoteId, "uidvalidity", QByteArray::number(selectResult.uidValidity));
262 });
263 })
264 // //First we fetch flag changes for all messages. Since we don't know which messages are locally available we just get everything and only apply to what we have.
265 .then([=] {
253 auto uidNext = syncStore().readValue(folderRemoteId, "uidnext").toLongLong(); 266 auto uidNext = syncStore().readValue(folderRemoteId, "uidnext").toLongLong();
254 bool ok = false; 267 bool ok = false;
255 const auto changedsince = syncStore().readValue(folderRemoteId, "changedsince").toLongLong(&ok); 268 const auto changedsince = syncStore().readValue(folderRemoteId, "changedsince").toLongLong(&ok);