diff options
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 3b263a7..cb51881 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -269,9 +269,9 @@ KAsync::Job<void> MaildirResource::replay(Sink::Storage &synchronizationStore, c | |||
269 | const auto parentFolderPath = parentFolderRemoteId; | 269 | const auto parentFolderPath = parentFolderRemoteId; |
270 | KPIM::Maildir maildir(parentFolderPath, false); | 270 | KPIM::Maildir maildir(parentFolderPath, false); |
271 | //FIXME assemble the MIME message | 271 | //FIXME assemble the MIME message |
272 | const auto id = maildir.addEntry("foobar"); | 272 | const auto remoteId = maildir.addEntry("foobar"); |
273 | Trace() << "Creating a new mail: " << id; | 273 | Trace() << "Creating a new mail: " << remoteId; |
274 | recordRemoteId(ENTITY_TYPE_MAIL, mail.identifier(), id.toUtf8(), synchronizationTransaction); | 274 | recordRemoteId(ENTITY_TYPE_MAIL, mail.identifier(), remoteId.toUtf8(), synchronizationTransaction); |
275 | } else if (operation == Sink::Operation_Removal) { | 275 | } else if (operation == Sink::Operation_Removal) { |
276 | const auto uid = Sink::Storage::uidFromKey(key); | 276 | const auto uid = Sink::Storage::uidFromKey(key); |
277 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction); | 277 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction); |
@@ -279,7 +279,26 @@ KAsync::Job<void> MaildirResource::replay(Sink::Storage &synchronizationStore, c | |||
279 | QFile::remove(remoteId); | 279 | QFile::remove(remoteId); |
280 | removeRemoteId(ENTITY_TYPE_MAIL, uid, remoteId, synchronizationTransaction); | 280 | removeRemoteId(ENTITY_TYPE_MAIL, uid, remoteId, synchronizationTransaction); |
281 | } else if (operation == Sink::Operation_Modification) { | 281 | } else if (operation == Sink::Operation_Modification) { |
282 | Warning() << "Mail modifications are not implemented"; | 282 | const auto uid = Sink::Storage::uidFromKey(key); |
283 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction); | ||
284 | Trace() << "Modifying a mail: " << remoteId; | ||
285 | auto parts = remoteId.split('/'); | ||
286 | const auto filename = parts.takeLast(); //filename | ||
287 | parts.removeLast(); //cur/new folder | ||
288 | auto maildirPath = parts.join('/'); | ||
289 | |||
290 | KPIM::Maildir maildir(maildirPath, false); | ||
291 | |||
292 | const Sink::ApplicationDomain::Mail mail(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, mMailAdaptorFactory->createAdaptor(entity)); | ||
293 | |||
294 | //get flags from | ||
295 | KPIM::Maildir::Flags flags; | ||
296 | if (!mail.getProperty("unread").toBool()) { | ||
297 | flags |= KPIM::Maildir::Seen; | ||
298 | } | ||
299 | |||
300 | auto newRemoteId = maildir.changeEntryFlags(filename, flags); | ||
301 | updateRemoteId(ENTITY_TYPE_MAIL, uid, QString(maildirPath + "/cur/" + newRemoteId).toUtf8(), synchronizationTransaction); | ||
283 | } else { | 302 | } else { |
284 | Warning() << "Unkown operation" << operation; | 303 | Warning() << "Unkown operation" << operation; |
285 | } | 304 | } |
@@ -303,11 +322,11 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray | |||
303 | if (property == "unread") { | 322 | if (property == "unread") { |
304 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); | 323 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); |
305 | const auto flags = KPIM::Maildir::readEntryFlags(remoteId.split('/').last()); | 324 | const auto flags = KPIM::Maildir::readEntryFlags(remoteId.split('/').last()); |
306 | if (expectedValue.toBool() && !(flags & KPIM::Maildir::Seen)) { | 325 | if (expectedValue.toBool() && (flags & KPIM::Maildir::Seen)) { |
307 | return KAsync::error<void>(1, "Expected seen but couldn't find it."); | 326 | return KAsync::error<void>(1, "Expected unread but couldn't find it."); |
308 | } | 327 | } |
309 | if (!expectedValue.toBool() && (flags & KPIM::Maildir::Seen)) { | 328 | if (!expectedValue.toBool() && !(flags & KPIM::Maildir::Seen)) { |
310 | return KAsync::error<void>(1, "Expected seen but couldn't find it."); | 329 | return KAsync::error<void>(1, "Expected read but couldn't find it."); |
311 | } | 330 | } |
312 | return KAsync::null<void>(); | 331 | return KAsync::null<void>(); |
313 | } | 332 | } |
@@ -319,7 +338,7 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray | |||
319 | msg->parse(); | 338 | msg->parse(); |
320 | 339 | ||
321 | if (msg->subject(true)->asUnicodeString() != expectedValue.toString()) { | 340 | if (msg->subject(true)->asUnicodeString() != expectedValue.toString()) { |
322 | return KAsync::error<void>(1, "Subject not as expected."); | 341 | return KAsync::error<void>(1, "Subject not as expected: " + msg->subject(true)->asUnicodeString()); |
323 | } | 342 | } |
324 | return KAsync::null<void>(); | 343 | return KAsync::null<void>(); |
325 | } | 344 | } |