diff options
author | Christopher Hockley <christopher@putcocoa.in> | 2015-01-27 13:52:40 +0100 |
---|---|---|
committer | Christopher Hockley <christopher@putcocoa.in> | 2015-01-27 13:52:40 +0100 |
commit | 4594ff3467e941f74cfaf987da5e640c60377795 (patch) | |
tree | 5c59905fc96d618804ea8040996a14adff5abd3e /src | |
parent | d4e863f70ff55a769a60ed3c2f3791805aa3cad9 (diff) |
AccountValidator Update
Diffstat (limited to 'src')
-rw-r--r-- | src/core/abstract/MCErrorMessage.cpp | 2 | ||||
-rw-r--r-- | src/core/provider/MCAccountValidator.cpp | 97 | ||||
-rw-r--r-- | src/core/provider/MCAccountValidator.h | 4 | ||||
-rw-r--r-- | src/objc/abstract/MCOConstants.h | 2 |
4 files changed, 56 insertions, 49 deletions
diff --git a/src/core/abstract/MCErrorMessage.cpp b/src/core/abstract/MCErrorMessage.cpp index c7205d42..15de9405 100644 --- a/src/core/abstract/MCErrorMessage.cpp +++ b/src/core/abstract/MCErrorMessage.cpp @@ -44,6 +44,8 @@ static const char * localizedDescriptionTable[] = { "A recipient is required to send message", /** MCOErrorNoRecipient */ "An error occured while performing a No-Op operation.", /** MCOErrorNoop */ "An application specific password is required", /** MCOErrorGmailApplicationSpecificPasswordRequired */ + "An error when requesting date", /** MCOErrorServerDate */ + "No valid server found", /** MCOErrorNoValidServerFound */ }; String * mailcore::errorMessageWithErrorCode(ErrorCode errorCode) diff --git a/src/core/provider/MCAccountValidator.cpp b/src/core/provider/MCAccountValidator.cpp index 5fc90d34..1fa7cfa3 100644 --- a/src/core/provider/MCAccountValidator.cpp +++ b/src/core/provider/MCAccountValidator.cpp @@ -23,6 +23,14 @@ using namespace mailcore; +/* this is the service being tested */ + +enum { + SERVICE_IMAP, /* IMAP service */ + SERVICE_POP, /* POP service */ + SERVICE_SMTP, /* SMTP service */ +}; + void AccountValidator::init() { mEmail = NULL; @@ -65,8 +73,8 @@ AccountValidator::~AccountValidator() void AccountValidator::start() { - if (setup()) test(); - else mCallback->operationFinished(this); + setup(); + test(); } void AccountValidator::operationFinished(Operation * op) @@ -74,10 +82,10 @@ void AccountValidator::operationFinished(Operation * op) opCompleted(); } -bool AccountValidator::setup() +void AccountValidator::setup() { if (mEmail == NULL) { - if (mUsername == NULL) return false; + if (mUsername == NULL) return; else mEmail = mUsername; }else if (mUsername == NULL){ mUsername = mEmail; @@ -91,58 +99,53 @@ bool AccountValidator::setup() components = mUsername->componentsSeparatedByString(MCSTR("@")); if (components->count() < 2) - return false; + return; domain = (String *) components->lastObject(); - provider = VTMxRecordForHostname(domain); + provider = ResolveProviderUsingMXRecord(domain); } if (provider != NULL) { mIdentifier = provider->identifier(); - - //If no custom Services have been set look for some in the provider - if (mImapServices->count() == 0) { - if (provider->imapServices()->count() > 0) { - mImapServices = provider->imapServices(); - } else { - mImapError = ErrorNoValidServerFound; - } - } + if (mImapServices->count() == 0 and provider->imapServices()->count() > 0) + mImapServices = provider->imapServices(); + + if (mPopServices->count() == 0 and provider->popServices()->count() > 0) + mPopServices = provider->popServices(); + + if (mSmtpServices->count() == 0 and provider->smtpServices()->count() > 0) + mSmtpServices = provider->smtpServices(); + } - if (mPopServices->count() == 0) { - if (provider->popServices()->count() > 0) { - mPopServices = provider->popServices(); - } else { - mPopError = ErrorNoValidServerFound; - } - } + if (mImapServices->count() == 0) + mImapError = ErrorNoValidServerFound; - if (mSmtpServices->count() == 0) { - if (provider->smtpServices()->count() > 0) { - mSmtpServices = provider->smtpServices(); - } else { - mSmtpError = ErrorNoValidServerFound; - } - } - } + if (mPopServices->count() == 0) + mPopError = ErrorNoValidServerFound; - return (mImapServices->count() > 0 || mPopServices->count() > 0 || mSmtpServices->count() > 0); + if (mSmtpServices->count() == 0) + mSmtpError = ErrorNoValidServerFound; } void AccountValidator::opCompleted() { - if (mCurrentServiceTested == 0) { - mImapError = ((IMAPOperation *)mOperation)->error(); - (mImapError == ErrorNone) ? mCurrentServiceTested ++ : mCurrentServiceIndex ++; - } else if (mCurrentServiceTested == 1) { - mPopError = ((POPOperation *)mOperation)->error(); - (mPopError == ErrorNone) ? mCurrentServiceTested ++ : mCurrentServiceIndex ++; - } else if (mCurrentServiceTested == 2) { - mSmtpError = ((SMTPOperation *)mOperation)->error(); - (mSmtpError == ErrorNone) ? mCurrentServiceTested ++ : mCurrentServiceIndex ++; + ErrorCode error = ErrorNone; + + if (mCurrentServiceTested == SERVICE_IMAP) { + error = mImapError = ((IMAPOperation *)mOperation)->error(); + } else if (mCurrentServiceTested == SERVICE_POP) { + error = mPopError = ((POPOperation *)mOperation)->error(); + } else if (mCurrentServiceTested == SERVICE_SMTP) { + error = mSmtpError = ((SMTPOperation *)mOperation)->error(); } - + + if (error == ErrorNone) { + mCurrentServiceTested ++; + } else { + mCurrentServiceIndex ++; + } + test(); } @@ -155,7 +158,7 @@ void AccountValidator::opCompleted() */ void AccountValidator::test() { - if (mCurrentServiceTested == 0) { + if (mCurrentServiceTested == SERVICE_IMAP) { if (mCurrentServiceIndex < mImapServices->count()) { IMAPAsyncSession *imapSession = new IMAPAsyncSession(); imapSession->setUsername(mUsername); @@ -171,11 +174,11 @@ void AccountValidator::test() mOperation->start(); } else { - mCurrentServiceTested = 1; + mCurrentServiceTested = SERVICE_POP; mCurrentServiceIndex = 0; test(); } - }else if (mCurrentServiceTested == 1){ + }else if (mCurrentServiceTested == SERVICE_POP){ if (mCurrentServiceIndex < mPopServices->count()) { POPAsyncSession *popSession = new POPAsyncSession(); popSession->setUsername(mUsername); @@ -190,11 +193,11 @@ void AccountValidator::test() mOperation->setCallback(this); mOperation->start(); } else { - mCurrentServiceTested = 2; + mCurrentServiceTested = SERVICE_SMTP; mCurrentServiceIndex = 0; test(); } - }else if (mCurrentServiceTested == 2){ + }else if (mCurrentServiceTested == SERVICE_SMTP){ if (mCurrentServiceIndex < mSmtpServices->count()) { SMTPAsyncSession *smtpSession = new SMTPAsyncSession(); smtpSession->setUsername(mUsername); @@ -217,7 +220,7 @@ void AccountValidator::test() } } -MailProvider* AccountValidator::VTMxRecordForHostname(String *hostname) +MailProvider* AccountValidator::ResolveProviderUsingMXRecord(String *hostname) { unsigned char response[NS_PACKETSZ]; ns_msg handle; diff --git a/src/core/provider/MCAccountValidator.h b/src/core/provider/MCAccountValidator.h index 27508996..8dc3d9aa 100644 --- a/src/core/provider/MCAccountValidator.h +++ b/src/core/provider/MCAccountValidator.h @@ -74,9 +74,9 @@ namespace mailcore { ErrorCode mPopError; ErrorCode mSmtpError; - bool setup(); + void setup(); void test(); - MailProvider * VTMxRecordForHostname(String *hostname); + MailProvider * ResolveProviderUsingMXRecord(String *hostname); //indexs for services being tested int mCurrentServiceIndex; diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index 826d047f..e4cbebef 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -409,6 +409,8 @@ typedef NS_ENUM(NSInteger, MCOErrorCode) { MCOErrorGmailApplicationSpecificPasswordRequired, // 40 /** NNTP: error when requesting date */ MCOErrorServerDate, + /** No valid server found */ + MCOErrorNoValidServerFound, /** The count of all errors */ MCOErrorCodeCount, }; |