summaryrefslogtreecommitdiffstats
path: root/examples
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
parent48c0f01320981319a9ac0f34a7ce117325bfbc13 (diff)
downloadsink-03fd475039b418f2f16b2890554fb59403d708dd.tar.gz
sink-03fd475039b418f2f16b2890554fb59403d708dd.zip
Track uidvalidity to detect changes behind our back.
Diffstat (limited to 'examples')
-rw-r--r--examples/imapresource/imapresource.cpp19
-rw-r--r--examples/imapresource/imapserverproxy.cpp11
-rw-r--r--examples/imapresource/imapserverproxy.h1
3 files changed, 25 insertions, 6 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);
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index b27ffb0..a5a64db 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -244,6 +244,11 @@ KAsync::Job<SelectResult> ImapServerProxy::select(const QString &mailbox)
244 }); 244 });
245} 245}
246 246
247KAsync::Job<SelectResult> ImapServerProxy::select(const Folder &folder)
248{
249 return select(mailboxFromFolder(folder));
250}
251
247KAsync::Job<qint64> ImapServerProxy::append(const QString &mailbox, const QByteArray &content, const QList<QByteArray> &flags, const QDateTime &internalDate) 252KAsync::Job<qint64> ImapServerProxy::append(const QString &mailbox, const QByteArray &content, const QList<QByteArray> &flags, const QDateTime &internalDate)
248{ 253{
249 auto append = new KIMAP2::AppendJob(mSession); 254 auto append = new KIMAP2::AppendJob(mSession);
@@ -577,7 +582,7 @@ QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const
577KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function<void(const Message &)> callback) 582KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function<void(const Message &)> callback)
578{ 583{
579 SinkTrace() << "Fetching flags " << folder.path(); 584 SinkTrace() << "Fetching flags " << folder.path();
580 return select(mailboxFromFolder(folder)).then<SelectResult, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<SelectResult> { 585 return select(folder).then<SelectResult, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<SelectResult> {
581 SinkTrace() << "Modeseq " << folder.path() << selectResult.highestModSequence << changedsince; 586 SinkTrace() << "Modeseq " << folder.path() << selectResult.highestModSequence << changedsince;
582 587
583 if (selectResult.highestModSequence == static_cast<quint64>(changedsince)) { 588 if (selectResult.highestModSequence == static_cast<quint64>(changedsince)) {
@@ -601,7 +606,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui
601{ 606{
602 auto time = QSharedPointer<QTime>::create(); 607 auto time = QSharedPointer<QTime>::create();
603 time->start(); 608 time->start();
604 return select(mailboxFromFolder(folder)).then<void, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { 609 return select(folder).then<void, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> {
605 SinkTrace() << "UIDNEXT " << folder.path() << selectResult.uidNext << uidNext; 610 SinkTrace() << "UIDNEXT " << folder.path() << selectResult.uidNext << uidNext;
606 if (selectResult.uidNext == (uidNext + 1)) { 611 if (selectResult.uidNext == (uidNext + 1)) {
607 SinkTrace()<< folder.path() << "Uidnext didn't change, nothing to do."; 612 SinkTrace()<< folder.path() << "Uidnext didn't change, nothing to do.";
@@ -624,7 +629,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, const QVe
624{ 629{
625 auto time = QSharedPointer<QTime>::create(); 630 auto time = QSharedPointer<QTime>::create();
626 time->start(); 631 time->start();
627 return select(mailboxFromFolder(folder)).then<void, SelectResult>([this, callback, folder, time, progress, uidsToFetch, headersOnly](const SelectResult &selectResult) -> KAsync::Job<void> { 632 return select(folder).then<void, SelectResult>([this, callback, folder, time, progress, uidsToFetch, headersOnly](const SelectResult &selectResult) -> KAsync::Job<void> {
628 633
629 SinkTrace() << "Fetching messages" << folder.path(); 634 SinkTrace() << "Fetching messages" << folder.path();
630 SinkTrace() << " Total: " << uidsToFetch.size(); 635 SinkTrace() << " Total: " << uidsToFetch.size();
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h
index 57b252d..c69fe67 100644
--- a/examples/imapresource/imapserverproxy.h
+++ b/examples/imapresource/imapserverproxy.h
@@ -261,6 +261,7 @@ public:
261 KAsync::Job<void> login(const QString &username, const QString &password); 261 KAsync::Job<void> login(const QString &username, const QString &password);
262 KAsync::Job<void> logout(); 262 KAsync::Job<void> logout();
263 KAsync::Job<SelectResult> select(const QString &mailbox); 263 KAsync::Job<SelectResult> select(const QString &mailbox);
264 KAsync::Job<SelectResult> select(const Folder &mailbox);
264 KAsync::Job<qint64> append(const QString &mailbox, const QByteArray &content, const QList<QByteArray> &flags = QList<QByteArray>(), const QDateTime &internalDate = QDateTime()); 265 KAsync::Job<qint64> append(const QString &mailbox, const QByteArray &content, const QList<QByteArray> &flags = QList<QByteArray>(), const QDateTime &internalDate = QDateTime());
265 KAsync::Job<void> store(const KIMAP2::ImapSet &set, const QList<QByteArray> &flags); 266 KAsync::Job<void> store(const KIMAP2::ImapSet &set, const QList<QByteArray> &flags);
266 KAsync::Job<void> storeFlags(const KIMAP2::ImapSet &set, const QList<QByteArray> &flags); 267 KAsync::Job<void> storeFlags(const KIMAP2::ImapSet &set, const QList<QByteArray> &flags);