summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-01 13:14:14 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-01 13:14:14 +0100
commit2f0605ded80cd4c216b8cbaaf228e98811207744 (patch)
tree98206b6ff9d5e277fdeb606693a4e05a48adba8f
parent0b233494a69b5e9cd86e91c60016a294e6c9ef50 (diff)
downloadsink-2f0605ded80cd4c216b8cbaaf228e98811207744.tar.gz
sink-2f0605ded80cd4c216b8cbaaf228e98811207744.zip
Ensure maildir flagchanges work completely
-rw-r--r--examples/maildirresource/libmaildir/maildir.cpp2
-rw-r--r--examples/maildirresource/libmaildir/maildir.h2
-rw-r--r--examples/maildirresource/maildirresource.cpp12
-rw-r--r--tests/maildirresourcetest.cpp97
4 files changed, 74 insertions, 39 deletions
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp
index 3d4630f..f8ca606 100644
--- a/examples/maildirresource/libmaildir/maildir.cpp
+++ b/examples/maildirresource/libmaildir/maildir.cpp
@@ -560,7 +560,7 @@ QDateTime Maildir::lastModified(const QString& key) const
560 return info.lastModified(); 560 return info.lastModified();
561} 561}
562 562
563QByteArray Maildir::readEntryHeadersFromFile(const QString& file) const 563QByteArray Maildir::readEntryHeadersFromFile(const QString& file)
564{ 564{
565 QByteArray result; 565 QByteArray result;
566 566
diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h
index a89a832..42d53e6 100644
--- a/examples/maildirresource/libmaildir/maildir.h
+++ b/examples/maildirresource/libmaildir/maildir.h
@@ -184,7 +184,7 @@ public:
184 * Return the contents of the headers section of the file the maildir with the given @p file, that 184 * Return the contents of the headers section of the file the maildir with the given @p file, that
185 * is a full path to the file. You can get it by using findRealKey(key) . 185 * is a full path to the file. You can get it by using findRealKey(key) .
186 */ 186 */
187 QByteArray readEntryHeadersFromFile( const QString& file ) const; 187 static QByteArray readEntryHeadersFromFile( const QString& file );
188 188
189 /** 189 /**
190 * Return the contents of the headers section of the file the maildir with the given @p key. 190 * Return the contents of the headers section of the file the maildir with the given @p key.
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index 33883a7..922eb5a 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -311,6 +311,18 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
311 } 311 }
312 return KAsync::null<void>(); 312 return KAsync::null<void>();
313 } 313 }
314 if (property == "subject") {
315 const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction);
316
317 KMime::Message *msg = new KMime::Message;
318 msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(remoteId)));
319 msg->parse();
320
321 if (msg->subject(true)->asUnicodeString() != expectedValue.toString()) {
322 return KAsync::error<void>(1, "Subject not as expected.");
323 }
324 return KAsync::null<void>();
325 }
314 } 326 }
315 if (inspectionType == Sink::Resources::Inspection::ExistenceInspectionType) { 327 if (inspectionType == Sink::Resources::Inspection::ExistenceInspectionType) {
316 const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); 328 const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction);
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index 6ad6ca6..85c329e 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -307,26 +307,26 @@ private Q_SLOTS:
307 Store::flushMessageQueue(query.resources).exec().waitForFinished(); 307 Store::flushMessageQueue(query.resources).exec().waitForFinished();
308 308
309 auto result = Store::fetchOne<Folder>( 309 auto result = Store::fetchOne<Folder>(
310 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 310 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")
311 )
312 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) {
313 return Store::fetchAll<Mail>(
314 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject")
311 ) 315 )
312 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { 316 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) {
313 return Store::fetchAll<Mail>( 317 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
314 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 318 if (mails.size() != 1) {
315 ) 319 return KAsync::error<void>(1, "Wrong number of mails.");
316 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 320 }
317 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 321 auto mail = mails.first();
318 if (mails.size() != 1) { 322
319 return KAsync::error<void>(1, "Wrong number of mails."); 323 return Store::remove(*mail)
320 } 324 .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already
321 auto mail = mails.first(); 325 .then(Resources::inspect<Mail>(Resources::Inspection::ExistenceInspection(*mail, false)));
322
323 return Store::remove(*mail)
324 .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already
325 .then(Resources::inspect<Mail>(Resources::Inspection::ExistenceInspection(*mail, false)));
326 })
327 .then<void>([](){});
328 }) 326 })
329 .exec(); 327 .then<void>([](){});
328 })
329 .exec();
330 result.waitForFinished(); 330 result.waitForFinished();
331 QVERIFY(!result.errorCode()); 331 QVERIFY(!result.errorCode());
332 } 332 }
@@ -340,31 +340,54 @@ private Q_SLOTS:
340 Store::synchronize(query).exec().waitForFinished(); 340 Store::synchronize(query).exec().waitForFinished();
341 Store::flushMessageQueue(query.resources).exec().waitForFinished(); 341 Store::flushMessageQueue(query.resources).exec().waitForFinished();
342 342
343 Folder f;
344
343 auto result = Store::fetchOne<Folder>( 345 auto result = Store::fetchOne<Folder>(
344 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 346 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")
347 )
348 .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) {
349 f = folder;
350 return Store::fetchAll<Mail>(
351 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject")
345 ) 352 )
346 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) {
347 Trace() << "Found a folder" << folder.identifier(); 353 Trace() << "Found a folder" << folder.identifier();
348 return Store::fetchAll<Mail>( 354 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) {
349 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 355 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
350 ) 356 if (mails.size() != 1) {
351 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 357 return KAsync::error<void>(1, "Wrong number of mails.");
352 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 358 }
353 if (mails.size() != 1) { 359 auto mail = mails.first();
354 return KAsync::error<void>(1, "Wrong number of mails."); 360 mail->setProperty("unread", true);
355 } 361 return Store::modify(*mail)
356 auto mail = mails.first(); 362 .then<void>(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already
357 mail->setProperty("unread", true); 363 .then(Resources::inspect<Mail>(Resources::Inspection::PropertyInspection(*mail, "unread", true)))
358 auto inspectionCommand = Resources::Inspection::PropertyInspection(*mail, "unread", true); 364 .then(Resources::inspect<Mail>(Resources::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject"))));
359 return Store::modify(*mail)
360 .then<void>(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already
361 .then(Resources::inspect<Mail>(inspectionCommand));
362 })
363 .then<void>([](){});
364 }) 365 })
365 .exec(); 366 .then<void>([](){});
367 })
368 .exec();
366 result.waitForFinished(); 369 result.waitForFinished();
367 QVERIFY(!result.errorCode()); 370 QVERIFY(!result.errorCode());
371
372 auto result2 = Store::fetchAll<Mail>(
373 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject")
374 )
375 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) {
376 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
377 if (mails.size() != 1) {
378 qWarning() << "Wrong number of mails";
379 return KAsync::error<void>(1, "Wrong number of mails.");
380 }
381 auto mail = mails.first();
382 if (mail->getProperty("subject").toString().isEmpty()) {
383 qWarning() << "Wrong subject";
384 return KAsync::error<void>(1, "Wrong subject.");
385 }
386 return KAsync::null<void>();
387 })
388 .exec();
389 result2.waitForFinished();
390 QVERIFY(!result2.errorCode());
368 } 391 }
369 392
370}; 393};