blob: 0c6161c430598338d0218f9d4cfd6d18025ed00b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
//
// MCOIMAPCheckAccountOperation.m
// mailcore2
//
// Created by Hoa V. DINH on 3/7/16.
// Copyright © 2016 MailCore. All rights reserved.
//
#import "MCOIMAPCheckAccountOperation.h"
#include "MCIMAPCheckAccountOperation.h"
#import "MCOOperation+Private.h"
#import "MCOUtils.h"
#import "MCOConstants.h"
typedef void (^CompletionType)(NSError *error);
@implementation MCOIMAPCheckAccountOperation {
CompletionType _completionBlock;
}
#define nativeType mailcore::IMAPCheckAccountOperation
+ (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))completionBlock
{
_completionBlock = [completionBlock copy];
[self start];
}
- (void) cancel
{
[_completionBlock release];
_completionBlock = nil;
[super cancel];
}
- (void) operationCompleted
{
if (_completionBlock == NULL)
return;
nativeType *op = MCO_NATIVE_INSTANCE;
if (op->error() == mailcore::ErrorNone) {
_completionBlock(nil);
} else {
NSError * error = [NSError mco_errorWithErrorCode:op->error()];
if (op->loginResponse() != NULL) {
NSMutableDictionary * userInfo = [[error userInfo] mutableCopy];
userInfo[MCOIMAPResponseKey] = MCO_TO_OBJC(op->loginResponse());
error = [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
[userInfo release];
}
_completionBlock(error);
}
[_completionBlock release];
_completionBlock = nil;
}
@end
|