aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar DINH Viet Hoa <dinh.viet.hoa@gmail.com>2013-03-23 16:27:20 -0700
committerGravatar DINH Viet Hoa <dinh.viet.hoa@gmail.com>2013-03-23 16:27:20 -0700
commitd9444ef87c866e3535562a693236b55d88379886 (patch)
treeabfef08ad60df8e84fa46549be7bdd10bb713c9a
parent77d8decc5071234189dc803d715015f0a93c7652 (diff)
Make IMAP ObjC bridge implementation consistent
-rw-r--r--build-mac/mailcore2.xcodeproj/project.pbxproj18
-rw-r--r--src/async/imap/MCIMAPAsyncSession.h14
-rw-r--r--src/objc/abstract/MCOAbstractMessage.h2
-rw-r--r--src/objc/abstract/MCOAbstractMessagePart.h4
-rw-r--r--src/objc/abstract/MCOAbstractPart.h2
-rw-r--r--src/objc/abstract/MCOAddress.mm16
-rw-r--r--src/objc/abstract/MCOMessageHeader.h4
-rw-r--r--src/objc/abstract/MCOMessageHeader.mm16
-rw-r--r--src/objc/imap/MCOIMAP.h2
-rw-r--r--src/objc/imap/MCOIMAPCheckAccountOperation.h19
-rw-r--r--src/objc/imap/MCOIMAPCheckAccountOperation.mm36
-rw-r--r--src/objc/imap/MCOIMAPFetchFoldersOperation.mm35
-rw-r--r--src/objc/imap/MCOIMAPOperation.h15
-rw-r--r--src/objc/imap/MCOIMAPOperation.mm49
-rw-r--r--src/objc/imap/MCOIMAPSession.h7
-rw-r--r--src/objc/imap/MCOIMAPSession.mm122
-rw-r--r--src/objc/rfc822/MCOAttachment.h2
-rw-r--r--src/objc/rfc822/MCOAttachment.mm8
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.mm8
-rw-r--r--src/objc/rfc822/MCOMessageParser.h2
-rw-r--r--src/objc/rfc822/MCOMessageParser.mm10
-rw-r--r--src/objc/rfc822/MCOMessagePart.mm8
-rw-r--r--src/objc/rfc822/MCOMultipart.mm8
-rw-r--r--src/objc/utils/MCOOperation+Private.h1
-rw-r--r--src/objc/utils/MCOOperation.mm26
-rw-r--r--src/objc/utils/NSObject+MCO.mm3
-rw-r--r--tests/main.mm4
27 files changed, 217 insertions, 224 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj
index 557af90d..e91d1d90 100644
--- a/build-mac/mailcore2.xcodeproj/project.pbxproj
+++ b/build-mac/mailcore2.xcodeproj/project.pbxproj
@@ -7,16 +7,16 @@
objects = {
/* Begin PBXBuildFile section */
- C07AD27FF065FA4408F65F19 /* MCOIMAPCheckAccountOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C07AD98150338A79BF83CCEF /* MCOIMAPCheckAccountOperation.h */; };
C07AD5D7FD82F8ACAB576231 /* NSError+MCO.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C07AD44B013BB42A240B4F04 /* NSError+MCO.h */; };
C07AD99B2E2054C684DB8FF6 /* NSError+MCO.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07ADFE43E22B38EFF23ADB5 /* NSError+MCO.mm */; };
- C07ADA0FE807DC9D166BBF37 /* MCOIMAPCheckAccountOperation.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07AD721E48D521D6E3F4943 /* MCOIMAPCheckAccountOperation.mm */; };
C07ADC28B83E7959BF114D46 /* MCOIMAPSession.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07AD057D3C8FBDC7AC95733 /* MCOIMAPSession.mm */; };
C623C58616FD6A50001BBEFC /* MCOConstants.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64BB26D16FD63F6000DB34C /* MCOConstants.h */; };
C623C58716FD6A61001BBEFC /* MCOOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64BB25716FD3BC2000DB34C /* MCOOperation.h */; };
C623C58816FD6DF6001BBEFC /* NSValue+MCO.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64BB25016FC2846000DB34C /* NSValue+MCO.h */; };
C623C58916FD8B71001BBEFC /* MCOUtils.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64BB26C16FD62FB000DB34C /* MCOUtils.h */; };
C623C58C16FE54C9001BBEFC /* MCOHTMLRendererDelegate.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C623C58B16FE52C0001BBEFC /* MCOHTMLRendererDelegate.h */; };
+ C623C58F16FE6B45001BBEFC /* MCOIMAPOperation.mm in Sources */ = {isa = PBXBuildFile; fileRef = C623C58E16FE6B45001BBEFC /* MCOIMAPOperation.mm */; };
+ C623C59016FE71B2001BBEFC /* MCOIMAPOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C623C58D16FE6B45001BBEFC /* MCOIMAPOperation.h */; };
C62C6ED416A2A0E600737497 /* MCIMAPIdentityOperation.cc in Sources */ = {isa = PBXBuildFile; fileRef = C62C6ED216A2A0E600737497 /* MCIMAPIdentityOperation.cc */; };
C62C6ED816A398FA00737497 /* MCIMAPFolderInfoOperation.cc in Sources */ = {isa = PBXBuildFile; fileRef = C62C6ED616A398FA00737497 /* MCIMAPFolderInfoOperation.cc */; };
C62C6EDA16A3D60700737497 /* MCIMAPAsyncConnection.cc in Sources */ = {isa = PBXBuildFile; fileRef = C64EA7FD16A295B500778456 /* MCIMAPAsyncConnection.cc */; };
@@ -245,10 +245,10 @@
C63CD68C16BE1BC800DB18F1 /* MCHTMLRendererCallback.h in CopyFiles */,
C623C58616FD6A50001BBEFC /* MCOConstants.h in CopyFiles */,
C623C58716FD6A61001BBEFC /* MCOOperation.h in CopyFiles */,
- C07AD27FF065FA4408F65F19 /* MCOIMAPCheckAccountOperation.h in CopyFiles */,
C64BB24816EEFCBC000DB34C /* MCOAbstractMessage.mm in CopyFiles */,
C63CD68E16BE324100DB18F1 /* MCOIMAPFetchFoldersOperation.h in CopyFiles */,
C623C58C16FE54C9001BBEFC /* MCOHTMLRendererDelegate.h in CopyFiles */,
+ C623C59016FE71B2001BBEFC /* MCOIMAPOperation.h in CopyFiles */,
C623C58916FD8B71001BBEFC /* MCOUtils.h in CopyFiles */,
C64EA74F169E859600778456 /* MCAbstractMessage.h in CopyFiles */,
C623C58816FD6DF6001BBEFC /* NSValue+MCO.h in CopyFiles */,
@@ -370,11 +370,11 @@
/* Begin PBXFileReference section */
C07AD057D3C8FBDC7AC95733 /* MCOIMAPSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPSession.mm; sourceTree = "<group>"; };
C07AD44B013BB42A240B4F04 /* NSError+MCO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+MCO.h"; sourceTree = "<group>"; };
- C07AD721E48D521D6E3F4943 /* MCOIMAPCheckAccountOperation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPCheckAccountOperation.mm; sourceTree = "<group>"; };
- C07AD98150338A79BF83CCEF /* MCOIMAPCheckAccountOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOIMAPCheckAccountOperation.h; sourceTree = "<group>"; };
C07ADFE43E22B38EFF23ADB5 /* NSError+MCO.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSError+MCO.mm"; sourceTree = "<group>"; };
C623C58A16FD8C22001BBEFC /* MCOAbstractMessage+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MCOAbstractMessage+Private.h"; sourceTree = "<group>"; };
C623C58B16FE52C0001BBEFC /* MCOHTMLRendererDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCOHTMLRendererDelegate.h; sourceTree = "<group>"; };
+ C623C58D16FE6B45001BBEFC /* MCOIMAPOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOIMAPOperation.h; sourceTree = "<group>"; };
+ C623C58E16FE6B45001BBEFC /* MCOIMAPOperation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPOperation.mm; sourceTree = "<group>"; };
C62C6ED216A2A0E600737497 /* MCIMAPIdentityOperation.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCIMAPIdentityOperation.cc; sourceTree = "<group>"; };
C62C6ED316A2A0E600737497 /* MCIMAPIdentityOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCIMAPIdentityOperation.h; sourceTree = "<group>"; };
C62C6ED616A398FA00737497 /* MCIMAPFolderInfoOperation.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCIMAPFolderInfoOperation.cc; sourceTree = "<group>"; };
@@ -1015,8 +1015,8 @@
children = (
C64FF38F16B3C13000F8C162 /* MCOObjectWrapper.h */,
C64FF39016B3C13000F8C162 /* MCOObjectWrapper.mm */,
- C64BB25916FD3BC8000DB34C /* MCOOperation+Private.h */,
C64BB25716FD3BC2000DB34C /* MCOOperation.h */,
+ C64BB25916FD3BC8000DB34C /* MCOOperation+Private.h */,
C64BB25816FD3BC5000DB34C /* MCOOperation.mm */,
C64BB26C16FD62FB000DB34C /* MCOUtils.h */,
C6EB30FD16B8E50F0091F4F1 /* NSArray+MCO.h */,
@@ -1043,10 +1043,10 @@
C64BB25416FD32A0000DB34C /* MCOIMAP.h */,
F8EA941416BAED6E0011AC6F /* MCOIMAPSession.h */,
C07AD057D3C8FBDC7AC95733 /* MCOIMAPSession.mm */,
- C07AD98150338A79BF83CCEF /* MCOIMAPCheckAccountOperation.h */,
- C07AD721E48D521D6E3F4943 /* MCOIMAPCheckAccountOperation.mm */,
F87F190816BB62690012652F /* MCOIMAPFetchFoldersOperation.h */,
F87F190B16BB62B00012652F /* MCOIMAPFetchFoldersOperation.mm */,
+ C623C58D16FE6B45001BBEFC /* MCOIMAPOperation.h */,
+ C623C58E16FE6B45001BBEFC /* MCOIMAPOperation.mm */,
);
path = imap;
sourceTree = "<group>";
@@ -1211,7 +1211,6 @@
C6D42C1E16AE03D6002BB4F9 /* NSString+MCO.mm in Sources */,
C64FF39116B3C13000F8C162 /* MCOObjectWrapper.mm in Sources */,
C07ADC28B83E7959BF114D46 /* MCOIMAPSession.mm in Sources */,
- C07ADA0FE807DC9D166BBF37 /* MCOIMAPCheckAccountOperation.mm in Sources */,
C07AD99B2E2054C684DB8FF6 /* NSError+MCO.mm in Sources */,
F87F190C16BB62B00012652F /* MCOIMAPFetchFoldersOperation.mm in Sources */,
C6EB30F716B8C9480091F4F1 /* NSDictionary+MCO.mm in Sources */,
@@ -1239,6 +1238,7 @@
C64BB26416FD43A1000DB34C /* MCOMessageParser.mm in Sources */,
C64BB26716FD43E2000DB34C /* MCOMessagePart.mm in Sources */,
C64BB26A16FD44C2000DB34C /* MCOMultipart.mm in Sources */,
+ C623C58F16FE6B45001BBEFC /* MCOIMAPOperation.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h
index 1722b2b1..5f9c5330 100644
--- a/src/async/imap/MCIMAPAsyncSession.h
+++ b/src/async/imap/MCIMAPAsyncSession.h
@@ -94,20 +94,6 @@ namespace mailcore {
virtual IMAPOperation * expungeOperation(String * folder);
-#if 0
- virtual IMAPFetchMessagesOperation * fetchMessagesByUIDOperation(String * folder, IMAPMessagesRequestKind requestKind,
- uint32_t firstUID, uint32_t lastUID);
- virtual IMAPFetchMessagesOperation * fetchMessagesByNumberOperation(String * folder, IMAPMessagesRequestKind requestKind,
- uint32_t firstNumber, uint32_t lastNumber);
- virtual IMAPFetchMessagesOperation * fetchMessagesByUIDOperation(String * folder, IMAPMessagesRequestKind requestKind,
- Array * numbers);
- virtual IMAPFetchMessagesOperation * fetchMessagesByNumberOperation(String * folder, IMAPMessagesRequestKind requestKind,
- Array * numbers);
- virtual IMAPFetchMessagesOperation * syncMessagesByUIDForModSeqOperation(String * folder, IMAPMessagesRequestKind requestKind,
- uint32_t firstUID, uint32_t lastUID, uint64_t modSeq);
- virtual IMAPFetchMessagesOperation * syncMessagesByUIDForModSeqOperation(String * folder, IMAPMessagesRequestKind requestKind,
- Array * uids, uint64_t modSeq);
-#endif
virtual IMAPFetchMessagesOperation * fetchMessagesByUIDOperation(String * folder, IMAPMessagesRequestKind requestKind,
IndexSet * indexes);
virtual IMAPFetchMessagesOperation * fetchMessagesByNumberOperation(String * folder, IMAPMessagesRequestKind requestKind,
diff --git a/src/objc/abstract/MCOAbstractMessage.h b/src/objc/abstract/MCOAbstractMessage.h
index c5a2f27f..e506e31e 100644
--- a/src/objc/abstract/MCOAbstractMessage.h
+++ b/src/objc/abstract/MCOAbstractMessage.h
@@ -17,7 +17,7 @@
@interface MCOAbstractMessage : NSObject
-@property (nonatomic, retain) MCOMessageHeader * header;
+@property (nonatomic, strong) MCOMessageHeader * header;
- (MCOAbstractPart *) partForContentID:(NSString *)contentID;
- (MCOAbstractPart *) partForUniqueID:(NSString *)uniqueID;
diff --git a/src/objc/abstract/MCOAbstractMessagePart.h b/src/objc/abstract/MCOAbstractMessagePart.h
index 8675fc17..75cda3cd 100644
--- a/src/objc/abstract/MCOAbstractMessagePart.h
+++ b/src/objc/abstract/MCOAbstractMessagePart.h
@@ -17,8 +17,8 @@
@interface MCOAbstractMessagePart : MCOAbstractPart
-@property (nonatomic, retain) MCOMessageHeader * header;
-@property (nonatomic, retain) MCOAbstractPart * mainPart;
+@property (nonatomic, strong) MCOMessageHeader * header;
+@property (nonatomic, strong) MCOAbstractPart * mainPart;
@end
diff --git a/src/objc/abstract/MCOAbstractPart.h b/src/objc/abstract/MCOAbstractPart.h
index b46f6724..bc1f3b7e 100644
--- a/src/objc/abstract/MCOAbstractPart.h
+++ b/src/objc/abstract/MCOAbstractPart.h
@@ -32,7 +32,7 @@ typedef enum {
@property (nonatomic, copy) NSString * contentID;
@property (nonatomic, copy) NSString * contentLocation;
@property (nonatomic, assign, getter=isInlineAttachment) BOOL inlineAttachment;
-@property (nonatomic, assign) MCOAbstractMessage * message;
+@property (nonatomic, weak) MCOAbstractMessage * message;
- (MCOAbstractPart *) partForContentID:(NSString *)contentID;
- (MCOAbstractPart *) partForUniqueID:(NSString *)uniqueID;
diff --git a/src/objc/abstract/MCOAddress.mm b/src/objc/abstract/MCOAddress.mm
index 6afb0134..da682582 100644
--- a/src/objc/abstract/MCOAddress.mm
+++ b/src/objc/abstract/MCOAddress.mm
@@ -26,6 +26,14 @@
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::Address * address = (mailcore::Address *) object;
@@ -107,14 +115,6 @@
[super dealloc];
}
-- (id) copyWithZone:(NSZone *)zone
-{
- mailcore::Address * address = (mailcore::Address *) _nativeAddress->copy();
- MCOAddress * result = [[MCOAddress alloc] initWithMCAddress:address];
- MC_SAFE_RELEASE(address);
- return result;
-}
-
- (NSString *) description
{
return MCO_OBJC_BRIDGE_GET(description);
diff --git a/src/objc/abstract/MCOMessageHeader.h b/src/objc/abstract/MCOMessageHeader.h
index 09ed130e..350c1379 100644
--- a/src/objc/abstract/MCOMessageHeader.h
+++ b/src/objc/abstract/MCOMessageHeader.h
@@ -19,8 +19,8 @@
@property (nonatomic, copy) NSString * messageID;
@property (nonatomic, copy) NSArray * references;
@property (nonatomic, copy) NSArray * inReplyTo;
-@property (nonatomic, retain) NSDate * date;
-@property (nonatomic, retain) NSDate * receivedDate;
+@property (nonatomic, strong) NSDate * date;
+@property (nonatomic, strong) NSDate * receivedDate;
@property (nonatomic, copy) MCOAddress * sender;
@property (nonatomic, copy) MCOAddress * from;
@property (nonatomic, copy) NSArray * to;
diff --git a/src/objc/abstract/MCOMessageHeader.mm b/src/objc/abstract/MCOMessageHeader.mm
index 649819e9..5b5844d0 100644
--- a/src/objc/abstract/MCOMessageHeader.mm
+++ b/src/objc/abstract/MCOMessageHeader.mm
@@ -31,6 +31,14 @@
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];
+}
+
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::MessageHeader * header = (mailcore::MessageHeader *) object;
@@ -69,14 +77,6 @@
return [[[self alloc] initWithMCMessageHeader:header] autorelease];
}
-- (id) copyWithZone:(NSZone *)zone
-{
- mailcore::MessageHeader * header = (mailcore::MessageHeader *) _nativeHeader->copy();
- MCOMessageHeader * result = [[MCOMessageHeader alloc] initWithMCMessageHeader:header];
- MC_SAFE_RELEASE(header);
- return result;
-}
-
- (NSString *) description
{
return MCO_OBJC_BRIDGE_GET(description);
diff --git a/src/objc/imap/MCOIMAP.h b/src/objc/imap/MCOIMAP.h
index f8dcb30d..3fae405b 100644
--- a/src/objc/imap/MCOIMAP.h
+++ b/src/objc/imap/MCOIMAP.h
@@ -11,7 +11,7 @@
#define __MAILCORE_MCOIMAP_H_
#import <mailcore/MCOIMAPSession.h>
-#import <mailcore/MCOIMAPCheckAccountOperation.h>
+#import <mailcore/MCOIMAPOperation.h>
#import <mailcore/MCOIMAPFetchFoldersOperation.h>
#endif
diff --git a/src/objc/imap/MCOIMAPCheckAccountOperation.h b/src/objc/imap/MCOIMAPCheckAccountOperation.h
deleted file mode 100644
index 3a14a1fe..00000000
--- a/src/objc/imap/MCOIMAPCheckAccountOperation.h
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// MCOIMAPCheckAccountOperation.h
-// mailcore2
-//
-// Created by Matt Ronge on 01/31/13.
-// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
-//
-
-#ifndef __MAILCORE_MCOIMAPCHECKACCOUNTOPERATION_H_
-
-#define __MAILCORE_MCOIMAPCHECKACCOUNTOPERATION_H_
-
-#import <mailcore/MCOOperation.h>
-
-@interface MCOIMAPCheckAccountOperation : MCOOperation
-- (void)start:(void (^)(NSError *error))completionBlock;
-@end
-
-#endif
diff --git a/src/objc/imap/MCOIMAPCheckAccountOperation.mm b/src/objc/imap/MCOIMAPCheckAccountOperation.mm
deleted file mode 100644
index 3eb0aeb1..00000000
--- a/src/objc/imap/MCOIMAPCheckAccountOperation.mm
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// MCOIMAPCheckAccountOperation.m
-// mailcore2
-//
-// Created by Matt Ronge on 01/31/13.
-// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
-//
-
-#import "MCOIMAPCheckAccountOperation.h"
-
-#import "MCAsync.h"
-
-#import "MCOOperation+Private.h"
-#import "MCOIMAPCheckAccountOperation.h"
-#import "NSError+MCO.h"
-
-using namespace mailcore;
-
-@interface MCOIMAPCheckAccountOperation ()
-@property (nonatomic, copy) void (^completionBlock)(NSError *error);
-@end
-
-@implementation MCOIMAPCheckAccountOperation
-
-- (void)start:(void (^)(NSError *error))completionBlock {
- self.completionBlock = completionBlock;
- [self start];
-}
-
-- (void)operationCompleted {
- IMAPOperation *op = (IMAPOperation *) [self mcOperation];
- NSError *error = [NSError mco_errorWithErrorCode:op->error()];
- self.completionBlock(error);
-}
-
-@end
diff --git a/src/objc/imap/MCOIMAPFetchFoldersOperation.mm b/src/objc/imap/MCOIMAPFetchFoldersOperation.mm
index 09d5d38e..d0af62b2 100644
--- a/src/objc/imap/MCOIMAPFetchFoldersOperation.mm
+++ b/src/objc/imap/MCOIMAPFetchFoldersOperation.mm
@@ -7,10 +7,12 @@
//
#import "MCOIMAPFetchFoldersOperation.h"
+
#import "NSError+MCO.h"
-#import "NSString+MCO.h"
#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
#import <Foundation/Foundation.h>
#import <mailcore/MCAsync.h>
@@ -20,7 +22,24 @@ using namespace mailcore;
@property (nonatomic, copy) void (^completionBlock)(NSError *error, NSArray *folder);
@end
-@implementation MCOIMAPFetchFoldersOperation
+@implementation MCOIMAPFetchFoldersOperation {
+ void (^_completionBlock)(NSError *error, NSArray *folder);
+}
+
+@synthesize completionBlock = _completionBlock;
+
+#define nativeType mailcore::IMAPFetchFoldersOperation
+
++ (void) initialize
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ mailcore::IMAPOperation * op = (mailcore::IMAPOperation *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
- (void)start:(void (^)(NSError *error, NSArray *folder))completionBlock {
self.completionBlock = completionBlock;
@@ -28,18 +47,12 @@ using namespace mailcore;
}
- (void)operationCompleted {
- IMAPFetchFoldersOperation *op = (IMAPFetchFoldersOperation *) [self mcOperation];
+ IMAPFetchFoldersOperation *op = MCO_NATIVE_INSTANCE;
if (op->error() == ErrorNone) {
- NSMutableArray *nsfolders = [NSMutableArray array];
- Array *folders = op->folders();
- for (int i = 0 ; i < folders->count(); i++) {
- NSString *folder = [NSString mco_stringWithMCObject:folders->objectAtIndex(i)];
- [nsfolders addObject:folder];
- }
-
- self.completionBlock(nil, nsfolders);
+ self.completionBlock(nil, MCO_TO_OBJC(op->folders()));
} else {
self.completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
}
}
+
@end
diff --git a/src/objc/imap/MCOIMAPOperation.h b/src/objc/imap/MCOIMAPOperation.h
new file mode 100644
index 00000000..baf8cdec
--- /dev/null
+++ b/src/objc/imap/MCOIMAPOperation.h
@@ -0,0 +1,15 @@
+//
+// MCOIMAPOperation.h
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 3/23/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#import "MCOOperation.h"
+
+@interface MCOIMAPOperation : MCOOperation
+
+- (void)start:(void (^)(NSError *error))completionBlock;
+
+@end
diff --git a/src/objc/imap/MCOIMAPOperation.mm b/src/objc/imap/MCOIMAPOperation.mm
new file mode 100644
index 00000000..c2b36e26
--- /dev/null
+++ b/src/objc/imap/MCOIMAPOperation.mm
@@ -0,0 +1,49 @@
+//
+// MCOIMAPOperation.m
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 3/23/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPOperation.h"
+
+#include "MCIMAPOperation.h"
+#import "MCOOperation+Private.h"
+
+#import "MCOUtils.h"
+
+@interface MCOIMAPOperation ()
+@property (nonatomic, copy) void (^completionBlock)(NSError *error);
+@end
+
+@implementation MCOIMAPOperation {
+ void (^_completionBlock)(NSError *error);
+}
+
+@synthesize completionBlock = _completionBlock;
+
+#define nativeType mailcore::IMAPOperation
+
++ (void) initialize
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ mailcore::IMAPOperation * op = (mailcore::IMAPOperation *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+- (void)start:(void (^)(NSError *error))completionBlock {
+ self.completionBlock = completionBlock;
+ [self start];
+}
+
+- (void)operationCompleted {
+ NSError * error = [NSError mco_errorWithErrorCode:MCO_NATIVE_INSTANCE->error()];
+ self.completionBlock(error);
+}
+
+@end
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index 2e0ab3d2..7019b792 100644
--- a/src/objc/imap/MCOIMAPSession.h
+++ b/src/objc/imap/MCOIMAPSession.h
@@ -12,10 +12,9 @@
#import <Foundation/Foundation.h>
#import <mailcore/MCOConstants.h>
-#import <mailcore/MCOOperation.h>
-@class MCOIMAPCheckAccountOperation;
@class MCOIMAPFetchFoldersOperation;
+@class MCOIMAPOperation;
@interface MCOIMAPSession : NSObject
@property (nonatomic, strong) NSString *hostname;
@@ -28,9 +27,9 @@
@property (nonatomic, assign) NSTimeInterval timeout;
@property (nonatomic, assign) BOOL checkCertificateEnabled;
@property (nonatomic, assign, getter=isVoIPEnabled) BOOL VoIPEnabled;
-@property (nonatomic, strong) NSString *delimiter;
+@property (nonatomic, assign) char delimiter;
-- (MCOIMAPCheckAccountOperation *)checkAccountOperation;
+- (MCOIMAPOperation *)checkAccountOperation;
- (MCOIMAPFetchFoldersOperation *)fetchAllFoldersOperation;
@end
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index 1bf23063..a4a6e5cc 100644
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -7,12 +7,13 @@
//
#import "MCOIMAPSession.h"
-#import "MCOOperation+Private.h"
+
+#import "MCOOperation.h"
#import "MCOObjectWrapper.h"
-#import "MCOIMAPCheckAccountOperation.h"
+#import "MCOIMAPOperation.h"
#import "MCOIMAPFetchFoldersOperation.h"
-#import "NSString+MCO.h"
+#import "MCOUtils.h"
#import <mailcore/MCAsync.h>
@@ -23,6 +24,13 @@ using namespace mailcore;
IMAPAsyncSession * _session;
}
+#define nativeType mailcore::IMAPAsyncSession
+
+- (mailcore::Object *) mco_mcObject
+{
+ return _session;
+}
+
- (id)init {
self = [super init];
if (self) {
@@ -36,106 +44,28 @@ using namespace mailcore;
[super dealloc];
}
-- (IMAPAsyncSession *)session {
- return _session;
-}
-
-- (NSString *)hostname {
- return [NSString mco_stringWithMCString:self.session->hostname()];
-}
-
-- (void)setHostname:(NSString *)hostname {
- self.session->setHostname([hostname mco_mcString]);
-}
-
-- (unsigned int)port {
- return self.session->port();
-}
-
-- (void)setPort:(unsigned int)port {
- self.session->setPort(port);
-}
-
-- (NSString *)username {
- return [NSString mco_stringWithMCString:self.session->username()];
-}
-
-- (void)setUsername:(NSString *)username {
- self.session->setUsername([username mco_mcString]);
-}
-
-- (NSString *)password {
- return [NSString mco_stringWithMCString:self.session->password()];
-}
-
-- (void)setPassword:(NSString *)password {
- self.session->setPassword([password mco_mcString]);
-}
-
-- (void)setAuthType:(MCOAuthType)authType {
- self.session->setAuthType((AuthType)authType);
-}
-
-- (MCOAuthType)authType {
- return (MCOAuthType)self.session->authType();
-}
-
-- (void)setConnectionType:(MCOConnectionType)connectionType {
- self.session->setConnectionType((ConnectionType)connectionType);
-}
-
-- (MCOConnectionType)connectionType{
- return (MCOConnectionType)self.session->connectionType();
-}
-
-- (void)setTimeout:(NSTimeInterval)timeout {
- self.session->setTimeout((time_t)timeout);
-}
-
-- (NSTimeInterval)timeout {
- return (NSTimeInterval)self.session->timeout();
-}
-
-- (void)setCheckCertificateEnabled:(BOOL)checkCertificateEnabled {
- self.session->setCheckCertificateEnabled(checkCertificateEnabled);
-}
-
-- (BOOL)checkCertificateEnabled {
- return (BOOL)self.session->isCheckCertificateEnabled();
-}
-
-- (void)setVoIPEnabled:(BOOL)VoIPEnabled {
- self.session->setVoIPEnabled(VoIPEnabled);
-}
-
-- (BOOL)isVoIPEnabled {
- return (BOOL)self.session->isVoIPEnabled();
-}
-
-- (NSString *)delimiter {
- char delim = self.session->delimiter();
- return [NSString stringWithFormat:@"%c", delim];
-}
-
-- (void)setDelimiter:(NSString *)delimiter {
- NSAssert(delimiter.length == 1, @"Delimiter has to be a single char");
- char delim = [delimiter characterAtIndex:0];
- self.session->setDelimiter(delim);
-}
+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(setVoIPEnabled, isVoIPEnabled)
+MCO_OBJC_SYNTHESIZE_SCALAR(char, char, setDelimiter, delimiter)
#pragma mark - Operations
-- (MCOIMAPCheckAccountOperation *)checkAccountOperation {
- IMAPOperation *coreOp = self.session->checkAccountOperation();
- MCOIMAPCheckAccountOperation *op = [[MCOIMAPCheckAccountOperation alloc] initWithMCOperation:coreOp];
- return [op autorelease];
+- (MCOIMAPOperation *)checkAccountOperation {
+ IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation();
+ return MCO_TO_OBJC(coreOp);
}
- (MCOIMAPFetchFoldersOperation *)fetchAllFoldersOperation {
- IMAPOperation *coreOp = self.session->fetchAllFoldersOperation();
- MCOIMAPFetchFoldersOperation *op = [[MCOIMAPFetchFoldersOperation alloc] initWithMCOperation:coreOp];
- return [op autorelease];
+ IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->fetchAllFoldersOperation();
+ return MCO_TO_OBJC(coreOp);
}
@end
diff --git a/src/objc/rfc822/MCOAttachment.h b/src/objc/rfc822/MCOAttachment.h
index fec04cc0..bb908501 100644
--- a/src/objc/rfc822/MCOAttachment.h
+++ b/src/objc/rfc822/MCOAttachment.h
@@ -20,7 +20,7 @@
+ (MCOAttachment *) attachmentWithRFC822Message:(NSData *)messageData;
+ (MCOAttachment *) attachmentWithText:(NSString *)text;
-@property (nonatomic, retain) NSData * data;
+@property (nonatomic, strong) NSData * data;
@end
diff --git a/src/objc/rfc822/MCOAttachment.mm b/src/objc/rfc822/MCOAttachment.mm
index d9906a10..d507ff50 100644
--- a/src/objc/rfc822/MCOAttachment.mm
+++ b/src/objc/rfc822/MCOAttachment.mm
@@ -26,6 +26,14 @@
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::Attachment * attachment = (mailcore::Attachment *) object;
diff --git a/src/objc/rfc822/MCOMessageBuilder.mm b/src/objc/rfc822/MCOMessageBuilder.mm
index d929e98a..b25bd3c4 100644
--- a/src/objc/rfc822/MCOMessageBuilder.mm
+++ b/src/objc/rfc822/MCOMessageBuilder.mm
@@ -22,6 +22,14 @@
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];
+}
+
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::MessageBuilder * msg = (mailcore::MessageBuilder *) object;
diff --git a/src/objc/rfc822/MCOMessageParser.h b/src/objc/rfc822/MCOMessageParser.h
index fd1f5304..1bd2c14e 100644
--- a/src/objc/rfc822/MCOMessageParser.h
+++ b/src/objc/rfc822/MCOMessageParser.h
@@ -16,7 +16,7 @@
@interface MCOMessageParser : MCOAbstractMessage
-@property (nonatomic, assign) id <MCOHTMLRendererDelegate> rendererDelegate;
+@property (nonatomic, weak) id <MCOHTMLRendererDelegate> rendererDelegate;
+ (MCOMessageParser *) messageParserWithData:(NSData *)data;
diff --git a/src/objc/rfc822/MCOMessageParser.mm b/src/objc/rfc822/MCOMessageParser.mm
index 5ff3db13..c3951d1d 100644
--- a/src/objc/rfc822/MCOMessageParser.mm
+++ b/src/objc/rfc822/MCOMessageParser.mm
@@ -142,6 +142,14 @@ private:
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];
+}
+
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::MessageParser * msg = (mailcore::MessageParser *) object;
@@ -158,7 +166,7 @@ private:
mailcore::MessageParser * message = new mailcore::MessageParser([data mco_mcData]);
self = [super initWithMCMessage:message];
_htmlRenderCallback = new MCOMessageParserRenderedCallback(self);
- message->release();
+ MC_SAFE_RELEASE(message);
return self;
}
diff --git a/src/objc/rfc822/MCOMessagePart.mm b/src/objc/rfc822/MCOMessagePart.mm
index 65e091dd..bb6c02cc 100644
--- a/src/objc/rfc822/MCOMessagePart.mm
+++ b/src/objc/rfc822/MCOMessagePart.mm
@@ -22,6 +22,14 @@
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];
+}
+
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::MessagePart * part = (mailcore::MessagePart *) object;
diff --git a/src/objc/rfc822/MCOMultipart.mm b/src/objc/rfc822/MCOMultipart.mm
index a0266503..f81e0c8a 100644
--- a/src/objc/rfc822/MCOMultipart.mm
+++ b/src/objc/rfc822/MCOMultipart.mm
@@ -22,6 +22,14 @@
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];
+}
+
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::Attachment * attachment = (mailcore::Attachment *) object;
diff --git a/src/objc/utils/MCOOperation+Private.h b/src/objc/utils/MCOOperation+Private.h
index ccd1b983..785abd91 100644
--- a/src/objc/utils/MCOOperation+Private.h
+++ b/src/objc/utils/MCOOperation+Private.h
@@ -21,7 +21,6 @@ namespace mailcore {
@interface MCOOperation (Private)
#ifdef __cplusplus
- (id)initWithMCOperation:(mailcore::Operation *)op;
-- (mailcore::Operation *)mcOperation;
#endif
- (void)start;
@end
diff --git a/src/objc/utils/MCOOperation.mm b/src/objc/utils/MCOOperation.mm
index b267dfc7..bc14ad36 100644
--- a/src/objc/utils/MCOOperation.mm
+++ b/src/objc/utils/MCOOperation.mm
@@ -12,6 +12,7 @@
#import "MCOperation.h"
#import "MCOperationCallback.h"
#import "MCOObjectWrapper.h"
+#import "MCOUtils.h"
#import <Foundation/Foundation.h>
@@ -42,6 +43,24 @@ public:
BOOL _started;
}
+#define nativeType mailcore::Operation
+
++ (void) initialize
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ mailcore::Operation * op = (mailcore::Operation *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+- (mailcore::Object *) mco_mcObject
+{
+ return _operation;
+}
+
- (id)initWithMCOperation:(Operation *)op
{
self = [super init];
@@ -64,7 +83,7 @@ public:
- (BOOL)isCancelled
{
- return _operation->isCancelled();
+ return MCO_NATIVE_INSTANCE->isCancelled();
}
- (void)cancel
@@ -83,11 +102,6 @@ public:
_operation->start();
}
-- (mailcore::Operation *)mcOperation
-{
- return _operation;
-}
-
- (void)_operationCompleted
{
_started = NO;
diff --git a/src/objc/utils/NSObject+MCO.mm b/src/objc/utils/NSObject+MCO.mm
index 0e0411d0..8ea1843e 100644
--- a/src/objc/utils/NSObject+MCO.mm
+++ b/src/objc/utils/NSObject+MCO.mm
@@ -58,6 +58,9 @@ static Class classWithTypeInfo(const std::type_info * info)
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
+ if (object == NULL)
+ return nil;
+
if (&typeid(object) == &typeid(mailcore::Value *)) {
return [NSValue mco_valueWithMCValue:(mailcore::Value *) object];
}
diff --git a/tests/main.mm b/tests/main.mm
index 7d2f3241..c82fca2e 100644
--- a/tests/main.mm
+++ b/tests/main.mm
@@ -282,7 +282,7 @@ void testObjC()
session.connectionType = MCOConnectionTypeTLS;
NSLog(@"check account");
- MCOCheckAccountOperation *checkOp = [session checkAccountOperation];
+ MCOIMAPOperation *checkOp = [session checkAccountOperation];
[checkOp start:^(NSError *err) {
NSLog(@"check account done");
if (err) {
@@ -290,7 +290,7 @@ void testObjC()
} else {
NSLog(@"CONNECTED");
NSLog(@"fetch all folders");
- MCOFetchFoldersOperation *foldersOp = [session fetchAllFoldersOperation];
+ MCOIMAPFetchFoldersOperation *foldersOp = [session fetchAllFoldersOperation];
[foldersOp start:^(NSError *err, NSArray *folders) {
NSLog(@"fetch all folders done");
if (err) {