From cf487248df311bd055844ce44786e28ea5aa7c2c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 26 Jun 2016 13:21:20 +0200 Subject: Reuse mailpreprocessor --- common/mailpreprocessor.cpp | 7 +++++- common/mailpreprocessor.h | 3 +++ examples/maildirresource/maildirresource.cpp | 35 ++++------------------------ 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/common/mailpreprocessor.cpp b/common/mailpreprocessor.cpp index 64cb3d9..005a93e 100644 --- a/common/mailpreprocessor.cpp +++ b/common/mailpreprocessor.cpp @@ -29,9 +29,14 @@ using namespace Sink; +QString MailPropertyExtractor::getFilePathFromMimeMessagePath(const QString &s) const +{ + return s; +} + void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail) { - const auto mimeMessagePath = mail.getMimeMessagePath(); + const auto mimeMessagePath = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); Trace() << "Updating indexed properties " << mimeMessagePath; QFile f(mimeMessagePath); if (!f.open(QIODevice::ReadOnly)) { diff --git a/common/mailpreprocessor.h b/common/mailpreprocessor.h index 715e336..473931c 100644 --- a/common/mailpreprocessor.h +++ b/common/mailpreprocessor.h @@ -26,6 +26,9 @@ public: virtual ~MailPropertyExtractor(){} virtual void newEntity(Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE; virtual void modifiedEntity(const Sink::ApplicationDomain::Mail &oldMail, Sink::ApplicationDomain::Mail &newMail,Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE; +protected: + virtual QString getFilePathFromMimeMessagePath(const QString &) const; + private: void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail); }; diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 92cfceb..b14a1bd 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -39,6 +39,7 @@ #include "synchronizer.h" #include "sourcewriteback.h" #include "adaptorfactoryregistry.h" +#include "mailpreprocessor.h" #include "specialpurposepreprocessor.h" #include #include @@ -71,38 +72,12 @@ static QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath) return list.first().filePath(); } -class MaildirMailPropertyExtractor : public Sink::Preprocessor +class MaildirMailPropertyExtractor : public MailPropertyExtractor { -public: - MaildirMailPropertyExtractor() {} - - void updatedIndexedProperties(Sink::ApplicationDomain::BufferAdaptor &newEntity) - { - const auto filePath = getFilePathFromMimeMessagePath(newEntity.getProperty("mimeMessage").toString()); - - KMime::Message *msg = new KMime::Message; - msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(filePath))); - msg->parse(); - - newEntity.setProperty("subject", msg->subject(true)->asUnicodeString()); - newEntity.setProperty("sender", msg->from(true)->asUnicodeString()); - newEntity.setProperty("senderName", msg->from(true)->asUnicodeString()); - newEntity.setProperty("date", msg->date(true)->dateTime()); - } - - void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE - { - updatedIndexedProperties(newEntity); - } - - void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, - Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE - { - updatedIndexedProperties(newEntity); - } - - void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE +protected: + virtual QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath) const Q_DECL_OVERRIDE { + return ::getFilePathFromMimeMessagePath(mimeMessagePath); } }; -- cgit v1.2.3