diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-30 22:40:11 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-30 22:40:11 +0100 |
commit | 437761ddf18934b479244f7322c47c43583b0bfe (patch) | |
tree | 276d6d2962af37af47ab5407b494d683190886f4 | |
parent | 46fae1714d9f2379eecfb08988b0d8e79ea11870 (diff) | |
download | sink-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.
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 24 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.h | 8 |
2 files changed, 17 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"; |
diff --git a/examples/maildirresource/maildirresource.h b/examples/maildirresource/maildirresource.h index 389b7f4..21ee637 100644 --- a/examples/maildirresource/maildirresource.h +++ b/examples/maildirresource/maildirresource.h | |||
@@ -31,6 +31,14 @@ | |||
31 | class MaildirMailAdaptorFactory; | 31 | class MaildirMailAdaptorFactory; |
32 | class MaildirFolderAdaptorFactory; | 32 | class MaildirFolderAdaptorFactory; |
33 | 33 | ||
34 | /** | ||
35 | * A maildir resource | ||
36 | * | ||
37 | * Implementation details: | ||
38 | * The remoteid's have the following formats: | ||
39 | * files: full file path | ||
40 | * directories: full directory path | ||
41 | */ | ||
34 | class MaildirResource : public Akonadi2::GenericResource | 42 | class MaildirResource : public Akonadi2::GenericResource |
35 | { | 43 | { |
36 | public: | 44 | public: |