From 2485dbb0f287d93061bc5098a8e11358d3d0d6f9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 18 May 2018 10:46:15 +0200 Subject: Test what happens if we add a bogus message to the imap resource. This test currently fails because we fail to recover. --- examples/imapresource/imapresource.cpp | 4 +++ tests/mailtest.cpp | 59 ++++++++++++++++++++++++++++++++++ tests/mailtest.h | 1 + 3 files changed, 64 insertions(+) diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index b9c819b..0527902 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -897,6 +897,10 @@ protected: const auto folderRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); const auto mailRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_MAIL, mail.identifier()); if (mailRemoteId.isEmpty() || folderRemoteId.isEmpty()) { + //There is no remote id to find if we expect the message to not exist + if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType && !expectedValue.toBool()) { + return KAsync::null(); + } SinkWarning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId; return KAsync::error(); } diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index 88cacd2..8e20fae 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -474,3 +474,62 @@ void MailTest::testModifyMailToTrash() } VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, true))); } + +void MailTest::testBogusMessageAppend() +{ + auto folder = Folder::create(mResourceInstanceIdentifier); + folder.setName("bogusfolder"); + VERIFYEXEC(Store::create(folder)); + + Mail bogusMail; + { + auto mail = Mail::create(mResourceInstanceIdentifier); + mail.setMimeMessage("Bogus message: \0 this doesn't make any sense and contains NUL."); + mail.setFolder(folder); + + VERIFYEXEC(Store::create(mail)); + + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + auto mails = Store::read(Query().request().request().request()); + QCOMPARE(mails.size(), 1); + bogusMail = mails.at(0); + + VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier)); + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, false))); + //The cache will be off by one (because we failed to replay) + // VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::CacheIntegrityInspection(folder))); + } + + + //Ensure we can still append further messages: + { + auto mail = Mail::create(mResourceInstanceIdentifier); + { + auto message = KMime::Message::Ptr::create(); + message->subject(true)->fromUnicodeString("Subject", "utf8"); + message->assemble(); + mail.setMimeMessage(message->encodedContent(true)); + } + mail.setFolder(folder); + VERIFYEXEC(Store::create(mail)); + + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + auto mails = Store::read(Query().request().request().request()); + QCOMPARE(mails.size(), 2); + + VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier)); + //The mail is still not available, because we'll end up trying to replay the bogus mail again. + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, false))); + + //Fix the situation by deleting the bogus mail and retrying to sync. + VERIFYEXEC(Store::remove(bogusMail)); + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier)); + + //This will fail because we still try to resync the previous mail + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, true))); + //The cache will be off by one (because we failed to replay) + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::CacheIntegrityInspection(folder))); + } + +} diff --git a/tests/mailtest.h b/tests/mailtest.h index b827188..757da1b 100644 --- a/tests/mailtest.h +++ b/tests/mailtest.h @@ -53,6 +53,7 @@ private slots: void testModifyMailToDraft(); void testModifyMailToTrash(); + void testBogusMessageAppend(); }; } -- cgit v1.2.3