aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2015-04-02 23:49:47 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2015-04-02 23:50:04 -0700
commit4f5458d374227507b0c6d4dc04478ad76e943689 (patch)
treeaff7fd172a05ab32dc7a437677a3e7d6ce2fa295
parentcbee27cd693ceed2738d88a39e71d7a599b9e28f (diff)
Improve account validation: fail on first error, validation of services can be disabled/enabled, no need to provide a list of servers when a provider is detected
-rw-r--r--src/core/provider/MCAccountValidator.cpp70
-rw-r--r--src/core/provider/MCAccountValidator.h34
-rw-r--r--src/objc/provider/MCOAccountValidator.h4
-rw-r--r--src/objc/provider/MCOAccountValidator.mm13
4 files changed, 98 insertions, 23 deletions
diff --git a/src/core/provider/MCAccountValidator.cpp b/src/core/provider/MCAccountValidator.cpp
index 15c3a041..753a0236 100644
--- a/src/core/provider/MCAccountValidator.cpp
+++ b/src/core/provider/MCAccountValidator.cpp
@@ -60,6 +60,10 @@ void AccountValidator::init()
mImapSession = NULL;
mPopSession = NULL;
mSmtpSession = NULL;
+
+ mImapEnabled = false;
+ mPopEnabled = false;
+ mSmtpEnabled = false;
}
AccountValidator::AccountValidator()
@@ -170,9 +174,11 @@ void AccountValidator::resolveMXDone()
Array * mxRecords = mResolveMX->mxRecords();
mc_foreacharray(String, mxRecord, mxRecords) {
- MailProvider *provider = MailProvidersManager::sharedManager()->providerForMX(mxRecord);
- if (provider){
+ MailProvider * provider = MailProvidersManager::sharedManager()->providerForMX(mxRecord);
+ if (provider != NULL){
mProvider = provider;
+ MC_SAFE_RETAIN(mProvider);
+ setupServices();
break;
}
}
@@ -180,6 +186,16 @@ void AccountValidator::resolveMXDone()
startCheckingHosts();
}
+void AccountValidator::setupServices()
+{
+ mImapServices = mProvider->imapServices();
+ MC_SAFE_RETAIN(mImapServices);
+ mPopServices = mProvider->popServices();
+ MC_SAFE_RETAIN(mPopServices);
+ mSmtpServices = mProvider->smtpServices();
+ MC_SAFE_RETAIN(mSmtpServices);
+}
+
void AccountValidator::startCheckingHosts()
{
if (mProvider != NULL) {
@@ -217,7 +233,7 @@ void AccountValidator::startCheckingHosts()
void AccountValidator::checkNextHost()
{
if (mCurrentServiceTested == SERVICE_IMAP) {
- if (mCurrentServiceIndex < mImapServices->count()) {
+ if (mImapEnabled && (mCurrentServiceIndex < mImapServices->count())) {
mImapSession = new IMAPAsyncSession();
mImapSession->setUsername(mUsername);
mImapSession->setPassword(mPassword);
@@ -236,6 +252,10 @@ void AccountValidator::checkNextHost()
mOperation->setCallback(this);
mOperation->start();
}
+ else if (mImapEnabled && (mImapServices->count() > 0)) {
+ mImapServer = NULL;
+ callback()->operationFinished(this);
+ }
else {
mCurrentServiceTested ++;
mCurrentServiceIndex = 0;
@@ -243,7 +263,7 @@ void AccountValidator::checkNextHost()
}
}
else if (mCurrentServiceTested == SERVICE_POP){
- if (mCurrentServiceIndex < mPopServices->count()) {
+ if (mPopEnabled && (mCurrentServiceIndex < mPopServices->count())) {
mPopSession = new POPAsyncSession();
mPopSession->setUsername(mUsername);
mPopSession->setPassword(mPassword);
@@ -258,6 +278,10 @@ void AccountValidator::checkNextHost()
mOperation->setCallback(this);
mOperation->start();
}
+ else if (mPopEnabled && (mPopServices->count() > 0)) {
+ mPopServer = NULL;
+ callback()->operationFinished(this);
+ }
else {
mCurrentServiceTested ++;
mCurrentServiceIndex = 0;
@@ -265,7 +289,7 @@ void AccountValidator::checkNextHost()
}
}
else if (mCurrentServiceTested == SERVICE_SMTP){
- if (mCurrentServiceIndex < mSmtpServices->count()) {
+ if (mPopEnabled && (mCurrentServiceIndex < mSmtpServices->count())) {
mSmtpSession = new SMTPAsyncSession();
mSmtpSession->setUsername(mUsername);
mSmtpSession->setPassword(mPassword);
@@ -284,6 +308,10 @@ void AccountValidator::checkNextHost()
mOperation->setCallback(this);
mOperation->start();
}
+ else if (mPopEnabled && (mSmtpServices->count() > 0)) {
+ mSmtpServer = NULL;
+ callback()->operationFinished(this);
+ }
else {
mCurrentServiceTested ++;
mCurrentServiceIndex = 0;
@@ -318,6 +346,7 @@ void AccountValidator::checkNextHostDone()
MC_SAFE_RELEASE(mOperation);
if (error == ErrorNone) {
+ mCurrentServiceIndex = 0;
mCurrentServiceTested ++;
}
else {
@@ -367,6 +396,37 @@ String * AccountValidator::OAuth2Token()
return mOAuth2Token;
}
+void AccountValidator::setImapEnabled(bool enabled)
+{
+ mImapEnabled = enabled;
+}
+
+bool AccountValidator::isImapEnabled()
+{
+ return mImapEnabled;
+}
+
+void AccountValidator::setPopEnabled(bool enabled)
+{
+ mPopEnabled = enabled;
+}
+
+bool AccountValidator::isPopEnabled()
+{
+ return mPopEnabled;
+}
+
+
+void AccountValidator::setSmtpEnabled(bool enabled)
+{
+ mSmtpEnabled = enabled;
+}
+
+bool AccountValidator::isSmtpEnabled()
+{
+ return mSmtpEnabled;
+}
+
void AccountValidator::setImapServices(Array * imapServices)
{
MC_SAFE_REPLACE_COPY(Array, mImapServices, imapServices);
diff --git a/src/core/provider/MCAccountValidator.h b/src/core/provider/MCAccountValidator.h
index 74447ac3..436317cf 100644
--- a/src/core/provider/MCAccountValidator.h
+++ b/src/core/provider/MCAccountValidator.h
@@ -22,7 +22,7 @@ namespace mailcore {
class IMAPAsyncSession;
class POPAsyncSession;
class SMTPAsyncSession;
-
+
class MAILCORE_EXPORT AccountValidator : public Operation, public OperationCallback {
public:
AccountValidator();
@@ -36,7 +36,16 @@ namespace mailcore {
virtual String * password();
virtual void setOAuth2Token(String * OAuth2Token);
virtual String * OAuth2Token();
-
+
+ virtual void setImapEnabled(bool enabled);
+ virtual bool isImapEnabled();
+
+ virtual void setPopEnabled(bool enabled);
+ virtual bool isPopEnabled();
+
+ virtual void setSmtpEnabled(bool enabled);
+ virtual bool isSmtpEnabled();
+
virtual void setImapServices(Array * imapServices);
virtual Array * /* NetService */ imapServices();
virtual void setSmtpServices(Array * smtpServices);
@@ -77,19 +86,10 @@ namespace mailcore {
MailProvider * mProvider;
- void resolveMX();
- void resolveMXDone();
-
- void startCheckingHosts();
- void checkNextHost();
- void checkNextHostDone();
-
//indexs for services being tested
int mCurrentServiceIndex;
int mCurrentServiceTested;
- void init();
-
Operation * mOperation;
virtual void operationFinished(Operation * op);
@@ -99,6 +99,18 @@ namespace mailcore {
IMAPAsyncSession * mImapSession;
POPAsyncSession * mPopSession;
SMTPAsyncSession * mSmtpSession;
+
+ bool mImapEnabled;
+ bool mPopEnabled;
+ bool mSmtpEnabled;
+
+ void init();
+ void setupServices();
+ void resolveMX();
+ void resolveMXDone();
+ void startCheckingHosts();
+ void checkNextHost();
+ void checkNextHostDone();
};
}
diff --git a/src/objc/provider/MCOAccountValidator.h b/src/objc/provider/MCOAccountValidator.h
index 0cdc25aa..b5f09bc2 100644
--- a/src/objc/provider/MCOAccountValidator.h
+++ b/src/objc/provider/MCOAccountValidator.h
@@ -30,6 +30,10 @@
@property (nonatomic, retain) NSArray * /* MCONetService */ popServers;
@property (nonatomic, retain) NSArray * /* MCONetService */ smtpServers;
+@property (nonatomic, assign, getter=isImapEnabled) BOOL imapEnabled;
+@property (nonatomic, assign, getter=isPopEnabled) BOOL popEnabled;
+@property (nonatomic, assign, getter=isSmtpEnabled) BOOL smtpEnabled;
+
// result
@property (nonatomic, retain, readonly) NSString * identifier;
@property (nonatomic, retain, readonly) MCONetService * imapServer;
diff --git a/src/objc/provider/MCOAccountValidator.mm b/src/objc/provider/MCOAccountValidator.mm
index b8260486..34d8992b 100644
--- a/src/objc/provider/MCOAccountValidator.mm
+++ b/src/objc/provider/MCOAccountValidator.mm
@@ -19,11 +19,7 @@ typedef void (^CompletionType)(void);
@interface MCOAccountValidator ()
-@property (nonatomic, retain) NSError * imapError;
-@property (nonatomic, retain) NSError * popError;
-@property (nonatomic, retain) NSError * smtpError;
-
-- (void) operationCompleted;
+- (void) _operationCompleted;
@end
@@ -36,7 +32,7 @@ public:
void operationFinished(mailcore::Operation * op)
{
- [mOperation operationCompleted];
+ [mOperation _operationCompleted];
}
private:
@@ -71,6 +67,9 @@ MCO_OBJC_SYNTHESIZE_STRING(setEmail, email)
MCO_OBJC_SYNTHESIZE_STRING(setUsername, username)
MCO_OBJC_SYNTHESIZE_STRING(setPassword, password)
MCO_OBJC_SYNTHESIZE_STRING(setOAuth2Token, OAuth2Token)
+MCO_OBJC_SYNTHESIZE_BOOL(setImapEnabled, isImapEnabled)
+MCO_OBJC_SYNTHESIZE_BOOL(setPopEnabled, isPopEnabled)
+MCO_OBJC_SYNTHESIZE_BOOL(setSmtpEnabled, isSmtpEnabled)
- (id) init
{
@@ -106,7 +105,7 @@ MCO_OBJC_SYNTHESIZE_STRING(setOAuth2Token, OAuth2Token)
[super cancel];
}
-- (void) operationCompleted
+- (void) _operationCompleted
{
if (_completionBlock == NULL)
return;