summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/dummyresource/resourcefactory.cpp12
-rw-r--r--examples/imapresource/imapresource.cpp99
-rw-r--r--examples/imapresource/imapserverproxy.cpp40
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp10
-rw-r--r--examples/maildirresource/facade.cpp4
-rw-r--r--examples/maildirresource/maildirresource.cpp57
-rw-r--r--examples/mailtransportresource/mailtransportresource.cpp18
7 files changed, 123 insertions, 117 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index 21a76ad..0f7463f 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -48,6 +48,8 @@
48#define ENTITY_TYPE_MAIL "mail" 48#define ENTITY_TYPE_MAIL "mail"
49#define ENTITY_TYPE_FOLDER "folder" 49#define ENTITY_TYPE_FOLDER "folder"
50 50
51SINK_DEBUG_AREA("dummyresource")
52
51class DummySynchronizer : public Sink::Synchronizer { 53class DummySynchronizer : public Sink::Synchronizer {
52 public: 54 public:
53 55
@@ -105,12 +107,12 @@ class DummySynchronizer : public Sink::Synchronizer {
105 auto entity = createEntity(remoteId, it.value()); 107 auto entity = createEntity(remoteId, it.value());
106 createOrModify(bufferType, remoteId, *entity); 108 createOrModify(bufferType, remoteId, *entity);
107 } 109 }
108 Trace() << "Sync of " << count << " entities of type " << bufferType << " done." << Sink::Log::TraceTime(time->elapsed()); 110 SinkTrace() << "Sync of " << count << " entities of type " << bufferType << " done." << Sink::Log::TraceTime(time->elapsed());
109 } 111 }
110 112
111 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 113 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
112 { 114 {
113 Log() << " Synchronizing with the source"; 115 SinkLog() << " Synchronizing with the source";
114 return KAsync::start<void>([this]() { 116 return KAsync::start<void>([this]() {
115 synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) { 117 synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) {
116 return createEvent(ridBuffer, data); 118 return createEvent(ridBuffer, data);
@@ -121,7 +123,7 @@ class DummySynchronizer : public Sink::Synchronizer {
121 synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) { 123 synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) {
122 return createFolder(ridBuffer, data); 124 return createFolder(ridBuffer, data);
123 }); 125 });
124 Log() << "Done Synchronizing"; 126 SinkLog() << "Done Synchronizing";
125 }); 127 });
126 } 128 }
127 129
@@ -147,7 +149,7 @@ DummyResource::~DummyResource()
147 149
148KAsync::Job<void> DummyResource::synchronizeWithSource() 150KAsync::Job<void> DummyResource::synchronizeWithSource()
149{ 151{
150 Trace() << "Synchronize with source and sending a notification about it"; 152 SinkTrace() << "Synchronize with source and sending a notification about it";
151 Sink::Notification n; 153 Sink::Notification n;
152 n.id = "connected"; 154 n.id = "connected";
153 n.type = Sink::Notification::Status; 155 n.type = Sink::Notification::Status;
@@ -160,7 +162,7 @@ KAsync::Job<void> DummyResource::synchronizeWithSource()
160KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) 162KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue)
161{ 163{
162 164
163 Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; 165 SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue;
164 if (property == "testInspection") { 166 if (property == "testInspection") {
165 if (expectedValue.toBool()) { 167 if (expectedValue.toBool()) {
166 //Success 168 //Success
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 57SINK_DEBUG_AREA("imapresource")
58#define DEBUG_AREA "resource.imap"
59 58
60using namespace Imap; 59using namespace Imap;
61using namespace Sink; 60using 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>();
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 1b0a2ec..73ec654 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -37,6 +37,8 @@
37 37
38#include "log.h" 38#include "log.h"
39 39
40SINK_DEBUG_AREA("imapserverproxy")
41
40using namespace Imap; 42using namespace Imap;
41 43
42const char* Imap::Flags::Seen = "\\Seen"; 44const char* Imap::Flags::Seen = "\\Seen";
@@ -54,16 +56,16 @@ static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f)
54{ 56{
55 return KAsync::start<T>([job, f](KAsync::Future<T> &future) { 57 return KAsync::start<T>([job, f](KAsync::Future<T> &future) {
56 QObject::connect(job, &KJob::result, [&future, f](KJob *job) { 58 QObject::connect(job, &KJob::result, [&future, f](KJob *job) {
57 Trace() << "Job done: " << job->metaObject()->className(); 59 SinkTrace() << "Job done: " << job->metaObject()->className();
58 if (job->error()) { 60 if (job->error()) {
59 Warning() << "Job failed: " << job->errorString(); 61 SinkWarning() << "Job failed: " << job->errorString();
60 future.setError(job->error(), job->errorString()); 62 future.setError(job->error(), job->errorString());
61 } else { 63 } else {
62 future.setValue(f(job)); 64 future.setValue(f(job));
63 future.setFinished(); 65 future.setFinished();
64 } 66 }
65 }); 67 });
66 Trace() << "Starting job: " << job->metaObject()->className(); 68 SinkTrace() << "Starting job: " << job->metaObject()->className();
67 job->start(); 69 job->start();
68 }); 70 });
69} 71}
@@ -72,15 +74,15 @@ static KAsync::Job<void> runJob(KJob *job)
72{ 74{
73 return KAsync::start<void>([job](KAsync::Future<void> &future) { 75 return KAsync::start<void>([job](KAsync::Future<void> &future) {
74 QObject::connect(job, &KJob::result, [&future](KJob *job) { 76 QObject::connect(job, &KJob::result, [&future](KJob *job) {
75 Trace() << "Job done: " << job->metaObject()->className(); 77 SinkTrace() << "Job done: " << job->metaObject()->className();
76 if (job->error()) { 78 if (job->error()) {
77 Warning() << "Job failed: " << job->errorString(); 79 SinkWarning() << "Job failed: " << job->errorString();
78 future.setError(job->error(), job->errorString()); 80 future.setError(job->error(), job->errorString());
79 } else { 81 } else {
80 future.setFinished(); 82 future.setFinished();
81 } 83 }
82 }); 84 });
83 Trace() << "Starting job: " << job->metaObject()->className(); 85 SinkTrace() << "Starting job: " << job->metaObject()->className();
84 job->start(); 86 job->start();
85 }); 87 });
86} 88}
@@ -117,11 +119,11 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString
117 auto namespaceJob = new KIMAP::NamespaceJob(mSession); 119 auto namespaceJob = new KIMAP::NamespaceJob(mSession);
118 120
119 return runJob(loginJob).then(runJob(capabilitiesJob)).then<void>([this](){ 121 return runJob(loginJob).then(runJob(capabilitiesJob)).then<void>([this](){
120 Trace() << "Supported capabilities: " << mCapabilities; 122 SinkTrace() << "Supported capabilities: " << mCapabilities;
121 QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; 123 QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE";
122 for (const auto &requiredExtension : requiredExtensions) { 124 for (const auto &requiredExtension : requiredExtensions) {
123 if (!mCapabilities.contains(requiredExtension)) { 125 if (!mCapabilities.contains(requiredExtension)) {
124 Warning() << "Server doesn't support required capability: " << requiredExtension; 126 SinkWarning() << "Server doesn't support required capability: " << requiredExtension;
125 //TODO fail the job 127 //TODO fail the job
126 } 128 }
127 } 129 }
@@ -138,9 +140,9 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString
138 mUserNamespaces << ns.name; 140 mUserNamespaces << ns.name;
139 mUserNamespaceSeparator = ns.separator; 141 mUserNamespaceSeparator = ns.separator;
140 } 142 }
141 Trace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator; 143 SinkTrace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator;
142 Trace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator; 144 SinkTrace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator;
143 Trace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator; 145 SinkTrace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator;
144 }); 146 });
145} 147}
146 148
@@ -291,8 +293,8 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox)
291 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 293 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
292 const QMap<qint64,KIMAP::MessageFlags> &flags, 294 const QMap<qint64,KIMAP::MessageFlags> &flags,
293 const QMap<qint64,KIMAP::MessagePtr> &messages) { 295 const QMap<qint64,KIMAP::MessagePtr> &messages) {
294 Trace() << "Received " << uids.size() << " headers from " << mailbox; 296 SinkTrace() << "Received " << uids.size() << " headers from " << mailbox;
295 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 297 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
296 298
297 //TODO based on the data available here, figure out which messages to actually fetch 299 //TODO based on the data available here, figure out which messages to actually fetch
298 //(we only fetched headers and structure so far) 300 //(we only fetched headers and structure so far)
@@ -344,7 +346,7 @@ KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailb
344 } else { 346 } else {
345 *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; 347 *folder = parentMailbox + mPersonalNamespaceSeparator + folderName;
346 } 348 }
347 Trace() << "Creating subfolder: " << *folder; 349 SinkTrace() << "Creating subfolder: " << *folder;
348 return create(*folder); 350 return create(*folder);
349 }) 351 })
350 .then<QString>([=]() { 352 .then<QString>([=]() {
@@ -360,7 +362,7 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
360 auto parts = oldMailbox.split(mPersonalNamespaceSeparator); 362 auto parts = oldMailbox.split(mPersonalNamespaceSeparator);
361 parts.removeLast(); 363 parts.removeLast();
362 *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; 364 *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName;
363 Trace() << "Renaming subfolder: " << oldMailbox << *folder; 365 SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder;
364 return rename(oldMailbox, *folder); 366 return rename(oldMailbox, *folder);
365 }) 367 })
366 .then<QString>([=]() { 368 .then<QString>([=]() {
@@ -370,14 +372,14 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
370 372
371KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback) 373KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback)
372{ 374{
373 Trace() << "Fetching folders"; 375 SinkTrace() << "Fetching folders";
374 return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ 376 return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){
375 QVector<Folder> list; 377 QVector<Folder> list;
376 for (int i = 0; i < mailboxes.size(); i++) { 378 for (int i = 0; i < mailboxes.size(); i++) {
377 const auto mailbox = mailboxes[i]; 379 const auto mailbox = mailboxes[i];
378 const auto mailboxFlags = flags[i]; 380 const auto mailboxFlags = flags[i];
379 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect)); 381 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect));
380 Log() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect; 382 SinkLog() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect;
381 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect}; 383 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect};
382 } 384 }
383 callback(list); 385 callback(list);
@@ -395,9 +397,9 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::func
395 Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); 397 Q_ASSERT(!mPersonalNamespaceSeparator.isNull());
396 return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> { 398 return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> {
397 return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){ 399 return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){
398 Trace() << "Uids to fetch: " << uidsToFetch; 400 SinkTrace() << "Uids to fetch: " << uidsToFetch;
399 if (uidsToFetch.isEmpty()) { 401 if (uidsToFetch.isEmpty()) {
400 Trace() << "Nothing to fetch"; 402 SinkTrace() << "Nothing to fetch";
401 callback(QVector<Message>()); 403 callback(QVector<Message>());
402 return KAsync::null<void>(); 404 return KAsync::null<void>();
403 } 405 }
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
index 6819685..d9af453 100644
--- a/examples/imapresource/tests/imapserverproxytest.cpp
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -12,6 +12,8 @@
12 12
13using namespace Imap; 13using namespace Imap;
14 14
15SINK_DEBUG_AREA("imapserverproxytest")
16
15/** 17/**
16 */ 18 */
17class ImapServerProxyTest : public QObject 19class ImapServerProxyTest : public QObject
@@ -81,8 +83,8 @@ private slots:
81 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 83 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
82 const QMap<qint64,KIMAP::MessageFlags> &flags, 84 const QMap<qint64,KIMAP::MessageFlags> &flags,
83 const QMap<qint64,KIMAP::MessagePtr> &messages) { 85 const QMap<qint64,KIMAP::MessagePtr> &messages) {
84 Trace() << "Received " << uids.size() << " messages from " << mailbox; 86 SinkTrace() << "Received " << uids.size() << " messages from " << mailbox;
85 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 87 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
86 count += uids.size(); 88 count += uids.size();
87 })); 89 }));
88 90
@@ -106,8 +108,8 @@ private slots:
106 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 108 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
107 const QMap<qint64,KIMAP::MessageFlags> &flags, 109 const QMap<qint64,KIMAP::MessageFlags> &flags,
108 const QMap<qint64,KIMAP::MessagePtr> &messages) { 110 const QMap<qint64,KIMAP::MessagePtr> &messages) {
109 Trace() << "Received " << uids.size() << " messages from " << mailbox; 111 SinkTrace() << "Received " << uids.size() << " messages from " << mailbox;
110 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 112 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
111 count += uids.size(); 113 count += uids.size();
112 })); 114 }));
113 115
diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp
index d8fc02d..256b255 100644
--- a/examples/maildirresource/facade.cpp
+++ b/examples/maildirresource/facade.cpp
@@ -38,11 +38,11 @@ MaildirResourceMailFacade::MaildirResourceMailFacade(const QByteArray &instanceI
38 const auto folderPath = parts.join('/'); 38 const auto folderPath = parts.join('/');
39 const auto path = folderPath + "/cur/"; 39 const auto path = folderPath + "/cur/";
40 40
41 Trace() << "Looking for mail in: " << path << key; 41 SinkTrace_("", "maildirfacade") << "Looking for mail in: " << path << key;
42 QDir dir(path); 42 QDir dir(path);
43 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); 43 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files);
44 if (list.size() != 1) { 44 if (list.size() != 1) {
45 Warning() << "Failed to find message " << path << key << list.size(); 45 SinkWarning_("", "maildirfacade") << "Failed to find message " << path << key << list.size();
46 value.setProperty("mimeMessage", QVariant()); 46 value.setProperty("mimeMessage", QVariant());
47 } else { 47 } else {
48 value.setProperty("mimeMessage", list.at(0).filePath()); 48 value.setProperty("mimeMessage", list.at(0).filePath());
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index e1fcfdf..d7a6fff 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -51,8 +51,7 @@
51#define ENTITY_TYPE_MAIL "mail" 51#define ENTITY_TYPE_MAIL "mail"
52#define ENTITY_TYPE_FOLDER "folder" 52#define ENTITY_TYPE_FOLDER "folder"
53 53
54#undef DEBUG_AREA 54SINK_DEBUG_AREA("maildirresource")
55#define DEBUG_AREA "resource.maildir"
56 55
57using namespace Sink; 56using namespace Sink;
58 57
@@ -65,8 +64,8 @@ static QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath)
65 QDir dir(path); 64 QDir dir(path);
66 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); 65 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files);
67 if (list.size() != 1) { 66 if (list.size() != 1) {
68 Warning() << "Failed to find message " << mimeMessagePath; 67 SinkWarning() << "Failed to find message " << mimeMessagePath;
69 Warning() << "Failed to find message " << path; 68 SinkWarning() << "Failed to find message " << path;
70 return QString(); 69 return QString();
71 } 70 }
72 return list.first().filePath(); 71 return list.first().filePath();
@@ -115,7 +114,7 @@ public:
115 const auto path = getPath(folder, transaction); 114 const auto path = getPath(folder, transaction);
116 KPIM::Maildir maildir(path, false); 115 KPIM::Maildir maildir(path, false);
117 if (!maildir.isValid(true)) { 116 if (!maildir.isValid(true)) {
118 Warning() << "Maildir is not existing: " << path; 117 SinkWarning() << "Maildir is not existing: " << path;
119 } 118 }
120 auto identifier = maildir.addEntryFromPath(oldPath); 119 auto identifier = maildir.addEntryFromPath(oldPath);
121 return path + "/" + identifier; 120 return path + "/" + identifier;
@@ -124,7 +123,7 @@ public:
124 const auto path = getPath(folder, transaction); 123 const auto path = getPath(folder, transaction);
125 KPIM::Maildir maildir(path, false); 124 KPIM::Maildir maildir(path, false);
126 if (!maildir.isValid(true)) { 125 if (!maildir.isValid(true)) {
127 Warning() << "Maildir is not existing: " << path; 126 SinkWarning() << "Maildir is not existing: " << path;
128 } 127 }
129 auto oldIdentifier = KPIM::Maildir::getKeyFromFile(oldPath); 128 auto oldIdentifier = KPIM::Maildir::getKeyFromFile(oldPath);
130 auto pathParts = oldPath.split('/'); 129 auto pathParts = oldPath.split('/');
@@ -135,7 +134,7 @@ public:
135 } 134 }
136 KPIM::Maildir oldMaildir(oldDirectory, false); 135 KPIM::Maildir oldMaildir(oldDirectory, false);
137 if (!oldMaildir.isValid(false)) { 136 if (!oldMaildir.isValid(false)) {
138 Warning() << "Maildir is not existing: " << path; 137 SinkWarning() << "Maildir is not existing: " << path;
139 } 138 }
140 auto identifier = oldMaildir.moveEntryTo(oldIdentifier, maildir); 139 auto identifier = oldMaildir.moveEntryTo(oldIdentifier, maildir);
141 return path + "/" + identifier; 140 return path + "/" + identifier;
@@ -158,7 +157,7 @@ public:
158 const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); 157 const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString();
159 const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); 158 const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString();
160 if (mimeMessageChanged || folderChanged) { 159 if (mimeMessageChanged || folderChanged) {
161 Trace() << "Moving mime message: " << mimeMessageChanged << folderChanged; 160 SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged;
162 auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction); 161 auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction);
163 if (newPath != oldEntity.getProperty("mimeMessage").toString()) { 162 if (newPath != oldEntity.getProperty("mimeMessage").toString()) {
164 const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); 163 const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString());
@@ -278,7 +277,7 @@ public:
278 { 277 {
279 const QByteArray bufferType = ENTITY_TYPE_FOLDER; 278 const QByteArray bufferType = ENTITY_TYPE_FOLDER;
280 QStringList folderList = listAvailableFolders(); 279 QStringList folderList = listAvailableFolders();
281 Trace() << "Found folders " << folderList; 280 SinkTrace() << "Found folders " << folderList;
282 281
283 scanForRemovals(bufferType, 282 scanForRemovals(bufferType,
284 [this, &bufferType](const std::function<void(const QByteArray &)> &callback) { 283 [this, &bufferType](const std::function<void(const QByteArray &)> &callback) {
@@ -304,23 +303,23 @@ public:
304 303
305 void synchronizeMails(const QString &path) 304 void synchronizeMails(const QString &path)
306 { 305 {
307 Trace() << "Synchronizing mails" << path; 306 SinkTrace() << "Synchronizing mails" << path;
308 auto time = QSharedPointer<QTime>::create(); 307 auto time = QSharedPointer<QTime>::create();
309 time->start(); 308 time->start();
310 const QByteArray bufferType = ENTITY_TYPE_MAIL; 309 const QByteArray bufferType = ENTITY_TYPE_MAIL;
311 310
312 KPIM::Maildir maildir(path, true); 311 KPIM::Maildir maildir(path, true);
313 if (!maildir.isValid()) { 312 if (!maildir.isValid()) {
314 Warning() << "Failed to sync folder."; 313 SinkWarning() << "Failed to sync folder.";
315 return; 314 return;
316 } 315 }
317 316
318 Trace() << "Importing new mail."; 317 SinkTrace() << "Importing new mail.";
319 maildir.importNewMails(); 318 maildir.importNewMails();
320 319
321 auto listingPath = maildir.pathToCurrent(); 320 auto listingPath = maildir.pathToCurrent();
322 auto entryIterator = QSharedPointer<QDirIterator>::create(listingPath, QDir::Files); 321 auto entryIterator = QSharedPointer<QDirIterator>::create(listingPath, QDir::Files);
323 Trace() << "Looking into " << listingPath; 322 SinkTrace() << "Looking into " << listingPath;
324 323
325 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); 324 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8());
326 325
@@ -332,7 +331,7 @@ public:
332 callback(sinkId); 331 callback(sinkId);
333 }, 332 },
334 [&](const Index::Error &error) { 333 [&](const Index::Error &error) {
335 Warning() << "Error in index: " << error.message << property; 334 SinkWarning() << "Error in index: " << error.message << property;
336 }); 335 });
337 }, 336 },
338 [](const QByteArray &remoteId) -> bool { 337 [](const QByteArray &remoteId) -> bool {
@@ -350,7 +349,7 @@ public:
350 const auto flags = maildir.readEntryFlags(fileName); 349 const auto flags = maildir.readEntryFlags(fileName);
351 const auto maildirKey = maildir.getKeyFromFile(fileName); 350 const auto maildirKey = maildir.getKeyFromFile(fileName);
352 351
353 Trace() << "Found a mail " << filePath << " : " << fileName; 352 SinkTrace() << "Found a mail " << filePath << " : " << fileName;
354 353
355 Sink::ApplicationDomain::Mail mail; 354 Sink::ApplicationDomain::Mail mail;
356 mail.setProperty("folder", folderLocalId); 355 mail.setProperty("folder", folderLocalId);
@@ -362,12 +361,12 @@ public:
362 createOrModify(bufferType, remoteId, mail); 361 createOrModify(bufferType, remoteId, mail);
363 } 362 }
364 const auto elapsed = time->elapsed(); 363 const auto elapsed = time->elapsed();
365 Log() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 364 SinkLog() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
366 } 365 }
367 366
368 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 367 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
369 { 368 {
370 Log() << " Synchronizing"; 369 SinkLog() << " Synchronizing";
371 return KAsync::start<void, KAsync::Job<void> >([this]() { 370 return KAsync::start<void, KAsync::Job<void> >([this]() {
372 KPIM::Maildir maildir(mMaildirPath, true); 371 KPIM::Maildir maildir(mMaildirPath, true);
373 if (!maildir.isValid(false)) { 372 if (!maildir.isValid(false)) {
@@ -381,7 +380,7 @@ public:
381 //Don't let the transaction grow too much 380 //Don't let the transaction grow too much
382 commit(); 381 commit();
383 } 382 }
384 Log() << "Done Synchronizing"; 383 SinkLog() << "Done Synchronizing";
385 return KAsync::null<void>(); 384 return KAsync::null<void>();
386 }); 385 });
387 } 386 }
@@ -402,15 +401,15 @@ public:
402 { 401 {
403 if (operation == Sink::Operation_Creation) { 402 if (operation == Sink::Operation_Creation) {
404 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); 403 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath());
405 Trace() << "Mail created: " << remoteId; 404 SinkTrace() << "Mail created: " << remoteId;
406 return KAsync::start<QByteArray>([=]() -> QByteArray { 405 return KAsync::start<QByteArray>([=]() -> QByteArray {
407 return remoteId.toUtf8(); 406 return remoteId.toUtf8();
408 }); 407 });
409 } else if (operation == Sink::Operation_Removal) { 408 } else if (operation == Sink::Operation_Removal) {
410 Trace() << "Removing a mail: " << oldRemoteId; 409 SinkTrace() << "Removing a mail: " << oldRemoteId;
411 return KAsync::null<QByteArray>(); 410 return KAsync::null<QByteArray>();
412 } else if (operation == Sink::Operation_Modification) { 411 } else if (operation == Sink::Operation_Modification) {
413 Trace() << "Modifying a mail: " << oldRemoteId; 412 SinkTrace() << "Modifying a mail: " << oldRemoteId;
414 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); 413 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath());
415 return KAsync::start<QByteArray>([=]() -> QByteArray { 414 return KAsync::start<QByteArray>([=]() -> QByteArray {
416 return remoteId.toUtf8(); 415 return remoteId.toUtf8();
@@ -425,7 +424,7 @@ public:
425 auto folderName = folder.getName(); 424 auto folderName = folder.getName();
426 //FIXME handle non toplevel folders 425 //FIXME handle non toplevel folders
427 auto path = mMaildirPath + "/" + folderName; 426 auto path = mMaildirPath + "/" + folderName;
428 Trace() << "Creating a new folder: " << path; 427 SinkTrace() << "Creating a new folder: " << path;
429 KPIM::Maildir maildir(path, false); 428 KPIM::Maildir maildir(path, false);
430 maildir.create(); 429 maildir.create();
431 return KAsync::start<QByteArray>([=]() -> QByteArray { 430 return KAsync::start<QByteArray>([=]() -> QByteArray {
@@ -433,12 +432,12 @@ public:
433 }); 432 });
434 } else if (operation == Sink::Operation_Removal) { 433 } else if (operation == Sink::Operation_Removal) {
435 const auto path = oldRemoteId; 434 const auto path = oldRemoteId;
436 Trace() << "Removing a folder: " << path; 435 SinkTrace() << "Removing a folder: " << path;
437 KPIM::Maildir maildir(path, false); 436 KPIM::Maildir maildir(path, false);
438 maildir.remove(); 437 maildir.remove();
439 return KAsync::null<QByteArray>(); 438 return KAsync::null<QByteArray>();
440 } else if (operation == Sink::Operation_Modification) { 439 } else if (operation == Sink::Operation_Modification) {
441 Warning() << "Folder modifications are not implemented"; 440 SinkWarning() << "Folder modifications are not implemented";
442 return KAsync::start<QByteArray>([=]() -> QByteArray { 441 return KAsync::start<QByteArray>([=]() -> QByteArray {
443 return oldRemoteId; 442 return oldRemoteId;
444 }); 443 });
@@ -472,7 +471,7 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh
472 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); 471 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>);
473 472
474 KPIM::Maildir dir(mMaildirPath, true); 473 KPIM::Maildir dir(mMaildirPath, true);
475 Trace() << "Started maildir resource for maildir: " << mMaildirPath; 474 SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath;
476 { 475 {
477 auto draftsFolder = dir.addSubFolder("Drafts"); 476 auto draftsFolder = dir.addSubFolder("Drafts");
478 auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts"); 477 auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts");
@@ -503,7 +502,7 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
503 auto entityStore = QSharedPointer<EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction); 502 auto entityStore = QSharedPointer<EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction);
504 auto syncStore = QSharedPointer<RemoteIdMap>::create(synchronizationTransaction); 503 auto syncStore = QSharedPointer<RemoteIdMap>::create(synchronizationTransaction);
505 504
506 Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; 505 SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue;
507 506
508 if (domainType == ENTITY_TYPE_MAIL) { 507 if (domainType == ENTITY_TYPE_MAIL) {
509 auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId); 508 auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId);
@@ -542,7 +541,7 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
542 auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId); 541 auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId);
543 542
544 if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { 543 if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) {
545 Trace() << "Inspecting cache integrity" << remoteId; 544 SinkTrace() << "Inspecting cache integrity" << remoteId;
546 if (!QDir(remoteId).exists()) { 545 if (!QDir(remoteId).exists()) {
547 return KAsync::error<void>(1, "The directory is not existing: " + remoteId); 546 return KAsync::error<void>(1, "The directory is not existing: " + remoteId);
548 } 547 }
@@ -553,14 +552,14 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
553 expectedCount++; 552 expectedCount++;
554 }, 553 },
555 [&](const Index::Error &error) { 554 [&](const Index::Error &error) {
556 Warning() << "Error in index: " << error.message << property; 555 SinkWarning() << "Error in index: " << error.message << property;
557 }); 556 });
558 557
559 QDir dir(remoteId + "/cur"); 558 QDir dir(remoteId + "/cur");
560 const QFileInfoList list = dir.entryInfoList(QDir::Files); 559 const QFileInfoList list = dir.entryInfoList(QDir::Files);
561 if (list.size() != expectedCount) { 560 if (list.size() != expectedCount) {
562 for (const auto &fileInfo : list) { 561 for (const auto &fileInfo : list) {
563 Warning() << "Found in cache: " << fileInfo.fileName(); 562 SinkWarning() << "Found in cache: " << fileInfo.fileName();
564 } 563 }
565 return KAsync::error<void>(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount)); 564 return KAsync::error<void>(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount));
566 } 565 }
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp
index 1e93bdf..a729d4d 100644
--- a/examples/mailtransportresource/mailtransportresource.cpp
+++ b/examples/mailtransportresource/mailtransportresource.cpp
@@ -44,6 +44,8 @@
44 44
45#define ENTITY_TYPE_MAIL "mail" 45#define ENTITY_TYPE_MAIL "mail"
46 46
47SINK_DEBUG_AREA("mailtransportresource")
48
47using namespace Sink; 49using namespace Sink;
48 50
49//TODO fold into synchronizer 51//TODO fold into synchronizer
@@ -58,7 +60,7 @@ public:
58 KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE 60 KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
59 { 61 {
60 if (operation == Sink::Operation_Creation) { 62 if (operation == Sink::Operation_Creation) {
61 Trace() << "Dispatching message."; 63 SinkTrace() << "Dispatching message.";
62 // return send(mail, mSettings); 64 // return send(mail, mSettings);
63 } else if (operation == Sink::Operation_Removal) { 65 } else if (operation == Sink::Operation_Removal) {
64 } else if (operation == Sink::Operation_Modification) { 66 } else if (operation == Sink::Operation_Modification) {
@@ -86,9 +88,9 @@ public:
86 msg->setHead(KMime::CRLFtoLF(data)); 88 msg->setHead(KMime::CRLFtoLF(data));
87 msg->parse(); 89 msg->parse();
88 if (settings.testMode) { 90 if (settings.testMode) {
89 Log() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); 91 SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier();
90 auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; 92 auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/";
91 Trace() << path; 93 SinkTrace() << path;
92 QDir dir; 94 QDir dir;
93 dir.mkpath(path); 95 dir.mkpath(path);
94 QFile f(path+ mail.identifier()); 96 QFile f(path+ mail.identifier());
@@ -97,9 +99,9 @@ public:
97 f.close(); 99 f.close();
98 } else { 100 } else {
99 if (MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8())) { 101 if (MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8())) {
100 Log() << "Sent message successfully"; 102 SinkLog() << "Sent message successfully";
101 } else { 103 } else {
102 Log() << "Failed to send message"; 104 SinkLog() << "Failed to send message";
103 return KAsync::error<void>(1, "Failed to send the message."); 105 return KAsync::error<void>(1, "Failed to send the message.");
104 } 106 }
105 } 107 }
@@ -108,13 +110,13 @@ public:
108 110
109 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 111 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
110 { 112 {
111 Log() << " Synchronizing"; 113 SinkLog() << " Synchronizing";
112 return KAsync::start<void>([this](KAsync::Future<void> future) { 114 return KAsync::start<void>([this](KAsync::Future<void> future) {
113 Sink::Query query; 115 Sink::Query query;
114 QList<ApplicationDomain::Mail> toSend; 116 QList<ApplicationDomain::Mail> toSend;
115 Log() << " Looking for mail"; 117 SinkLog() << " Looking for mail";
116 store().reader<ApplicationDomain::Mail>().query(query, [&](const ApplicationDomain::Mail &mail) -> bool { 118 store().reader<ApplicationDomain::Mail>().query(query, [&](const ApplicationDomain::Mail &mail) -> bool {
117 Trace() << "Found mail: " << mail.identifier(); 119 SinkTrace() << "Found mail: " << mail.identifier();
118 if (!mail.getSent()) { 120 if (!mail.getSent()) {
119 toSend << mail; 121 toSend << mail;
120 } 122 }