diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-03-30 19:42:26 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-03-30 19:42:26 -0700 |
commit | 1e5482c0745a77b158ac07e1cc602f9ab2cc0caa (patch) | |
tree | cdcfff5920c926f0f3b681210905aa5ead1e9137 /src/objc/smtp | |
parent | c51a8a2b44e6934de9d45d74ddec4b70b00f1abb (diff) |
Implemented ObjC API for SMTP and POP
Diffstat (limited to 'src/objc/smtp')
-rw-r--r-- | src/objc/smtp/MCOSMTP.h | 16 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPOperation.h | 19 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPOperation.mm | 40 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPSendOperation.h | 25 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPSendOperation.mm | 99 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPSession.h | 38 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPSession.mm | 67 |
7 files changed, 304 insertions, 0 deletions
diff --git a/src/objc/smtp/MCOSMTP.h b/src/objc/smtp/MCOSMTP.h new file mode 100644 index 00000000..df8cec4d --- /dev/null +++ b/src/objc/smtp/MCOSMTP.h @@ -0,0 +1,16 @@ +// +// MCOSMTP.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef mailcore2_MCOSMTP_h +#define mailcore2_MCOSMTP_h + +#import <mailcore/MCOSMTPSession.h> +#import <mailcore/MCOSMTPSendOperation.h> +#import <mailcore/MCOSMTPOperation.h> + +#endif diff --git a/src/objc/smtp/MCOSMTPOperation.h b/src/objc/smtp/MCOSMTPOperation.h new file mode 100644 index 00000000..28b91857 --- /dev/null +++ b/src/objc/smtp/MCOSMTPOperation.h @@ -0,0 +1,19 @@ +// +// MCOSMTPCheckAccountOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOSMTPOPERATION_H_ + +#define __MAILCORE_MCOSMTPOPERATION_H_ + +#import <mailcore/MCOOperation.h> + +@interface MCOSMTPOperation : MCOOperation +- (void)start:(void (^)(NSError *error))completionBlock; +@end + +#endif diff --git a/src/objc/smtp/MCOSMTPOperation.mm b/src/objc/smtp/MCOSMTPOperation.mm new file mode 100644 index 00000000..5bd5ab3a --- /dev/null +++ b/src/objc/smtp/MCOSMTPOperation.mm @@ -0,0 +1,40 @@ +// +// MCOSMTPCheckAccountOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOSMTPOperation.h" + +#include "MCAsyncSMTP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +typedef void (^CompletionType)(NSError *error); + +@implementation MCOSMTPOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::SMTPOperation + +- (void) dealloc +{ + [_completionBlock release]; + [super dealloc]; +} + +- (void)start:(void (^)(NSError *error))completionBlock { + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void)operationCompleted { + NSError * error = [NSError mco_errorWithErrorCode:MCO_NATIVE_INSTANCE->error()]; + _completionBlock(error); +} + +@end diff --git a/src/objc/smtp/MCOSMTPSendOperation.h b/src/objc/smtp/MCOSMTPSendOperation.h new file mode 100644 index 00000000..e0ce3a05 --- /dev/null +++ b/src/objc/smtp/MCOSMTPSendOperation.h @@ -0,0 +1,25 @@ +// +// MCOSMTPSendOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOSMTPSENDOPERATION_H_ + +#define __MAILCORE_MCOSMTPSENDOPERATION_H_ + +#import <mailcore/MCOSMTPOperation.h> + +typedef void (^MCOSMTPOperationProgressBlock)(unsigned int current, unsigned int maximum); + +@interface MCOSMTPSendOperation : MCOSMTPOperation + +@property (nonatomic, copy) MCOSMTPOperationProgressBlock progress; + +- (void)start:(void (^)(NSError *error))completionBlock; + +@end + +#endif diff --git a/src/objc/smtp/MCOSMTPSendOperation.mm b/src/objc/smtp/MCOSMTPSendOperation.mm new file mode 100644 index 00000000..fcad264b --- /dev/null +++ b/src/objc/smtp/MCOSMTPSendOperation.mm @@ -0,0 +1,99 @@ +// +// MCOSMTPSendOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOSMTPSendOperation.h" + +#include "MCAsyncSMTP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +#define nativeType mailcore::SMTPOperation + +typedef void (^CompletionType)(NSError *error); + +@interface MCOSMTPSendOperation () + +- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum; + +@end + +class MCOSMTPSendOperationCallback : public mailcore::SMTPOperationCallback { +public: + MCOSMTPSendOperationCallback(MCOSMTPSendOperation * op) + { + mOperation = op; + } + + virtual void bodyProgress(mailcore::SMTPOperation * session, unsigned int current, unsigned int maximum) { + [mOperation bodyProgress:current maximum:maximum]; + } + +private: + MCOSMTPSendOperation * mOperation; +}; + +@implementation MCOSMTPSendOperation { + CompletionType _completionBlock; + MCOSMTPSendOperationCallback * _smtpCallback; + MCOSMTPOperationProgressBlock _progress; +} + +@synthesize progress = _progress; + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + nativeType * op = (nativeType *) object; + return [[[self alloc] initWithMCOperation:op] autorelease]; +} + +- (id)initWithMCOperation:(mailcore::Operation *)op +{ + self = [super initWithMCOperation:op]; + + _smtpCallback = new MCOSMTPSendOperationCallback(self); + ((mailcore::SMTPOperation *) op)->setSmtpCallback(_smtpCallback); + + return self; +} + +- (void) dealloc +{ + [_progress release]; + [_completionBlock release]; + delete _smtpCallback; + [super dealloc]; +} + +- (void)start:(void (^)(NSError *error))completionBlock { + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void)operationCompleted { + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + _completionBlock(nil); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()]); + } +} + +- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum +{ + if (_progress != NULL) { + _progress(current, maximum); + } +} + +@end diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h new file mode 100644 index 00000000..d5c940b9 --- /dev/null +++ b/src/objc/smtp/MCOSMTPSession.h @@ -0,0 +1,38 @@ +// +// MCOSMTPSession.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOSMTPSESSION_H_ + +#define __MAILCORE_MCOSMTPSESSION_H_ + +#import <Foundation/Foundation.h> + +#import <mailcore/MCOConstants.h> + +@class MCOSMTPSendOperation; +@class MCOSMTPOperation; +@class MCOAddress; + +@interface MCOSMTPSession : NSObject + +@property (nonatomic, copy) NSString * hostname; +@property (nonatomic, assign) unsigned int port; +@property (nonatomic, copy) NSString * username; +@property (nonatomic, copy) NSString * password; +@property (nonatomic, assign) MCOAuthType authType; +@property (nonatomic, assign) MCOConnectionType connectionType; +@property (nonatomic, assign) NSTimeInterval timeout; +@property (nonatomic, assign, getter=isCheckCertificateEnabled) BOOL checkCertificateEnabled; +@property (nonatomic, assign, getter=isUseHeloIPEnabled) BOOL useHeloIPEnabled; + +- (MCOSMTPSendOperation *) sendOperationWithData:(NSData *)messageData; +- (MCOSMTPOperation *) checkAccountOperationWithFrom:(MCOAddress *)from; + +@end + +#endif diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm new file mode 100644 index 00000000..ad8f212e --- /dev/null +++ b/src/objc/smtp/MCOSMTPSession.mm @@ -0,0 +1,67 @@ +// +// MCOSMTPSession.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOSMTPSession.h" + +#include "MCAsyncSMTP.h" + +#import "MCOUtils.h" +#import "MCOSMTPSendOperation.h" +#import "MCOSMTPOperation.h" +#import "MCOOperation+Private.h" +#import "MCOAddress.h" + +@implementation MCOSMTPSession { + mailcore::SMTPAsyncSession * _session; +} + +#define nativeType mailcore::SMTPAsyncSession + +- (mailcore::Object *) mco_mcObject +{ + return _session; +} + +- (id)init { + self = [super init]; + if (self) { + _session = new mailcore::SMTPAsyncSession(); + } + return self; +} + +- (void)dealloc { + _session->release(); + [super dealloc]; +} + +MCO_OBJC_SYNTHESIZE_STRING(setHostname, hostname) +MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setPort, port) +MCO_OBJC_SYNTHESIZE_STRING(setUsername, username) +MCO_OBJC_SYNTHESIZE_STRING(setPassword, password) +MCO_OBJC_SYNTHESIZE_SCALAR(MCOAuthType, mailcore::AuthType, setAuthType, authType) +MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConnectionType, connectionType) +MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout) +MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled) +MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled) + +#pragma mark - Operations + +- (MCOSMTPSendOperation *) sendOperationWithData:(NSData *)messageData +{ + mailcore::SMTPOperation * coreOp = MCO_NATIVE_INSTANCE->sendMessageOperation([messageData mco_mcData]); + return [[[MCOSMTPSendOperation alloc] initWithMCOperation:coreOp] autorelease]; +} + +- (MCOOperation *) checkAccountOperationWithFrom:(MCOAddress *)from +{ + mailcore::SMTPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation(MCO_FROM_OBJC(mailcore::Address, from)); + return [[[MCOSMTPOperation alloc] initWithMCOperation:coreOp] autorelease]; +} + +@end |