summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource/maildirresource.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-30 22:40:11 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-30 22:40:11 +0100
commit437761ddf18934b479244f7322c47c43583b0bfe (patch)
tree276d6d2962af37af47ab5407b494d683190886f4 /examples/maildirresource/maildirresource.cpp
parent46fae1714d9f2379eecfb08988b0d8e79ea11870 (diff)
downloadsink-437761ddf18934b479244f7322c47c43583b0bfe.tar.gz
sink-437761ddf18934b479244f7322c47c43583b0bfe.zip
Fixed maildir mail removal.
During removal we no longer have access to the entity, while that could be fixed by keeping a copy of the entity in the removed entity, we can also just use the full path.
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r--examples/maildirresource/maildirresource.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index 22794da..70f6ae5 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -156,24 +156,23 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti
156 Warning() << "Error in index: " << error.message << property; 156 Warning() << "Error in index: " << error.message << property;
157 }); 157 });
158 }, 158 },
159 [&listingPath](const QByteArray &remoteId) -> bool { 159 [](const QByteArray &remoteId) -> bool {
160 return QFile(listingPath + "/" + remoteId).exists(); 160 return QFile(remoteId).exists();
161 } 161 }
162 ); 162 );
163 163
164 while (entryIterator->hasNext()) { 164 while (entryIterator->hasNext()) {
165 QString filePath = entryIterator->next(); 165 const QString filePath = QDir::fromNativeSeparators(entryIterator->next());
166 QString fileName = entryIterator->fileName(); 166 const QString fileName = entryIterator->fileName();
167 const auto remoteId = fileName.toUtf8(); 167 const auto remoteId = filePath.toUtf8();
168 168
169 KMime::Message *msg = new KMime::Message; 169 KMime::Message *msg = new KMime::Message;
170 auto filepath = listingPath + "/" + fileName; 170 msg->setHead(KMime::CRLFtoLF(maildir.readEntryHeadersFromFile(filePath)));
171 msg->setHead(KMime::CRLFtoLF(maildir.readEntryHeadersFromFile(filepath)));
172 msg->parse(); 171 msg->parse();
173 172
174 const auto flags = maildir.readEntryFlags(fileName); 173 const auto flags = maildir.readEntryFlags(fileName);
175 174
176 Trace() << "Found a mail " << filePath << fileName << msg->subject(true)->asUnicodeString(); 175 Trace() << "Found a mail " << filePath << " : " << fileName << msg->subject(true)->asUnicodeString();
177 176
178 Akonadi2::ApplicationDomain::Mail mail; 177 Akonadi2::ApplicationDomain::Mail mail;
179 mail.setProperty("subject", msg->subject(true)->asUnicodeString()); 178 mail.setProperty("subject", msg->subject(true)->asUnicodeString());
@@ -181,7 +180,7 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti
181 mail.setProperty("senderName", msg->from(true)->asUnicodeString()); 180 mail.setProperty("senderName", msg->from(true)->asUnicodeString());
182 mail.setProperty("date", msg->date(true)->dateTime()); 181 mail.setProperty("date", msg->date(true)->dateTime());
183 mail.setProperty("folder", folderLocalId); 182 mail.setProperty("folder", folderLocalId);
184 mail.setProperty("mimeMessage", filepath); 183 mail.setProperty("mimeMessage", filePath);
185 mail.setProperty("unread", !flags.testFlag(KPIM::Maildir::Seen)); 184 mail.setProperty("unread", !flags.testFlag(KPIM::Maildir::Seen));
186 mail.setProperty("important", flags.testFlag(KPIM::Maildir::Flagged)); 185 mail.setProperty("important", flags.testFlag(KPIM::Maildir::Flagged));
187 186
@@ -275,13 +274,8 @@ KAsync::Job<void> MaildirResource::replay(Akonadi2::Storage &synchronizationStor
275 } else if (operation == Akonadi2::Operation_Removal) { 274 } else if (operation == Akonadi2::Operation_Removal) {
276 const auto uid = Akonadi2::Storage::uidFromKey(key); 275 const auto uid = Akonadi2::Storage::uidFromKey(key);
277 const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction); 276 const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction);
278 const Akonadi2::ApplicationDomain::Mail mail(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mMailAdaptorFactory->createAdaptor(entity));
279 auto parentFolder = mail.getProperty("folder").toByteArray();
280 const auto parentFolderRemoteId = resolveLocalId(ENTITY_TYPE_FOLDER, parentFolder, synchronizationTransaction);
281 const auto parentFolderPath = parentFolderRemoteId;
282 KPIM::Maildir maildir(parentFolderPath, false);
283 Trace() << "Removing a mail: " << remoteId; 277 Trace() << "Removing a mail: " << remoteId;
284 maildir.removeEntry(remoteId); 278 QFile::remove(remoteId);
285 removeRemoteId(ENTITY_TYPE_MAIL, uid, remoteId, synchronizationTransaction); 279 removeRemoteId(ENTITY_TYPE_MAIL, uid, remoteId, synchronizationTransaction);
286 } else if (operation == Akonadi2::Operation_Modification) { 280 } else if (operation == Akonadi2::Operation_Modification) {
287 Warning() << "Mail modifications are not implemented"; 281 Warning() << "Mail modifications are not implemented";