diff options
author | Christopher Hockley <christopher@putcocoa.in> | 2015-01-26 11:03:06 +0100 |
---|---|---|
committer | Christopher Hockley <christopher@putcocoa.in> | 2015-01-26 11:03:06 +0100 |
commit | e4374684684264f4264e85c4b12b02e4bcdcdb34 (patch) | |
tree | 607de58075d1491a13ed368a31b2d2c65c26c2b8 /src/objc | |
parent | 49afff2da8d8b658faf8f10e5229b06252359d17 (diff) |
AccountValidator
Added AccountValidator to used to validate an email provider and it's
associated metadata and credentials.
Diffstat (limited to 'src/objc')
-rw-r--r-- | src/objc/provider/MCOAccountValidator.h | 50 | ||||
-rw-r--r-- | src/objc/provider/MCOAccountValidator.mm | 154 | ||||
-rw-r--r-- | src/objc/provider/MCOProvider.h | 2 |
3 files changed, 205 insertions, 1 deletions
diff --git a/src/objc/provider/MCOAccountValidator.h b/src/objc/provider/MCOAccountValidator.h new file mode 100644 index 00000000..0cdc25aa --- /dev/null +++ b/src/objc/provider/MCOAccountValidator.h @@ -0,0 +1,50 @@ +// +// MCOAccountValidator.h +// mailcore2 +// +// Created by Christopher Hockley on 20/01/15. +// Copyright (c) 2015 MailCore. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import <MailCore/MCOOperation.h> + +/** + This class is used to validate an email provider and it's associated + metadata and credentials. + + An app might want to use this during setup to limit the number of settings + a user has to input. + */ + +@class MCONetService; + +@interface MCOAccountValidator : MCOOperation + +@property (nonatomic, copy) NSString * email; /* for SMTP */ +@property (nonatomic, copy) NSString * username; +@property (nonatomic, copy) NSString * password; +@property (nonatomic, copy) NSString * OAuth2Token; + +@property (nonatomic, retain) NSArray * /* MCONetService */ imapServers; +@property (nonatomic, retain) NSArray * /* MCONetService */ popServers; +@property (nonatomic, retain) NSArray * /* MCONetService */ smtpServers; + +// result +@property (nonatomic, retain, readonly) NSString * identifier; +@property (nonatomic, retain, readonly) MCONetService * imapServer; +@property (nonatomic, retain, readonly) MCONetService * popServer; +@property (nonatomic, retain, readonly) MCONetService * smtpServer; +@property (nonatomic, retain, readonly) NSError * imapError; +@property (nonatomic, retain, readonly) NSError * popError; +@property (nonatomic, retain, readonly) NSError * smtpError; + +/** + Starts the asynchronous account validation operation. + + @param completionBlock Called when the operation is finished. + */ +- (void) start:(void (^)(void))completionBlock; + + +@end diff --git a/src/objc/provider/MCOAccountValidator.mm b/src/objc/provider/MCOAccountValidator.mm new file mode 100644 index 00000000..172fd8a6 --- /dev/null +++ b/src/objc/provider/MCOAccountValidator.mm @@ -0,0 +1,154 @@ +// +// MCOAccountValidator.m +// mailcore2 +// +// Created by Christopher Hockley on 20/01/15. +// Copyright (c) 2015 MailCore. All rights reserved. +// + +#import "MCOAccountValidator.h" +#include "MCAccountValidator.h" +#include "MCNetService.h" + +#import "MCOOperation+Private.h" +#import "MCOUtils.h" +#import "MCOperationCallback.h" +#import "MCONetService.h" + +typedef void (^CompletionType)(void); + +@interface MCOAccountValidator () + +@property (nonatomic, retain) NSError * imapError; +@property (nonatomic, retain) NSError * popError; +@property (nonatomic, retain) NSError * smtpError; + +- (void) operationCompleted; + +@end + +class MCOValidatorOperationCallback: public mailcore::Object, public mailcore::OperationCallback { +public: + MCOValidatorOperationCallback(MCOAccountValidator * op) + { + mOperation = op; + } + + void operationFinished(mailcore::Operation * op) + { + [mOperation operationCompleted]; + } + +private: + MCOAccountValidator * mOperation; +}; + +@implementation MCOAccountValidator{ + CompletionType _completionBlock; + mailcore::AccountValidator * _validator; + MCOValidatorOperationCallback * _imapCallback; +} + +#define nativeType mailcore::AccountValidator + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + +- (mailcore::Object *) mco_mcObject +{ + return _validator; +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + mailcore::AccountValidator * validator = (mailcore::AccountValidator *) object; + return [[[self alloc] initWithMCValidator:validator] autorelease]; +} + +MCO_OBJC_SYNTHESIZE_STRING(setEmail, email) +MCO_OBJC_SYNTHESIZE_STRING(setUsername, username) +MCO_OBJC_SYNTHESIZE_STRING(setPassword, password) +MCO_OBJC_SYNTHESIZE_STRING(setOAuth2Token, OAuth2Token) + +- (id) init +{ + mailcore::AccountValidator * msg = new mailcore::AccountValidator(); + self = [self initWithMCValidator:msg]; + msg->release(); + return self; +} + +- (id) initWithMCValidator:(mailcore::AccountValidator *)validator +{ + self = [super initWithMCOperation:validator]; + + _validator = validator; + _imapCallback = new MCOValidatorOperationCallback(self); + _validator->setCallback(_imapCallback); + _validator->retain(); + + return self; +} + +- (void) start:(void (^)(void))completionBlock +{ + _completionBlock = [completionBlock copy]; + + [self start]; +} + +- (void) cancel +{ + [_completionBlock release]; + _completionBlock = nil; + [super cancel]; +} + +- (void) operationCompleted +{ + if (_completionBlock == NULL) + return; + + _completionBlock(); + [_completionBlock release]; + _completionBlock = nil; +} + +- (NSString *) identifier +{ + return MCO_OBJC_BRIDGE_GET(identifier); +} + +- (MCONetService *) imapServer +{ + return MCO_OBJC_BRIDGE_GET(imapServer); +} + +- (MCONetService *) popServer +{ + return MCO_OBJC_BRIDGE_GET(popServer); +} + +- (MCONetService *) smtpServer +{ + return MCO_OBJC_BRIDGE_GET(smtpServer); +} + +- (NSError *) imapError +{ + return [NSError mco_errorWithErrorCode:_validator->imapError()]; +} + +- (NSError *) popError +{ + return [NSError mco_errorWithErrorCode:_validator->popError()]; +} + +- (NSError *) smtpError +{ + return [NSError mco_errorWithErrorCode:_validator->smtpError()]; +} + +@end diff --git a/src/objc/provider/MCOProvider.h b/src/objc/provider/MCOProvider.h index 09f2cb05..3c7bf7ce 100644 --- a/src/objc/provider/MCOProvider.h +++ b/src/objc/provider/MCOProvider.h @@ -9,9 +9,9 @@ #ifndef _MAILCORE__MCOPROVIDER_h #define _MAILCORE__MCOPROVIDER_h - #import <MailCore/MCONetService.h> #import <MailCore/MCOMailProvider.h> #import <MailCore/MCOMailProvidersManager.h> +#import <MailCore/MCOAccountValidator.h> #endif |