diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-02 11:10:08 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-02 11:10:08 +0100 |
commit | 11b790ba6f06141db802273628ce2d191982677e (patch) | |
tree | 55f94884b5dc6da786a0f11a3b507ee23987264f /examples | |
parent | 9c4720653cb40092b76a7f9226a014d26eafb7c3 (diff) | |
download | sink-11b790ba6f06141db802273628ce2d191982677e.tar.gz sink-11b790ba6f06141db802273628ce2d191982677e.zip |
Avoid ending up with a connection lost error when a select fails
Diffstat (limited to 'examples')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 13 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 1 |
2 files changed, 11 insertions, 3 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 8a791a2..b27ffb0 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -62,8 +62,11 @@ const char* Imap::Capabilities::Namespace = "NAMESPACE"; | |||
62 | const char* Imap::Capabilities::Uidplus = "UIDPLUS"; | 62 | const char* Imap::Capabilities::Uidplus = "UIDPLUS"; |
63 | const char* Imap::Capabilities::Condstore = "CONDSTORE"; | 63 | const char* Imap::Capabilities::Condstore = "CONDSTORE"; |
64 | 64 | ||
65 | static int translateImapError(int error, bool isLoginJob) | 65 | static int translateImapError(KJob *job) |
66 | { | 66 | { |
67 | const int error = job->error(); | ||
68 | const bool isLoginJob = dynamic_cast<KIMAP2::LoginJob*>(job); | ||
69 | const bool isSelectJob = dynamic_cast<KIMAP2::SelectJob*>(job); | ||
67 | switch (error) { | 70 | switch (error) { |
68 | case KIMAP2::LoginJob::ErrorCode::ERR_HOST_NOT_FOUND: | 71 | case KIMAP2::LoginJob::ErrorCode::ERR_HOST_NOT_FOUND: |
69 | return Imap::HostNotFoundError; | 72 | return Imap::HostNotFoundError; |
@@ -76,6 +79,10 @@ static int translateImapError(int error, bool isLoginJob) | |||
76 | if (isLoginJob) { | 79 | if (isLoginJob) { |
77 | return Imap::LoginFailed; | 80 | return Imap::LoginFailed; |
78 | } | 81 | } |
82 | //Hack to detect selection errors | ||
83 | if (isSelectJob) { | ||
84 | return Imap::SelectFailed; | ||
85 | } | ||
79 | //Hack to detect connection lost | 86 | //Hack to detect connection lost |
80 | if (error == KJob::UserDefinedError) { | 87 | if (error == KJob::UserDefinedError) { |
81 | return Imap::ConnectionLost; | 88 | return Imap::ConnectionLost; |
@@ -91,7 +98,7 @@ static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f) | |||
91 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 98 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
92 | if (job->error()) { | 99 | if (job->error()) { |
93 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); | 100 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); |
94 | auto proxyError = translateImapError(job->error(), dynamic_cast<KIMAP2::LoginJob*>(job)); | 101 | auto proxyError = translateImapError(job); |
95 | future.setError(proxyError, job->errorString()); | 102 | future.setError(proxyError, job->errorString()); |
96 | } else { | 103 | } else { |
97 | future.setValue(f(job)); | 104 | future.setValue(f(job)); |
@@ -110,7 +117,7 @@ static KAsync::Job<void> runJob(KJob *job) | |||
110 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 117 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
111 | if (job->error()) { | 118 | if (job->error()) { |
112 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); | 119 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); |
113 | auto proxyError = translateImapError(job->error(), dynamic_cast<KIMAP2::LoginJob*>(job)); | 120 | auto proxyError = translateImapError(job); |
114 | future.setError(proxyError, job->errorString()); | 121 | future.setError(proxyError, job->errorString()); |
115 | } else { | 122 | } else { |
116 | future.setFinished(); | 123 | future.setFinished(); |
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 0dc6e55..57b252d 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -37,6 +37,7 @@ enum ErrorCode { | |||
37 | SslHandshakeError, | 37 | SslHandshakeError, |
38 | ConnectionLost, | 38 | ConnectionLost, |
39 | MissingCredentialsError, | 39 | MissingCredentialsError, |
40 | SelectFailed, | ||
40 | UnknownError | 41 | UnknownError |
41 | }; | 42 | }; |
42 | 43 | ||