diff options
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 38 | ||||
-rw-r--r-- | tests/maildirresourcetest.cpp | 9 |
2 files changed, 34 insertions, 13 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index c64fc35..72610a1 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -79,7 +79,7 @@ public: | |||
79 | } | 79 | } |
80 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 80 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); |
81 | if (mimeMessage.isValid()) { | 81 | if (mimeMessage.isValid()) { |
82 | const auto oldPath = newEntity.getProperty("mimeMessage").toString(); | 82 | const auto oldPath = mimeMessage.toString(); |
83 | if (oldPath.startsWith(Sink::temporaryFileLocation())) { | 83 | if (oldPath.startsWith(Sink::temporaryFileLocation())) { |
84 | auto folder = newEntity.getProperty("folder").toByteArray(); | 84 | auto folder = newEntity.getProperty("folder").toByteArray(); |
85 | const auto path = getPath(folder, transaction); | 85 | const auto path = getPath(folder, transaction); |
@@ -88,10 +88,32 @@ public: | |||
88 | qWarning() << "Maildir is not existing: " << path; | 88 | qWarning() << "Maildir is not existing: " << path; |
89 | } | 89 | } |
90 | auto identifier = maildir.addEntryFromPath(oldPath); | 90 | auto identifier = maildir.addEntryFromPath(oldPath); |
91 | auto newPath = path + "/cur/" + identifier; | 91 | newEntity.setProperty("mimeMessage", path + "/" + identifier); |
92 | newEntity.setProperty("mimeMessage", QVariant::fromValue(newPath)); | ||
93 | } | 92 | } |
94 | } | 93 | } |
94 | |||
95 | { | ||
96 | const auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); | ||
97 | auto parts = mimeMessagePath.split('/'); | ||
98 | const auto key = parts.takeLast(); | ||
99 | const auto path = parts.join("/") + "/cur/"; | ||
100 | |||
101 | QDir dir(path); | ||
102 | const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); | ||
103 | if (list.size() != 1) { | ||
104 | Warning() << "Failed to find message " << path << key << list.size(); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | KMime::Message *msg = new KMime::Message; | ||
109 | msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(list.first().filePath()))); | ||
110 | msg->parse(); | ||
111 | |||
112 | newEntity.setProperty("subject", msg->subject(true)->asUnicodeString()); | ||
113 | newEntity.setProperty("sender", msg->from(true)->asUnicodeString()); | ||
114 | newEntity.setProperty("senderName", msg->from(true)->asUnicodeString()); | ||
115 | newEntity.setProperty("date", msg->date(true)->dateTime()); | ||
116 | } | ||
95 | } | 117 | } |
96 | 118 | ||
97 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 119 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, |
@@ -287,20 +309,12 @@ void MaildirResource::synchronizeMails(Sink::Storage::Transaction &transaction, | |||
287 | const QString fileName = entryIterator->fileName(); | 309 | const QString fileName = entryIterator->fileName(); |
288 | const auto remoteId = filePath.toUtf8(); | 310 | const auto remoteId = filePath.toUtf8(); |
289 | 311 | ||
290 | KMime::Message *msg = new KMime::Message; | ||
291 | msg->setHead(KMime::CRLFtoLF(maildir.readEntryHeadersFromFile(filePath))); | ||
292 | msg->parse(); | ||
293 | |||
294 | const auto flags = maildir.readEntryFlags(fileName); | 312 | const auto flags = maildir.readEntryFlags(fileName); |
295 | const auto maildirKey = maildir.getKeyFromFile(fileName); | 313 | const auto maildirKey = maildir.getKeyFromFile(fileName); |
296 | 314 | ||
297 | Trace() << "Found a mail " << filePath << " : " << fileName << msg->subject(true)->asUnicodeString(); | 315 | Trace() << "Found a mail " << filePath << " : " << fileName; |
298 | 316 | ||
299 | Sink::ApplicationDomain::Mail mail; | 317 | Sink::ApplicationDomain::Mail mail; |
300 | mail.setProperty("subject", msg->subject(true)->asUnicodeString()); | ||
301 | mail.setProperty("sender", msg->from(true)->asUnicodeString()); | ||
302 | mail.setProperty("senderName", msg->from(true)->asUnicodeString()); | ||
303 | mail.setProperty("date", msg->date(true)->dateTime()); | ||
304 | mail.setProperty("folder", folderLocalId); | 318 | mail.setProperty("folder", folderLocalId); |
305 | //We only store the directory path + key, so we facade can add the changing bits (flags) | 319 | //We only store the directory path + key, so we facade can add the changing bits (flags) |
306 | mail.setProperty("mimeMessage", KPIM::Maildir::getDirectoryFromFile(filePath) + maildirKey); | 320 | mail.setProperty("mimeMessage", KPIM::Maildir::getDirectoryFromFile(filePath) + maildirKey); |
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index f53750f..6d78242 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp | |||
@@ -307,7 +307,7 @@ private slots: | |||
307 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | 307 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); |
308 | message->assemble(); | 308 | message->assemble(); |
309 | 309 | ||
310 | Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); | 310 | auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Mail>("org.kde.maildir.instance1"); |
311 | mail.setBlobProperty("mimeMessage", message->encodedContent()); | 311 | mail.setBlobProperty("mimeMessage", message->encodedContent()); |
312 | //FIXME generate accessors | 312 | //FIXME generate accessors |
313 | // mail.setMimeMessage(message->encodedContent()); | 313 | // mail.setMimeMessage(message->encodedContent()); |
@@ -317,6 +317,13 @@ private slots: | |||
317 | // Ensure all local data is processed | 317 | // Ensure all local data is processed |
318 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 318 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
319 | 319 | ||
320 | //Ensure extracted properties are up to date. | ||
321 | auto future = Sink::Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "subject")) | ||
322 | .then<void, ApplicationDomain::Mail>([](const ApplicationDomain::Mail &mail) { | ||
323 | QCOMPARE(mail.getProperty("subject").toString(), QString::fromLatin1("Foobar")); | ||
324 | }).exec(); | ||
325 | future.waitForFinished(); | ||
326 | |||
320 | auto targetPath = tempDir.path() + "/maildir1/cur"; | 327 | auto targetPath = tempDir.path() + "/maildir1/cur"; |
321 | QDir dir(targetPath); | 328 | QDir dir(targetPath); |
322 | dir.setFilter(QDir::Files); | 329 | dir.setFilter(QDir::Files); |