aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc
diff options
context:
space:
mode:
authorGravatar Daryle Walker <dwalker07@yahoo.com>2016-02-22 18:47:45 -0500
committerGravatar Daryle Walker <dwalker07@yahoo.com>2016-02-22 18:47:45 -0500
commit79f2bebdb77914c44e8d92ebf0fe373971844e14 (patch)
tree51619ce4ded93aabbed152e2e13a482336878366 /src/objc
parentcb5963c42d0cb69df12ea9e2b19cb61298b2831d (diff)
Add upload functionality to NNTP sessions.
Add new methods to core, async, and objc NNTP sessions to upload message data. For the async and objc sessions, add classes to wrap upload operations.
Diffstat (limited to 'src/objc')
-rw-r--r--src/objc/nntp/MCONNTP.h1
-rw-r--r--src/objc/nntp/MCONNTPSendOperation.h41
-rw-r--r--src/objc/nntp/MCONNTPSendOperation.mm116
-rw-r--r--src/objc/nntp/MCONNTPSession.h27
-rw-r--r--src/objc/nntp/MCONNTPSession.mm12
5 files changed, 197 insertions, 0 deletions
diff --git a/src/objc/nntp/MCONNTP.h b/src/objc/nntp/MCONNTP.h
index 71979dfa..213384c4 100644
--- a/src/objc/nntp/MCONNTP.h
+++ b/src/objc/nntp/MCONNTP.h
@@ -18,6 +18,7 @@
#include <MailCore/MCONNTPListNewsgroupsOperation.h>
#include <MailCore/MCONNTPFetchOverviewOperation.h>
#include <MailCore/MCONNTPFetchServerTimeOperation.h>
+#include <MailCore/MCONNTPSendOperation.h>
#include <MailCore/MCONNTPGroupInfo.h>
#endif
diff --git a/src/objc/nntp/MCONNTPSendOperation.h b/src/objc/nntp/MCONNTPSendOperation.h
new file mode 100644
index 00000000..b59c6e80
--- /dev/null
+++ b/src/objc/nntp/MCONNTPSendOperation.h
@@ -0,0 +1,41 @@
+//
+// MCONNTPSendOperation.h
+// mailcore2
+//
+// Created by Daryle Walker on 2/21/16.
+// Copyright © 2016 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPSENDOPERATION_H
+
+#define MAILCORE_MCONNTPSENDOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+/** Send a message from NNTP3 */
+
+typedef void (^MCONNTPOperationProgressBlock)(unsigned int current, unsigned int maximum);
+
+NS_ASSUME_NONNULL_BEGIN
+@interface MCONNTPSendOperation : MCONNTPOperation
+
+/** This block will be called as data is downloaded from the network */
+@property (nonatomic, copy) MCONNTPOperationProgressBlock progress;
+
+/**
+ Starts the asynchronous send 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 * __nullable error))completionBlock;
+
+@end
+NS_ASSUME_NONNULL_END
+
+#endif
diff --git a/src/objc/nntp/MCONNTPSendOperation.mm b/src/objc/nntp/MCONNTPSendOperation.mm
new file mode 100644
index 00000000..db1277af
--- /dev/null
+++ b/src/objc/nntp/MCONNTPSendOperation.mm
@@ -0,0 +1,116 @@
+//
+// MCONNTPSendOperation.mm
+// mailcore2
+//
+// Created by Daryle Walker on 2/21/16.
+// Copyright © 2016 MailCore. All rights reserved.
+//
+
+#import "MCONNTPSendOperation.h"
+
+#import "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+
+#define nativeType mailcore::NNTPSendOperation
+
+typedef void (^CompletionType)(NSError *error);
+
+@interface MCONNTPSendOperation ()
+
+- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum;
+
+@end
+
+class MCONNTPSendOperationCallback : public mailcore::NNTPOperationCallback {
+public:
+ MCONNTPSendOperationCallback(MCONNTPSendOperation * op)
+ {
+ mOperation = op;
+ }
+ virtual ~MCONNTPSendOperationCallback()
+ {
+ }
+
+ virtual void bodyProgress(mailcore::NNTPOperation * session, unsigned int current, unsigned int maximum) {
+ [mOperation bodyProgress:current maximum:maximum];
+ }
+
+private:
+ MCONNTPSendOperation * mOperation;
+};
+
+@implementation MCONNTPSendOperation {
+ CompletionType _completionBlock;
+ MCONNTPSendOperationCallback * _popCallback;
+ MCONNTPOperationProgressBlock _progress;
+}
+
+@synthesize progress = _progress;
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ nativeType * op = (nativeType *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+- (instancetype) initWithMCOperation:(mailcore::Operation *)op
+{
+ self = [super initWithMCOperation:op];
+
+ _popCallback = new MCONNTPSendOperationCallback(self);
+ ((mailcore::NNTPOperation *) op)->setNNTPCallback(_popCallback);
+
+ return self;
+}
+
+- (void) dealloc
+{
+ [_progress release];
+ [_completionBlock release];
+ delete _popCallback;
+ [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;
+
+ nativeType *op = MCO_NATIVE_INSTANCE;
+ if (op->error() == mailcore::ErrorNone) {
+ _completionBlock(nil);
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()]);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum
+{
+ if (_progress != NULL) {
+ _progress(current, maximum);
+ }
+}
+
+@end
diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h
index 29fe18af..84b1c5e7 100644
--- a/src/objc/nntp/MCONNTPSession.h
+++ b/src/objc/nntp/MCONNTPSession.h
@@ -20,6 +20,7 @@
@class MCONNTPListNewsgroupsOperation;
@class MCONNTPFetchOverviewOperation;
@class MCONNTPFetchServerTimeOperation;
+@class MCONNTPSendOperation;
@class MCONNTPOperation;
@class MCOIndexSet;
@@ -182,6 +183,32 @@ NS_ASSUME_NONNULL_BEGIN
- (MCONNTPListNewsgroupsOperation *) listDefaultNewsgroupsOperation;
/**
+ Returns an operation that will send the given message through NNTP.
+ It will use the newsgroups set in the message data.
+ It will also filter out Bcc from the content of the message.
+
+ Generate RFC 822 data using MCOMessageBuilder
+
+ MCONNTPOperation * op = [session sendOperationWithData:rfc822Data];
+ [op start:^(NSError * __nullable error) {
+ ...
+ }];
+ */
+- (MCONNTPSendOperation *) sendOperationWithData:(NSData *)messageData;
+
+/**
+ Returns an operation that will send the message from the given file through NNTP.
+ It will use the newsgroups set in the message data.
+ It will also filter out Bcc from the content of the message.
+
+ MCONNTPOperation * op = [session sendOperationWithContentsOfFile:rfc822DataFilename];
+ [op start:^(NSError * __nullable error) {
+ ...
+ }];
+ */
+- (MCONNTPSendOperation *) sendOperationWithContentsOfFile:(NSString *)path;
+
+/**
Returns an operation that will disconnect the session.
MCONNTPOperation * op = [session disconnectOperation];
diff --git a/src/objc/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm
index 8237145c..4a6e0c9a 100644
--- a/src/objc/nntp/MCONNTPSession.mm
+++ b/src/objc/nntp/MCONNTPSession.mm
@@ -14,6 +14,7 @@
#import "MCONNTPOperation.h"
#import "MCOOperation+Private.h"
#import "MCONNTPFetchAllArticlesOperation.h"
+#import "MCONNTPSendOperation.h"
#import "MCONNTPOperation+Private.h"
#include "MCOperationQueueCallback.h"
@@ -205,6 +206,17 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return MCO_TO_OBJC_OP(coreOp);
}
+- (MCONNTPSendOperation *) sendOperationWithData:(NSData *)messageData {
+ mailcore::NNTPSendOperation * coreOp = MCO_NATIVE_INSTANCE->sendMessageOperation(MCO_FROM_OBJC(mailcore::Data, messageData));
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPSendOperation *) sendOperationWithContentsOfFile:(NSString *)path
+{
+ mailcore::NNTPSendOperation * coreOp = MCO_NATIVE_INSTANCE->sendMessageOperation(MCO_FROM_OBJC(mailcore::String, path));
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
- (MCONNTPOperation *) disconnectOperation
{
mailcore::NNTPOperation * coreOp = MCO_NATIVE_INSTANCE->disconnectOperation();