diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-12 11:11:21 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-12 11:11:21 +0100 |
commit | af8baff21529b5bc47725da3e9e00ec81e5b6f1b (patch) | |
tree | 1c66c5ab472b7324ba3fd9b38a66c316dec796b5 /examples/imapresource/imapresource.cpp | |
parent | 1af958f5b178b9ed405f01f896d760e2a10d3942 (diff) | |
download | sink-af8baff21529b5bc47725da3e9e00ec81e5b6f1b.tar.gz sink-af8baff21529b5bc47725da3e9e00ec81e5b6f1b.zip |
Logout after changereplay
Diffstat (limited to 'examples/imapresource/imapresource.cpp')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 49639c3..a204f4c 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -529,12 +529,13 @@ public: | |||
529 | { | 529 | { |
530 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 530 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); |
531 | auto login = imap->login(mUser, mPassword); | 531 | auto login = imap->login(mUser, mPassword); |
532 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); | ||
532 | if (operation == Sink::Operation_Creation) { | 533 | if (operation == Sink::Operation_Creation) { |
533 | QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); | 534 | QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); |
534 | QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); | 535 | QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); |
535 | auto flags = getFlags(mail); | 536 | auto flags = getFlags(mail); |
536 | QDateTime internalDate = mail.getDate(); | 537 | QDateTime internalDate = mail.getDate(); |
537 | return login.then(imap->append(mailbox, content, flags, internalDate)) | 538 | job = login.then(imap->append(mailbox, content, flags, internalDate)) |
538 | .addToContext(imap) | 539 | .addToContext(imap) |
539 | .syncThen<QByteArray, qint64>([mail](qint64 uid) { | 540 | .syncThen<QByteArray, qint64>([mail](qint64 uid) { |
540 | const auto remoteId = assembleMailRid(mail, uid); | 541 | const auto remoteId = assembleMailRid(mail, uid); |
@@ -548,7 +549,7 @@ public: | |||
548 | SinkTrace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; | 549 | SinkTrace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; |
549 | KIMAP2::ImapSet set; | 550 | KIMAP2::ImapSet set; |
550 | set.add(uid); | 551 | set.add(uid); |
551 | return login.then(imap->remove(mailbox, set)) | 552 | job = login.then(imap->remove(mailbox, set)) |
552 | .syncThen<QByteArray>([imap, oldRemoteId] { | 553 | .syncThen<QByteArray>([imap, oldRemoteId] { |
553 | SinkTrace() << "Finished removing a mail: " << oldRemoteId; | 554 | SinkTrace() << "Finished removing a mail: " << oldRemoteId; |
554 | return QByteArray(); | 555 | return QByteArray(); |
@@ -571,7 +572,7 @@ public: | |||
571 | QDateTime internalDate = mail.getDate(); | 572 | QDateTime internalDate = mail.getDate(); |
572 | KIMAP2::ImapSet set; | 573 | KIMAP2::ImapSet set; |
573 | set.add(uid); | 574 | set.add(uid); |
574 | return login.then(imap->append(mailbox, content, flags, internalDate)) | 575 | job = login.then(imap->append(mailbox, content, flags, internalDate)) |
575 | .addToContext(imap) | 576 | .addToContext(imap) |
576 | .then<QByteArray, qint64>([=](qint64 uid) { | 577 | .then<QByteArray, qint64>([=](qint64 uid) { |
577 | const auto remoteId = assembleMailRid(mail, uid); | 578 | const auto remoteId = assembleMailRid(mail, uid); |
@@ -582,7 +583,7 @@ public: | |||
582 | SinkTrace() << "Updating flags only."; | 583 | SinkTrace() << "Updating flags only."; |
583 | KIMAP2::ImapSet set; | 584 | KIMAP2::ImapSet set; |
584 | set.add(uid); | 585 | set.add(uid); |
585 | return login.then(imap->select(mailbox)) | 586 | job = login.then(imap->select(mailbox)) |
586 | .addToContext(imap) | 587 | .addToContext(imap) |
587 | .then(imap->storeFlags(set, flags)) | 588 | .then(imap->storeFlags(set, flags)) |
588 | .syncThen<QByteArray>([=] { | 589 | .syncThen<QByteArray>([=] { |
@@ -591,7 +592,16 @@ public: | |||
591 | }); | 592 | }); |
592 | } | 593 | } |
593 | } | 594 | } |
594 | return KAsync::null<QByteArray>(); | 595 | return job |
596 | .then<QByteArray, QByteArray>([=] (const KAsync::Error &error, const QByteArray &remoteId) { | ||
597 | if (error) { | ||
598 | SinkWarning() << "Error during changereplay: " << error.errorMessage; | ||
599 | return imap->logout() | ||
600 | .then<QByteArray>(KAsync::error<QByteArray>(error)); | ||
601 | } | ||
602 | return imap->logout() | ||
603 | .then<QByteArray>(KAsync::value(remoteId)); | ||
604 | }); | ||
595 | } | 605 | } |
596 | 606 | ||
597 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Folder &folder, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE | 607 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Folder &folder, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE |