From ba16fd400dfd3468e90b9fe2683a4d9606fc99ee Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 19 Jun 2016 12:38:46 +0200 Subject: Use shared preprocessors in mailtransport. --- .../mailtransportresource.cpp | 53 ++-------------------- .../tests/mailtransporttest.cpp | 4 +- 2 files changed, 5 insertions(+), 52 deletions(-) diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 51e4976..1e93bdf 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp @@ -39,60 +39,13 @@ #include #include #include +#include +#include #define ENTITY_TYPE_MAIL "mail" using namespace Sink; -class MimeMessageMover : public Sink::EntityPreprocessor -{ -public: - MimeMessageMover(const QByteArray &resourceInstanceIdentifier) : Sink::EntityPreprocessor(), mResourceInstanceIdentifier(resourceInstanceIdentifier) {} - - QString moveMessage(const QString &oldPath, const Sink::ApplicationDomain::Mail &mail) - { - const auto directory = Sink::resourceStorageLocation(mResourceInstanceIdentifier); - const auto filePath = directory + "/" + mail.identifier(); - if (oldPath != filePath) { - if (!QDir().mkpath(directory)) { - Warning() << "Failed to create the directory: " << directory; - } - QFile::remove(filePath); - QFile origFile(oldPath); - if (!origFile.open(QIODevice::ReadWrite)) { - Warning() << "Failed to open the original file with write rights: " << origFile.errorString(); - } - if (!origFile.rename(filePath)) { - Warning() << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); - } - origFile.close(); - return filePath; - } - return oldPath; - } - - void newEntity(Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE - { - if (!mail.getMimeMessagePath().isEmpty()) { - mail.setMimeMessagePath(moveMessage(mail.getMimeMessagePath(), mail)); - } - } - - void modifiedEntity(const Sink::ApplicationDomain::Mail &oldMail, Sink::ApplicationDomain::Mail &newMail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE - { - if (!newMail.getMimeMessagePath().isEmpty()) { - newMail.setMimeMessagePath(moveMessage(newMail.getMimeMessagePath(), newMail)); - } - } - - void deletedEntity(const Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE - { - QFile::remove(mail.getMimeMessagePath()); - } - QByteArray mResourceInstanceIdentifier; -}; - - //TODO fold into synchronizer class MailtransportWriteback : public Sink::SourceWriteBack { @@ -210,7 +163,7 @@ MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifie changereplay->mSettings = mSettings; setupChangereplay(changereplay); - setupPreprocessors(ENTITY_TYPE_MAIL, QVector() << new MimeMessageMover(mResourceInstanceIdentifier)); + setupPreprocessors(ENTITY_TYPE_MAIL, QVector() << new MimeMessageMover << new MailPropertyExtractor << new DefaultIndexUpdater); } void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp index f1190a7..3ce5f82 100644 --- a/examples/mailtransportresource/tests/mailtransporttest.cpp +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp @@ -65,9 +65,9 @@ private slots: VERIFYEXEC(Store::synchronize(Query::ResourceFilter(mResourceInstanceIdentifier))); VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, true))); - auto sentMail = Store::readOne(Query::IdentityFilter(mail).request()); + auto sentMail = Store::readOne(Query::IdentityFilter(mail).request().request()); QVERIFY(sentMail.getSent()); - + QVERIFY(!sentMail.getSubject().isEmpty()); } //TODO test mail that fails to be sent. add a special header to the mail and have the resource fail sending. Ensure we can modify the mail to fix sending of the message. -- cgit v1.2.3