diff options
-rwxr-xr-x | build-mac/mailcore2.xcodeproj/project.pbxproj | 26 | ||||
-rw-r--r-- | src/async/MCAsync.h | 1 | ||||
-rw-r--r-- | src/async/mx/MCResolveProviderUsingMXRecord.cpp | 84 | ||||
-rw-r--r-- | src/async/mx/MCResolveProviderUsingMXRecord.h | 43 | ||||
-rw-r--r-- | src/cmake/async.cmake | 6 | ||||
-rw-r--r-- | src/cmake/core.cmake | 1 | ||||
-rw-r--r-- | src/cmake/objc.cmake | 3 | ||||
-rw-r--r-- | src/cmake/public-headers.cmake | 3 | ||||
-rw-r--r-- | src/core/provider/MCAccountValidator.cpp | 225 | ||||
-rw-r--r-- | src/core/provider/MCAccountValidator.h | 23 |
10 files changed, 310 insertions, 105 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index 0657c2d7..00f18501 100755 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 2744B16A1A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2744B1681A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp */; }; + 2744B16B1A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2744B1681A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp */; }; 27478E801A764698004AE621 /* MCAccountValidator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27478E7E1A764698004AE621 /* MCAccountValidator.cpp */; }; 27478E811A764699004AE621 /* MCAccountValidator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27478E7E1A764698004AE621 /* MCAccountValidator.cpp */; }; 27478E841A7646F8004AE621 /* MCOAccountValidator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 27478E831A7646F8004AE621 /* MCOAccountValidator.mm */; }; @@ -15,6 +17,7 @@ 27478E871A76475F004AE621 /* MCAccountValidator.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 27478E7F1A764698004AE621 /* MCAccountValidator.h */; }; 27478E881A7647AC004AE621 /* MCOAccountValidator.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 27478E821A7646F8004AE621 /* MCOAccountValidator.h */; }; 27478E891A7647AC004AE621 /* MCAccountValidator.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 27478E7F1A764698004AE621 /* MCAccountValidator.h */; }; + 276A65D01A7B7E7D008722C2 /* MCResolveProviderUsingMXRecord.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2744B1691A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.h */; }; 27780C2E19CF9CD100C77E44 /* MCOFramework.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6BD28A9170BDB6B00A91AC1 /* MCOFramework.mm */; }; 27780C3219CF9CD100C77E44 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6ED6D1917A1919500A4A14C /* Security.framework */; }; 27780C3619CF9CD100C77E44 /* providers.json in Resources */ = {isa = PBXBuildFile; fileRef = 84AF9E7D172DBAF600E60AA3 /* providers.json */; }; @@ -1231,6 +1234,7 @@ dstPath = include/MailCore; dstSubfolderSpec = 16; files = ( + 276A65D01A7B7E7D008722C2 /* MCResolveProviderUsingMXRecord.h in CopyFiles */, 27478E881A7647AC004AE621 /* MCOAccountValidator.h in CopyFiles */, 27478E891A7647AC004AE621 /* MCAccountValidator.h in CopyFiles */, C673EBEF1A46B44E00A53F7F /* MCIMAPFolderInfo.h in CopyFiles */, @@ -1450,6 +1454,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 2744B1681A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MCResolveProviderUsingMXRecord.cpp; path = mx/MCResolveProviderUsingMXRecord.cpp; sourceTree = "<group>"; }; + 2744B1691A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MCResolveProviderUsingMXRecord.h; path = mx/MCResolveProviderUsingMXRecord.h; sourceTree = "<group>"; }; 27478E7E1A764698004AE621 /* MCAccountValidator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCAccountValidator.cpp; sourceTree = "<group>"; }; 27478E7F1A764698004AE621 /* MCAccountValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCAccountValidator.h; sourceTree = "<group>"; }; 27478E821A7646F8004AE621 /* MCOAccountValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOAccountValidator.h; sourceTree = "<group>"; }; @@ -2143,6 +2149,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 2744B1671A7A459C009E9E67 /* mx */ = { + isa = PBXGroup; + children = ( + 2744B1681A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp */, + 2744B1691A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.h */, + ); + name = mx; + sourceTree = "<group>"; + }; 8491899A18C93F6E002063A3 /* nntp */ = { isa = PBXGroup; children = ( @@ -2475,6 +2490,7 @@ C64EA68D169E847800778456 /* pop */, 84D73728199BF61B005124E5 /* nntp */, C64EA68E169E847800778456 /* smtp */, + 2744B1671A7A459C009E9E67 /* mx */, C64EA7E416A14A4500778456 /* MCAsync.h */, ); path = async; @@ -3473,6 +3489,7 @@ C64EA7DA16A1386600778456 /* MCSMTPOperation.cpp in Sources */, C64EA7EA16A154B300778456 /* MCSMTPCheckAccountOperation.cpp in Sources */, C64EA7F116A15A4D00778456 /* MCIMAPOperation.cpp in Sources */, + 2744B16A1A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp in Sources */, BDCD7CDB1A70771B0001DCC3 /* ucln_in.cpp in Sources */, C64EA7F816A15A7800778456 /* MCIMAPCheckAccountOperation.cpp in Sources */, 943F1A9A17D964F600F0C798 /* MCIMAPConnectOperation.cpp in Sources */, @@ -3743,6 +3760,7 @@ C6BA2BC01705F4E6003F0E9E /* MCSMTPSendWithDataOperation.cpp in Sources */, C6BA2BC11705F4E6003F0E9E /* MCSMTPOperation.cpp in Sources */, C6BA2BC21705F4E6003F0E9E /* MCSMTPCheckAccountOperation.cpp in Sources */, + 2744B16B1A7A4637009E9E67 /* MCResolveProviderUsingMXRecord.cpp in Sources */, BDCD7CDC1A70771B0001DCC3 /* ucln_in.cpp in Sources */, C6BA2BC31705F4E6003F0E9E /* MCIMAPOperation.cpp in Sources */, C6BA2BC41705F4E6003F0E9E /* MCIMAPCheckAccountOperation.cpp in Sources */, @@ -3982,6 +4000,7 @@ "-ltidy", "-lz", "-ObjC", + "-lresolv", ); PRODUCT_NAME = MailCore; SDKROOT = iphoneos; @@ -4009,6 +4028,7 @@ "-ltidy", "-lz", "-ObjC", + "-lresolv", ); PRODUCT_NAME = MailCore; SDKROOT = iphoneos; @@ -4052,6 +4072,7 @@ "-ObjC", "-lcrypto", "-lssl", + "-lresolv", ); PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -4091,6 +4112,7 @@ "-ObjC", "-lcrypto", "-lssl", + "-lresolv", ); PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -4250,6 +4272,7 @@ "-all_load", "-ltidy", "-lz", + "-lresolv", ); PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -4281,6 +4304,7 @@ "-all_load", "-ltidy", "-lz", + "-lresolv", ); PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -4402,6 +4426,7 @@ "-all_load", "-ltidy", "-lz", + "-lresolv", ); PRODUCT_NAME = MailCore; SDKROOT = macosx; @@ -4430,6 +4455,7 @@ "-all_load", "-ltidy", "-lz", + "-lresolv", ); PRODUCT_NAME = MailCore; SDKROOT = macosx; diff --git a/src/async/MCAsync.h b/src/async/MCAsync.h index 90b3e263..b68ed422 100644 --- a/src/async/MCAsync.h +++ b/src/async/MCAsync.h @@ -14,5 +14,6 @@ #include <MailCore/MCAsyncIMAP.h> #include <MailCore/MCAsyncPOP.h> #include <MailCore/MCAsyncNNTP.h> +#include <MailCore/MCResolveProviderUsingMXRecord.h> #endif diff --git a/src/async/mx/MCResolveProviderUsingMXRecord.cpp b/src/async/mx/MCResolveProviderUsingMXRecord.cpp new file mode 100644 index 00000000..00d3e036 --- /dev/null +++ b/src/async/mx/MCResolveProviderUsingMXRecord.cpp @@ -0,0 +1,84 @@ +// +// MCFetchAsyncMXRecord.cpp +// mailcore2 +// +// Created by Christopher Hockley on 29/01/15. +// Copyright (c) 2015 MailCore. All rights reserved. +// + +#include "MCResolveProviderUsingMXRecord.h" + +#include "MCMailProvider.h" +#include "MCMailProvidersManager.h" + +#include <arpa/inet.h> +#include <resolv.h> + +using namespace mailcore; + +ResolveProviderUsingMXRecord::ResolveProviderUsingMXRecord() +{ + mHostname = NULL; + mProvider = NULL; +} + +ResolveProviderUsingMXRecord::~ResolveProviderUsingMXRecord() +{ + MC_SAFE_RELEASE(mProvider); +} + +void ResolveProviderUsingMXRecord::setHostname(String * hostname) +{ + MC_SAFE_REPLACE_COPY(String, mHostname, hostname); +} + +String * ResolveProviderUsingMXRecord::hostname() +{ + return mHostname; +} + +MailProvider * ResolveProviderUsingMXRecord::provider() +{ + return mProvider; +} + +void ResolveProviderUsingMXRecord::main() +{ + unsigned char response[NS_PACKETSZ]; + ns_msg handle; + ns_rr rr; + int len; + char dispbuf[4096]; + + if (((len = res_search(MCUTF8(mHostname), ns_c_in, ns_t_mx, response, sizeof(response))) >= 0) and + (ns_initparse(response, len, &handle) >= 0) and + (ns_msg_count(handle, ns_s_an) >= 0)) { + + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, CFSTR("providers"), CFSTR("json"), NULL); + CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle); + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); + const char *path = CFStringGetCStringPtr(imagePath, encodingMethod); + + String * sPath = String::stringWithUTF8Characters(path); + + MailProvidersManager::sharedManager()->registerProvidersWithFilename(sPath); + + for (int ns_index = 0; ns_index < len; ns_index++) { + if (ns_parserr(&handle, ns_s_an, ns_index, &rr)) { + /* WARN: ns_parserr failed */ + continue; + } + ns_sprintrr (&handle, &rr, NULL, NULL, dispbuf, sizeof (dispbuf)); + if (ns_rr_class(rr) == ns_c_in and ns_rr_type(rr) == ns_t_mx) { + char mxname[4096]; + dn_expand(ns_msg_base(handle), ns_msg_base(handle) + ns_msg_size(handle), ns_rr_rdata(rr) + NS_INT16SZ, mxname, sizeof(mxname)); + String * str = String::stringWithUTF8Characters(mxname); + MailProvider *provider = MailProvidersManager::sharedManager()->providerForMX(str); + if (provider) + mProvider = provider; + } + } + } +} + diff --git a/src/async/mx/MCResolveProviderUsingMXRecord.h b/src/async/mx/MCResolveProviderUsingMXRecord.h new file mode 100644 index 00000000..d8c014f1 --- /dev/null +++ b/src/async/mx/MCResolveProviderUsingMXRecord.h @@ -0,0 +1,43 @@ +// +// ResolveProviderUsingMXRecordAsync.h +// mailcore2 +// +// Created by Christopher Hockley on 29/01/15. +// Copyright (c) 2015 MailCore. All rights reserved. +// + +#ifndef MAILCORE_MCFETCHASYNCMXRECORD_H + +#define MAILCORE_MCFETCHASYNCMXRECORD_H + +#include <MailCore/MCBaseTypes.h> +#include <MailCore/MCMessageConstants.h> + +#ifdef __cplusplus + +namespace mailcore { + + class MailProvider; + + class MAILCORE_EXPORT ResolveProviderUsingMXRecord : public Operation { + public: + ResolveProviderUsingMXRecord(); + virtual ~ResolveProviderUsingMXRecord(); + + virtual void setHostname(String * hostname); + virtual String * hostname(); + + virtual MailProvider * provider(); + + public: // subclass behavior + virtual void main(); + + private: + MailProvider * mProvider; + String * mHostname; + }; +} + +#endif + +#endif diff --git a/src/cmake/async.cmake b/src/cmake/async.cmake index c1eb3faf..f829ab02 100644 --- a/src/cmake/async.cmake +++ b/src/cmake/async.cmake @@ -68,11 +68,16 @@ set(async_nntp_files async/nntp/MCNNTPOperation.cpp ) +set(async_mx_files + async/mx/MCResolveProviderUsingMXRecord.cpp +) + set(async_files ${async_imap_files} ${async_pop_files} ${async_smtp_files} ${async_nntp_files} + ${async_mx_files} ) # Includes for build @@ -83,4 +88,5 @@ set(async_includes "${CMAKE_CURRENT_SOURCE_DIR}/async/pop" "${CMAKE_CURRENT_SOURCE_DIR}/async/smtp" "${CMAKE_CURRENT_SOURCE_DIR}/async/nntp" + "${CMAKE_CURRENT_SOURCE_DIR}/async/mx" ) diff --git a/src/cmake/core.cmake b/src/cmake/core.cmake index 2f33f0d5..24e1a266 100644 --- a/src/cmake/core.cmake +++ b/src/cmake/core.cmake @@ -117,6 +117,7 @@ set(provider_files core/provider/MCMailProvider.cpp core/provider/MCMailProvidersManager.cpp core/provider/MCNetService.cpp + core/provider/MCAccountValidator.cpp ) set(renderer_files diff --git a/src/cmake/objc.cmake b/src/cmake/objc.cmake index f67d76e4..dfca7aee 100644 --- a/src/cmake/objc.cmake +++ b/src/cmake/objc.cmake @@ -58,6 +58,7 @@ set(objc_provider_files objc/provider/MCOMailProvider.mm objc/provider/MCOMailProvidersManager.mm objc/provider/MCONetService.mm + objc/provider/MCOAccountValidator.mm ) set(objc_rfc822_files @@ -109,6 +110,7 @@ set(objc_files ${objc_abstract_files} ${objc_imap_files} ${objc_pop_files} + ${objc_provider_files} ${objc_nntp_files} ${objc_rfc822_files} ${objc_smtp_files} @@ -123,6 +125,7 @@ set(objc_includes "${CMAKE_CURRENT_SOURCE_DIR}/objc/abstract" "${CMAKE_CURRENT_SOURCE_DIR}/objc/imap" "${CMAKE_CURRENT_SOURCE_DIR}/objc/pop" + "${CMAKE_CURRENT_SOURCE_DIR}/objc/provider" "${CMAKE_CURRENT_SOURCE_DIR}/objc/nntp" "${CMAKE_CURRENT_SOURCE_DIR}/objc/rfc822" "${CMAKE_CURRENT_SOURCE_DIR}/objc/smtp" diff --git a/src/cmake/public-headers.cmake b/src/cmake/public-headers.cmake index 40286dde..6829c3f2 100644 --- a/src/cmake/public-headers.cmake +++ b/src/cmake/public-headers.cmake @@ -73,6 +73,7 @@ core/provider/MCProvider.h core/provider/MCMailProvidersManager.h core/provider/MCMailProvider.h core/provider/MCNetService.h +core/provider/MCAccountValidator.h async/MCAsync.h async/smtp/MCAsyncSMTP.h async/smtp/MCSMTPAsyncSession.h @@ -115,6 +116,7 @@ async/nntp/MCNNTPListNewsgroupsOperation.h async/nntp/MCNNTPFetchOverviewOperation.h async/nntp/MCNNTPFetchServerTimeOperation.h async/nntp/MCNNTPOperationCallback.h +async/mx/MCResolveProviderUsingMXRecord.h objc/MCObjC.h objc/utils/MCOUtils.h objc/utils/MCOObjectWrapper.h @@ -200,4 +202,5 @@ objc/provider/MCOProvider.h objc/provider/MCONetService.h objc/provider/MCOMailProvider.h objc/provider/MCOMailProvidersManager.h +objc/provider/MCOAccountValidator.h ) diff --git a/src/core/provider/MCAccountValidator.cpp b/src/core/provider/MCAccountValidator.cpp index 1fa7cfa3..9b6e234b 100644 --- a/src/core/provider/MCAccountValidator.cpp +++ b/src/core/provider/MCAccountValidator.cpp @@ -17,9 +17,8 @@ #include "MCIMAPOperation.h" #include "MCPOPOperation.h" #include "MCSMTPOperation.h" - -#include <arpa/inet.h> -#include <resolv.h> +#include "MCResolveProviderUsingMXRecord.h" +#include "MCOperationQueueCallback.h" using namespace mailcore; @@ -31,6 +30,35 @@ enum { SERVICE_SMTP, /* SMTP service */ }; +namespace mailcore { + + class ValidatorOperationQueueCallback : public Object, public OperationQueueCallback { + public: + ValidatorOperationQueueCallback(AccountValidator * validator) { + mValidator = validator; + } + + virtual ~ValidatorOperationQueueCallback() { + } + + virtual void queueStartRunning() { + if (mValidator->operationQueueCallback() != NULL) { + mValidator->operationQueueCallback()->queueStartRunning(); + } + } + + virtual void queueStoppedRunning() { + if (mValidator->operationQueueCallback() != NULL) { + mValidator->operationQueueCallback()->queueStoppedRunning(); + } + + mValidator->setup(); + } + private: + AccountValidator * mValidator; + }; +} + void AccountValidator::init() { mEmail = NULL; @@ -52,6 +80,13 @@ void AccountValidator::init() mCurrentServiceIndex = 0; mCurrentServiceTested = 0; + + mProvider = NULL; + + mQueue = new OperationQueue(); + mQueueCallback = new ValidatorOperationQueueCallback(this); + mQueue->setCallback(mQueueCallback); + mOperationQueueCallback = NULL; } AccountValidator::AccountValidator() @@ -69,12 +104,46 @@ AccountValidator::~AccountValidator() MC_SAFE_RELEASE(mSmtpServices); MC_SAFE_RELEASE(mPopServices); MC_SAFE_RELEASE(mIdentifier); + MC_SAFE_RELEASE(mProvider); } void AccountValidator::start() { - setup(); - test(); + if (mEmail == NULL) { + if (mUsername == NULL) { + return; + } + else { + mEmail = mUsername; + } + } + else if (mUsername == NULL){ + mUsername = mEmail; + } + + mProvider = MailProvidersManager::sharedManager()->providerForEmail(mUsername); + + if (mProvider == NULL) { + Array * components; + String * domain; + + components = mUsername->componentsSeparatedByString(MCSTR("@")); + if (components->count() >= 2) { + domain = (String *) components->lastObject(); + mResolveMX = new ResolveProviderUsingMXRecord(); + mResolveMX->setHostname(domain); + mQueue->addOperation(mResolveMX); + } + } + else{ + setup(); + } +} + +void AccountValidator::cancel() +{ + mOperation->cancel(); + Operation::cancel(); } void AccountValidator::operationFinished(Operation * op) @@ -84,38 +153,21 @@ void AccountValidator::operationFinished(Operation * op) void AccountValidator::setup() { - if (mEmail == NULL) { - if (mUsername == NULL) return; - else mEmail = mUsername; - }else if (mUsername == NULL){ - mUsername = mEmail; + if (mResolveMX != NULL) { + mProvider = mResolveMX->provider(); } - MailProvider *provider = MailProvidersManager::sharedManager()->providerForEmail(mUsername); - - if (provider == NULL) { - Array * components; - String * domain; - - components = mUsername->componentsSeparatedByString(MCSTR("@")); - if (components->count() < 2) - return; - - domain = (String *) components->lastObject(); - provider = ResolveProviderUsingMXRecord(domain); - } - - if (provider != NULL) { - mIdentifier = provider->identifier(); + if (mProvider != NULL) { + mIdentifier = mProvider->identifier(); - if (mImapServices->count() == 0 and provider->imapServices()->count() > 0) - mImapServices = provider->imapServices(); + if (mImapServices->count() == 0 and mProvider->imapServices()->count() > 0) + mImapServices = mProvider->imapServices(); - if (mPopServices->count() == 0 and provider->popServices()->count() > 0) - mPopServices = provider->popServices(); + if (mPopServices->count() == 0 and mProvider->popServices()->count() > 0) + mPopServices = mProvider->popServices(); - if (mSmtpServices->count() == 0 and provider->smtpServices()->count() > 0) - mSmtpServices = provider->smtpServices(); + if (mSmtpServices->count() == 0 and mProvider->smtpServices()->count() > 0) + mSmtpServices = mProvider->smtpServices(); } if (mImapServices->count() == 0) @@ -126,6 +178,8 @@ void AccountValidator::setup() if (mSmtpServices->count() == 0) mSmtpError = ErrorNoValidServerFound; + + test(); } void AccountValidator::opCompleted() @@ -133,16 +187,22 @@ void AccountValidator::opCompleted() 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(); + mImapError = ((IMAPOperation *)mOperation)->error(); + error = mImapError; + } + else if (mCurrentServiceTested == SERVICE_POP) { + mPopError = ((POPOperation *)mOperation)->error(); + error = mPopError; + } + else if (mCurrentServiceTested == SERVICE_SMTP) { + mSmtpError = ((SMTPOperation *)mOperation)->error(); + error = mSmtpError; } if (error == ErrorNone) { mCurrentServiceTested ++; - } else { + } + else { mCurrentServiceIndex ++; } @@ -173,12 +233,14 @@ void AccountValidator::test() mOperation->setCallback(this); mOperation->start(); - } else { + } + else { mCurrentServiceTested = SERVICE_POP; mCurrentServiceIndex = 0; test(); } - }else if (mCurrentServiceTested == SERVICE_POP){ + } + else if (mCurrentServiceTested == SERVICE_POP){ if (mCurrentServiceIndex < mPopServices->count()) { POPAsyncSession *popSession = new POPAsyncSession(); popSession->setUsername(mUsername); @@ -192,12 +254,14 @@ void AccountValidator::test() mOperation = (POPOperation *)popSession->checkAccountOperation(); mOperation->setCallback(this); mOperation->start(); - } else { + } + else { mCurrentServiceTested = SERVICE_SMTP; mCurrentServiceIndex = 0; test(); } - }else if (mCurrentServiceTested == SERVICE_SMTP){ + } + else if (mCurrentServiceTested == SERVICE_SMTP){ if (mCurrentServiceIndex < mSmtpServices->count()) { SMTPAsyncSession *smtpSession = new SMTPAsyncSession(); smtpSession->setUsername(mUsername); @@ -212,65 +276,16 @@ void AccountValidator::test() mOperation->setCallback(this); mOperation->start(); - } else { - mCallback->operationFinished(this); - } - } else { - mCallback->operationFinished(this); - } -} - -MailProvider* AccountValidator::ResolveProviderUsingMXRecord(String *hostname) -{ - unsigned char response[NS_PACKETSZ]; - ns_msg handle; - ns_rr rr; - int len; - char dispbuf[4096]; - - if ((len = res_search(MCUTF8(hostname), ns_c_in, ns_t_mx, response, sizeof(response))) < 0) { - /* WARN: res_search failed */ - return nil; - } - - if (ns_initparse(response, len, &handle) < 0) { - return nil; - } - - len = ns_msg_count(handle, ns_s_an); - if (len < 0) - return nil; - - CFBundleRef mainBundle = CFBundleGetMainBundle(); - CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, CFSTR("providers"), CFSTR("json"), NULL); - CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle); - CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); - const char *path = CFStringGetCStringPtr(imagePath, encodingMethod); - - String * sPath = String::stringWithUTF8Characters(path); - - MailProvidersManager::sharedManager()->registerProvidersWithFilename(sPath); - - for (int ns_index = 0; ns_index < len; ns_index++) { - if (ns_parserr(&handle, ns_s_an, ns_index, &rr)) { - /* WARN: ns_parserr failed */ - continue; } - ns_sprintrr (&handle, &rr, NULL, NULL, dispbuf, sizeof (dispbuf)); - if (ns_rr_class(rr) == ns_c_in and ns_rr_type(rr) == ns_t_mx) { - char mxname[4096]; - dn_expand(ns_msg_base(handle), ns_msg_base(handle) + ns_msg_size(handle), ns_rr_rdata(rr) + NS_INT16SZ, mxname, sizeof(mxname)); - String * str = String::stringWithUTF8Characters(mxname); - MailProvider *provider = MailProvidersManager::sharedManager()->providerForMX(str); - if (provider) - return provider; + else { + callback()->operationFinished(this); } } - - return nil; + else { + callback()->operationFinished(this); + } } - void AccountValidator::setEmail(String * email) { MC_SAFE_REPLACE_COPY(String, mEmail, email); @@ -376,12 +391,22 @@ ErrorCode AccountValidator::smtpError() return mSmtpError; } -void AccountValidator::setCallback(OperationCallback * callback) +void POPAsyncSession::setOperationQueueCallback(OperationQueueCallback * callback) +{ + mOperationQueueCallback = callback; +} + +OperationQueueCallback * POPAsyncSession::operationQueueCallback() +{ + return mOperationQueueCallback; +} + +bool POPAsyncSession::isOperationQueueRunning() { - mCallback = callback; + return mQueue->count() > 0; } -OperationCallback * AccountValidator::Callback() +void POPAsyncSession::cancelAllOperations() { - return mCallback; + mQueue->cancelAllOperations(); } diff --git a/src/core/provider/MCAccountValidator.h b/src/core/provider/MCAccountValidator.h index 8dc3d9aa..9db5ff83 100644 --- a/src/core/provider/MCAccountValidator.h +++ b/src/core/provider/MCAccountValidator.h @@ -19,6 +19,8 @@ namespace mailcore { class NetService; class MailProvider; class IMAPOperation; + class ValidatorOperationQueueCallback; + class ResolveProviderUsingMXRecord; class MAILCORE_EXPORT AccountValidator : public Operation, public OperationCallback { public: @@ -51,9 +53,12 @@ namespace mailcore { virtual ErrorCode smtpError(); virtual void start(); + virtual void cancel(); - virtual void setCallback(OperationCallback * callback); - virtual OperationCallback * Callback(); + virtual void setOperationQueueCallback(OperationQueueCallback * callback); + virtual OperationQueueCallback * operationQueueCallback(); + virtual bool isOperationQueueRunning(); + virtual void cancelAllOperations(); private: String * mEmail; /* for SMTP */ @@ -74,9 +79,9 @@ namespace mailcore { ErrorCode mPopError; ErrorCode mSmtpError; - void setup(); + MailProvider * mProvider; + void test(); - MailProvider * ResolveProviderUsingMXRecord(String *hostname); //indexs for services being tested int mCurrentServiceIndex; @@ -84,10 +89,18 @@ namespace mailcore { void init(); - OperationCallback * mCallback; Operation * mOperation; void opCompleted(); virtual void operationFinished(Operation * op); + + OperationQueue * mQueue; + ValidatorOperationQueueCallback * mQueueCallback; + OperationQueueCallback * mOperationQueueCallback; + ResolveProviderUsingMXRecord * mResolveMX; + + public://private + void setup(); + }; } |