aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/nntp
diff options
context:
space:
mode:
authorGravatar CodaFi <devteam.codafi@gmail.com>2014-08-13 14:53:51 -0600
committerGravatar CodaFi <devteam.codafi@gmail.com>2014-08-13 14:53:51 -0600
commit38d848cb9c8d64e910804b7b6d559a9a31d2ad99 (patch)
treed249b20e796b5927842b2712086ab9c3bc438a47 /src/objc/nntp
parent988fe081b340e5c1040a6d78db793107972c7bfb (diff)
NNTP support
Diffstat (limited to 'src/objc/nntp')
-rw-r--r--src/objc/nntp/MCONNTP.h23
-rw-r--r--src/objc/nntp/MCONNTPDisconnectOperation.h21
-rw-r--r--src/objc/nntp/MCONNTPDisconnectOperation.mm31
-rw-r--r--src/objc/nntp/MCONNTPFetchHeaderOperation.h39
-rw-r--r--src/objc/nntp/MCONNTPFetchHeaderOperation.mm69
-rw-r--r--src/objc/nntp/MCONNTPFetchMessageOperation.h39
-rw-r--r--src/objc/nntp/MCONNTPFetchMessageOperation.mm116
-rw-r--r--src/objc/nntp/MCONNTPFetchMessagesOperation.h34
-rw-r--r--src/objc/nntp/MCONNTPFetchMessagesOperation.mm70
-rw-r--r--src/objc/nntp/MCONNTPGroupInfo.h27
-rw-r--r--src/objc/nntp/MCONNTPGroupInfo.mm70
-rw-r--r--src/objc/nntp/MCONNTPListNewsgroupsOperation.h32
-rw-r--r--src/objc/nntp/MCONNTPListNewsgroupsOperation.mm69
-rw-r--r--src/objc/nntp/MCONNTPMessageInfo.h31
-rw-r--r--src/objc/nntp/MCONNTPMessageInfo.mm71
-rw-r--r--src/objc/nntp/MCONNTPOperation+Private.h20
-rw-r--r--src/objc/nntp/MCONNTPOperation.h37
-rw-r--r--src/objc/nntp/MCONNTPOperation.mm59
-rw-r--r--src/objc/nntp/MCONNTPSession.h141
-rw-r--r--src/objc/nntp/MCONNTPSession.mm169
20 files changed, 1168 insertions, 0 deletions
diff --git a/src/objc/nntp/MCONNTP.h b/src/objc/nntp/MCONNTP.h
new file mode 100644
index 00000000..d81e8f26
--- /dev/null
+++ b/src/objc/nntp/MCONNTP.h
@@ -0,0 +1,23 @@
+//
+// MCONNTP.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTP_H
+
+#define MAILCORE_MCONNTP_H
+
+#include <MailCore/MCONNTPAsyncSession.h>
+#include <MailCore/MCONNTPOperation.h>
+#include <MailCore/MCONNTPFetchHeaderOperation.h>
+#include <MailCore/MCONNTPFetchMessageOperation.h>
+#include <MailCore/MCONNTPFetchMessagesOperation.h>
+#include <MailCore/MCONNTPListNewsgroupsOperation.h>
+#include <MailCore/MCONNTPMessageInfo.h>
+#include <MailCore/MCONNTPGroupInfo.h>
+#include <MailCore/MCONNTPOperationCallback.h>
+
+#endif
diff --git a/src/objc/nntp/MCONNTPDisconnectOperation.h b/src/objc/nntp/MCONNTPDisconnectOperation.h
new file mode 100644
index 00000000..7d8986bb
--- /dev/null
+++ b/src/objc/nntp/MCONNTPDisconnectOperation.h
@@ -0,0 +1,21 @@
+//
+// MCONNTPDisconnectOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPDICONNECTOPERATION_H
+
+#define MAILCORE_MCONNTPDICONNECTOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+/* The class is used to perform a disconnect operation. */
+@interface MCONNTPDisconnectOperation : NSObject
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPDisconnectOperation.mm b/src/objc/nntp/MCONNTPDisconnectOperation.mm
new file mode 100644
index 00000000..2c8290e3
--- /dev/null
+++ b/src/objc/nntp/MCONNTPDisconnectOperation.mm
@@ -0,0 +1,31 @@
+//
+// MCONNTPDisconnectOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPDisconnectOperation.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+#include "MCNNTPDisconnectOperation.h"
+
+@implementation MCONNTPDisconnectOperation
+
+#define nativeType mailcore::NNTPDisconnectOperation
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ nativeType * op = (nativeType *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+@end
diff --git a/src/objc/nntp/MCONNTPFetchHeaderOperation.h b/src/objc/nntp/MCONNTPFetchHeaderOperation.h
new file mode 100644
index 00000000..63ce7677
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchHeaderOperation.h
@@ -0,0 +1,39 @@
+//
+// MCONNTPFetchHeaderOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPFETCHHEADEROPERATION_H
+
+#define MAILCORE_MCONNTPFETCHHEADEROPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+/**
+ This is an asynchronous operation that will fetch the header of a message.
+ @See MCONNTPSession
+ */
+
+@class MCOMessageHeader;
+
+@interface MCONNTPFetchHeaderOperation : MCONNTPOperation
+
+/**
+ Starts the asynchronous fetch operation.
+
+ @param completionBlock Called when the operation is finished.
+
+ - On success `error` will be nil and `header` will contain the message header
+
+ - On failure, `error` will be set with `MCOErrorDomain` as domain and an
+ error code available in MCOConstants.h, `header` will be null
+ */
+- (void) start:(void (^)(NSError * error, MCOMessageHeader * header))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPFetchHeaderOperation.mm b/src/objc/nntp/MCONNTPFetchHeaderOperation.mm
new file mode 100644
index 00000000..c74f6b26
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchHeaderOperation.mm
@@ -0,0 +1,69 @@
+//
+// MCONNTPFetchHeaderOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPFetchHeaderOperation.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+
+typedef void (^CompletionType)(NSError *error, MCOMessageHeader * header);
+
+@implementation MCONNTPFetchHeaderOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::NNTPFetchHeaderOperation
+
++ (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, MCOMessageHeader * header))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, MCO_TO_OBJC(op->header()));
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end
diff --git a/src/objc/nntp/MCONNTPFetchMessageOperation.h b/src/objc/nntp/MCONNTPFetchMessageOperation.h
new file mode 100644
index 00000000..c0cfbf68
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchMessageOperation.h
@@ -0,0 +1,39 @@
+//
+// MCONNTPFetchMessageOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPFETCHMESSAGEOPERATION_H
+
+#define MAILCORE_MCONNTPFETCHMESSAGEOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+/** Fetch a message from NNTP3 */
+
+typedef void (^MCONNTPOperationProgressBlock)(unsigned int current, unsigned int maximum);
+
+@interface MCONNTPFetchMessageOperation : MCONNTPOperation
+
+/** This block will be called as data is downloaded from the network */
+@property (nonatomic, copy) MCONNTPOperationProgressBlock progress;
+
+/**
+ Starts the asynchronous fetch operation.
+
+ @param completionBlock Called when the operation is finished.
+
+ - On success `error` will be nil and `data` will contain the message data
+
+ - On failure, `error` will be set with `MCOErrorDomain` as domain and an
+ error code available in MCOConstants.h, `data` will be nil
+ */
+- (void) start:(void (^)(NSError * error, NSData * messageData))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPFetchMessageOperation.mm b/src/objc/nntp/MCONNTPFetchMessageOperation.mm
new file mode 100644
index 00000000..6de52de3
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchMessageOperation.mm
@@ -0,0 +1,116 @@
+//
+// MCONNTPFetchMessageOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPFetchMessageOperation.h"
+
+#import "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+
+#define nativeType mailcore::NNTPFetchMessageOperation
+
+typedef void (^CompletionType)(NSError *error, NSData * messageData);
+
+@interface MCONNTPFetchMessageOperation ()
+
+- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum;
+
+@end
+
+class MCONNTPFetchMessageOperationCallback : public mailcore::NNTPOperationCallback {
+public:
+ MCONNTPFetchMessageOperationCallback(MCONNTPFetchMessageOperation * op)
+ {
+ mOperation = op;
+ }
+ virtual ~MCONNTPFetchMessageOperationCallback()
+ {
+ }
+
+ virtual void bodyProgress(mailcore::NNTPOperation * session, unsigned int current, unsigned int maximum) {
+ [mOperation bodyProgress:current maximum:maximum];
+ }
+
+private:
+ MCONNTPFetchMessageOperation * mOperation;
+};
+
+@implementation MCONNTPFetchMessageOperation {
+ CompletionType _completionBlock;
+ MCONNTPFetchMessageOperationCallback * _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];
+}
+
+- (id)initWithMCOperation:(mailcore::Operation *)op
+{
+ self = [super initWithMCOperation:op];
+
+ _popCallback = new MCONNTPFetchMessageOperationCallback(self);
+ ((mailcore::NNTPOperation *) op)->setNNTPCallback(_popCallback);
+
+ return self;
+}
+
+- (void) dealloc
+{
+ [_progress release];
+ [_completionBlock release];
+ delete _popCallback;
+ [super dealloc];
+}
+
+- (void) start:(void (^)(NSError *error, NSData * messageData))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, MCO_TO_OBJC(op->data()));
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+ [_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/MCONNTPFetchMessagesOperation.h b/src/objc/nntp/MCONNTPFetchMessagesOperation.h
new file mode 100644
index 00000000..57159ad0
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchMessagesOperation.h
@@ -0,0 +1,34 @@
+//
+// MCONNTPFetchMessagesOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPFETCHMESSAGESOPERATION_H
+
+#define MAILCORE_MCONNTPFETCHMESSAGESOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+/** This is an asynchronous operation that will fetch the list of a messages on the NNTP3 account. */
+
+@interface MCONNTPFetchMessagesOperation : MCONNTPOperation
+
+/**
+ Starts the asynchronous fetch operation.
+
+ @param completionBlock Called when the operation is finished.
+
+ - On success `error` will be nil and `messages` will be an array of MCONNTPMessageInfo
+
+ - On failure, `error` will be set with `MCOErrorDomain` as domain and an
+ error code available in MCOConstants.h, `messages` will be null
+ */
+- (void) start:(void (^)(NSError * error, NSArray * /* MCONNTPMessageInfo */ messages))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPFetchMessagesOperation.mm b/src/objc/nntp/MCONNTPFetchMessagesOperation.mm
new file mode 100644
index 00000000..338af1fa
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchMessagesOperation.mm
@@ -0,0 +1,70 @@
+//
+// MCONNTPFetchMessagesOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPFetchMessagesOperation.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSError *error, NSArray * messages);
+
+@implementation MCONNTPFetchMessagesOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::NNTPFetchMessagesOperation
+
++ (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, NSArray * messages))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, MCO_TO_OBJC(op->messages()));
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+
+@end
diff --git a/src/objc/nntp/MCONNTPGroupInfo.h b/src/objc/nntp/MCONNTPGroupInfo.h
new file mode 100644
index 00000000..e34445a9
--- /dev/null
+++ b/src/objc/nntp/MCONNTPGroupInfo.h
@@ -0,0 +1,27 @@
+//
+// MCONNTPGroupInfo.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPGROUPINFO_H
+
+#define MAILCORE_MCONNTPGROUPINFO_H
+
+#import <Foundation/Foundation.h>
+
+/** This is information of a message fetched by MCONNTPListNewsgroupsOperation.*/
+
+@interface MCONNTPGroupInfo : NSObject <NSCopying>
+
+/** The name of the news group. */
+@property (nonatomic, copy) NSString *name;
+
+/** The number of messages in the news group. */
+@property (nonatomic, assign) unsigned int messageCount;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPGroupInfo.mm b/src/objc/nntp/MCONNTPGroupInfo.mm
new file mode 100644
index 00000000..342192f2
--- /dev/null
+++ b/src/objc/nntp/MCONNTPGroupInfo.mm
@@ -0,0 +1,70 @@
+//
+// MCONNTPGroupInfo.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPGroupInfo.h"
+
+#include "MCAsyncNNTP.h"
+#include "MCNNTP.h"
+
+#import "MCOUtils.h"
+
+@implementation MCONNTPGroupInfo {
+ mailcore::NNTPGroupInfo * _nativeInfo;
+}
+
+#define nativeType mailcore::NNTPGroupInfo
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
+- (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];
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ mailcore::NNTPGroupInfo * groupInfo = (mailcore::NNTPGroupInfo *) object;
+ return [[[self alloc] initWithMCNNTPGroupInfo:groupInfo] autorelease];
+}
+
+- (mailcore::Object *) mco_mcObject
+{
+ return _nativeInfo;
+}
+
+- (NSString *) description
+{
+ return MCO_OBJC_BRIDGE_GET(description);
+}
+
+- (id) initWithMCNNTPGroupInfo:(mailcore::NNTPGroupInfo *)info
+{
+ self = [super init];
+
+ _nativeInfo = info;
+ _nativeInfo->retain();
+
+ return self;
+}
+
+- (void) dealloc
+{
+ MC_SAFE_RELEASE(_nativeInfo);
+ [super dealloc];
+}
+
+MCO_OBJC_SYNTHESIZE_STRING(setName, name)
+MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMessageCount, messageCount)
+
+@end
diff --git a/src/objc/nntp/MCONNTPListNewsgroupsOperation.h b/src/objc/nntp/MCONNTPListNewsgroupsOperation.h
new file mode 100644
index 00000000..ea702b75
--- /dev/null
+++ b/src/objc/nntp/MCONNTPListNewsgroupsOperation.h
@@ -0,0 +1,32 @@
+//
+// MCONNTPListNewsgroupsOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPLISTNEWSGROUPSOPERATION_H
+
+#define MAILCORE_MCONNTPLISTNEWSGROUPSOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+@interface MCONNTPListNewsgroupsOperation : MCONNTPOperation
+
+/**
+ Starts the asynchronous fetch operation.
+
+ @param completionBlock Called when the operation is finished.
+
+ - On success `error` will be nil and `messages` will be an array of MCONNTPGroupInfo
+
+ - On failure, `error` will be set with `MCOErrorDomain` as domain and an
+ error code available in MCOConstants.h, `messages` will be null
+ */
+- (void) start:(void (^)(NSError * error, NSArray * /* MCONNTPGroupInfo */ messages))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPListNewsgroupsOperation.mm b/src/objc/nntp/MCONNTPListNewsgroupsOperation.mm
new file mode 100644
index 00000000..155a93a3
--- /dev/null
+++ b/src/objc/nntp/MCONNTPListNewsgroupsOperation.mm
@@ -0,0 +1,69 @@
+//
+// MCONNTPListNewsgroupsOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPListNewsgroupsOperation.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+
+typedef void (^CompletionType)(NSError *error, NSArray * groups);
+
+@implementation MCONNTPListNewsgroupsOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::NNTPListNewsgroupsOperation
+
++ (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, NSArray * groups))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, MCO_TO_OBJC(op->groups()));
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end
diff --git a/src/objc/nntp/MCONNTPMessageInfo.h b/src/objc/nntp/MCONNTPMessageInfo.h
new file mode 100644
index 00000000..0b62547a
--- /dev/null
+++ b/src/objc/nntp/MCONNTPMessageInfo.h
@@ -0,0 +1,31 @@
+//
+// MCONNTPMessageInfo.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPMESSAGEINFO_H
+
+#define MAILCORE_MCONNTPMESSAGEINFO_H
+
+#import <Foundation/Foundation.h>
+
+/** This is information of a message fetched by MCONNTPFetchMessagesOperation.*/
+
+@interface MCONNTPMessageInfo : NSObject <NSCopying>
+
+/** This is the index of a given message.*/
+@property (nonatomic, assign) unsigned int index;
+
+/** This is the size of the given message.*/
+@property (nonatomic, assign) unsigned int size;
+
+/** This is the unique identifier of the message.
+ It can be used as a cache identifier.*/
+@property (nonatomic, copy) NSString * uid;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPMessageInfo.mm b/src/objc/nntp/MCONNTPMessageInfo.mm
new file mode 100644
index 00000000..f69267ab
--- /dev/null
+++ b/src/objc/nntp/MCONNTPMessageInfo.mm
@@ -0,0 +1,71 @@
+//
+// MCONNTPMessageInfo.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPMessageInfo.h"
+
+#include "MCAsyncNNTP.h"
+#include "MCNNTP.h"
+
+#import "MCOUtils.h"
+
+@implementation MCONNTPMessageInfo {
+ mailcore::NNTPMessageInfo * _nativeInfo;
+}
+
+#define nativeType mailcore::NNTPMessageInfo
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
+- (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];
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ mailcore::NNTPMessageInfo * folder = (mailcore::NNTPMessageInfo *) object;
+ return [[[self alloc] initWithMCNNTPMessageInfo:folder] autorelease];
+}
+
+- (mailcore::Object *) mco_mcObject
+{
+ return _nativeInfo;
+}
+
+- (NSString *) description
+{
+ return MCO_OBJC_BRIDGE_GET(description);
+}
+
+- (id) initWithMCNNTPMessageInfo:(mailcore::NNTPMessageInfo *)info
+{
+ self = [super init];
+
+ _nativeInfo = info;
+ _nativeInfo->retain();
+
+ return self;
+}
+
+- (void) dealloc
+{
+ MC_SAFE_RELEASE(_nativeInfo);
+ [super dealloc];
+}
+
+MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setIndex, index)
+MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setSize, size)
+MCO_OBJC_SYNTHESIZE_STRING(setUid, uid)
+
+@end
diff --git a/src/objc/nntp/MCONNTPOperation+Private.h b/src/objc/nntp/MCONNTPOperation+Private.h
new file mode 100644
index 00000000..2ab429f2
--- /dev/null
+++ b/src/objc/nntp/MCONNTPOperation+Private.h
@@ -0,0 +1,20 @@
+//
+// MCONNTPOperation_Private.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPOPERATION_PRIVATE_H
+#define MAILCORE_MCONNTPOPERATION_PRIVATE_H
+
+@class MCONNTPSession;
+
+@interface MCONNTPOperation (Private)
+
+@property (nonatomic, retain) MCONNTPSession * session;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPOperation.h b/src/objc/nntp/MCONNTPOperation.h
new file mode 100644
index 00000000..9d4e2fcf
--- /dev/null
+++ b/src/objc/nntp/MCONNTPOperation.h
@@ -0,0 +1,37 @@
+//
+// MCONNTPOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPOPERATION_H
+
+#define MAILCORE_MCONNTPOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCOOperation.h>
+
+/**
+ This is a generic asynchronous NNTP3 operation.
+ @see MCONNTPSession
+ */
+
+@interface MCONNTPOperation : MCOOperation
+
+/**
+ 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/nntp/MCONNTPOperation.mm b/src/objc/nntp/MCONNTPOperation.mm
new file mode 100644
index 00000000..862b5259
--- /dev/null
+++ b/src/objc/nntp/MCONNTPOperation.mm
@@ -0,0 +1,59 @@
+//
+// MCONNTPOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPOperation.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+#import "MCONNTPSession.h"
+
+typedef void (^CompletionType)(NSError *error);
+
+@implementation MCONNTPOperation {
+ CompletionType _completionBlock;
+ MCONNTPSession * _session;
+}
+
+#define nativeType mailcore::NNTPOperation
+
+- (void) dealloc
+{
+ [_session release];
+ [_completionBlock release];
+ [super dealloc];
+}
+
+- (void)start:(void (^)(NSError *error))completionBlock {
+ _completionBlock = [completionBlock copy];
+ [self start];
+}
+
+- (void)operationCompleted {
+ if (_completionBlock == NULL)
+ return;
+
+ NSError * error = [NSError mco_errorWithErrorCode:MCO_NATIVE_INSTANCE->error()];
+ _completionBlock(error);
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+- (void) setSession:(MCONNTPSession *)session
+{
+ [_session release];
+ _session = [session retain];
+}
+
+- (MCONNTPSession *) session
+{
+ return _session;
+}
+
+@end
diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h
new file mode 100644
index 00000000..7f9f78cd
--- /dev/null
+++ b/src/objc/nntp/MCONNTPSession.h
@@ -0,0 +1,141 @@
+//
+// MCONNTPSession.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#ifndef MAILCORE_MCONNTPSESSION_H
+
+#define MAILCORE_MCONNTPSESSION_H
+
+#import <Foundation/Foundation.h>
+
+#import <MailCore/MCOConstants.h>
+
+@class MCONNTPFetchMessagesOperation;
+@class MCONNTPFetchHeaderOperation;
+@class MCONNTPFetchMessageOperation;
+@class MCONNTPListNewsgroupsOperation;
+@class MCONNTPOperation;
+
+/** This class implements asynchronous access to the NNTP protocol.*/
+
+@interface MCONNTPSession : NSObject
+
+/** This is the hostname of the NNTP server to connect to.*/
+@property (nonatomic, copy) NSString * hostname;
+
+/** This is the port of the NNTP server to connect to.*/
+@property (nonatomic, assign) unsigned int port;
+
+/** This is the username of the account.*/
+@property (nonatomic, copy) NSString * username;
+
+/** This is the password of the account.*/
+@property (nonatomic, copy) NSString * password;
+
+/** This is the encryption type to use.
+ See MCOConnectionType for more information.*/
+@property (nonatomic, assign) MCOConnectionType connectionType;
+
+/** This is the timeout of the connection.*/
+@property (nonatomic, assign) NSTimeInterval timeout;
+
+/** When set to YES, the connection will fail if the certificate is incorrect.*/
+@property (nonatomic, assign, getter=isCheckCertificateEnabled) BOOL checkCertificateEnabled;
+
+/**
+ Sets logger callback. The network traffic will be sent to this block.
+
+ [session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) {
+ ...
+ }];
+ */
+@property (nonatomic, copy) MCOConnectionLogger connectionLogger;
+
+/** This property provides some hints to MCONNTPSession about where it's called from.
+ It will make MCONNTPSession safe. It will also set all the callbacks of operations to run on this given queue.
+ Defaults to the main queue.
+ This property should be used only if there's performance issue using MCONNTPSession in the main thread. */
+@property (nonatomic, assign) dispatch_queue_t dispatchQueue;
+
+/** @name Operations */
+
+/**
+ Returns an operation that will fetch the list of messages.
+
+ MCONNTPFetchMessagesOperation * op = [session fetchMessagesOperation];
+ [op start:^(NSError * error, NSArray * messages) {
+ // messages is an array of MCONNTPMessageInfo
+ // [info index] can be used as reference for a given message in the other operations.
+ }];
+ */
+- (MCONNTPFetchMessagesOperation *) fetchMessagesOperation:(NSString *)group;
+
+/**
+ Returns an operation that will fetch the header of the given message.
+
+ MCONNTPFetchHeaderOperation * op = [session fetchHeaderOperationWithIndex:idx];
+ [op start:^(NSError * error, MCOMessageHeader * header) {
+ // header is the parsed header of the message.
+ }];
+ */
+- (MCONNTPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index;
+
+/**
+ Returns an operation that will fetch the content of the given message.
+
+ MCONNTPFetchMessageOperation * op = [session fetchMessageOperationWithIndex:idx];
+ [op start:^(NSError * error, NSData * messageData) {
+ // messageData is the RFC 822 formatted message data.
+ }];
+ */
+- (MCONNTPFetchMessageOperation *) fetchMessageOperationWithIndex:(unsigned int)index;
+
+/**
+ Returns an operation that will list all available newsgroups.
+
+ MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation];
+ [op start:^(NSError * error, NSData * messageData) {
+ // messageData is the RFC 822 formatted message data.
+ }];
+ */
+- (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation;
+
+/**
+ Returns an operation that will list all newsgroups subscribed to by the user.
+
+ MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation];
+ [op start:^(NSError * error, NSData * messageData) {
+ // messageData is the RFC 822 formatted message data.
+ }];
+ */
+- (MCONNTPListNewsgroupsOperation *) listSubscribedNewsgroupsOperation;
+
+/**
+ Returns an operation that will disconnect the session.
+
+ MCONNTPOperation * op = [session disconnectOperation];
+ [op start:^(NSError * error) {
+ ...
+ }];
+ */
+- (MCONNTPOperation *) disconnectOperation;
+
+/**
+ Returns an operation that will check whether the NNTP account is valid.
+
+ MCONNTPOperation * op = [session checkAccountOperation];
+ [op start:^(NSError * error) {
+ ...
+ }];
+ */
+- (MCONNTPOperation *) checkAccountOperation;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm
new file mode 100644
index 00000000..f300d97c
--- /dev/null
+++ b/src/objc/nntp/MCONNTPSession.mm
@@ -0,0 +1,169 @@
+//
+// MCONNTPSession.m
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPSession.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCONNTPOperation.h"
+#import "MCOOperation+Private.h"
+#import "MCONNTPFetchMessagesOperation.h"
+#import "MCONNTPOperation+Private.h"
+
+using namespace mailcore;
+
+@interface MCONNTPSession ()
+
+- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data;
+
+@end
+
+class MCONNTPConnectionLoggerBridge : public Object, public ConnectionLogger {
+public:
+ MCONNTPConnectionLoggerBridge(MCONNTPSession * session)
+ {
+ mSession = session;
+ }
+
+ virtual void log(void * sender, ConnectionLogType logType, Data * data)
+ {
+ [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
+ }
+
+private:
+ MCONNTPSession * mSession;
+};
+
+@implementation MCONNTPSession {
+ mailcore::NNTPAsyncSession * _session;
+ MCOConnectionLogger _connectionLogger;
+ MCONNTPConnectionLoggerBridge * _loggerBridge;
+}
+
+#define nativeType mailcore::NNTPAsyncSession
+
+- (mailcore::Object *) mco_mcObject
+{
+ return _session;
+}
+
+- (NSString *) description
+{
+ return MCO_OBJC_BRIDGE_GET(description);
+}
+
+- (id)init {
+ self = [super init];
+
+ _session = new mailcore::NNTPAsyncSession();
+ _loggerBridge = new MCONNTPConnectionLoggerBridge(self);
+
+ return self;
+}
+
+- (void)dealloc {
+ MC_SAFE_RELEASE(_loggerBridge);
+ [_connectionLogger release];
+ _session->release();
+ [super dealloc];
+}
+
+MCO_OBJC_SYNTHESIZE_STRING(setHostname, hostname)
+MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setPort, port)
+MCO_OBJC_SYNTHESIZE_STRING(setUsername, username)
+MCO_OBJC_SYNTHESIZE_STRING(setPassword, password)
+MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConnectionType, connectionType)
+MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout)
+MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled)
+MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue, dispatchQueue);
+
+- (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger
+{
+ [_connectionLogger release];
+ _connectionLogger = [connectionLogger copy];
+
+ if (_connectionLogger != nil) {
+ _session->setConnectionLogger(_loggerBridge);
+ }
+ else {
+ _session->setConnectionLogger(NULL);
+ }
+}
+
+- (MCOConnectionLogger) connectionLogger
+{
+ return _connectionLogger;
+}
+
+#pragma mark - Operations
+
+
+#define MCO_TO_OBJC_OP(op) [self _objcOperationFromNativeOp:op];
+#define OPAQUE_OPERATION(op) [self _objcOpaqueOperationFromNativeOp:op]
+
+- (id) _objcOperationFromNativeOp:(mailcore::NNTPOperation *)op
+{
+ MCONNTPOperation * result = MCO_TO_OBJC(op);
+ [result setSession:self];
+ return result;
+}
+
+- (id) _objcOpaqueOperationFromNativeOp:(mailcore::NNTPOperation *)op
+{
+ MCONNTPOperation * result = [[[MCONNTPOperation alloc] initWithMCOperation:op] autorelease];
+ [result setSession:self];
+ return result;
+}
+
+- (MCONNTPFetchMessagesOperation *) fetchMessagesOperation:(NSString *)group
+{
+ mailcore::NNTPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessagesOperation(MCO_FROM_OBJC(mailcore::String, group));
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index
+{
+ mailcore::NNTPFetchHeaderOperation * coreOp = MCO_NATIVE_INSTANCE->fetchHeaderOperation(index);
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPFetchMessageOperation *) fetchMessageOperationWithIndex:(unsigned int)index;
+{
+ mailcore::NNTPFetchMessageOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageOperation(index);
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation {
+ mailcore::NNTPListNewsgroupsOperation * coreOp = MCO_NATIVE_INSTANCE->listAllNewsgroupsOperation();
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPListNewsgroupsOperation *) listSubscribedNewsgroupsOperation {
+ mailcore::NNTPListNewsgroupsOperation * coreOp = MCO_NATIVE_INSTANCE->listSubscribedNewsgroupsOperation();
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPOperation *) disconnectOperation
+{
+ mailcore::NNTPOperation * coreOp = MCO_NATIVE_INSTANCE->disconnectOperation();
+ return OPAQUE_OPERATION(coreOp);
+}
+
+- (MCONNTPOperation *) checkAccountOperation
+{
+ mailcore::NNTPOperation * coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation();
+ return OPAQUE_OPERATION(coreOp);
+}
+
+- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data
+{
+ _connectionLogger(sender, logType, data);
+}
+
+@end