aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/provider/MCONetService.mm
blob: eb2ad6f5ed4cd43019781b15799523f80529135a (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
78
79
80
81
82
83
84
85
86
87
88
89
90
//
//  MCONetService.m
//  mailcore2
//
//  Created by Robert Widmann on 4/28/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#import "MCONetService.h"
#include "MCNetService.h"

#import "NSDictionary+MCO.h"
#import "NSString+MCO.h"

@implementation MCONetService {
	mailcore::NetService * _netService;
}

- (mailcore::Object *) mco_mcObject
{
    return _netService;
}

+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
    mailcore::NetService * netService = (mailcore::NetService *) object;
    return [[self alloc] initWithNetService:netService];
}

+ (MCONetService *) netServiceWithInfo:(NSDictionary *)info
{
	return [[[MCONetService alloc] initWithInfo:info] autorelease];
}

- (id) initWithInfo:(NSDictionary *)info
{
	self = [super init];
	
	_netService = new mailcore::NetService(info.mco_mcHashMap);
	
	return self;
}

- (id) initWithNetService:(mailcore::NetService *)netService
{
	self = [super init];
	
	_netService = netService;
	
	return self;
}

- (void) setHostname:(NSString *)hostname {
	_netService->setHostname(hostname.mco_mcString);
}

- (NSString *) hostname {
	return [NSString mco_stringWithMCString:_netService->hostname()];
}

- (void) setPort:(unsigned int)port {
	_netService->setPort(port);
}

- (unsigned int) port {
	return _netService->port();
}

- (MCONetServiceConnectionType) connectionType {
	return (MCONetServiceConnectionType) _netService->connectionType();
}

- (NSDictionary *) info
{
	return [NSDictionary mco_dictionaryWithMCHashMap:_netService->info()];
}

- (NSString*)hostnameWithEmail:(NSString*)email
{
	NSString *result = nil;
	NSArray *components = [email componentsSeparatedByString:@"@"];
	if (components.count == 0) {
		return self.hostname;
	} else {
		result = [self.hostname stringByReplacingOccurrencesOfString:@"{domain}" withString:[components lastObject]];
	}
	return [NSString mco_stringWithMCString:_netService->normalizedHostnameWithEmail(email.mco_mcString)];
}

@end