diff options
author | 2013-08-24 18:46:54 -0700 | |
---|---|---|
committer | 2013-08-24 18:46:54 -0700 | |
commit | b7febcf978c5faf6d70a132b88394d074df9c790 (patch) | |
tree | ed9cd7885ab0b42d6272bb7bf65e9bbb68cdefcd /src/objc | |
parent | 88c28fa7b259a27648f7306afeebe2497ddb1507 (diff) |
Fixed #277: automatic ID. Cleaner API for identity API and also allows to specify custom fields.
Diffstat (limited to 'src/objc')
-rwxr-xr-x | src/objc/imap/MCOIMAP.h | 1 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPIdentity.h | 42 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPIdentity.mm | 96 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.h | 19 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.mm | 19 |
5 files changed, 163 insertions, 14 deletions
diff --git a/src/objc/imap/MCOIMAP.h b/src/objc/imap/MCOIMAP.h index e2036291..538c3492 100755 --- a/src/objc/imap/MCOIMAP.h +++ b/src/objc/imap/MCOIMAP.h @@ -19,6 +19,7 @@ #import <MailCore/MCOIMAPMultipart.h> #import <MailCore/MCOIMAPNamespace.h> #import <MailCore/MCOIMAPNamespaceItem.h> +#import <MailCore/MCOIMAPIdentity.h> #import <MailCore/MCOIMAPPart.h> #import <MailCore/MCOIMAPFolderInfoOperation.h> #import <MailCore/MCOIMAPFolderInfo.h> diff --git a/src/objc/imap/MCOIMAPIdentity.h b/src/objc/imap/MCOIMAPIdentity.h new file mode 100644 index 00000000..32ce8b5c --- /dev/null +++ b/src/objc/imap/MCOIMAPIdentity.h @@ -0,0 +1,42 @@ +// +// MCOIMAPIdentity.h +// mailcore2 +// +// Created by Hoa V. DINH on 8/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOIMAPIDENTITY_H_ + +#define __MAILCORE_MCOIMAPIDENTITY_H_ + +#import <Foundation/Foundation.h> + +@interface MCOIMAPIdentity : NSObject <NSCopying> + +/** Returns a simple identity */ ++ (MCOIMAPIdentity *) identityWithVendor:(NSString *)vendor + name:(NSString *)name + version:(NSString *)version; + +/** Vendor of the IMAP client */ +@property (nonatomic, copy) NSString * vendor; + +/** Name of the IMAP client */ +@property (nonatomic, copy) NSString * name; + +/** Version of the IMAP client */ +@property (nonatomic, copy) NSString * version; + +/** All fields names of the identity of the client */ +- (NSArray *) allInfoKeys; + +/** Set a custom field in the identity */ +- (NSString *) infoForKey:(NSString *)key; + +/** Retrieve a custom field in the identity */ +- (void) setInfo:(NSString *)value forKey:(NSString *)key; + +@end + +#endif diff --git a/src/objc/imap/MCOIMAPIdentity.mm b/src/objc/imap/MCOIMAPIdentity.mm new file mode 100644 index 00000000..0beb092b --- /dev/null +++ b/src/objc/imap/MCOIMAPIdentity.mm @@ -0,0 +1,96 @@ +// +// MCOIMAPIdentity.m +// mailcore2 +// +// Created by Hoa V. DINH on 8/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOIMAPIdentity.h" +#import "NSObject+MCO.h" +#import "NSString+MCO.h" + +#include "MCIMAPIdentity.h" + +#define nativeType mailcore::IMAPIdentity + +@implementation MCOIMAPIdentity { + mailcore::IMAPIdentity * _nativeIdentity; +} + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + +- (id) initWithMCIdentity:(mailcore::IMAPIdentity *)identity +{ + self = [super init]; + + identity->retain(); + _nativeIdentity = identity; + + return self; +} + +- (void) dealloc +{ + MC_SAFE_RELEASE(_nativeIdentity); + [super dealloc]; +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + mailcore::IMAPIdentity * identity = (mailcore::IMAPIdentity *) object; + return [[[self alloc] initWithMCIdentity:identity] autorelease]; +} + +- (mailcore::Object *) mco_mcObject +{ + return _nativeIdentity; +} + +- (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]; +} + +- (NSString *) description +{ + return MCO_OBJC_BRIDGE_GET(description); +} + +MCO_OBJC_SYNTHESIZE_STRING(setVendor, vendor) +MCO_OBJC_SYNTHESIZE_STRING(setName, name) +MCO_OBJC_SYNTHESIZE_STRING(setVersion, version) + +- (NSArray *) allInfoKeys +{ + return MCO_OBJC_BRIDGE_GET(allInfoKeys); +} + +- (NSString *) infoForKey:(NSString *)key +{ + return MCO_TO_OBJC(MCO_NATIVE_INSTANCE->infoForKey([key mco_mcString])); +} + +- (void) setInfo:(NSString *)value forKey:(NSString *)key +{ + MCO_NATIVE_INSTANCE->setInfoForKey([key mco_mcString], [value mco_mcString]); +} + ++ (MCOIMAPIdentity *) identityWithVendor:(NSString *)vendor + name:(NSString *)name + version:(NSString *)version +{ + MCOIMAPIdentity * identity = [[[MCOIMAPIdentity alloc] init] autorelease]; + [identity setVendor:vendor]; + [identity setName:name]; + [identity setVersion:version]; + return identity; +} + +@end diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index e92a0636..66b76276 100755 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -32,6 +32,7 @@ @class MCOIMAPQuotaOperation; @class MCOIMAPMessageRenderingOperation; @class MCOIMAPMessage; +@class MCOIMAPIdentity; /** This is the main IMAP class from which all operations are created @@ -82,6 +83,12 @@ /** The default namespace. */ @property (nonatomic, strong) MCOIMAPNamespace * defaultNamespace; +/** The identity of the IMAP client. */ +@property (nonatomic, strong, readonly) MCOIMAPIdentity * clientIdentity; + +/** The identity of the IMAP server. */ +@property (nonatomic, strong, readonly) MCOIMAPIdentity * serverIdentity; + /** When set to YES, the session is allowed open to open several connections to the same folder. @warning Some older IMAP servers don't like this @@ -469,17 +476,13 @@ /** Returns an operation to send the client or get the server identity. - MCOIMAPIdentityOperation * op = [session identityOperationWithVendor:@"Mozilla" - name:@"Thunderbird" - version:@"17.0.5"]; - [op start:^(NSError * error, NSDictionary * serverIdentity) { + MCOIMAPIdentity * identity = [MCOIMAPIdentity identityWithVendor:@"Mozilla" name:@"Thunderbird" version:@"17.0.5"]; + MCOIMAPIdentityOperation * op = [session identityOperationWithClientIdentity:identity]; + [op start:^(NSError * error, MCOIMAPIdentity * serverIdentity) { ... }]; */ -- (MCOIMAPIdentityOperation *) identityOperationWithVendor:(NSString *)vendor - name:(NSString *)name - version:(NSString *)version; - +- (MCOIMAPIdentityOperation *) identityOperationWithClientIdentity:(MCOIMAPIdentity *)identity; /** Returns an operation that will check whether the IMAP account is valid. diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index b3584f4d..ce814435 100755 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -15,6 +15,7 @@ #import "MCOIMAPFetchFoldersOperation.h" #import "MCOIMAPBaseOperation+Private.h" #import "MCOIMAPMessageRenderingOperation.h" +#import "MCOIMAPIdentity.h" #import "MCOUtils.h" @@ -99,6 +100,16 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma return MCO_TO_OBJC(_session->defaultNamespace()); } +- (MCOIMAPIdentity *) clientIdentity +{ + return MCO_OBJC_BRIDGE_GET(clientIdentity); +} + +- (MCOIMAPIdentity *) serverIdentity +{ + return MCO_OBJC_BRIDGE_GET(serverIdentity); +} + - (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger { [_connectionLogger release]; @@ -339,13 +350,9 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma return MCO_TO_OBJC_OP(coreOp); } -- (MCOIMAPIdentityOperation *) identityOperationWithVendor:(NSString *)vendor - name:(NSString *)name - version:(NSString *)version +- (MCOIMAPIdentityOperation *) identityOperationWithClientIdentity:(MCOIMAPIdentity *)identity { - IMAPIdentityOperation * coreOp = MCO_NATIVE_INSTANCE->identityOperation([vendor mco_mcString], - [name mco_mcString], - [version mco_mcString]); + IMAPIdentityOperation * coreOp = MCO_NATIVE_INSTANCE->identityOperation(MCO_FROM_OBJC(IMAPIdentity, identity)); return MCO_TO_OBJC_OP(coreOp); } |