diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 10:11:27 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 10:11:27 +0100 |
commit | 9bd53f793c6eb1b3ce9a866d226fbb07a8036ff7 (patch) | |
tree | 011f264ef0032f086103fae756cfca3827333a32 /examples | |
parent | 6b7458332c1937de4393ae5104d3b6dcaffd886d (diff) | |
download | sink-9bd53f793c6eb1b3ce9a866d226fbb07a8036ff7.tar.gz sink-9bd53f793c6eb1b3ce9a866d226fbb07a8036ff7.zip |
Don't try to fetch flags on initial sync.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 04781ef..e16a8d7 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -193,24 +193,34 @@ public: | |||
193 | bool canDoIncrementalRemovals = false; | 193 | bool canDoIncrementalRemovals = false; |
194 | return KAsync::start<void>([=]() { | 194 | return KAsync::start<void>([=]() { |
195 | //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. | 195 | //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. |
196 | SinkLog() << "About to update flags" << folder.path(); | ||
197 | auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); | 196 | auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); |
198 | const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(); | 197 | bool ok = false; |
199 | return imap->fetchFlags(folder, KIMAP2::ImapSet(1, qMax(uidNext, qint64(1))), changedsince, [this, folder](const Message &message) { | 198 | const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(&ok); |
200 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folder.normalizedPath().toUtf8()); | 199 | SinkLog() << "About to update flags" << folder.path() << "changedsince: " << changedsince; |
201 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); | 200 | if (ok) { |
201 | return imap->fetchFlags(folder, KIMAP2::ImapSet(1, qMax(uidNext, qint64(1))), changedsince, [this, folder](const Message &message) { | ||
202 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folder.normalizedPath().toUtf8()); | ||
203 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); | ||
202 | 204 | ||
203 | SinkLog() << "Updating mail flags " << remoteId << message.flags; | 205 | SinkLog() << "Updating mail flags " << remoteId << message.flags; |
204 | 206 | ||
205 | auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); | 207 | auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); |
206 | mail.setUnread(!message.flags.contains(Imap::Flags::Seen)); | 208 | mail.setUnread(!message.flags.contains(Imap::Flags::Seen)); |
207 | mail.setImportant(message.flags.contains(Imap::Flags::Flagged)); | 209 | mail.setImportant(message.flags.contains(Imap::Flags::Flagged)); |
208 | 210 | ||
209 | modify(ENTITY_TYPE_MAIL, remoteId, mail); | 211 | modify(ENTITY_TYPE_MAIL, remoteId, mail); |
210 | }) | 212 | }) |
211 | .syncThen<void, SelectResult>([this, folder](const SelectResult &selectResult) { | 213 | .syncThen<void, SelectResult>([this, folder](const SelectResult &selectResult) { |
212 | syncStore().writeValue(folder.normalizedPath().toUtf8() + "changedsince", QByteArray::number(selectResult.highestModSequence)); | 214 | SinkLog() << "Flags updated. New changedsince value: " << selectResult.highestModSequence; |
213 | }); | 215 | syncStore().writeValue(folder.normalizedPath().toUtf8() + "changedsince", QByteArray::number(selectResult.highestModSequence)); |
216 | }); | ||
217 | } else { | ||
218 | return imap->select(imap->mailboxFromFolder(folder)) | ||
219 | .syncThen<void, SelectResult>([this, folder](const SelectResult &selectResult) { | ||
220 | SinkLog() << "No flags to update. New changedsince value: " << selectResult.highestModSequence; | ||
221 | syncStore().writeValue(folder.normalizedPath().toUtf8() + "changedsince", QByteArray::number(selectResult.highestModSequence)); | ||
222 | }); | ||
223 | } | ||
214 | }) | 224 | }) |
215 | .then<void>([=]() { | 225 | .then<void>([=]() { |
216 | auto job = [&] { | 226 | auto job = [&] { |