From 6ea3534c94ced99a10682916c2718be8b93056da Mon Sep 17 00:00:00 2001 From: Dmitry Isaikin Date: Thu, 19 May 2016 20:58:38 +0400 Subject: Store last server response on login command in case of parse error (#1436) --- src/core/imap/MCIMAPSession.cpp | 19 ++++++++++++++++++- src/core/imap/MCIMAPSession.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index 5cee16b1..61be95c3 100644 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -356,6 +356,7 @@ void IMAPSession::init() mShouldDisconnect = false; mLoginResponse = NULL; mGmailUserDisplayName = NULL; + mUnparsedResponseData = NULL; } IMAPSession::IMAPSession() @@ -365,6 +366,7 @@ IMAPSession::IMAPSession() IMAPSession::~IMAPSession() { + MC_SAFE_RELEASE(mUnparsedResponseData); MC_SAFE_RELEASE(mGmailUserDisplayName); MC_SAFE_RELEASE(mLoginResponse); MC_SAFE_RELEASE(mClientIdentity); @@ -485,6 +487,11 @@ String * IMAPSession::loginResponse() return mLoginResponse; } +Data * IMAPSession::unparsedResponseData() +{ + return mUnparsedResponseData; +} + static bool hasError(int errorCode) { return ((errorCode != MAILIMAP_NO_ERROR) && (errorCode != MAILIMAP_NO_ERROR_AUTHENTICATED) && @@ -716,7 +723,10 @@ void IMAPSession::login(ErrorCode * pError) MCLog("login"); MCAssert(mState == STATE_CONNECTED); - + + MC_SAFE_RELEASE(mLoginResponse); + MC_SAFE_RELEASE(mUnparsedResponseData); + if (mImap->imap_connection_info != NULL) { if (mImap->imap_connection_info->imap_capability != NULL) { mailimap_capability_data_free(mImap->imap_connection_info->imap_capability); @@ -832,6 +842,13 @@ void IMAPSession::login(ErrorCode * pError) else if (r == MAILIMAP_ERROR_PARSE) { mShouldDisconnect = true; * pError = ErrorParse; + + Data * unparsed_response = Data::data(); + if (mImap->imap_stream_buffer != NULL) { + unparsed_response = Data::dataWithBytes(mImap->imap_stream_buffer->str, (unsigned int) mImap->imap_stream_buffer->len); + } + MC_SAFE_REPLACE_RETAIN(Data, mUnparsedResponseData, unparsed_response); + return; } else if (hasError(r)) { diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h index 8b3fed0f..adbecd43 100644 --- a/src/core/imap/MCIMAPSession.h +++ b/src/core/imap/MCIMAPSession.h @@ -209,6 +209,8 @@ namespace mailcore { virtual bool isAutomaticConfigurationEnabled(); virtual String * loginResponse(); + /** Filled by unparsed protocol data in case of ParseError (only for login for now). */ + virtual Data * unparsedResponseData(); public: // private virtual void loginIfNeeded(ErrorCode * pError); @@ -276,6 +278,7 @@ namespace mailcore { String * mLoginResponse; String * mGmailUserDisplayName; + Data * mUnparsedResponseData; void init(); void bodyProgress(unsigned int current, unsigned int maximum); -- cgit v1.2.3