diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-11 11:55:29 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-11 11:55:29 +0200 |
commit | 3a3118e768e1447dc7524328e84b8d7faef81fe1 (patch) | |
tree | af5582170ed6164fffc9365f34b17bf449c0db40 /examples/imapresource/imapresource.cpp | |
parent | f9379318d801df204cc50385c5eca1f28e91755e (diff) | |
parent | ce2fd2666f084eebe443598f6f3740a02913091e (diff) | |
download | sink-3a3118e768e1447dc7524328e84b8d7faef81fe1.tar.gz sink-3a3118e768e1447dc7524328e84b8d7faef81fe1.zip |
Merge branch 'feature/notifications' into develop
Diffstat (limited to 'examples/imapresource/imapresource.cpp')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index e23add8..92f64bf 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -54,8 +54,7 @@ | |||
54 | #define ENTITY_TYPE_MAIL "mail" | 54 | #define ENTITY_TYPE_MAIL "mail" |
55 | #define ENTITY_TYPE_FOLDER "folder" | 55 | #define ENTITY_TYPE_FOLDER "folder" |
56 | 56 | ||
57 | #undef DEBUG_AREA | 57 | SINK_DEBUG_AREA("imapresource") |
58 | #define DEBUG_AREA "resource.imap" | ||
59 | 58 | ||
60 | using namespace Imap; | 59 | using namespace Imap; |
61 | using namespace Sink; | 60 | using namespace Sink; |
@@ -95,7 +94,7 @@ public: | |||
95 | 94 | ||
96 | QByteArray createFolder(const QString &folderName, const QString &folderPath, const QString &parentFolderRid, const QByteArray &icon) | 95 | QByteArray createFolder(const QString &folderName, const QString &folderPath, const QString &parentFolderRid, const QByteArray &icon) |
97 | { | 96 | { |
98 | Trace() << "Creating folder: " << folderName << parentFolderRid; | 97 | SinkTrace() << "Creating folder: " << folderName << parentFolderRid; |
99 | const auto remoteId = folderPath.toUtf8(); | 98 | const auto remoteId = folderPath.toUtf8(); |
100 | const auto bufferType = ENTITY_TYPE_FOLDER; | 99 | const auto bufferType = ENTITY_TYPE_FOLDER; |
101 | Sink::ApplicationDomain::Folder folder; | 100 | Sink::ApplicationDomain::Folder folder; |
@@ -118,7 +117,7 @@ public: | |||
118 | void synchronizeFolders(const QVector<Folder> &folderList) | 117 | void synchronizeFolders(const QVector<Folder> &folderList) |
119 | { | 118 | { |
120 | const QByteArray bufferType = ENTITY_TYPE_FOLDER; | 119 | const QByteArray bufferType = ENTITY_TYPE_FOLDER; |
121 | Trace() << "Found folders " << folderList.size(); | 120 | SinkTrace() << "Found folders " << folderList.size(); |
122 | 121 | ||
123 | scanForRemovals(bufferType, | 122 | scanForRemovals(bufferType, |
124 | [this, &bufferType](const std::function<void(const QByteArray &)> &callback) { | 123 | [this, &bufferType](const std::function<void(const QByteArray &)> &callback) { |
@@ -154,7 +153,7 @@ public: | |||
154 | time->start(); | 153 | time->start(); |
155 | const QByteArray bufferType = ENTITY_TYPE_MAIL; | 154 | const QByteArray bufferType = ENTITY_TYPE_MAIL; |
156 | 155 | ||
157 | Trace() << "Importing new mail." << path; | 156 | SinkTrace() << "Importing new mail." << path; |
158 | 157 | ||
159 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); | 158 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); |
160 | 159 | ||
@@ -163,7 +162,7 @@ public: | |||
163 | count++; | 162 | count++; |
164 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); | 163 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); |
165 | 164 | ||
166 | Trace() << "Found a mail " << remoteId << message.msg->subject(true)->asUnicodeString() << message.flags; | 165 | SinkTrace() << "Found a mail " << remoteId << message.msg->subject(true)->asUnicodeString() << message.flags; |
167 | 166 | ||
168 | auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); | 167 | auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); |
169 | mail.setFolder(folderLocalId); | 168 | mail.setFolder(folderLocalId); |
@@ -174,7 +173,7 @@ public: | |||
174 | createOrModify(bufferType, remoteId, mail); | 173 | createOrModify(bufferType, remoteId, mail); |
175 | } | 174 | } |
176 | const auto elapsed = time->elapsed(); | 175 | const auto elapsed = time->elapsed(); |
177 | Log() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; | 176 | SinkLog() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; |
178 | } | 177 | } |
179 | 178 | ||
180 | void synchronizeRemovals(const QString &path, const QSet<qint64> &messages) | 179 | void synchronizeRemovals(const QString &path, const QSet<qint64> &messages) |
@@ -183,7 +182,7 @@ public: | |||
183 | time->start(); | 182 | time->start(); |
184 | const QByteArray bufferType = ENTITY_TYPE_MAIL; | 183 | const QByteArray bufferType = ENTITY_TYPE_MAIL; |
185 | 184 | ||
186 | Trace() << "Finding removed mail."; | 185 | SinkTrace() << "Finding removed mail."; |
187 | 186 | ||
188 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); | 187 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); |
189 | 188 | ||
@@ -196,7 +195,7 @@ public: | |||
196 | callback(sinkId); | 195 | callback(sinkId); |
197 | }, | 196 | }, |
198 | [&](const Index::Error &error) { | 197 | [&](const Index::Error &error) { |
199 | Warning() << "Error in index: " << error.message << property; | 198 | SinkWarning() << "Error in index: " << error.message << property; |
200 | }); | 199 | }); |
201 | }, | 200 | }, |
202 | [messages, path, &count](const QByteArray &remoteId) -> bool { | 201 | [messages, path, &count](const QByteArray &remoteId) -> bool { |
@@ -209,24 +208,24 @@ public: | |||
209 | ); | 208 | ); |
210 | 209 | ||
211 | const auto elapsed = time->elapsed(); | 210 | const auto elapsed = time->elapsed(); |
212 | Log() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; | 211 | SinkLog() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; |
213 | } | 212 | } |
214 | 213 | ||
215 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | 214 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE |
216 | { | 215 | { |
217 | Log() << " Synchronizing"; | 216 | SinkLog() << " Synchronizing"; |
218 | return KAsync::start<void>([this](KAsync::Future<void> future) { | 217 | return KAsync::start<void>([this](KAsync::Future<void> future) { |
219 | Trace() << "Connecting to:" << mServer << mPort; | 218 | SinkTrace() << "Connecting to:" << mServer << mPort; |
220 | Trace() << "as:" << mUser; | 219 | SinkTrace() << "as:" << mUser; |
221 | ImapServerProxy imap(mServer, mPort); | 220 | ImapServerProxy imap(mServer, mPort); |
222 | auto loginFuture = imap.login(mUser, mPassword).exec(); | 221 | auto loginFuture = imap.login(mUser, mPassword).exec(); |
223 | loginFuture.waitForFinished(); | 222 | loginFuture.waitForFinished(); |
224 | if (loginFuture.errorCode()) { | 223 | if (loginFuture.errorCode()) { |
225 | Warning() << "Login failed."; | 224 | SinkWarning() << "Login failed."; |
226 | future.setError(1, "Login failed"); | 225 | future.setError(1, "Login failed"); |
227 | return; | 226 | return; |
228 | } else { | 227 | } else { |
229 | Trace() << "Login was successful"; | 228 | SinkTrace() << "Login was successful"; |
230 | } | 229 | } |
231 | 230 | ||
232 | QVector<Folder> folderList; | 231 | QVector<Folder> folderList; |
@@ -238,11 +237,11 @@ public: | |||
238 | }).exec(); | 237 | }).exec(); |
239 | folderFuture.waitForFinished(); | 238 | folderFuture.waitForFinished(); |
240 | if (folderFuture.errorCode()) { | 239 | if (folderFuture.errorCode()) { |
241 | Warning() << "Folder sync failed."; | 240 | SinkWarning() << "Folder sync failed."; |
242 | future.setError(1, "Folder list sync failed"); | 241 | future.setError(1, "Folder list sync failed"); |
243 | return; | 242 | return; |
244 | } else { | 243 | } else { |
245 | Trace() << "Folder sync was successful"; | 244 | SinkTrace() << "Folder sync was successful"; |
246 | } | 245 | } |
247 | 246 | ||
248 | for (const auto &folder : folderList) { | 247 | for (const auto &folder : folderList) { |
@@ -251,7 +250,7 @@ public: | |||
251 | } | 250 | } |
252 | QSet<qint64> uids; | 251 | QSet<qint64> uids; |
253 | auto messagesFuture = imap.fetchMessages(folder, [this, folder, &uids](const QVector<Message> &messages) { | 252 | auto messagesFuture = imap.fetchMessages(folder, [this, folder, &uids](const QVector<Message> &messages) { |
254 | Trace() << "Synchronizing mails" << folder.normalizedPath(); | 253 | SinkTrace() << "Synchronizing mails" << folder.normalizedPath(); |
255 | for (const auto &msg : messages) { | 254 | for (const auto &msg : messages) { |
256 | uids << msg.uid; | 255 | uids << msg.uid; |
257 | } | 256 | } |
@@ -260,16 +259,16 @@ public: | |||
260 | messagesFuture.waitForFinished(); | 259 | messagesFuture.waitForFinished(); |
261 | commit(); | 260 | commit(); |
262 | if (messagesFuture.errorCode()) { | 261 | if (messagesFuture.errorCode()) { |
263 | Warning() << "Folder sync failed: " << folder.normalizedPath(); | 262 | SinkWarning() << "Folder sync failed: " << folder.normalizedPath(); |
264 | continue; | 263 | continue; |
265 | } | 264 | } |
266 | //Remove what there is to remove | 265 | //Remove what there is to remove |
267 | synchronizeRemovals(folder.normalizedPath(), uids); | 266 | synchronizeRemovals(folder.normalizedPath(), uids); |
268 | commit(); | 267 | commit(); |
269 | Trace() << "Folder synchronized: " << folder.normalizedPath(); | 268 | SinkTrace() << "Folder synchronized: " << folder.normalizedPath(); |
270 | } | 269 | } |
271 | 270 | ||
272 | Log() << "Done Synchronizing"; | 271 | SinkLog() << "Done Synchronizing"; |
273 | future.setFinished(); | 272 | future.setFinished(); |
274 | }); | 273 | }); |
275 | } | 274 | } |
@@ -310,7 +309,7 @@ public: | |||
310 | .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { | 309 | .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { |
311 | const auto remoteId = assembleMailRid(mail, uid); | 310 | const auto remoteId = assembleMailRid(mail, uid); |
312 | //FIXME this get's called after the final error handler? WTF? | 311 | //FIXME this get's called after the final error handler? WTF? |
313 | Trace() << "Finished creating a new mail: " << remoteId; | 312 | SinkTrace() << "Finished creating a new mail: " << remoteId; |
314 | *rid = remoteId; | 313 | *rid = remoteId; |
315 | }).then<QByteArray>([rid, imap]() { //FIXME fix KJob so we don't need this extra clause | 314 | }).then<QByteArray>([rid, imap]() { //FIXME fix KJob so we don't need this extra clause |
316 | return *rid; | 315 | return *rid; |
@@ -319,19 +318,19 @@ public: | |||
319 | const auto folderId = folderIdFromMailRid(oldRemoteId); | 318 | const auto folderId = folderIdFromMailRid(oldRemoteId); |
320 | const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); | 319 | const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); |
321 | const auto uid = uidFromMailRid(oldRemoteId); | 320 | const auto uid = uidFromMailRid(oldRemoteId); |
322 | Trace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; | 321 | SinkTrace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; |
323 | KIMAP::ImapSet set; | 322 | KIMAP::ImapSet set; |
324 | set.add(uid); | 323 | set.add(uid); |
325 | return login.then(imap->remove(mailbox, set)) | 324 | return login.then(imap->remove(mailbox, set)) |
326 | .then<QByteArray>([imap, oldRemoteId]() { | 325 | .then<QByteArray>([imap, oldRemoteId]() { |
327 | Trace() << "Finished removing a mail: " << oldRemoteId; | 326 | SinkTrace() << "Finished removing a mail: " << oldRemoteId; |
328 | return QByteArray(); | 327 | return QByteArray(); |
329 | }); | 328 | }); |
330 | } else if (operation == Sink::Operation_Modification) { | 329 | } else if (operation == Sink::Operation_Modification) { |
331 | const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); | 330 | const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); |
332 | const auto uid = uidFromMailRid(oldRemoteId); | 331 | const auto uid = uidFromMailRid(oldRemoteId); |
333 | 332 | ||
334 | Trace() << "Modifying a mail: " << oldRemoteId << " in the mailbox: " << mailbox << changedProperties; | 333 | SinkTrace() << "Modifying a mail: " << oldRemoteId << " in the mailbox: " << mailbox << changedProperties; |
335 | 334 | ||
336 | QByteArrayList flags; | 335 | QByteArrayList flags; |
337 | if (!mail.getUnread()) { | 336 | if (!mail.getUnread()) { |
@@ -344,7 +343,7 @@ public: | |||
344 | const bool messageMoved = changedProperties.contains(ApplicationDomain::Mail::Folder::name); | 343 | const bool messageMoved = changedProperties.contains(ApplicationDomain::Mail::Folder::name); |
345 | const bool messageChanged = changedProperties.contains(ApplicationDomain::Mail::MimeMessage::name); | 344 | const bool messageChanged = changedProperties.contains(ApplicationDomain::Mail::MimeMessage::name); |
346 | if (messageChanged || messageMoved) { | 345 | if (messageChanged || messageMoved) { |
347 | Trace() << "Replacing message."; | 346 | SinkTrace() << "Replacing message."; |
348 | const auto folderId = folderIdFromMailRid(oldRemoteId); | 347 | const auto folderId = folderIdFromMailRid(oldRemoteId); |
349 | const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); | 348 | const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); |
350 | QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); | 349 | QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); |
@@ -355,7 +354,7 @@ public: | |||
355 | return login.then(imap->append(mailbox, content, flags, internalDate)) | 354 | return login.then(imap->append(mailbox, content, flags, internalDate)) |
356 | .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { | 355 | .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { |
357 | const auto remoteId = assembleMailRid(mail, uid); | 356 | const auto remoteId = assembleMailRid(mail, uid); |
358 | Trace() << "Finished creating a modified mail: " << remoteId; | 357 | SinkTrace() << "Finished creating a modified mail: " << remoteId; |
359 | *rid = remoteId; | 358 | *rid = remoteId; |
360 | }) | 359 | }) |
361 | .then(imap->remove(oldMailbox, set)) | 360 | .then(imap->remove(oldMailbox, set)) |
@@ -363,13 +362,13 @@ public: | |||
363 | return *rid; | 362 | return *rid; |
364 | }); | 363 | }); |
365 | } else { | 364 | } else { |
366 | Trace() << "Updating flags only."; | 365 | SinkTrace() << "Updating flags only."; |
367 | KIMAP::ImapSet set; | 366 | KIMAP::ImapSet set; |
368 | set.add(uid); | 367 | set.add(uid); |
369 | return login.then(imap->select(mailbox)) | 368 | return login.then(imap->select(mailbox)) |
370 | .then(imap->storeFlags(set, flags)) | 369 | .then(imap->storeFlags(set, flags)) |
371 | .then<void>([imap, mailbox]() { | 370 | .then<void>([imap, mailbox]() { |
372 | Trace() << "Finished modifying mail"; | 371 | SinkTrace() << "Finished modifying mail"; |
373 | }) | 372 | }) |
374 | .then<QByteArray>([oldRemoteId, imap]() { | 373 | .then<QByteArray>([oldRemoteId, imap]() { |
375 | return oldRemoteId; | 374 | return oldRemoteId; |
@@ -388,11 +387,11 @@ public: | |||
388 | if (!folder.getParent().isEmpty()) { | 387 | if (!folder.getParent().isEmpty()) { |
389 | parentFolder = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folder.getParent()); | 388 | parentFolder = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folder.getParent()); |
390 | } | 389 | } |
391 | Trace() << "Creating a new folder: " << parentFolder << folder.getName(); | 390 | SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName(); |
392 | auto rid = QSharedPointer<QByteArray>::create(); | 391 | auto rid = QSharedPointer<QByteArray>::create(); |
393 | auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName())) | 392 | auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName())) |
394 | .then<void, QString>([imap, rid](const QString &createdFolder) { | 393 | .then<void, QString>([imap, rid](const QString &createdFolder) { |
395 | Trace() << "Finished creating a new folder: " << createdFolder; | 394 | SinkTrace() << "Finished creating a new folder: " << createdFolder; |
396 | *rid = createdFolder.toUtf8(); | 395 | *rid = createdFolder.toUtf8(); |
397 | }); | 396 | }); |
398 | if (folder.getSpecialPurpose().isEmpty()) { | 397 | if (folder.getSpecialPurpose().isEmpty()) { |
@@ -414,15 +413,15 @@ public: | |||
414 | for (const auto &purpose : folder.getSpecialPurpose()) { | 413 | for (const auto &purpose : folder.getSpecialPurpose()) { |
415 | if (specialPurposeFolders->contains(purpose)) { | 414 | if (specialPurposeFolders->contains(purpose)) { |
416 | auto f = specialPurposeFolders->value(purpose); | 415 | auto f = specialPurposeFolders->value(purpose); |
417 | Trace() << "Merging specialpurpose folder with: " << f << " with purpose: " << purpose; | 416 | SinkTrace() << "Merging specialpurpose folder with: " << f << " with purpose: " << purpose; |
418 | *rid = f.toUtf8(); | 417 | *rid = f.toUtf8(); |
419 | return KAsync::null<void>(); | 418 | return KAsync::null<void>(); |
420 | } | 419 | } |
421 | } | 420 | } |
422 | Trace() << "No match found for merging, creating a new folder"; | 421 | SinkTrace() << "No match found for merging, creating a new folder"; |
423 | return imap->createSubfolder(parentFolder, folder.getName()) | 422 | return imap->createSubfolder(parentFolder, folder.getName()) |
424 | .then<void, QString>([imap, rid](const QString &createdFolder) { | 423 | .then<void, QString>([imap, rid](const QString &createdFolder) { |
425 | Trace() << "Finished creating a new folder: " << createdFolder; | 424 | SinkTrace() << "Finished creating a new folder: " << createdFolder; |
426 | *rid = createdFolder.toUtf8(); | 425 | *rid = createdFolder.toUtf8(); |
427 | }); | 426 | }); |
428 | 427 | ||
@@ -433,18 +432,18 @@ public: | |||
433 | return mergeJob; | 432 | return mergeJob; |
434 | } | 433 | } |
435 | } else if (operation == Sink::Operation_Removal) { | 434 | } else if (operation == Sink::Operation_Removal) { |
436 | Trace() << "Removing a folder: " << oldRemoteId; | 435 | SinkTrace() << "Removing a folder: " << oldRemoteId; |
437 | return login.then<void>(imap->remove(oldRemoteId)) | 436 | return login.then<void>(imap->remove(oldRemoteId)) |
438 | .then<QByteArray>([oldRemoteId, imap]() { | 437 | .then<QByteArray>([oldRemoteId, imap]() { |
439 | Trace() << "Finished removing a folder: " << oldRemoteId; | 438 | SinkTrace() << "Finished removing a folder: " << oldRemoteId; |
440 | return QByteArray(); | 439 | return QByteArray(); |
441 | }); | 440 | }); |
442 | } else if (operation == Sink::Operation_Modification) { | 441 | } else if (operation == Sink::Operation_Modification) { |
443 | Trace() << "Renaming a folder: " << oldRemoteId << folder.getName(); | 442 | SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName(); |
444 | auto rid = QSharedPointer<QByteArray>::create(); | 443 | auto rid = QSharedPointer<QByteArray>::create(); |
445 | return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName())) | 444 | return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName())) |
446 | .then<void, QString>([imap, rid](const QString &createdFolder) { | 445 | .then<void, QString>([imap, rid](const QString &createdFolder) { |
447 | Trace() << "Finished renaming a folder: " << createdFolder; | 446 | SinkTrace() << "Finished renaming a folder: " << createdFolder; |
448 | *rid = createdFolder.toUtf8(); | 447 | *rid = createdFolder.toUtf8(); |
449 | }) | 448 | }) |
450 | .then<QByteArray>([rid](){ | 449 | .then<QByteArray>([rid](){ |
@@ -515,7 +514,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
515 | auto entityStore = QSharedPointer<Sink::EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction); | 514 | auto entityStore = QSharedPointer<Sink::EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction); |
516 | auto syncStore = QSharedPointer<Sink::RemoteIdMap>::create(synchronizationTransaction); | 515 | auto syncStore = QSharedPointer<Sink::RemoteIdMap>::create(synchronizationTransaction); |
517 | 516 | ||
518 | Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | 517 | SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; |
519 | 518 | ||
520 | if (domainType == ENTITY_TYPE_MAIL) { | 519 | if (domainType == ENTITY_TYPE_MAIL) { |
521 | const auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId); | 520 | const auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId); |
@@ -523,11 +522,11 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
523 | const auto folderRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); | 522 | const auto folderRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); |
524 | const auto mailRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_MAIL, mail.identifier()); | 523 | const auto mailRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_MAIL, mail.identifier()); |
525 | if (mailRemoteId.isEmpty() || folderRemoteId.isEmpty()) { | 524 | if (mailRemoteId.isEmpty() || folderRemoteId.isEmpty()) { |
526 | Warning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId; | 525 | SinkWarning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId; |
527 | return KAsync::error<void>(); | 526 | return KAsync::error<void>(); |
528 | } | 527 | } |
529 | const auto uid = uidFromMailRid(mailRemoteId); | 528 | const auto uid = uidFromMailRid(mailRemoteId); |
530 | Trace() << "Mail remote id: " << folderRemoteId << mailRemoteId << mail.identifier() << folder.identifier(); | 529 | SinkTrace() << "Mail remote id: " << folderRemoteId << mailRemoteId << mail.identifier() << folder.identifier(); |
531 | 530 | ||
532 | KIMAP::ImapSet set; | 531 | KIMAP::ImapSet set; |
533 | set.add(uid); | 532 | set.add(uid); |
@@ -538,8 +537,8 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
538 | scope.mode = KIMAP::FetchJob::FetchScope::Full; | 537 | scope.mode = KIMAP::FetchJob::FetchScope::Full; |
539 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 538 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); |
540 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); | 539 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); |
541 | Trace() << "Connecting to:" << mServer << mPort; | 540 | SinkTrace() << "Connecting to:" << mServer << mPort; |
542 | Trace() << "as:" << mUser; | 541 | SinkTrace() << "as:" << mUser; |
543 | auto inspectionJob = imap->login(mUser, mPassword) | 542 | auto inspectionJob = imap->login(mUser, mPassword) |
544 | .then<void>(imap->select(folderRemoteId)) | 543 | .then<void>(imap->select(folderRemoteId)) |
545 | .then<void>(imap->fetch(set, scope, [imap, messageByUid](const QVector<Imap::Message> &messages) { | 544 | .then<void>(imap->fetch(set, scope, [imap, messageByUid](const QVector<Imap::Message> &messages) { |
@@ -574,8 +573,8 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
574 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { | 573 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { |
575 | return inspectionJob.then<void, KAsync::Job<void>>([=]() { | 574 | return inspectionJob.then<void, KAsync::Job<void>>([=]() { |
576 | if (!messageByUid->contains(uid)) { | 575 | if (!messageByUid->contains(uid)) { |
577 | Warning() << "Existing messages are: " << messageByUid->keys(); | 576 | SinkWarning() << "Existing messages are: " << messageByUid->keys(); |
578 | Warning() << "We're looking for: " << uid; | 577 | SinkWarning() << "We're looking for: " << uid; |
579 | return KAsync::error<void>(1, "Couldn't find message: " + mailRemoteId); | 578 | return KAsync::error<void>(1, "Couldn't find message: " + mailRemoteId); |
580 | } | 579 | } |
581 | return KAsync::null<void>(); | 580 | return KAsync::null<void>(); |
@@ -587,7 +586,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
587 | const auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId); | 586 | const auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId); |
588 | 587 | ||
589 | if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { | 588 | if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { |
590 | Log() << "Inspecting cache integrity" << remoteId; | 589 | SinkLog() << "Inspecting cache integrity" << remoteId; |
591 | 590 | ||
592 | int expectedCount = 0; | 591 | int expectedCount = 0; |
593 | Index index("mail.index.folder", transaction); | 592 | Index index("mail.index.folder", transaction); |
@@ -595,7 +594,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
595 | expectedCount++; | 594 | expectedCount++; |
596 | }, | 595 | }, |
597 | [&](const Index::Error &error) { | 596 | [&](const Index::Error &error) { |
598 | Warning() << "Error in index: " << error.message << property; | 597 | SinkWarning() << "Error in index: " << error.message << property; |
599 | }); | 598 | }); |
600 | 599 | ||
601 | auto set = KIMAP::ImapSet::fromImapSequenceSet("1:*"); | 600 | auto set = KIMAP::ImapSet::fromImapSequenceSet("1:*"); |
@@ -630,10 +629,10 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
630 | *folderByName << f.pathParts.last(); | 629 | *folderByName << f.pathParts.last(); |
631 | } | 630 | } |
632 | })) | 631 | })) |
633 | .then<void, KAsync::Job<void>>([folderByName, folderByPath, folder, remoteId, imap]() { | 632 | .then<void, KAsync::Job<void>>([this, folderByName, folderByPath, folder, remoteId, imap]() { |
634 | if (!folderByName->contains(folder.getName())) { | 633 | if (!folderByName->contains(folder.getName())) { |
635 | Warning() << "Existing folders are: " << *folderByPath; | 634 | SinkWarning() << "Existing folders are: " << *folderByPath; |
636 | Warning() << "We're looking for: " << folder.getName(); | 635 | SinkWarning() << "We're looking for: " << folder.getName(); |
637 | return KAsync::error<void>(1, "Wrong folder name: " + remoteId); | 636 | return KAsync::error<void>(1, "Wrong folder name: " + remoteId); |
638 | } | 637 | } |
639 | return KAsync::null<void>(); | 638 | return KAsync::null<void>(); |