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 | |
parent | c51a8a2b44e6934de9d45d74ddec4b70b00f1abb (diff) |
Implemented ObjC API for SMTP and POP
Diffstat (limited to 'src/objc')
36 files changed, 908 insertions, 31 deletions
diff --git a/src/objc/MCObjC.h b/src/objc/MCObjC.h index 8336de13..ca817cff 100644 --- a/src/objc/MCObjC.h +++ b/src/objc/MCObjC.h @@ -15,6 +15,8 @@ #import <mailcore/MCOAbstract.h> #import <mailcore/MCOIMAP.h> #import <mailcore/MCORFC822.h> +#import <mailcore/MCOPOP.h> +#import <mailcore/MCOSMTP.h> #endif diff --git a/src/objc/imap/MCOIMAPAppendMessageOperation.mm b/src/objc/imap/MCOIMAPAppendMessageOperation.mm index dc3409f7..678fb79d 100644 --- a/src/objc/imap/MCOIMAPAppendMessageOperation.mm +++ b/src/objc/imap/MCOIMAPAppendMessageOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, uint32_t createdUID); +typedef void (^CompletionType)(NSError *error, uint32_t createdUID); @implementation MCOIMAPAppendMessageOperation { - completionType _completionBlock; + CompletionType _completionBlock; MCOIMAPBaseOperationProgressBlock _progress; } diff --git a/src/objc/imap/MCOIMAPBaseOperation.mm b/src/objc/imap/MCOIMAPBaseOperation.mm index f89afc0f..be398ece 100644 --- a/src/objc/imap/MCOIMAPBaseOperation.mm +++ b/src/objc/imap/MCOIMAPBaseOperation.mm @@ -12,10 +12,6 @@ #import "MCAsyncIMAP.h" -@interface MCOIMAPBaseOperation () - -@end - class MCOIMAPBaseOperationIMAPCallback : public mailcore::IMAPOperationCallback { public: MCOIMAPBaseOperationIMAPCallback(MCOIMAPBaseOperation * op) diff --git a/src/objc/imap/MCOIMAPCapabilityOperation.mm b/src/objc/imap/MCOIMAPCapabilityOperation.mm index 97a635da..8e103bbc 100644 --- a/src/objc/imap/MCOIMAPCapabilityOperation.mm +++ b/src/objc/imap/MCOIMAPCapabilityOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, MCOIndexSet * capabilities); +typedef void (^CompletionType)(NSError *error, MCOIndexSet * capabilities); @implementation MCOIMAPCapabilityOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPCapabilityOperation diff --git a/src/objc/imap/MCOIMAPCopyMessagesOperation.mm b/src/objc/imap/MCOIMAPCopyMessagesOperation.mm index ddc80af6..8ac94c4e 100644 --- a/src/objc/imap/MCOIMAPCopyMessagesOperation.mm +++ b/src/objc/imap/MCOIMAPCopyMessagesOperation.mm @@ -14,10 +14,10 @@ #import "MCOUtils.h" #import "MCOIndexSet.h" -typedef void (^completionType)(NSError *error, MCOIndexSet * destUids); +typedef void (^CompletionType)(NSError *error, MCOIndexSet * destUids); @implementation MCOIMAPCopyMessagesOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPCopyMessagesOperation diff --git a/src/objc/imap/MCOIMAPFetchContentOperation.mm b/src/objc/imap/MCOIMAPFetchContentOperation.mm index d4e4192b..1f84d9d8 100644 --- a/src/objc/imap/MCOIMAPFetchContentOperation.mm +++ b/src/objc/imap/MCOIMAPFetchContentOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, NSData * data); +typedef void (^CompletionType)(NSError *error, NSData * data); @implementation MCOIMAPFetchContentOperation { - completionType _completionBlock; + CompletionType _completionBlock; MCOIMAPBaseOperationProgressBlock _progress; } diff --git a/src/objc/imap/MCOIMAPFetchFoldersOperation.h b/src/objc/imap/MCOIMAPFetchFoldersOperation.h index 65410c39..8f7b6592 100644 --- a/src/objc/imap/MCOIMAPFetchFoldersOperation.h +++ b/src/objc/imap/MCOIMAPFetchFoldersOperation.h @@ -10,9 +10,9 @@ #define __MAILCORE_MCOIMAPFETCHFOLDERSOPERATION_H_ -#import <mailcore/MCOOperation.h> +#import <mailcore/MCOIMAPBaseOperation.h> -@interface MCOIMAPFetchFoldersOperation : MCOOperation +@interface MCOIMAPFetchFoldersOperation : MCOIMAPBaseOperation - (void)start:(void (^)(NSError *error, NSArray *folder))completionBlock; @end diff --git a/src/objc/imap/MCOIMAPFetchFoldersOperation.mm b/src/objc/imap/MCOIMAPFetchFoldersOperation.mm index abf59611..7e33efe2 100644 --- a/src/objc/imap/MCOIMAPFetchFoldersOperation.mm +++ b/src/objc/imap/MCOIMAPFetchFoldersOperation.mm @@ -18,10 +18,10 @@ using namespace mailcore; -typedef void (^completionType)(NSError *error, NSArray *folder); +typedef void (^CompletionType)(NSError *error, NSArray *folder); @implementation MCOIMAPFetchFoldersOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPFetchFoldersOperation diff --git a/src/objc/imap/MCOIMAPFetchMessagesOperation.mm b/src/objc/imap/MCOIMAPFetchMessagesOperation.mm index c6a3699d..6aca50c2 100644 --- a/src/objc/imap/MCOIMAPFetchMessagesOperation.mm +++ b/src/objc/imap/MCOIMAPFetchMessagesOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, NSArray * messages, MCOIndexSet * vanishedMessages); +typedef void (^CompletionType)(NSError *error, NSArray * messages, MCOIndexSet * vanishedMessages); @implementation MCOIMAPFetchMessagesOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPFetchMessagesOperation diff --git a/src/objc/imap/MCOIMAPFetchNamespaceOperation.mm b/src/objc/imap/MCOIMAPFetchNamespaceOperation.mm index 798194b2..cc3a7473 100644 --- a/src/objc/imap/MCOIMAPFetchNamespaceOperation.mm +++ b/src/objc/imap/MCOIMAPFetchNamespaceOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, NSDictionary * namespaces); +typedef void (^CompletionType)(NSError *error, NSDictionary * namespaces); @implementation MCOIMAPFetchNamespaceOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPFetchNamespaceOperation diff --git a/src/objc/imap/MCOIMAPFolderInfoOperation.h b/src/objc/imap/MCOIMAPFolderInfoOperation.h index ebe881b2..ed11da95 100644 --- a/src/objc/imap/MCOIMAPFolderInfoOperation.h +++ b/src/objc/imap/MCOIMAPFolderInfoOperation.h @@ -7,7 +7,6 @@ // #import <mailcore/MCOIMAPBaseOperation.h> -#import <mailcore/MCOIMAPOperation.h> #ifndef __MAILCORE_MCOIMAPFOLDERINFOOPERATION_H_ diff --git a/src/objc/imap/MCOIMAPFolderInfoOperation.mm b/src/objc/imap/MCOIMAPFolderInfoOperation.mm index 5a7697d7..f896eac8 100644 --- a/src/objc/imap/MCOIMAPFolderInfoOperation.mm +++ b/src/objc/imap/MCOIMAPFolderInfoOperation.mm @@ -14,10 +14,10 @@ #import "MCOIMAPFolderInfo.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, MCOIMAPFolderInfo *info); +typedef void (^CompletionType)(NSError *error, MCOIMAPFolderInfo *info); @implementation MCOIMAPFolderInfoOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPFolderInfoOperation diff --git a/src/objc/imap/MCOIMAPIdentityOperation.mm b/src/objc/imap/MCOIMAPIdentityOperation.mm index ab358adf..ab4dab6a 100644 --- a/src/objc/imap/MCOIMAPIdentityOperation.mm +++ b/src/objc/imap/MCOIMAPIdentityOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error, NSDictionary * serverIdentity); +typedef void (^CompletionType)(NSError *error, NSDictionary * serverIdentity); @implementation MCOIMAPIdentityOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPIdentityOperation diff --git a/src/objc/imap/MCOIMAPIdleOperation.mm b/src/objc/imap/MCOIMAPIdleOperation.mm index 3de7b141..76591d72 100644 --- a/src/objc/imap/MCOIMAPIdleOperation.mm +++ b/src/objc/imap/MCOIMAPIdleOperation.mm @@ -13,10 +13,10 @@ #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^completionType)(NSError *error); +typedef void (^CompletionType)(NSError *error); @implementation MCOIMAPIdleOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPIdleOperation diff --git a/src/objc/imap/MCOIMAPOperation.mm b/src/objc/imap/MCOIMAPOperation.mm index a928fede..e0938fd3 100644 --- a/src/objc/imap/MCOIMAPOperation.mm +++ b/src/objc/imap/MCOIMAPOperation.mm @@ -13,10 +13,10 @@ #import "MCOUtils.h" -typedef void (^completionType)(NSError *error); +typedef void (^CompletionType)(NSError *error); @implementation MCOIMAPOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPOperation diff --git a/src/objc/imap/MCOIMAPSearchOperation.mm b/src/objc/imap/MCOIMAPSearchOperation.mm index 1246ca02..a8eaf937 100644 --- a/src/objc/imap/MCOIMAPSearchOperation.mm +++ b/src/objc/imap/MCOIMAPSearchOperation.mm @@ -14,10 +14,10 @@ #import "MCOUtils.h" #import "MCOIndexSet.h" -typedef void (^completionType)(NSError *error, MCOIndexSet * searchResult); +typedef void (^CompletionType)(NSError *error, MCOIndexSet * searchResult); @implementation MCOIMAPSearchOperation { - completionType _completionBlock; + CompletionType _completionBlock; } #define nativeType mailcore::IMAPSearchOperation diff --git a/src/objc/pop/MCOPOP.h b/src/objc/pop/MCOPOP.h new file mode 100644 index 00000000..e06022e5 --- /dev/null +++ b/src/objc/pop/MCOPOP.h @@ -0,0 +1,19 @@ +// +// MCOPOP.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/30/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef mailcore2_MCOPOP_h +#define mailcore2_MCOPOP_h + +#import <mailcore/MCOPOPSession.h> +#import <mailcore/MCOPOPOperation.h> +#import <mailcore/MCOPOPFetchHeaderOperation.h> +#import <mailcore/MCOPOPFetchMessageOperation.h> +#import <mailcore/MCOPOPFetchMessagesOperation.h> +#import <mailcore/MCOPOPMessageInfo.h> + +#endif diff --git a/src/objc/pop/MCOPOPFetchHeaderOperation.h b/src/objc/pop/MCOPOPFetchHeaderOperation.h new file mode 100644 index 00000000..74ed96ef --- /dev/null +++ b/src/objc/pop/MCOPOPFetchHeaderOperation.h @@ -0,0 +1,22 @@ +// +// MCOFetchHeaderOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPFETCHHEADEROPERATION_H_ + +#define __MAILCORE_MCOPOPFETCHHEADEROPERATION_H_ + +#import <Foundation/Foundation.h> +#import <mailcore/MCOPOPOperation.h> + +@class MCOMessageHeader; + +@interface MCOPOPFetchHeaderOperation : MCOPOPOperation +- (void)start:(void (^)(NSError *error, MCOMessageHeader * header))completionBlock; +@end + +#endif diff --git a/src/objc/pop/MCOPOPFetchHeaderOperation.mm b/src/objc/pop/MCOPOPFetchHeaderOperation.mm new file mode 100644 index 00000000..f7efea81 --- /dev/null +++ b/src/objc/pop/MCOPOPFetchHeaderOperation.mm @@ -0,0 +1,56 @@ +// +// MCOFetchHeaderOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPFetchHeaderOperation.h" + +#include "MCAsyncPOP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +typedef void (^CompletionType)(NSError *error, MCOMessageHeader * header); + +@implementation MCOPOPFetchHeaderOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::POPFetchHeaderOperation + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + nativeType * op = (nativeType *) object; + return [[[self alloc] initWithMCOperation:op] autorelease]; +} + +- (void) dealloc +{ + [_completionBlock release]; + [super dealloc]; +} + +- (void)start:(void (^)(NSError *error, MCOMessageHeader * header))completionBlock +{ + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void)operationCompleted { + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + _completionBlock(nil, MCO_TO_OBJC(op->header())); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } +} + +@end diff --git a/src/objc/pop/MCOPOPFetchMessageOperation.h b/src/objc/pop/MCOPOPFetchMessageOperation.h new file mode 100644 index 00000000..231a5cb8 --- /dev/null +++ b/src/objc/pop/MCOPOPFetchMessageOperation.h @@ -0,0 +1,26 @@ +// +// MCOFetchMessageOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPFETCHMESSAGEOPERATION_H_ + +#define __MAILCORE_MCOPOPFETCHMESSAGEOPERATION_H_ + +#import <Foundation/Foundation.h> +#import <mailcore/MCOPOPOperation.h> + +typedef void (^MCOPOPOperationProgressBlock)(unsigned int current, unsigned int maximum); + +@interface MCOPOPFetchMessageOperation : MCOPOPOperation + +@property (nonatomic, copy) MCOPOPOperationProgressBlock progress; + +- (void)start:(void (^)(NSError *error, NSData * messageData))completionBlock; + +@end + +#endif diff --git a/src/objc/pop/MCOPOPFetchMessageOperation.mm b/src/objc/pop/MCOPOPFetchMessageOperation.mm new file mode 100644 index 00000000..d2c1fde7 --- /dev/null +++ b/src/objc/pop/MCOPOPFetchMessageOperation.mm @@ -0,0 +1,99 @@ +// +// MCOFetchMessageOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPFetchMessageOperation.h" + +#import "MCAsyncPOP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +#define nativeType mailcore::POPFetchMessageOperation + +typedef void (^CompletionType)(NSError *error, NSData * messageData); + +@interface MCOPOPFetchMessageOperation () + +- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum; + +@end + +class MCOPOPFetchMessageOperationCallback : public mailcore::POPOperationCallback { +public: + MCOPOPFetchMessageOperationCallback(MCOPOPFetchMessageOperation * op) + { + mOperation = op; + } + + virtual void bodyProgress(mailcore::POPOperation * session, unsigned int current, unsigned int maximum) { + [mOperation bodyProgress:current maximum:maximum]; + } + +private: + MCOPOPFetchMessageOperation * mOperation; +}; + +@implementation MCOPOPFetchMessageOperation { + CompletionType _completionBlock; + MCOPOPFetchMessageOperationCallback * _popCallback; + MCOPOPOperationProgressBlock _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]; + + _popCallback = new MCOPOPFetchMessageOperationCallback(self); + ((mailcore::POPOperation *) op)->setPopCallback(_popCallback); + + return self; +} + +- (void) dealloc +{ + [_progress release]; + [_completionBlock release]; + delete _popCallback; + [super dealloc]; +} + +- (void)start:(void (^)(NSError *error, NSData * messageData))completionBlock { + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void)operationCompleted { + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + _completionBlock(nil, MCO_TO_OBJC(op->data())); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } +} + +- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum +{ + if (_progress != NULL) { + _progress(current, maximum); + } +} + +@end diff --git a/src/objc/pop/MCOPOPFetchMessagesOperation.h b/src/objc/pop/MCOPOPFetchMessagesOperation.h new file mode 100644 index 00000000..d6d33965 --- /dev/null +++ b/src/objc/pop/MCOPOPFetchMessagesOperation.h @@ -0,0 +1,22 @@ +// +// MCOPOPFetchMessagesOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPFETCHMESSAGESOPERATION_H_ + +#define __MAILCORE_MCOPOPFETCHMESSAGESOPERATION_H_ + +#import <Foundation/Foundation.h> +#import <mailcore/MCOPOPOperation.h> + +@interface MCOPOPFetchMessagesOperation : MCOPOPOperation + +- (void)start:(void (^)(NSError *error, NSArray * messages))completionBlock; + +@end + +#endif diff --git a/src/objc/pop/MCOPOPFetchMessagesOperation.mm b/src/objc/pop/MCOPOPFetchMessagesOperation.mm new file mode 100644 index 00000000..61168f80 --- /dev/null +++ b/src/objc/pop/MCOPOPFetchMessagesOperation.mm @@ -0,0 +1,57 @@ +// +// MCOPOPFetchMessagesOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPFetchMessagesOperation.h" + +#include "MCAsyncPOP.h" + +#import "MCOOperation+Private.h" +#import "MCOUtils.h" + +typedef void (^CompletionType)(NSError *error, NSArray * messages); + +@implementation MCOPOPFetchMessagesOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::POPFetchMessagesOperation + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + nativeType * op = (nativeType *) object; + return [[[self alloc] initWithMCOperation:op] autorelease]; +} + +- (void) dealloc +{ + [_completionBlock release]; + [super dealloc]; +} + +- (void)start:(void (^)(NSError *error, NSArray * messages))completionBlock +{ + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void)operationCompleted { + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + _completionBlock(nil, MCO_TO_OBJC(op->messages())); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } +} + + +@end diff --git a/src/objc/pop/MCOPOPMessageInfo.h b/src/objc/pop/MCOPOPMessageInfo.h new file mode 100644 index 00000000..5c6b529f --- /dev/null +++ b/src/objc/pop/MCOPOPMessageInfo.h @@ -0,0 +1,17 @@ +// +// MCOPOPMessageInfo.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/30/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@interface MCOPOPMessageInfo : NSObject <NSCopying> + +@property (nonatomic, assign) unsigned int index; +@property (nonatomic, assign) unsigned int size; +@property (nonatomic, copy) NSString * uid; + +@end diff --git a/src/objc/pop/MCOPOPMessageInfo.mm b/src/objc/pop/MCOPOPMessageInfo.mm new file mode 100644 index 00000000..55a4e1b6 --- /dev/null +++ b/src/objc/pop/MCOPOPMessageInfo.mm @@ -0,0 +1,71 @@ +// +// MCOPOPMessageInfo.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/30/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPMessageInfo.h" + +#include "MCAsyncPOP.h" +#include "MCPOP.h" + +#import "MCOUtils.h" + +@implementation MCOPOPMessageInfo { + mailcore::POPMessageInfo * _nativeInfo; +} + +#define nativeType mailcore::POPMessageInfo + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + +- (id) copyWithZone:(NSZone *)zone +{ + nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy(); + id result = [[self class] mco_objectWithMCObject:nativeObject]; + MC_SAFE_RELEASE(nativeObject); + return [result retain]; +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + mailcore::POPMessageInfo * folder = (mailcore::POPMessageInfo *) object; + return [[[self alloc] initWithMCPOPMessageInfo:folder] autorelease]; +} + +- (mailcore::Object *) mco_mcObject +{ + return _nativeInfo; +} + +- (NSString *) description +{ + return MCO_OBJC_BRIDGE_GET(description); +} + +- (id) initWithMCPOPMessageInfo:(mailcore::POPMessageInfo *)info +{ + self = [super init]; + + _nativeInfo = info; + _nativeInfo->retain(); + + return self; +} + +- (void) dealloc +{ + MC_SAFE_RELEASE(_nativeInfo); + [super dealloc]; +} + +MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setIndex, index) +MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setSize, size) +MCO_OBJC_SYNTHESIZE_STRING(setUid, uid) + +@end diff --git a/src/objc/pop/MCOPOPOperation.h b/src/objc/pop/MCOPOPOperation.h new file mode 100644 index 00000000..774ff4ac --- /dev/null +++ b/src/objc/pop/MCOPOPOperation.h @@ -0,0 +1,20 @@ +// +// MCODeleteMessagesOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPOPERATION_H_ + +#define __MAILCORE_MCOPOPOPERATION_H_ + +#import <Foundation/Foundation.h> +#import <mailcore/MCOOperation.h> + +@interface MCOPOPOperation : MCOOperation +- (void)start:(void (^)(NSError *error))completionBlock; +@end + +#endif diff --git a/src/objc/pop/MCOPOPOperation.mm b/src/objc/pop/MCOPOPOperation.mm new file mode 100644 index 00000000..d224846a --- /dev/null +++ b/src/objc/pop/MCOPOPOperation.mm @@ -0,0 +1,41 @@ +// +// MCODeleteMessagesOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPOperation.h" + +#include "MCAsyncPOP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +typedef void (^CompletionType)(NSError *error); + +@implementation MCOPOPOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::POPOperation + +- (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/pop/MCOPOPSession.h b/src/objc/pop/MCOPOPSession.h new file mode 100644 index 00000000..ae9bf1d9 --- /dev/null +++ b/src/objc/pop/MCOPOPSession.h @@ -0,0 +1,43 @@ +// +// MCOPOPSession.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPSESSION_H_ + +#define __MAILCORE_MCOPOPSESSION_H_ + +#import <Foundation/Foundation.h> + +#import <mailcore/MCOConstants.h> + +@class MCOPOPFetchMessagesOperation; +@class MCOPOPFetchHeaderOperation; +@class MCOPOPFetchMessageOperation; +@class MCOPOPOperation; +@class MCOIndexSet; + +@interface MCOPOPSession : 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; + +- (MCOPOPFetchMessagesOperation *) fetchMessagesOperation; +- (MCOPOPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index; +- (MCOPOPFetchMessageOperation *) fetchMessageOperationWithIndex:(unsigned int)index; + +// Will disconnect. +- (MCOPOPOperation *) deleteMessagesWithIndexes:(MCOIndexSet *)indexes; + +@end + +#endif diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm new file mode 100644 index 00000000..1f468e99 --- /dev/null +++ b/src/objc/pop/MCOPOPSession.mm @@ -0,0 +1,83 @@ +// +// MCOPOPSession.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/29/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPSession.h" + +#include "MCAsyncPOP.h" + +#import "MCOUtils.h" +#import "MCOPOPOperation.h" +#import "MCOOperation+Private.h" +#import "MCOPOPFetchMessagesOperation.h" + +@implementation MCOPOPSession { + mailcore::POPAsyncSession * _session; +} + +#define nativeType mailcore::POPAsyncSession + +- (mailcore::Object *) mco_mcObject +{ + return _session; +} + +- (NSString *) description +{ + return MCO_OBJC_BRIDGE_GET(description); +} + +- (id)init { + self = [super init]; + if (self) { + _session = new mailcore::POPAsyncSession(); + } + 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) + +#pragma mark - Operations + +- (MCOPOPFetchMessagesOperation *) fetchMessagesOperation +{ + mailcore::POPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessagesOperation(); + return MCO_TO_OBJC(coreOp); +} + +- (MCOPOPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index +{ + mailcore::POPFetchHeaderOperation * coreOp = MCO_NATIVE_INSTANCE->fetchHeaderOperation(index); + return MCO_TO_OBJC(coreOp); +} + +- (MCOPOPFetchMessageOperation *) fetchMessageOperationWithIndex:(unsigned int)index; +{ + mailcore::POPFetchMessageOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageOperation(index); + return MCO_TO_OBJC(coreOp); +} + +// Will disconnect. +- (MCOPOPOperation *) deleteMessagesWithIndexes:(MCOIndexSet *)indexes +{ + mailcore::POPOperation * coreOp = MCO_NATIVE_INSTANCE->deleteMessagesOperation(MCO_FROM_OBJC(mailcore::IndexSet, indexes)); + return [[[MCOPOPOperation alloc] initWithMCOperation:coreOp] autorelease]; +} + +@end 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 |