From bc1311ddf3b8f8e19018c2e54d282ab767f50ff4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 9 May 2016 11:57:55 +0200 Subject: Updated extracted properties in pipeline. .. and store the correct mimeMesage path (without cur) --- examples/maildirresource/maildirresource.cpp | 38 +++++++++++++++++++--------- 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: } const auto mimeMessage = newEntity.getProperty("mimeMessage"); if (mimeMessage.isValid()) { - const auto oldPath = newEntity.getProperty("mimeMessage").toString(); + const auto oldPath = mimeMessage.toString(); if (oldPath.startsWith(Sink::temporaryFileLocation())) { auto folder = newEntity.getProperty("folder").toByteArray(); const auto path = getPath(folder, transaction); @@ -88,10 +88,32 @@ public: qWarning() << "Maildir is not existing: " << path; } auto identifier = maildir.addEntryFromPath(oldPath); - auto newPath = path + "/cur/" + identifier; - newEntity.setProperty("mimeMessage", QVariant::fromValue(newPath)); + newEntity.setProperty("mimeMessage", path + "/" + identifier); } } + + { + const auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); + auto parts = mimeMessagePath.split('/'); + const auto key = parts.takeLast(); + const auto path = parts.join("/") + "/cur/"; + + QDir dir(path); + const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); + if (list.size() != 1) { + Warning() << "Failed to find message " << path << key << list.size(); + return; + } + + KMime::Message *msg = new KMime::Message; + msg->setHead(KMime::CRLFtoLF(KPIM::Maildir::readEntryHeadersFromFile(list.first().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 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, const QString fileName = entryIterator->fileName(); const auto remoteId = filePath.toUtf8(); - KMime::Message *msg = new KMime::Message; - msg->setHead(KMime::CRLFtoLF(maildir.readEntryHeadersFromFile(filePath))); - msg->parse(); - const auto flags = maildir.readEntryFlags(fileName); const auto maildirKey = maildir.getKeyFromFile(fileName); - Trace() << "Found a mail " << filePath << " : " << fileName << msg->subject(true)->asUnicodeString(); + Trace() << "Found a mail " << filePath << " : " << fileName; Sink::ApplicationDomain::Mail mail; - mail.setProperty("subject", msg->subject(true)->asUnicodeString()); - mail.setProperty("sender", msg->from(true)->asUnicodeString()); - mail.setProperty("senderName", msg->from(true)->asUnicodeString()); - mail.setProperty("date", msg->date(true)->dateTime()); mail.setProperty("folder", folderLocalId); //We only store the directory path + key, so we facade can add the changing bits (flags) 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: message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); message->assemble(); - Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); + auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity("org.kde.maildir.instance1"); mail.setBlobProperty("mimeMessage", message->encodedContent()); //FIXME generate accessors // mail.setMimeMessage(message->encodedContent()); @@ -317,6 +317,13 @@ private slots: // Ensure all local data is processed Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + //Ensure extracted properties are up to date. + auto future = Sink::Store::fetchOne(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "subject")) + .then([](const ApplicationDomain::Mail &mail) { + QCOMPARE(mail.getProperty("subject").toString(), QString::fromLatin1("Foobar")); + }).exec(); + future.waitForFinished(); + auto targetPath = tempDir.path() + "/maildir1/cur"; QDir dir(targetPath); dir.setFilter(QDir::Files); -- cgit v1.2.3