diff options
Diffstat (limited to 'examples/imapresource')
-rw-r--r-- | examples/imapresource/CMakeLists.txt | 3 | ||||
-rw-r--r-- | examples/imapresource/imapresource.cpp | 11 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 35 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 4 |
4 files changed, 34 insertions, 19 deletions
diff --git a/examples/imapresource/CMakeLists.txt b/examples/imapresource/CMakeLists.txt index 5d2d38b..f5f51f8 100644 --- a/examples/imapresource/CMakeLists.txt +++ b/examples/imapresource/CMakeLists.txt | |||
@@ -9,8 +9,7 @@ find_package(KIMAP2 0.2 REQUIRED) | |||
9 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | 9 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) |
10 | 10 | ||
11 | add_library(${PROJECT_NAME} SHARED imapresource.cpp imapserverproxy.cpp) | 11 | add_library(${PROJECT_NAME} SHARED imapresource.cpp imapserverproxy.cpp) |
12 | qt5_use_modules(${PROJECT_NAME} Core Network) | 12 | target_link_libraries(${PROJECT_NAME} sink Qt5::Core Qt5::Network KF5::Mime KIMAP2) |
13 | target_link_libraries(${PROJECT_NAME} sink KF5::Mime KIMAP2) | ||
14 | 13 | ||
15 | install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) | 14 | install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) |
16 | 15 | ||
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 81c808b..3ae7fd7 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -511,6 +511,8 @@ public: | |||
511 | return {ApplicationDomain::LoginError, error.errorMessage}; | 511 | return {ApplicationDomain::LoginError, error.errorMessage}; |
512 | case Imap::HostNotFoundError: | 512 | case Imap::HostNotFoundError: |
513 | return {ApplicationDomain::NoServerError, error.errorMessage}; | 513 | return {ApplicationDomain::NoServerError, error.errorMessage}; |
514 | case Imap::ConnectionLost: | ||
515 | return {ApplicationDomain::ConnectionLostError, error.errorMessage}; | ||
514 | default: | 516 | default: |
515 | return {ApplicationDomain::UnknownError, error.errorMessage}; | 517 | return {ApplicationDomain::UnknownError, error.errorMessage}; |
516 | } | 518 | } |
@@ -619,6 +621,15 @@ public: | |||
619 | 621 | ||
620 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE | 622 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE |
621 | { | 623 | { |
624 | if (operation != Sink::Operation_Creation) { | ||
625 | if(oldRemoteId.isEmpty()) { | ||
626 | // return KAsync::error<QByteArray>("Tried to replay modification without old remoteId."); | ||
627 | qWarning() << "Tried to replay modification without old remoteId."; | ||
628 | // Since we can't recover from the situation we just skip over the revision. | ||
629 | // FIXME figure out how we can ever end up in this situation | ||
630 | return KAsync::null<QByteArray>(); | ||
631 | } | ||
632 | } | ||
622 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); | 633 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); |
623 | auto login = imap->login(mUser, mPassword); | 634 | auto login = imap->login(mUser, mPassword); |
624 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); | 635 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); |
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 538105c..5c2e07c 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -61,6 +61,21 @@ const char* Imap::Capabilities::Namespace = "NAMESPACE"; | |||
61 | const char* Imap::Capabilities::Uidplus = "UIDPLUS"; | 61 | const char* Imap::Capabilities::Uidplus = "UIDPLUS"; |
62 | const char* Imap::Capabilities::Condstore = "CONDSTORE"; | 62 | const char* Imap::Capabilities::Condstore = "CONDSTORE"; |
63 | 63 | ||
64 | static int translateImapError(int error) | ||
65 | { | ||
66 | switch (error) { | ||
67 | case KJob::UserDefinedError: | ||
68 | return Imap::ConnectionLost; | ||
69 | case KIMAP2::LoginJob::ErrorCode::ERR_HOST_NOT_FOUND: | ||
70 | return Imap::HostNotFoundError; | ||
71 | case KIMAP2::LoginJob::ErrorCode::ERR_COULD_NOT_CONNECT: | ||
72 | return Imap::CouldNotConnectError; | ||
73 | case KIMAP2::LoginJob::ErrorCode::ERR_SSL_HANDSHAKE_FAILED: | ||
74 | return Imap::SslHandshakeError; | ||
75 | } | ||
76 | return Imap::UnknownError; | ||
77 | } | ||
78 | |||
64 | template <typename T> | 79 | template <typename T> |
65 | static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f) | 80 | static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f) |
66 | { | 81 | { |
@@ -69,7 +84,8 @@ static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f) | |||
69 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 84 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
70 | if (job->error()) { | 85 | if (job->error()) { |
71 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className(); | 86 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className(); |
72 | future.setError(job->error(), job->errorString()); | 87 | auto proxyError = translateImapError(job->error()); |
88 | future.setError(proxyError, job->errorString()); | ||
73 | } else { | 89 | } else { |
74 | future.setValue(f(job)); | 90 | future.setValue(f(job)); |
75 | future.setFinished(); | 91 | future.setFinished(); |
@@ -87,7 +103,8 @@ static KAsync::Job<void> runJob(KJob *job) | |||
87 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 103 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
88 | if (job->error()) { | 104 | if (job->error()) { |
89 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className(); | 105 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className(); |
90 | future.setError(job->error(), job->errorString()); | 106 | auto proxyError = translateImapError(job->error()); |
107 | future.setError(proxyError, job->errorString()); | ||
91 | } else { | 108 | } else { |
92 | future.setFinished(); | 109 | future.setFinished(); |
93 | } | 110 | } |
@@ -166,20 +183,6 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString | |||
166 | // SinkTrace() << "Found personal namespaces: " << mNamespaces.personal; | 183 | // SinkTrace() << "Found personal namespaces: " << mNamespaces.personal; |
167 | // SinkTrace() << "Found shared namespaces: " << mNamespaces.shared; | 184 | // SinkTrace() << "Found shared namespaces: " << mNamespaces.shared; |
168 | // SinkTrace() << "Found user namespaces: " << mNamespaces.user; | 185 | // SinkTrace() << "Found user namespaces: " << mNamespaces.user; |
169 | }).then([=] (const KAsync::Error &error) { | ||
170 | if (error) { | ||
171 | switch (error.errorCode) { | ||
172 | case KIMAP2::LoginJob::ErrorCode::ERR_HOST_NOT_FOUND: | ||
173 | return KAsync::error(HostNotFoundError, "Host not found: " + error.errorMessage); | ||
174 | case KIMAP2::LoginJob::ErrorCode::ERR_COULD_NOT_CONNECT: | ||
175 | return KAsync::error(CouldNotConnectError, "Failed to connect: " + error.errorMessage); | ||
176 | case KIMAP2::LoginJob::ErrorCode::ERR_SSL_HANDSHAKE_FAILED: | ||
177 | return KAsync::error(SslHandshakeError, "Ssl handshake failed: " + error.errorMessage); | ||
178 | default: | ||
179 | return KAsync::error(error); | ||
180 | } | ||
181 | } | ||
182 | return KAsync::null(); | ||
183 | }); | 186 | }); |
184 | } | 187 | } |
185 | 188 | ||
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 82f4f58..f9b854b 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -33,7 +33,9 @@ enum ErrorCode { | |||
33 | NoError, | 33 | NoError, |
34 | HostNotFoundError, | 34 | HostNotFoundError, |
35 | CouldNotConnectError, | 35 | CouldNotConnectError, |
36 | SslHandshakeError | 36 | SslHandshakeError, |
37 | ConnectionLost, | ||
38 | UnknownError | ||
37 | }; | 39 | }; |
38 | 40 | ||
39 | namespace Flags | 41 | namespace Flags |