aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/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/async/nntp
parent988fe081b340e5c1040a6d78db793107972c7bfb (diff)
NNTP support
Diffstat (limited to 'src/async/nntp')
-rw-r--r--src/async/nntp/MCAsyncNNTP.h21
-rw-r--r--src/async/nntp/MCNNTPAsyncSession.cpp271
-rw-r--r--src/async/nntp/MCNNTPAsyncSession.h85
-rw-r--r--src/async/nntp/MCNNTPCheckAccountOperation.cpp30
-rw-r--r--src/async/nntp/MCNNTPCheckAccountOperation.h32
-rw-r--r--src/async/nntp/MCNNTPDisconnectOperation.cpp30
-rw-r--r--src/async/nntp/MCNNTPDisconnectOperation.h32
-rw-r--r--src/async/nntp/MCNNTPFetchHeaderOperation.cpp51
-rw-r--r--src/async/nntp/MCNNTPFetchHeaderOperation.h44
-rw-r--r--src/async/nntp/MCNNTPFetchMessageOperation.cpp49
-rw-r--r--src/async/nntp/MCNNTPFetchMessageOperation.h41
-rw-r--r--src/async/nntp/MCNNTPFetchMessagesOperation.cpp49
-rw-r--r--src/async/nntp/MCNNTPFetchMessagesOperation.h41
-rw-r--r--src/async/nntp/MCNNTPListNewsgroupsOperation.cpp48
-rw-r--r--src/async/nntp/MCNNTPListNewsgroupsOperation.h41
-rw-r--r--src/async/nntp/MCNNTPOperation.cpp104
-rw-r--r--src/async/nntp/MCNNTPOperation.h53
-rw-r--r--src/async/nntp/MCNNTPOperationCallback.h28
18 files changed, 1050 insertions, 0 deletions
diff --git a/src/async/nntp/MCAsyncNNTP.h b/src/async/nntp/MCAsyncNNTP.h
new file mode 100644
index 00000000..e96788ca
--- /dev/null
+++ b/src/async/nntp/MCAsyncNNTP.h
@@ -0,0 +1,21 @@
+//
+// MCAsyncNNTP.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCASYNCNNTP_H
+
+#define MAILCORE_MCASYNCNNTP_H
+
+#include <MailCore/MCNNTPAsyncSession.h>
+#include <MailCore/MCNNTPOperation.h>
+#include <MailCore/MCNNTPFetchHeaderOperation.h>
+#include <MailCore/MCNNTPFetchMessageOperation.h>
+#include <MailCore/MCNNTPFetchMessagesOperation.h>
+#include <MailCore/MCNNTPListNewsgroupsOperation.h>
+#include <MailCore/MCNNTPOperationCallback.h>
+
+#endif
diff --git a/src/async/nntp/MCNNTPAsyncSession.cpp b/src/async/nntp/MCNNTPAsyncSession.cpp
new file mode 100644
index 00000000..4aa9b906
--- /dev/null
+++ b/src/async/nntp/MCNNTPAsyncSession.cpp
@@ -0,0 +1,271 @@
+//
+// MCNNTPAsyncSession.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPAsyncSession.h"
+
+#include "MCNNTP.h"
+#include "MCNNTPFetchHeaderOperation.h"
+#include "MCNNTPFetchMessageOperation.h"
+#include "MCNNTPFetchMessagesOperation.h"
+#include "MCNNTPListNewsgroupsOperation.h"
+#include "MCNNTPCheckAccountOperation.h"
+#include "MCNNTPDisconnectOperation.h"
+#include "MCOperationQueueCallback.h"
+#include "MCConnectionLogger.h"
+
+using namespace mailcore;
+
+namespace mailcore {
+ class NNTPOperationQueueCallback : public Object, public OperationQueueCallback {
+ public:
+ NNTPOperationQueueCallback(NNTPAsyncSession * session) {
+ mSession = session;
+ }
+
+ virtual ~NNTPOperationQueueCallback() {
+ }
+
+ virtual void queueStartRunning() {
+ mSession->retain();
+ }
+
+ virtual void queueStoppedRunning() {
+ mSession->release();
+ }
+
+ private:
+ NNTPAsyncSession * mSession;
+ };
+
+ class NNTPConnectionLogger : public Object, public ConnectionLogger {
+ public:
+ NNTPConnectionLogger(NNTPAsyncSession * session) {
+ mSession = session;
+ }
+
+ virtual ~NNTPConnectionLogger() {
+ }
+
+ virtual void log(void * sender, ConnectionLogType logType, Data * buffer)
+ {
+ mSession->logConnection(logType, buffer);
+ }
+
+ private:
+ NNTPAsyncSession * mSession;
+ };
+
+}
+
+NNTPAsyncSession::NNTPAsyncSession()
+{
+ mSession = new NNTPSession();
+ mQueue = new OperationQueue();
+ mQueueCallback = new NNTPOperationQueueCallback(this);
+ mQueue->setCallback(mQueueCallback);
+ mConnectionLogger = NULL;
+ pthread_mutex_init(&mConnectionLoggerLock, NULL);
+ mInternalLogger = new NNTPConnectionLogger(this);
+ mSession->setConnectionLogger(mInternalLogger);
+}
+
+NNTPAsyncSession::~NNTPAsyncSession()
+{
+ MC_SAFE_RELEASE(mInternalLogger);
+ pthread_mutex_destroy(&mConnectionLoggerLock);
+ MC_SAFE_RELEASE(mQueueCallback);
+ MC_SAFE_RELEASE(mSession);
+ MC_SAFE_RELEASE(mQueue);
+}
+
+void NNTPAsyncSession::setHostname(String * hostname)
+{
+ mSession->setHostname(hostname);
+}
+
+String * NNTPAsyncSession::hostname()
+{
+ return mSession->hostname();
+}
+
+void NNTPAsyncSession::setPort(unsigned int port)
+{
+ mSession->setPort(port);
+}
+
+unsigned int NNTPAsyncSession::port()
+{
+ return mSession->port();
+}
+
+void NNTPAsyncSession::setUsername(String * username)
+{
+ mSession->setUsername(username);
+}
+
+String * NNTPAsyncSession::username()
+{
+ return mSession->username();
+}
+
+void NNTPAsyncSession::setPassword(String * password)
+{
+ mSession->setPassword(password);
+}
+
+String * NNTPAsyncSession::password()
+{
+ return mSession->password();
+}
+
+void NNTPAsyncSession::setConnectionType(ConnectionType connectionType)
+{
+ mSession->setConnectionType(connectionType);
+}
+
+ConnectionType NNTPAsyncSession::connectionType()
+{
+ return mSession->connectionType();
+}
+
+void NNTPAsyncSession::setTimeout(time_t timeout)
+{
+ mSession->setTimeout(timeout);
+}
+
+time_t NNTPAsyncSession::timeout()
+{
+ return mSession->timeout();
+}
+
+void NNTPAsyncSession::setCheckCertificateEnabled(bool enabled)
+{
+ mSession->setCheckCertificateEnabled(enabled);
+}
+
+bool NNTPAsyncSession::isCheckCertificateEnabled()
+{
+ return mSession->isCheckCertificateEnabled();
+}
+
+NNTPFetchMessagesOperation * NNTPAsyncSession::fetchMessagesOperation(String * group)
+{
+ NNTPFetchMessagesOperation * op = new NNTPFetchMessagesOperation();
+ op->setSession(this);
+ op->setGroupName(group);
+ op->autorelease();
+ return op;
+}
+
+NNTPFetchHeaderOperation * NNTPAsyncSession::fetchHeaderOperation(unsigned int index)
+{
+ NNTPFetchHeaderOperation * op = new NNTPFetchHeaderOperation();
+ op->setSession(this);
+ op->setMessageIndex(index);
+ op->autorelease();
+ return op;
+}
+
+NNTPFetchMessageOperation * NNTPAsyncSession::fetchMessageOperation(unsigned int index)
+{
+ NNTPFetchMessageOperation * op = new NNTPFetchMessageOperation();
+ op->setSession(this);
+ op->setMessageIndex(index);
+ op->autorelease();
+ return op;
+}
+
+
+NNTPListNewsgroupsOperation * NNTPAsyncSession::listAllNewsgroupsOperation()
+{
+ NNTPListNewsgroupsOperation * op = new NNTPListNewsgroupsOperation();
+ op->setSession(this);
+ op->setListsSubscribed(false);
+ op->autorelease();
+ return op;
+}
+
+NNTPListNewsgroupsOperation * NNTPAsyncSession::listSubscribedNewsgroupsOperation()
+{
+ NNTPListNewsgroupsOperation * op = new NNTPListNewsgroupsOperation();
+ op->setSession(this);
+ op->setListsSubscribed(true);
+ op->autorelease();
+ return op;
+}
+
+NNTPOperation * NNTPAsyncSession::disconnectOperation()
+{
+ NNTPDisconnectOperation * op = new NNTPDisconnectOperation();
+ op->setSession(this);
+ op->autorelease();
+ return op;
+}
+
+NNTPOperation * NNTPAsyncSession::checkAccountOperation()
+{
+ NNTPCheckAccountOperation * op = new NNTPCheckAccountOperation();
+ op->setSession(this);
+ op->autorelease();
+ return op;
+}
+
+NNTPSession * NNTPAsyncSession::session()
+{
+ return mSession;
+}
+
+void NNTPAsyncSession::runOperation(NNTPOperation * operation)
+{
+ mQueue->addOperation(operation);
+}
+
+void NNTPAsyncSession::setConnectionLogger(ConnectionLogger * logger)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ mConnectionLogger = logger;
+ if (mConnectionLogger != NULL) {
+ mSession->setConnectionLogger(mInternalLogger);
+ }
+ else {
+ mSession->setConnectionLogger(NULL);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
+
+ConnectionLogger * NNTPAsyncSession::connectionLogger()
+{
+ ConnectionLogger * result;
+
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ result = mConnectionLogger;
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+
+ return result;
+}
+
+void NNTPAsyncSession::logConnection(ConnectionLogType logType, Data * buffer)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ if (mConnectionLogger != NULL) {
+ mConnectionLogger->log(this, logType, buffer);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
+
+#if __APPLE__
+void NNTPAsyncSession::setDispatchQueue(dispatch_queue_t dispatchQueue)
+{
+ mQueue->setDispatchQueue(dispatchQueue);
+}
+
+dispatch_queue_t NNTPAsyncSession::dispatchQueue()
+{
+ return mQueue->dispatchQueue();
+}
+#endif
diff --git a/src/async/nntp/MCNNTPAsyncSession.h b/src/async/nntp/MCNNTPAsyncSession.h
new file mode 100644
index 00000000..ad2ee699
--- /dev/null
+++ b/src/async/nntp/MCNNTPAsyncSession.h
@@ -0,0 +1,85 @@
+#ifndef MAILCORE_MCNNTPASYNCSESSION_H
+
+#define MAILCORE_MCNNTPASYNCSESSION_H
+
+#include <MailCore/MCBaseTypes.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPOperation;
+ class NNTPSession;
+ class NNTPFetchHeaderOperation;
+ class NNTPFetchMessageOperation;
+ class NNTPFetchMessagesOperation;
+ class NNTPListNewsgroupsOperation;
+ class NNTPOperationQueueCallback;
+ class NNTPConnectionLogger;
+
+ class NNTPAsyncSession : public Object {
+ public:
+ NNTPAsyncSession();
+ virtual ~NNTPAsyncSession();
+
+ virtual void setHostname(String * hostname);
+ virtual String * hostname();
+
+ virtual void setPort(unsigned int port);
+ virtual unsigned int port();
+
+ virtual void setUsername(String * login);
+ virtual String * username();
+
+ virtual void setPassword(String * password);
+ virtual String * password();
+
+ virtual void setConnectionType(ConnectionType connectionType);
+ virtual ConnectionType connectionType();
+
+ virtual void setTimeout(time_t timeout);
+ virtual time_t timeout();
+
+ virtual void setCheckCertificateEnabled(bool enabled);
+ virtual bool isCheckCertificateEnabled();
+
+ virtual void setConnectionLogger(ConnectionLogger * logger);
+ virtual ConnectionLogger * connectionLogger();
+
+#ifdef __APPLE__
+ virtual void setDispatchQueue(dispatch_queue_t dispatchQueue);
+ virtual dispatch_queue_t dispatchQueue();
+#endif
+
+ virtual NNTPFetchMessagesOperation * fetchMessagesOperation(String * group);
+
+ virtual NNTPFetchHeaderOperation * fetchHeaderOperation(unsigned int index);
+
+ virtual NNTPFetchMessageOperation * fetchMessageOperation(unsigned int index);
+
+ virtual NNTPListNewsgroupsOperation * listAllNewsgroupsOperation();
+ virtual NNTPListNewsgroupsOperation * listSubscribedNewsgroupsOperation();
+
+ virtual NNTPOperation * disconnectOperation();
+
+ virtual NNTPOperation * checkAccountOperation();
+
+ private:
+ NNTPSession * mSession;
+ OperationQueue * mQueue;
+ NNTPOperationQueueCallback * mQueueCallback;
+ ConnectionLogger * mConnectionLogger;
+ pthread_mutex_t mConnectionLoggerLock;
+ NNTPConnectionLogger * mInternalLogger;
+
+ public: // private
+ virtual void runOperation(NNTPOperation * operation);
+ virtual NNTPSession * session();
+ virtual void logConnection(ConnectionLogType logType, Data * buffer);
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPCheckAccountOperation.cpp b/src/async/nntp/MCNNTPCheckAccountOperation.cpp
new file mode 100644
index 00000000..29b050f0
--- /dev/null
+++ b/src/async/nntp/MCNNTPCheckAccountOperation.cpp
@@ -0,0 +1,30 @@
+//
+// MCNNTPCheckAccountOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPCheckAccountOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPCheckAccountOperation::NNTPCheckAccountOperation()
+{
+}
+
+NNTPCheckAccountOperation::~NNTPCheckAccountOperation()
+{
+}
+
+void NNTPCheckAccountOperation::main()
+{
+ ErrorCode error;
+
+ session()->session()->checkAccount(&error);
+ setError(error);
+}
diff --git a/src/async/nntp/MCNNTPCheckAccountOperation.h b/src/async/nntp/MCNNTPCheckAccountOperation.h
new file mode 100644
index 00000000..28db9c58
--- /dev/null
+++ b/src/async/nntp/MCNNTPCheckAccountOperation.h
@@ -0,0 +1,32 @@
+//
+// MCNNTPCheckAccountOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPCHECKACCOUNTOPERATION_H
+
+#define MAILCORE_MCNNTPCHECKACCOUNTOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPCheckAccountOperation : public NNTPOperation {
+ public:
+ NNTPCheckAccountOperation();
+ virtual ~NNTPCheckAccountOperation();
+
+ public: // subclass behavior
+ virtual void main();
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPDisconnectOperation.cpp b/src/async/nntp/MCNNTPDisconnectOperation.cpp
new file mode 100644
index 00000000..d269904a
--- /dev/null
+++ b/src/async/nntp/MCNNTPDisconnectOperation.cpp
@@ -0,0 +1,30 @@
+//
+// MCNNTPDisconnectOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPDisconnectOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPDisconnectOperation::NNTPDisconnectOperation()
+{
+}
+
+NNTPDisconnectOperation::~NNTPDisconnectOperation()
+{
+}
+
+void NNTPDisconnectOperation::main()
+{
+ ErrorCode error;
+
+ session()->session()->checkAccount(&error);
+ setError(error);
+}
diff --git a/src/async/nntp/MCNNTPDisconnectOperation.h b/src/async/nntp/MCNNTPDisconnectOperation.h
new file mode 100644
index 00000000..f2b5d138
--- /dev/null
+++ b/src/async/nntp/MCNNTPDisconnectOperation.h
@@ -0,0 +1,32 @@
+//
+// MCNNTPDisconnectOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPDISCONNECTOPERATION_H
+
+#define MAILCORE_MCNNTPDISCONNECTOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPDisconnectOperation : public NNTPOperation {
+ public:
+ NNTPDisconnectOperation();
+ virtual ~NNTPDisconnectOperation();
+
+ public: // subclass behavior
+ virtual void main();
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPFetchHeaderOperation.cpp b/src/async/nntp/MCNNTPFetchHeaderOperation.cpp
new file mode 100644
index 00000000..ea374527
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchHeaderOperation.cpp
@@ -0,0 +1,51 @@
+//
+// MCNNTPFetchHeaderOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPFetchHeaderOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+#include "MCMessageHeader.h"
+
+using namespace mailcore;
+
+NNTPFetchHeaderOperation::NNTPFetchHeaderOperation()
+{
+ mMessageIndex = 0;
+ mHeader = NULL;
+}
+
+NNTPFetchHeaderOperation::~NNTPFetchHeaderOperation()
+{
+ MC_SAFE_RELEASE(mHeader);
+}
+
+void NNTPFetchHeaderOperation::setMessageIndex(unsigned int messageIndex)
+{
+ mMessageIndex = messageIndex;
+}
+
+unsigned int NNTPFetchHeaderOperation::messageIndex()
+{
+ return mMessageIndex;
+}
+
+MessageHeader * NNTPFetchHeaderOperation::header()
+{
+ return mHeader;
+}
+
+void NNTPFetchHeaderOperation::main()
+{
+ ErrorCode error;
+ mHeader = session()->session()->fetchHeader(mMessageIndex, &error);
+ if (mHeader != NULL) {
+ mHeader->retain();
+ }
+ setError(error);
+}
diff --git a/src/async/nntp/MCNNTPFetchHeaderOperation.h b/src/async/nntp/MCNNTPFetchHeaderOperation.h
new file mode 100644
index 00000000..91ded8ee
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchHeaderOperation.h
@@ -0,0 +1,44 @@
+//
+// MCNNTPFetchHeaderOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPFETCHHEADEROPERATION_H
+
+#define MAILCORE_MCNNTPFETCHHEADEROPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class MessageHeader;
+
+ class NNTPFetchHeaderOperation : public NNTPOperation {
+ public:
+ NNTPFetchHeaderOperation();
+ virtual ~NNTPFetchHeaderOperation();
+
+ virtual void setMessageIndex(unsigned int messageIndex);
+ virtual unsigned int messageIndex();
+
+ virtual MessageHeader * header();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ unsigned int mMessageIndex;
+ MessageHeader * mHeader;
+
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPFetchMessageOperation.cpp b/src/async/nntp/MCNNTPFetchMessageOperation.cpp
new file mode 100644
index 00000000..3610a51e
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchMessageOperation.cpp
@@ -0,0 +1,49 @@
+//
+// MCNNTPFetchMessagesOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPFetchMessageOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPFetchMessageOperation::NNTPFetchMessageOperation()
+{
+ mMessageIndex = 0;
+ mData = NULL;
+}
+
+NNTPFetchMessageOperation::~NNTPFetchMessageOperation()
+{
+ MC_SAFE_RELEASE(mData);
+}
+
+void NNTPFetchMessageOperation::setMessageIndex(unsigned int messageIndex)
+{
+ mMessageIndex = messageIndex;
+}
+
+unsigned int NNTPFetchMessageOperation::messageIndex()
+{
+ return mMessageIndex;
+}
+
+Data * NNTPFetchMessageOperation::data()
+{
+ return mData;
+}
+
+void NNTPFetchMessageOperation::main()
+{
+ ErrorCode error;
+ mData = session()->session()->fetchMessage(mMessageIndex, this, &error);
+ MC_SAFE_RETAIN(mData);
+ setError(error);
+}
+
diff --git a/src/async/nntp/MCNNTPFetchMessageOperation.h b/src/async/nntp/MCNNTPFetchMessageOperation.h
new file mode 100644
index 00000000..f1bb0a65
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchMessageOperation.h
@@ -0,0 +1,41 @@
+//
+// MCNNTPFetchMessagesOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPFETCHMESSAGEOPERATION_H
+
+#define MAILCORE_MCNNTPFETCHMESSAGEOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+ class NNTPFetchMessageOperation : public NNTPOperation {
+ public:
+ NNTPFetchMessageOperation();
+ virtual ~NNTPFetchMessageOperation();
+
+ virtual void setMessageIndex(unsigned int messageIndex);
+ virtual unsigned int messageIndex();
+
+ virtual Data * data();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ unsigned int mMessageIndex;
+ Data * mData;
+
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPFetchMessagesOperation.cpp b/src/async/nntp/MCNNTPFetchMessagesOperation.cpp
new file mode 100644
index 00000000..03a91510
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchMessagesOperation.cpp
@@ -0,0 +1,49 @@
+//
+// MCNNTPFetchMessagesOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPFetchMessagesOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPFetchMessagesOperation::NNTPFetchMessagesOperation()
+{
+ mGroupName = NULL;
+ mMessages = NULL;
+}
+
+NNTPFetchMessagesOperation::~NNTPFetchMessagesOperation()
+{
+ MC_SAFE_RELEASE(mGroupName);
+ MC_SAFE_RELEASE(mMessages);
+}
+
+void NNTPFetchMessagesOperation::setGroupName(String * groupname)
+{
+ MC_SAFE_REPLACE_COPY(String, mGroupName, groupname);
+}
+
+String * NNTPFetchMessagesOperation::groupName()
+{
+ return mGroupName;
+}
+
+Array * NNTPFetchMessagesOperation::messages()
+{
+ return mMessages;
+}
+
+void NNTPFetchMessagesOperation::main()
+{
+ ErrorCode error;
+ mMessages = session()->session()->fetchMessages(mGroupName, &error);
+ setError(error);
+ MC_SAFE_RETAIN(mMessages);
+}
diff --git a/src/async/nntp/MCNNTPFetchMessagesOperation.h b/src/async/nntp/MCNNTPFetchMessagesOperation.h
new file mode 100644
index 00000000..91390c1f
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchMessagesOperation.h
@@ -0,0 +1,41 @@
+//
+// MCNNTPFetchMessagesOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPFETCHMESSAGESOPERATION_H
+
+#define MAILCORE_MCNNTPFETCHMESSAGESOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPFetchMessagesOperation : public NNTPOperation {
+ public:
+ NNTPFetchMessagesOperation();
+ virtual ~NNTPFetchMessagesOperation();
+
+ virtual void setGroupName(String * groupName);
+ virtual String * groupName();
+
+ virtual Array * /* NNTPMessageInfo */ messages();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ String * mGroupName;
+ Array * /* NNTPMessageInfo */ mMessages;
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPListNewsgroupsOperation.cpp b/src/async/nntp/MCNNTPListNewsgroupsOperation.cpp
new file mode 100644
index 00000000..253b38d0
--- /dev/null
+++ b/src/async/nntp/MCNNTPListNewsgroupsOperation.cpp
@@ -0,0 +1,48 @@
+//
+// MCNNTPListNewsgroupsMessagesOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPListNewsgroupsOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPListNewsgroupsOperation::NNTPListNewsgroupsOperation()
+{
+}
+
+NNTPListNewsgroupsOperation::~NNTPListNewsgroupsOperation()
+{
+}
+
+void NNTPListNewsgroupsOperation::setListsSubscribed(bool listsSubscribed)
+{
+ mListsSuscribed = listsSubscribed;
+}
+
+bool NNTPListNewsgroupsOperation::listsSubscribed()
+{
+ return mListsSuscribed;
+}
+
+Array * NNTPListNewsgroupsOperation::groups() {
+ return mGroups;
+}
+
+void NNTPListNewsgroupsOperation::main()
+{
+ ErrorCode error;
+
+ if (mListsSuscribed) {
+ mGroups = session()->session()->listSubscribedNewsgroups(&error);
+ } else {
+ mGroups = session()->session()->listAllNewsgroups(&error);
+ }
+ setError(error);
+}
diff --git a/src/async/nntp/MCNNTPListNewsgroupsOperation.h b/src/async/nntp/MCNNTPListNewsgroupsOperation.h
new file mode 100644
index 00000000..54156012
--- /dev/null
+++ b/src/async/nntp/MCNNTPListNewsgroupsOperation.h
@@ -0,0 +1,41 @@
+//
+// MCNNTPListNewsgroupsMessagesOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPLISTNEWSGROUPSOPERATION_H
+
+#define MAILCORE_MCNNTPLISTNEWSGROUPSOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPListNewsgroupsOperation : public NNTPOperation {
+ public:
+ NNTPListNewsgroupsOperation();
+ virtual ~NNTPListNewsgroupsOperation();
+
+ virtual void setListsSubscribed(bool listsSubscribed);
+ virtual bool listsSubscribed();
+
+ virtual Array * groups();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ bool mListsSuscribed;
+ Array * /* NNTPGroupInfo */ mGroups;
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPOperation.cpp b/src/async/nntp/MCNNTPOperation.cpp
new file mode 100644
index 00000000..3368ba0e
--- /dev/null
+++ b/src/async/nntp/MCNNTPOperation.cpp
@@ -0,0 +1,104 @@
+//
+// MCNNTPOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPOperation.h"
+
+#include <stdlib.h>
+
+#include "MCNNTPSession.h"
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPOperationCallback.h"
+
+using namespace mailcore;
+
+NNTPOperation::NNTPOperation()
+{
+ mSession = NULL;
+ mPopCallback = NULL;
+ mError = ErrorNone;
+}
+
+NNTPOperation::~NNTPOperation()
+{
+ MC_SAFE_RELEASE(mSession);
+}
+
+void NNTPOperation::setSession(NNTPAsyncSession * session)
+{
+ MC_SAFE_REPLACE_RETAIN(NNTPAsyncSession, mSession, session);
+#if __APPLE__
+ dispatch_queue_t queue;
+ if (session != NULL) {
+ queue = session->dispatchQueue();
+ }
+ else {
+ queue = dispatch_get_main_queue();
+ }
+ setCallbackDispatchQueue(queue);
+#endif
+}
+
+NNTPAsyncSession * NNTPOperation::session()
+{
+ return mSession;
+}
+
+void NNTPOperation::setNNTPCallback(NNTPOperationCallback * callback)
+{
+ mPopCallback = callback;
+}
+
+NNTPOperationCallback * NNTPOperation::nntpCallback()
+{
+ return mPopCallback;
+}
+
+void NNTPOperation::setError(ErrorCode error)
+{
+ mError = error;
+}
+
+ErrorCode NNTPOperation::error()
+{
+ return mError;
+}
+
+void NNTPOperation::start()
+{
+ mSession->runOperation(this);
+}
+
+struct progressContext {
+ unsigned int current;
+ unsigned int maximum;
+};
+
+void NNTPOperation::bodyProgress(NNTPSession * session, unsigned int current, unsigned int maximum)
+{
+ struct progressContext * context = (struct progressContext *) calloc(sizeof(* context), 1);
+ context->current = current;
+ context->maximum = maximum;
+
+ retain();
+ performMethodOnCallbackThread((Object::Method) &NNTPOperation::bodyProgressOnMainThread, context);
+}
+
+void NNTPOperation::bodyProgressOnMainThread(void * ctx)
+{
+ if (isCancelled()) {
+ release();
+ return;
+ }
+
+ struct progressContext * context = (struct progressContext *) ctx;
+ if (mPopCallback != NULL) {
+ mPopCallback->bodyProgress(this, context->current, context->maximum);
+ }
+ free(context);
+ release();
+}
diff --git a/src/async/nntp/MCNNTPOperation.h b/src/async/nntp/MCNNTPOperation.h
new file mode 100644
index 00000000..fb40e9df
--- /dev/null
+++ b/src/async/nntp/MCNNTPOperation.h
@@ -0,0 +1,53 @@
+//
+// MCNNTPOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPOPERATION_H
+
+#define MAILCORE_MCNNTPOPERATION_H
+
+#include <MailCore/MCBaseTypes.h>
+#include <MailCore/MCNNTPProgressCallback.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPAsyncSession;
+ class NNTPOperationCallback;
+
+ class NNTPOperation : public Operation, public NNTPProgressCallback {
+ public:
+ NNTPOperation();
+ virtual ~NNTPOperation();
+
+ virtual void setSession(NNTPAsyncSession * session);
+ virtual NNTPAsyncSession * session();
+
+ virtual void setNNTPCallback(NNTPOperationCallback * callback);
+ virtual NNTPOperationCallback * nntpCallback();
+
+ virtual void setError(ErrorCode error);
+ virtual ErrorCode error();
+
+ virtual void start();
+
+ private:
+ NNTPAsyncSession * mSession;
+ NNTPOperationCallback * mPopCallback;
+ ErrorCode mError;
+ private:
+ virtual void bodyProgress(NNTPSession * session, unsigned int current, unsigned int maximum);
+ virtual void bodyProgressOnMainThread(void * context);
+
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPOperationCallback.h b/src/async/nntp/MCNNTPOperationCallback.h
new file mode 100644
index 00000000..f6166610
--- /dev/null
+++ b/src/async/nntp/MCNNTPOperationCallback.h
@@ -0,0 +1,28 @@
+//
+// MCNNTPOperationCallback.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPOPERATIONCALLBACK_H
+
+#define MAILCORE_MCNNTPOPERATIONCALLBACK_H
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPOperation;
+
+ class NNTPOperationCallback {
+ public:
+ virtual void bodyProgress(NNTPOperation * session, unsigned int current, unsigned int maximum) {};
+ };
+
+}
+
+#endif
+
+#endif