diff options
-rw-r--r-- | common/mailpreprocessor.cpp | 7 | ||||
-rw-r--r-- | common/mailpreprocessor.h | 3 | ||||
-rw-r--r-- | 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 @@ | |||
29 | 29 | ||
30 | using namespace Sink; | 30 | using namespace Sink; |
31 | 31 | ||
32 | QString MailPropertyExtractor::getFilePathFromMimeMessagePath(const QString &s) const | ||
33 | { | ||
34 | return s; | ||
35 | } | ||
36 | |||
32 | void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail) | 37 | void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail) |
33 | { | 38 | { |
34 | const auto mimeMessagePath = mail.getMimeMessagePath(); | 39 | const auto mimeMessagePath = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); |
35 | Trace() << "Updating indexed properties " << mimeMessagePath; | 40 | Trace() << "Updating indexed properties " << mimeMessagePath; |
36 | QFile f(mimeMessagePath); | 41 | QFile f(mimeMessagePath); |
37 | if (!f.open(QIODevice::ReadOnly)) { | 42 | 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: | |||
26 | virtual ~MailPropertyExtractor(){} | 26 | virtual ~MailPropertyExtractor(){} |
27 | virtual void newEntity(Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE; | 27 | virtual void newEntity(Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE; |
28 | virtual void modifiedEntity(const Sink::ApplicationDomain::Mail &oldMail, Sink::ApplicationDomain::Mail &newMail,Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE; | 28 | virtual void modifiedEntity(const Sink::ApplicationDomain::Mail &oldMail, Sink::ApplicationDomain::Mail &newMail,Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE; |
29 | protected: | ||
30 | virtual QString getFilePathFromMimeMessagePath(const QString &) const; | ||
31 | |||
29 | private: | 32 | private: |
30 | void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail); | 33 | void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail); |
31 | }; | 34 | }; |
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 @@ | |||
39 | #include "synchronizer.h" | 39 | #include "synchronizer.h" |
40 | #include "sourcewriteback.h" | 40 | #include "sourcewriteback.h" |
41 | #include "adaptorfactoryregistry.h" | 41 | #include "adaptorfactoryregistry.h" |
42 | #include "mailpreprocessor.h" | ||
42 | #include "specialpurposepreprocessor.h" | 43 | #include "specialpurposepreprocessor.h" |
43 | #include <QDate> | 44 | #include <QDate> |
44 | #include <QUuid> | 45 | #include <QUuid> |
@@ -71,38 +72,12 @@ static QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath) | |||
71 | return list.first().filePath(); | 72 | return list.first().filePath(); |
72 | } | 73 | } |
73 | 74 | ||
74 | class MaildirMailPropertyExtractor : public Sink::Preprocessor | 75 | class MaildirMailPropertyExtractor : public MailPropertyExtractor |
75 | { | 76 | { |
76 | public: | 77 | protected: |
77 | MaildirMailPropertyExtractor() {} | 78 | virtual QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath) const Q_DECL_OVERRIDE |
78 | |||
79 | void updatedIndexedProperties(Sink::ApplicationDomain::BufferAdaptor &newEntity) | ||
80 | { | ||
81 | const auto filePath = getFilePathFromMimeMessagePath(newEntity.getProperty("mimeMessage").toString()); | ||
82 | |||
83 | KMime::Message *msg = new KMime::Message; | ||
84 | msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(filePath))); | ||
85 | msg->parse(); | ||
86 | |||
87 | newEntity.setProperty("subject", msg->subject(true)->asUnicodeString()); | ||
88 | newEntity.setProperty("sender", msg->from(true)->asUnicodeString()); | ||
89 | newEntity.setProperty("senderName", msg->from(true)->asUnicodeString()); | ||
90 | newEntity.setProperty("date", msg->date(true)->dateTime()); | ||
91 | } | ||
92 | |||
93 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
94 | { | ||
95 | updatedIndexedProperties(newEntity); | ||
96 | } | ||
97 | |||
98 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | ||
99 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
100 | { | ||
101 | updatedIndexedProperties(newEntity); | ||
102 | } | ||
103 | |||
104 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
105 | { | 79 | { |
80 | return ::getFilePathFromMimeMessagePath(mimeMessagePath); | ||
106 | } | 81 | } |
107 | }; | 82 | }; |
108 | 83 | ||