aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/nntp
diff options
context:
space:
mode:
Diffstat (limited to 'src/async/nntp')
-rw-r--r--src/async/nntp/MCAsyncNNTP.h21
-rw-r--r--src/async/nntp/MCNNTPAsyncSession.cc272
-rw-r--r--src/async/nntp/MCNNTPAsyncSession.h85
-rw-r--r--src/async/nntp/MCNNTPCheckAccountOperation.cc30
-rw-r--r--src/async/nntp/MCNNTPCheckAccountOperation.h32
-rw-r--r--src/async/nntp/MCNNTPDisconnectOperation.cc30
-rw-r--r--src/async/nntp/MCNNTPDisconnectOperation.h32
-rw-r--r--src/async/nntp/MCNNTPFetchArticleOperation.cc57
-rw-r--r--src/async/nntp/MCNNTPFetchArticleOperation.h45
-rw-r--r--src/async/nntp/MCNNTPFetchArticlesOperation.cc49
-rw-r--r--src/async/nntp/MCNNTPFetchArticlesOperation.h41
-rw-r--r--src/async/nntp/MCNNTPFetchHeaderOperation.cc59
-rw-r--r--src/async/nntp/MCNNTPFetchHeaderOperation.h48
-rw-r--r--src/async/nntp/MCNNTPListNewsgroupsOperation.cc48
-rw-r--r--src/async/nntp/MCNNTPListNewsgroupsOperation.h41
-rw-r--r--src/async/nntp/MCNNTPOperation.cc104
-rw-r--r--src/async/nntp/MCNNTPOperation.h53
-rw-r--r--src/async/nntp/MCNNTPOperationCallback.h28
18 files changed, 1075 insertions, 0 deletions
diff --git a/src/async/nntp/MCAsyncNNTP.h b/src/async/nntp/MCAsyncNNTP.h
new file mode 100644
index 00000000..56509ff8
--- /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/MCNNTPFetchArticleOperation.h>
+#include <MailCore/MCNNTPFetchArticlesOperation.h>
+#include <MailCore/MCNNTPListNewsgroupsOperation.h>
+#include <MailCore/MCNNTPOperationCallback.h>
+
+#endif
diff --git a/src/async/nntp/MCNNTPAsyncSession.cc b/src/async/nntp/MCNNTPAsyncSession.cc
new file mode 100644
index 00000000..833bf4d5
--- /dev/null
+++ b/src/async/nntp/MCNNTPAsyncSession.cc
@@ -0,0 +1,272 @@
+//
+// 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 "MCNNTPFetchArticleOperation.h"
+#include "MCNNTPFetchArticlesOperation.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();
+}
+
+MCNNTPFetchArticlesOperation * NNTPAsyncSession::fetchArticlesOperation(String * group)
+{
+ MCNNTPFetchArticlesOperation * op = new MCNNTPFetchArticlesOperation();
+ op->setSession(this);
+ op->setGroupName(group);
+ op->autorelease();
+ return op;
+}
+
+NNTPFetchHeaderOperation * NNTPAsyncSession::fetchHeaderOperation(String * groupName, unsigned int index)
+{
+ NNTPFetchHeaderOperation * op = new NNTPFetchHeaderOperation();
+ op->setSession(this);
+ op->setGroupName(groupName);
+ op->setMessageIndex(index);
+ op->autorelease();
+ return op;
+}
+
+NNTPFetchArticleOperation * NNTPAsyncSession::fetchArticleOperation(String * groupName, unsigned int index)
+{
+ NNTPFetchArticleOperation * op = new NNTPFetchArticleOperation();
+ op->setSession(this);
+ op->setGroupName(groupName);
+ 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..66f0cc0d
--- /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 NNTPFetchArticleOperation;
+ class MCNNTPFetchArticlesOperation;
+ 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 MCNNTPFetchArticlesOperation * fetchArticlesOperation(String * group);
+
+ virtual NNTPFetchHeaderOperation * fetchHeaderOperation(String * groupName, unsigned int index);
+
+ virtual NNTPFetchArticleOperation * fetchArticleOperation(String *groupName, 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.cc b/src/async/nntp/MCNNTPCheckAccountOperation.cc
new file mode 100644
index 00000000..29b050f0
--- /dev/null
+++ b/src/async/nntp/MCNNTPCheckAccountOperation.cc
@@ -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.cc b/src/async/nntp/MCNNTPDisconnectOperation.cc
new file mode 100644
index 00000000..d269904a
--- /dev/null
+++ b/src/async/nntp/MCNNTPDisconnectOperation.cc
@@ -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/MCNNTPFetchArticleOperation.cc b/src/async/nntp/MCNNTPFetchArticleOperation.cc
new file mode 100644
index 00000000..a12f346f
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchArticleOperation.cc
@@ -0,0 +1,57 @@
+//
+// MCMCNNTPFetchArticlesOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPFetchArticleOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPFetchArticleOperation::NNTPFetchArticleOperation()
+{
+ mMessageIndex = 0;
+ mData = NULL;
+}
+
+NNTPFetchArticleOperation::~NNTPFetchArticleOperation()
+{
+ MC_SAFE_RELEASE(mData);
+}
+
+void NNTPFetchArticleOperation::setGroupName(String * groupName) {
+ MC_SAFE_REPLACE_COPY(String, mGroupName, groupName);
+}
+
+String * NNTPFetchArticleOperation::groupName() {
+ return mGroupName;
+}
+
+void NNTPFetchArticleOperation::setMessageIndex(unsigned int messageIndex)
+{
+ mMessageIndex = messageIndex;
+}
+
+unsigned int NNTPFetchArticleOperation::messageIndex()
+{
+ return mMessageIndex;
+}
+
+Data * NNTPFetchArticleOperation::data()
+{
+ return mData;
+}
+
+void NNTPFetchArticleOperation::main()
+{
+ ErrorCode error;
+ mData = session()->session()->fetchArticle(mGroupName, mMessageIndex, this, &error);
+ MC_SAFE_RETAIN(mData);
+ setError(error);
+}
+
diff --git a/src/async/nntp/MCNNTPFetchArticleOperation.h b/src/async/nntp/MCNNTPFetchArticleOperation.h
new file mode 100644
index 00000000..4f607c4f
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchArticleOperation.h
@@ -0,0 +1,45 @@
+//
+// MCMCNNTPFetchArticlesOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPFETCHARTICLEOPERATION_H
+
+#define MAILCORE_MCNNTPFETCHARTICLEOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+ class NNTPFetchArticleOperation : public NNTPOperation {
+ public:
+ NNTPFetchArticleOperation();
+ virtual ~NNTPFetchArticleOperation();
+
+ virtual void setGroupName(String * groupName);
+ virtual String * groupName();
+
+ virtual void setMessageIndex(unsigned int messageIndex);
+ virtual unsigned int messageIndex();
+
+ virtual Data * data();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ String * mGroupName;
+ unsigned int mMessageIndex;
+ Data * mData;
+
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPFetchArticlesOperation.cc b/src/async/nntp/MCNNTPFetchArticlesOperation.cc
new file mode 100644
index 00000000..39446f35
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchArticlesOperation.cc
@@ -0,0 +1,49 @@
+//
+// MCMCNNTPFetchArticlesOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPFetchArticlesOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+MCNNTPFetchArticlesOperation::MCNNTPFetchArticlesOperation()
+{
+ mGroupName = NULL;
+ mArticles = NULL;
+}
+
+MCNNTPFetchArticlesOperation::~MCNNTPFetchArticlesOperation()
+{
+ MC_SAFE_RELEASE(mGroupName);
+ MC_SAFE_RELEASE(mArticles);
+}
+
+void MCNNTPFetchArticlesOperation::setGroupName(String * groupname)
+{
+ MC_SAFE_REPLACE_COPY(String, mGroupName, groupname);
+}
+
+String * MCNNTPFetchArticlesOperation::groupName()
+{
+ return mGroupName;
+}
+
+IndexSet * MCNNTPFetchArticlesOperation::articles()
+{
+ return mArticles;
+}
+
+void MCNNTPFetchArticlesOperation::main()
+{
+ ErrorCode error;
+ mArticles = session()->session()->fetchArticles(mGroupName, &error);
+ setError(error);
+ MC_SAFE_RETAIN(mArticles);
+}
diff --git a/src/async/nntp/MCNNTPFetchArticlesOperation.h b/src/async/nntp/MCNNTPFetchArticlesOperation.h
new file mode 100644
index 00000000..fa0037c8
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchArticlesOperation.h
@@ -0,0 +1,41 @@
+//
+// MCMCNNTPFetchArticlesOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 8/13/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPFETCHARTICLESOPERATION_H
+
+#define MAILCORE_MCNNTPFETCHARTICLESOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class MCNNTPFetchArticlesOperation : public NNTPOperation {
+ public:
+ MCNNTPFetchArticlesOperation();
+ virtual ~MCNNTPFetchArticlesOperation();
+
+ virtual void setGroupName(String * groupName);
+ virtual String * groupName();
+
+ virtual IndexSet * articles();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ String * mGroupName;
+ IndexSet * mArticles;
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPFetchHeaderOperation.cc b/src/async/nntp/MCNNTPFetchHeaderOperation.cc
new file mode 100644
index 00000000..386dc142
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchHeaderOperation.cc
@@ -0,0 +1,59 @@
+//
+// 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::setGroupName(String * groupName) {
+ MC_SAFE_REPLACE_COPY(String, mGroupName, groupName);
+}
+
+String * NNTPFetchHeaderOperation::groupName() {
+ return mGroupName;
+}
+
+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(mGroupName, 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..97b12b05
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchHeaderOperation.h
@@ -0,0 +1,48 @@
+//
+// 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 setGroupName(String * groupName);
+ virtual String * groupName();
+
+ virtual void setMessageIndex(unsigned int messageIndex);
+ virtual unsigned int messageIndex();
+
+ virtual MessageHeader * header();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ String * mGroupName;
+ unsigned int mMessageIndex;
+ MessageHeader * mHeader;
+
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/async/nntp/MCNNTPListNewsgroupsOperation.cc b/src/async/nntp/MCNNTPListNewsgroupsOperation.cc
new file mode 100644
index 00000000..253b38d0
--- /dev/null
+++ b/src/async/nntp/MCNNTPListNewsgroupsOperation.cc
@@ -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.cc b/src/async/nntp/MCNNTPOperation.cc
new file mode 100644
index 00000000..3368ba0e
--- /dev/null
+++ b/src/async/nntp/MCNNTPOperation.cc
@@ -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