aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/smtp
diff options
context:
space:
mode:
authorGravatar robario <webmaster@robario.com>2014-10-29 17:32:09 +0900
committerGravatar robario <webmaster@robario.com>2014-10-29 18:12:59 +0900
commitaeb15860575a764dd444108098dcb95c73d4d6df (patch)
tree222c675c1fbdf04d44c535d7bc6208c5869eb2c5 /src/objc/smtp
parent2f6f1ca69d59e2692f85d56941e7d996195cd6e8 (diff)
Add a new operation for SMTP login.
Diffstat (limited to 'src/objc/smtp')
-rw-r--r--src/objc/smtp/MCOSMTP.h1
-rw-r--r--src/objc/smtp/MCOSMTPLoginOperation.h32
-rw-r--r--src/objc/smtp/MCOSMTPLoginOperation.mm66
-rw-r--r--src/objc/smtp/MCOSMTPSession.h10
-rw-r--r--src/objc/smtp/MCOSMTPSession.mm9
5 files changed, 118 insertions, 0 deletions
diff --git a/src/objc/smtp/MCOSMTP.h b/src/objc/smtp/MCOSMTP.h
index 49d01de3..7434a855 100644
--- a/src/objc/smtp/MCOSMTP.h
+++ b/src/objc/smtp/MCOSMTP.h
@@ -11,6 +11,7 @@
#define MAILCORE_MCOSMTP_H
#import <MailCore/MCOSMTPSession.h>
+#import <MailCore/MCOSMTPLoginOperation.h>
#import <MailCore/MCOSMTPSendOperation.h>
#import <MailCore/MCOSMTPOperation.h>
diff --git a/src/objc/smtp/MCOSMTPLoginOperation.h b/src/objc/smtp/MCOSMTPLoginOperation.h
new file mode 100644
index 00000000..7eee9986
--- /dev/null
+++ b/src/objc/smtp/MCOSMTPLoginOperation.h
@@ -0,0 +1,32 @@
+//
+// MCOSMTPLoginOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 9/24/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCOSMTPLOGINOPERATION_H
+
+#define MAILCORE_MCOSMTPLOGINOPERATION_H
+
+#import <MailCore/MCOSMTPOperation.h>
+
+/** This is an asynchronous operation that will perform a noop operation through SMTP. */
+@interface MCOSMTPLoginOperation : MCOSMTPOperation
+
+/*
+ Starts the asynchronous operation.
+
+ @param completionBlock Called when the operation is finished.
+
+ - On success `error` will be nil
+
+ - On failure, `error` will be set with `MCOErrorDomain` as domain and an
+ error code available in MCOConstants.h,
+ */
+- (void) start:(void (^)(NSError * error))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/smtp/MCOSMTPLoginOperation.mm b/src/objc/smtp/MCOSMTPLoginOperation.mm
new file mode 100644
index 00000000..ece721ee
--- /dev/null
+++ b/src/objc/smtp/MCOSMTPLoginOperation.mm
@@ -0,0 +1,66 @@
+//
+// MCOSMTPLoginOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 9/24/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#import "MCOSMTPLoginOperation.h"
+
+#include "MCSMTPLoginOperation.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+
+typedef void (^CompletionType)(NSError *error);
+
+@implementation MCOSMTPLoginOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::SMTPLoginOperation
+
++ (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;
+
+ NSError * error = [NSError mco_errorWithErrorCode:MCO_NATIVE_INSTANCE->error()];
+ _completionBlock(error);
+ [_completionBlock release];
+ _completionBlock = NULL;
+}
+
+
+@end
diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h
index 286cd7c3..d462dbfb 100644
--- a/src/objc/smtp/MCOSMTPSession.h
+++ b/src/objc/smtp/MCOSMTPSession.h
@@ -89,6 +89,16 @@
/** @name Operations */
/**
+ Returns an operation that will perform a login.
+
+ MCOPOPOperation * op = [session loginOperation];
+ [op start:^(NSError * error) {
+ ...
+ }];
+ */
+- (MCOSMTPOperation *) loginOperation;
+
+/**
Returns an operation that will send the given message through SMTP.
It will use the recipient set in the message data (To, Cc and Bcc).
It will also filter out Bcc from the content of the message.
diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm
index e0eb2a7d..6b40c709 100644
--- a/src/objc/smtp/MCOSMTPSession.mm
+++ b/src/objc/smtp/MCOSMTPSession.mm
@@ -11,6 +11,7 @@
#include "MCAsyncSMTP.h"
#import "MCOUtils.h"
+#import "MCOSMTPLoginOperation.h"
#import "MCOSMTPSendOperation.h"
#import "MCOSMTPNoopOperation.h"
#import "MCOSMTPOperation.h"
@@ -104,6 +105,14 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
#pragma mark - Operations
+- (MCOSMTPOperation *) loginOperation
+{
+ mailcore::SMTPOperation * coreOp = MCO_NATIVE_INSTANCE->loginOperation();
+ MCOSMTPLoginOperation * result = [[[MCOSMTPLoginOperation alloc] initWithMCOperation:coreOp] autorelease];
+ [result setSession:self];
+ return result;
+}
+
- (MCOSMTPSendOperation *) sendOperationWithData:(NSData *)messageData
{
mailcore::SMTPOperation * coreOp = MCO_NATIVE_INSTANCE->sendMessageOperation([messageData mco_mcData]);