From 1e5482c0745a77b158ac07e1cc602f9ab2cc0caa Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Sat, 30 Mar 2013 19:42:26 -0700 Subject: Implemented ObjC API for SMTP and POP --- src/objc/pop/MCOPOPFetchHeaderOperation.mm | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/objc/pop/MCOPOPFetchHeaderOperation.mm (limited to 'src/objc/pop/MCOPOPFetchHeaderOperation.mm') 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 -- cgit v1.2.3