summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource/maildirresource.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-09 11:57:55 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-09 11:57:55 +0200
commitbc1311ddf3b8f8e19018c2e54d282ab767f50ff4 (patch)
treef5e81b95b43d62bed6084ef1a782039f278bb1f8 /examples/maildirresource/maildirresource.cpp
parent8a5b4510aedc92749424086067e45d3be52c5e07 (diff)
downloadsink-bc1311ddf3b8f8e19018c2e54d282ab767f50ff4.tar.gz
sink-bc1311ddf3b8f8e19018c2e54d282ab767f50ff4.zip
Updated extracted properties in pipeline.
.. and store the correct mimeMesage path (without cur)
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r--examples/maildirresource/maildirresource.cpp38
1 files changed, 26 insertions, 12 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);