diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-26 13:21:20 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-26 13:21:20 +0200 |
commit | cf487248df311bd055844ce44786e28ea5aa7c2c (patch) | |
tree | 06c9bd80278855e4810cb194362e6e597a5329ee /examples/maildirresource/maildirresource.cpp | |
parent | 3db36de42fc986341b0fac8c4cbfe869f0bac356 (diff) | |
download | sink-cf487248df311bd055844ce44786e28ea5aa7c2c.tar.gz sink-cf487248df311bd055844ce44786e28ea5aa7c2c.zip |
Reuse mailpreprocessor
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 35 |
1 files changed, 5 insertions, 30 deletions
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 | ||