diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-29 15:57:59 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-29 15:57:59 +0200 |
commit | 66a37692cb3d20de354cfeb51ef6cb1d19bd55b1 (patch) | |
tree | ab254e9072264b2aff30f9b453400d9abfae4ec4 /examples/maildirresource/maildirresource.cpp | |
parent | f211ffd9aaa57fe46a792c3b005981d55dde670f (diff) | |
download | sink-66a37692cb3d20de354cfeb51ef6cb1d19bd55b1.tar.gz sink-66a37692cb3d20de354cfeb51ef6cb1d19bd55b1.zip |
Separated the mail property extractor
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 9503971..feccefc 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -70,6 +70,41 @@ static QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath) | |||
70 | return list.first().filePath(); | 70 | return list.first().filePath(); |
71 | } | 71 | } |
72 | 72 | ||
73 | class MailPropertyExtractor : public Sink::Preprocessor | ||
74 | { | ||
75 | public: | ||
76 | MailPropertyExtractor() {} | ||
77 | |||
78 | void updatedIndexedProperties(Sink::ApplicationDomain::BufferAdaptor &newEntity) | ||
79 | { | ||
80 | const auto filePath = getFilePathFromMimeMessagePath(newEntity.getProperty("mimeMessage").toString()); | ||
81 | |||
82 | KMime::Message *msg = new KMime::Message; | ||
83 | msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(filePath))); | ||
84 | msg->parse(); | ||
85 | |||
86 | newEntity.setProperty("subject", msg->subject(true)->asUnicodeString()); | ||
87 | newEntity.setProperty("sender", msg->from(true)->asUnicodeString()); | ||
88 | newEntity.setProperty("senderName", msg->from(true)->asUnicodeString()); | ||
89 | newEntity.setProperty("date", msg->date(true)->dateTime()); | ||
90 | } | ||
91 | |||
92 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
93 | { | ||
94 | updatedIndexedProperties(newEntity); | ||
95 | } | ||
96 | |||
97 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | ||
98 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
99 | { | ||
100 | updatedIndexedProperties(newEntity); | ||
101 | } | ||
102 | |||
103 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
104 | { | ||
105 | } | ||
106 | }; | ||
107 | |||
73 | class FolderUpdater : public Sink::Preprocessor | 108 | class FolderUpdater : public Sink::Preprocessor |
74 | { | 109 | { |
75 | public: | 110 | public: |
@@ -112,20 +147,6 @@ public: | |||
112 | return oldPath; | 147 | return oldPath; |
113 | } | 148 | } |
114 | 149 | ||
115 | void updatedIndexedProperties(Sink::ApplicationDomain::BufferAdaptor &newEntity) | ||
116 | { | ||
117 | const auto filePath = getFilePathFromMimeMessagePath(newEntity.getProperty("mimeMessage").toString()); | ||
118 | |||
119 | KMime::Message *msg = new KMime::Message; | ||
120 | msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(filePath))); | ||
121 | msg->parse(); | ||
122 | |||
123 | newEntity.setProperty("subject", msg->subject(true)->asUnicodeString()); | ||
124 | newEntity.setProperty("sender", msg->from(true)->asUnicodeString()); | ||
125 | newEntity.setProperty("senderName", msg->from(true)->asUnicodeString()); | ||
126 | newEntity.setProperty("date", msg->date(true)->dateTime()); | ||
127 | } | ||
128 | |||
129 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | 150 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE |
130 | { | 151 | { |
131 | if (newEntity.getProperty("draft").toBool()) { | 152 | if (newEntity.getProperty("draft").toBool()) { |
@@ -135,7 +156,6 @@ public: | |||
135 | if (mimeMessage.isValid()) { | 156 | if (mimeMessage.isValid()) { |
136 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); | 157 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); |
137 | } | 158 | } |
138 | updatedIndexedProperties(newEntity); | ||
139 | } | 159 | } |
140 | 160 | ||
141 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 161 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, |
@@ -166,9 +186,7 @@ public: | |||
166 | flags |= KPIM::Maildir::Flagged; | 186 | flags |= KPIM::Maildir::Flagged; |
167 | } | 187 | } |
168 | 188 | ||
169 | const auto newRemoteId = maildir.changeEntryFlags(identifier, flags); | 189 | maildir.changeEntryFlags(identifier, flags); |
170 | |||
171 | updatedIndexedProperties(newEntity); | ||
172 | } | 190 | } |
173 | 191 | ||
174 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | 192 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE |
@@ -453,7 +471,7 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh | |||
453 | setupChangereplay(changereplay); | 471 | setupChangereplay(changereplay); |
454 | 472 | ||
455 | auto folderUpdater = new FolderUpdater(QByteArray()); | 473 | auto folderUpdater = new FolderUpdater(QByteArray()); |
456 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << folderUpdater << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); | 474 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << folderUpdater << new MailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); |
457 | auto folderPreprocessor = new FolderPreprocessor; | 475 | auto folderPreprocessor = new FolderPreprocessor; |
458 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << folderPreprocessor << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); | 476 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << folderPreprocessor << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); |
459 | 477 | ||