From 03fd475039b418f2f16b2890554fb59403d708dd Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 23 Jan 2018 17:05:10 +0100 Subject: Track uidvalidity to detect changes behind our back. --- examples/imapresource/imapresource.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'examples/imapresource/imapresource.cpp') 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: SinkWarningCtx(mLogCtx) << "Invalid folder " << folderRemoteId << folder.path(); return KAsync::error("Invalid folder"); } - // auto capabilities = imap->getCapabilities(); - //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. - return KAsync::start([=]() { + //Start by checking if UIDVALIDITY is still correct + return KAsync::start([=] { + bool ok = false; + const auto uidvalidity = syncStore().readValue(folderRemoteId, "uidvalidity").toLongLong(&ok); + return imap->select(folder) + .then([=](const SelectResult &selectResult) { + SinkLogCtx(mLogCtx) << "Checking UIDVALIDITY. Local" << uidvalidity << "remote " << selectResult.uidValidity; + if (ok && selectResult.uidValidity != uidvalidity) { + SinkWarningCtx(mLogCtx) << "UIDVALIDITY changed " << selectResult.uidValidity << uidvalidity; + syncStore().removePrefix(folderRemoteId); + } + syncStore().writeValue(folderRemoteId, "uidvalidity", QByteArray::number(selectResult.uidValidity)); + }); + }) + // //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. + .then([=] { auto uidNext = syncStore().readValue(folderRemoteId, "uidnext").toLongLong(); bool ok = false; const auto changedsince = syncStore().readValue(folderRemoteId, "changedsince").toLongLong(&ok); -- cgit v1.2.3