Permalink
Browse files

Fix to CTSMTPAsyncConnection so that it can also use SMTP with SSL on…

… port 465.

Copied the changes made in the commit to CTSMTPConnection 2ac9928 on 20th November 2012 to enable the same feature.
  • Loading branch information...
1 parent 3a5e94a commit 73380c7541a228108d9d9596a1f1c79584bcb2bf @DanGonz DanGonz committed Apr 4, 2013
Showing with 25 additions and 15 deletions.
  1. +5 −5 Source/CTSMTPAsyncConnection.h
  2. +20 −10 Source/CTSMTPAsyncConnection.m
@@ -47,7 +47,7 @@
@class CTSMTP;
-@interface CTSMTPAsyncConnection : NSObject
+@interface CTSMTPAsyncConnection : NSObject
{
CTSMTP* mSMTPObj;
mailsmtp* mSMTP;
@@ -63,11 +63,11 @@
@property (retain) CTCoreMessage* message;
@property (readonly) CTSMTPAsyncStatus status;
-- (id)initWithServer:(NSString *)aServer
+- (id)initWithServer:(NSString *)aServer
username:(NSString *)aUsername
- password:(NSString *)aPassword
- port:(unsigned int)aPort
- useTLS:(BOOL)aTls
+ password:(NSString *)aPassword
+ port:(unsigned int)aPort
+ connectionType:(CTSMTPConnectionType)connectionType
useAuth:(BOOL)aAuth
delegate:(id<CTSMTPConnectionDelegate>)aDelegate;
@@ -73,7 +73,7 @@ - (id)initWithServer:(NSString *)aServer
username:(NSString *)aUsername
password:(NSString *)aPassword
port:(unsigned int)aPort
- useTLS:(BOOL)aTls
+ connectionType:(CTSMTPConnectionType)connectionType
useAuth:(BOOL)aAuth
delegate:(id <CTSMTPConnectionDelegate>)aDelegate {
@@ -90,7 +90,7 @@ - (id)initWithServer:(NSString *)aServer
aUsername, @"username",
aPassword, @"password",
[NSNumber numberWithInt:aPort], @"port",
- [NSNumber numberWithBool:aTls], @"tls",
+ [NSNumber numberWithInt:connectionType], @"connectionType",
[NSNumber numberWithBool:aAuth], @"auth", nil] retain];
//save clients from themselves (they could be leaking us - no dealloc)
@@ -169,9 +169,19 @@ - (void)sendMailThread {
mSMTPObj = [[CTESMTP alloc] initWithResource:mSMTP];
NSDictionary *theSettings = self.serverSettings;
-
- success = [mSMTPObj connectToServer:[theSettings objectForKey:@"server"]
- port:[[theSettings objectForKey:@"port"] unsignedIntValue]];
+ CTSMTPConnectionType connectionType = [[theSettings objectForKey:@"connectionType"] unsignedIntValue];
+ NSString* server = [theSettings objectForKey:@"server"];
+ unsigned int port = [[theSettings objectForKey:@"port"] unsignedIntValue];
+ BOOL auth = [[theSettings objectForKey:@"auth"] boolValue];
+ NSString* username = [theSettings objectForKey:@"username"];
+ NSString* password = [theSettings objectForKey:@"password"];
+
+ if (connectionType == CTSMTPConnectionTypeStartTLS || connectionType == CTSMTPConnectionTypePlain) {
+ success = [mSMTPObj connectToServer:server port:port];
+ } else if (connectionType == CTSMTPConnectionTypeTLS) {
+ success = [mSMTPObj connectWithTlsToServer:server port:port];
+ }
+
if (!success) {
goto error;
}
@@ -184,16 +194,16 @@ - (void)sendMailThread {
goto error;
}
}
- if ([(NSNumber *) [theSettings objectForKey:@"tls"] boolValue]) {
+
+ if (connectionType == CTSMTPConnectionTypeStartTLS) {
success = [mSMTPObj startTLS];
if (!success) {
goto error;
}
}
- if ([(NSNumber *) [theSettings objectForKey:@"auth"] boolValue]) {
- success = [mSMTPObj authenticateWithUsername:[theSettings objectForKey:@"username"]
- password:[theSettings objectForKey:@"password"]
- server:[theSettings objectForKey:@"server"]];
+
+ if (auth) {
+ success = [mSMTPObj authenticateWithUsername:username password:password server:server];
if (!success) {
goto error;
}

0 comments on commit 73380c7

Please sign in to comment.