diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-22 08:32:39 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-22 08:32:39 +0200 |
commit | 8b24f7f4919c1d4a3a91cf4b21ad76b610dcddf1 (patch) | |
tree | 89982283bec0e43aa128ee08f6c686ba357e099a | |
parent | 00e37715c4d0d436e4ddd2f8713af559065f9667 (diff) | |
download | sink-8b24f7f4919c1d4a3a91cf4b21ad76b610dcddf1.tar.gz sink-8b24f7f4919c1d4a3a91cf4b21ad76b610dcddf1.zip |
Detect login failures
-rw-r--r-- | examples/imapresource/imapresource.cpp | 2 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 20 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 1 |
3 files changed, 16 insertions, 7 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index fde8260..14c3a3e 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -509,6 +509,8 @@ public: | |||
509 | return {ApplicationDomain::ConnectionError, error.errorMessage}; | 509 | return {ApplicationDomain::ConnectionError, error.errorMessage}; |
510 | case Imap::SslHandshakeError: | 510 | case Imap::SslHandshakeError: |
511 | return {ApplicationDomain::LoginError, error.errorMessage}; | 511 | return {ApplicationDomain::LoginError, error.errorMessage}; |
512 | case Imap::LoginFailed: | ||
513 | return {ApplicationDomain::LoginError, error.errorMessage}; | ||
512 | case Imap::HostNotFoundError: | 514 | case Imap::HostNotFoundError: |
513 | return {ApplicationDomain::NoServerError, error.errorMessage}; | 515 | return {ApplicationDomain::NoServerError, error.errorMessage}; |
514 | case Imap::ConnectionLost: | 516 | case Imap::ConnectionLost: |
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 317fbdc..9a84327 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -62,11 +62,9 @@ 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) | 65 | static int translateImapError(int error, bool isLoginJob) |
66 | { | 66 | { |
67 | switch (error) { | 67 | switch (error) { |
68 | case KJob::UserDefinedError: | ||
69 | return Imap::ConnectionLost; | ||
70 | case KIMAP2::LoginJob::ErrorCode::ERR_HOST_NOT_FOUND: | 68 | case KIMAP2::LoginJob::ErrorCode::ERR_HOST_NOT_FOUND: |
71 | return Imap::HostNotFoundError; | 69 | return Imap::HostNotFoundError; |
72 | case KIMAP2::LoginJob::ErrorCode::ERR_COULD_NOT_CONNECT: | 70 | case KIMAP2::LoginJob::ErrorCode::ERR_COULD_NOT_CONNECT: |
@@ -74,6 +72,14 @@ static int translateImapError(int error) | |||
74 | case KIMAP2::LoginJob::ErrorCode::ERR_SSL_HANDSHAKE_FAILED: | 72 | case KIMAP2::LoginJob::ErrorCode::ERR_SSL_HANDSHAKE_FAILED: |
75 | return Imap::SslHandshakeError; | 73 | return Imap::SslHandshakeError; |
76 | } | 74 | } |
75 | //Hack to detect login failures | ||
76 | if (isLoginJob) { | ||
77 | return Imap::LoginFailed; | ||
78 | } | ||
79 | //Hack to detect connection lost | ||
80 | if (error == KJob::UserDefinedError) { | ||
81 | return Imap::ConnectionLost; | ||
82 | } | ||
77 | return Imap::UnknownError; | 83 | return Imap::UnknownError; |
78 | } | 84 | } |
79 | 85 | ||
@@ -84,8 +90,8 @@ static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f) | |||
84 | QObject::connect(job, &KJob::result, [&future, f](KJob *job) { | 90 | QObject::connect(job, &KJob::result, [&future, f](KJob *job) { |
85 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 91 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
86 | if (job->error()) { | 92 | if (job->error()) { |
87 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className(); | 93 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); |
88 | auto proxyError = translateImapError(job->error()); | 94 | auto proxyError = translateImapError(job->error(), dynamic_cast<KIMAP2::LoginJob*>(job)); |
89 | future.setError(proxyError, job->errorString()); | 95 | future.setError(proxyError, job->errorString()); |
90 | } else { | 96 | } else { |
91 | future.setValue(f(job)); | 97 | future.setValue(f(job)); |
@@ -103,8 +109,8 @@ static KAsync::Job<void> runJob(KJob *job) | |||
103 | QObject::connect(job, &KJob::result, [&future](KJob *job) { | 109 | QObject::connect(job, &KJob::result, [&future](KJob *job) { |
104 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 110 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
105 | if (job->error()) { | 111 | if (job->error()) { |
106 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className(); | 112 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); |
107 | auto proxyError = translateImapError(job->error()); | 113 | auto proxyError = translateImapError(job->error(), dynamic_cast<KIMAP2::LoginJob*>(job)); |
108 | future.setError(proxyError, job->errorString()); | 114 | future.setError(proxyError, job->errorString()); |
109 | } else { | 115 | } else { |
110 | future.setFinished(); | 116 | future.setFinished(); |
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 9e73f68..7044a5e 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -31,6 +31,7 @@ namespace Imap { | |||
31 | 31 | ||
32 | enum ErrorCode { | 32 | enum ErrorCode { |
33 | NoError, | 33 | NoError, |
34 | LoginFailed, | ||
34 | HostNotFoundError, | 35 | HostNotFoundError, |
35 | CouldNotConnectError, | 36 | CouldNotConnectError, |
36 | SslHandshakeError, | 37 | SslHandshakeError, |