aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Robert Widmann <devteam.codafi@gmail.com>2014-10-21 17:31:59 -0600
committerGravatar Robert Widmann <devteam.codafi@gmail.com>2014-10-21 17:31:59 -0600
commit96f2623c2f1cba2fb5f625dbeae8a38eb20203c1 (patch)
treea11c883f368161e9d6f5b4600e66158eed90a502 /src
parentdb7ec6896ffa7e1072d814d02fee2c5abae22ff2 (diff)
XOVER
Diffstat (limited to 'src')
-rw-r--r--src/async/nntp/MCAsyncNNTP.h1
-rw-r--r--src/async/nntp/MCNNTPAsyncSession.cc25
-rw-r--r--src/async/nntp/MCNNTPAsyncSession.h8
-rw-r--r--src/async/nntp/MCNNTPFetchOverviewOperation.cc68
-rw-r--r--src/async/nntp/MCNNTPFetchOverviewOperation.h45
-rw-r--r--src/cmake/async.cmake1
-rw-r--r--src/cmake/objc.cmake1
-rw-r--r--src/cmake/public-headers.cmake2
-rw-r--r--src/core/nntp/MCNNTPSession.cc327
-rw-r--r--src/core/nntp/MCNNTPSession.h12
-rw-r--r--src/objc/nntp/MCONNTPFetchOverviewOperation.h32
-rw-r--r--src/objc/nntp/MCONNTPFetchOverviewOperation.mm69
-rw-r--r--src/objc/nntp/MCONNTPSession.h22
-rw-r--r--src/objc/nntp/MCONNTPSession.mm12
14 files changed, 611 insertions, 14 deletions
diff --git a/src/async/nntp/MCAsyncNNTP.h b/src/async/nntp/MCAsyncNNTP.h
index 56509ff8..618cd3d0 100644
--- a/src/async/nntp/MCAsyncNNTP.h
+++ b/src/async/nntp/MCAsyncNNTP.h
@@ -16,6 +16,7 @@
#include <MailCore/MCNNTPFetchArticleOperation.h>
#include <MailCore/MCNNTPFetchArticlesOperation.h>
#include <MailCore/MCNNTPListNewsgroupsOperation.h>
+#include <MailCore/MCNNTPFetchOverviewOperation.h>
#include <MailCore/MCNNTPOperationCallback.h>
#endif
diff --git a/src/async/nntp/MCNNTPAsyncSession.cc b/src/async/nntp/MCNNTPAsyncSession.cc
index a290b8d3..f250a23e 100644
--- a/src/async/nntp/MCNNTPAsyncSession.cc
+++ b/src/async/nntp/MCNNTPAsyncSession.cc
@@ -13,6 +13,7 @@
#include "MCNNTPFetchArticleOperation.h"
#include "MCNNTPFetchArticlesOperation.h"
#include "MCNNTPListNewsgroupsOperation.h"
+#include "MCNNTPFetchOverviewOperation.h"
#include "MCNNTPCheckAccountOperation.h"
#include "MCNNTPDisconnectOperation.h"
#include "MCOperationQueueCallback.h"
@@ -153,9 +154,9 @@ bool NNTPAsyncSession::isCheckCertificateEnabled()
return mSession->isCheckCertificateEnabled();
}
-MCNNTPFetchArticlesOperation * NNTPAsyncSession::fetchAllArticlesOperation(String * group)
+NNTPFetchArticlesOperation * NNTPAsyncSession::fetchAllArticlesOperation(String * group)
{
- MCNNTPFetchArticlesOperation * op = new MCNNTPFetchArticlesOperation();
+ NNTPFetchArticlesOperation * op = new NNTPFetchArticlesOperation();
op->setSession(this);
op->setGroupName(group);
op->autorelease();
@@ -182,6 +183,26 @@ NNTPFetchArticleOperation * NNTPAsyncSession::fetchArticleOperation(String * gro
return op;
}
+NNTPFetchArticleOperation * NNTPAsyncSession::fetchArticleByMessageIDOperation(String *groupName, String *messageID)
+{
+ NNTPFetchArticleOperation * op = new NNTPFetchArticleOperation();
+ op->setSession(this);
+ op->setGroupName(groupName);
+ op->setMessageID(messageID);
+ op->autorelease();
+ return op;
+}
+
+NNTPFetchOverviewOperation * NNTPAsyncSession::fetchOverviewOperationWithIndexes(String * groupName, IndexSet * indexes)
+{
+ NNTPFetchOverviewOperation * op = new NNTPFetchOverviewOperation();
+ op->setSession(this);
+ op->setGroupName(groupName);
+ op->setIndexes(indexes);
+ op->autorelease();
+ return op;
+}
+
NNTPListNewsgroupsOperation * NNTPAsyncSession::listAllNewsgroupsOperation()
{
NNTPListNewsgroupsOperation * op = new NNTPListNewsgroupsOperation();
diff --git a/src/async/nntp/MCNNTPAsyncSession.h b/src/async/nntp/MCNNTPAsyncSession.h
index d0fea2d0..b0686614 100644
--- a/src/async/nntp/MCNNTPAsyncSession.h
+++ b/src/async/nntp/MCNNTPAsyncSession.h
@@ -12,7 +12,8 @@ namespace mailcore {
class NNTPSession;
class NNTPFetchHeaderOperation;
class NNTPFetchArticleOperation;
- class MCNNTPFetchArticlesOperation;
+ class NNTPFetchArticlesOperation;
+ class NNTPFetchOverviewOperation;
class NNTPListNewsgroupsOperation;
class NNTPOperationQueueCallback;
class NNTPConnectionLogger;
@@ -51,11 +52,14 @@ namespace mailcore {
virtual dispatch_queue_t dispatchQueue();
#endif
- virtual MCNNTPFetchArticlesOperation * fetchAllArticlesOperation(String * group);
+ virtual NNTPFetchArticlesOperation * fetchAllArticlesOperation(String * group);
virtual NNTPFetchHeaderOperation * fetchHeaderOperation(String * groupName, unsigned int index);
virtual NNTPFetchArticleOperation * fetchArticleOperation(String *groupName, unsigned int index);
+ virtual NNTPFetchArticleOperation * fetchArticleByMessageIDOperation(String * groupname, String * messageID);
+
+ virtual NNTPFetchOverviewOperation * fetchOverviewOperationWithIndexes(String * groupName, IndexSet * indexes);
virtual NNTPListNewsgroupsOperation * listAllNewsgroupsOperation();
virtual NNTPListNewsgroupsOperation * listDefaultNewsgroupsOperation();
diff --git a/src/async/nntp/MCNNTPFetchOverviewOperation.cc b/src/async/nntp/MCNNTPFetchOverviewOperation.cc
new file mode 100644
index 00000000..9bd47fba
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchOverviewOperation.cc
@@ -0,0 +1,68 @@
+//
+// NNTPFetchOverviewOperation.cpp
+// mailcore2
+//
+// Created by Robert Widmann on 10/21/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCNNTPFetchOverviewOperation.h"
+
+#include "MCNNTPAsyncSession.h"
+#include "MCNNTPSession.h"
+
+using namespace mailcore;
+
+NNTPFetchOverviewOperation::NNTPFetchOverviewOperation()
+{
+ mArticles = NULL;
+ mIndexes = NULL;
+ mGroupName = NULL;
+}
+
+NNTPFetchOverviewOperation::~NNTPFetchOverviewOperation()
+{
+ MC_SAFE_RELEASE(mIndexes);
+ MC_SAFE_RELEASE(mGroupName);
+}
+
+void NNTPFetchOverviewOperation::setIndexes(IndexSet * indexes)
+{
+ MC_SAFE_REPLACE_RETAIN(IndexSet, mIndexes, indexes);
+}
+
+IndexSet * NNTPFetchOverviewOperation::indexes()
+{
+ return mIndexes;
+}
+
+void NNTPFetchOverviewOperation::setGroupName(String * groupname)
+{
+ MC_SAFE_REPLACE_COPY(String, mGroupName, groupname);
+}
+
+String * NNTPFetchOverviewOperation::groupName()
+{
+ return mGroupName;
+}
+
+Array * NNTPFetchOverviewOperation::articles() {
+ return mArticles;
+}
+
+void NNTPFetchOverviewOperation::main()
+{
+ ErrorCode error;
+ mArticles = Array::array();
+ for(unsigned int i = 0 ; i < mIndexes->rangesCount() ; i ++) {
+ Range range = mIndexes->allRanges()[i];
+ if (error != ErrorNone) {
+ setError(error);
+ mArticles->removeAllObjects();
+ return;
+ }
+ mArticles->addObjectsFromArray(session()->session()->fetchOverArticlesInRange(range, mGroupName, &error));
+ }
+
+ setError(error);
+}
diff --git a/src/async/nntp/MCNNTPFetchOverviewOperation.h b/src/async/nntp/MCNNTPFetchOverviewOperation.h
new file mode 100644
index 00000000..0582864d
--- /dev/null
+++ b/src/async/nntp/MCNNTPFetchOverviewOperation.h
@@ -0,0 +1,45 @@
+//
+// NNTPFetchOverviewOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 10/21/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCNNTPFETCHOVERVIEWOPERATION_H
+
+#define MAILCORE_MCNNTPFETCHOVERVIEWOPERATION_H
+
+#include <MailCore/MCNNTPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class NNTPFetchOverviewOperation : public NNTPOperation {
+ public:
+ NNTPFetchOverviewOperation();
+ virtual ~NNTPFetchOverviewOperation();
+
+ virtual void setIndexes(IndexSet * indexes);
+ virtual IndexSet * indexes();
+
+ virtual void setGroupName(String * groupName);
+ virtual String * groupName();
+
+ virtual Array * articles();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ IndexSet * mIndexes;
+ String * mGroupName;
+ Array * /* NNTPGroupInfo */ mArticles;
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/cmake/async.cmake b/src/cmake/async.cmake
index e38bffe2..22a7d1ba 100644
--- a/src/cmake/async.cmake
+++ b/src/cmake/async.cmake
@@ -60,6 +60,7 @@ set(async_nntp_files
async/nntp/MCNNTPFetchArticlesOperation.cc
async/nntp/MCNNTPFetchHeaderOperation.cc
async/nntp/MCNNTPListNewsgroupsOperation.cc
+ async/nntp/MCNNTPFetchOverviewOperation.cc
async/nntp/MCNNTPOperation.cc
)
diff --git a/src/cmake/objc.cmake b/src/cmake/objc.cmake
index af1cfcf5..f9e11b42 100644
--- a/src/cmake/objc.cmake
+++ b/src/cmake/objc.cmake
@@ -81,6 +81,7 @@ set(objc_nntp_files
objc/nntp/MCONNTPFetchHeaderOperation.mm
objc/nntp/MCONNTPGroupInfo.mm
objc/nntp/MCONNTPListNewsgroupsOperation.mm
+ objc/nntp/MCONNTPFetchOverviewOperation.mm
objc/nntp/MCONNTPOperation.mm
objc/nntp/MCONNTPSession.mm
)
diff --git a/src/cmake/public-headers.cmake b/src/cmake/public-headers.cmake
index 705fbc66..5c1c6b79 100644
--- a/src/cmake/public-headers.cmake
+++ b/src/cmake/public-headers.cmake
@@ -111,6 +111,7 @@ async/nntp/MCNNTPFetchArticleOperation.h
async/nntp/MCNNTPFetchArticlesOperation.h
async/nntp/MCNNTPFetchHeaderOperation.h
async/nntp/MCNNTPListNewsgroupsOperation.h
+async/nntp/MCNNTPFetchOverviewOperation.h
async/nntp/MCNNTPOperation.h
async/nntp/MCNNTPOperationCallback.h
objc/MCObjC.h
@@ -193,6 +194,7 @@ objc/nntp/MCONNTPFetchHeaderOperation.h
objc/nntp/MCONNTPFetchHeaderOperation.mm
objc/nntp/MCONNTPGroupInfo.h
objc/nntp/MCONNTPListNewsgroupsOperation.h
+objc/nntp/MCONNTPFetchOverviewOperation.h
objc/nntp/MCONNTPOperation.h
objc/nntp/MCONNTPSession.h
objc/provider/MCOProvider.h
diff --git a/src/core/nntp/MCNNTPSession.cc b/src/core/nntp/MCNNTPSession.cc
index a1a4646b..2374da41 100644
--- a/src/core/nntp/MCNNTPSession.cc
+++ b/src/core/nntp/MCNNTPSession.cc
@@ -21,6 +21,8 @@
using namespace mailcore;
+static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, struct mailimf_fields ** result);
+
enum {
STATE_DISCONNECTED,
STATE_CONNECTED,
@@ -466,6 +468,72 @@ Data * NNTPSession::fetchArticle(String *groupName, unsigned int index, NNTPProg
return result;
}
+Data * NNTPSession::fetchArticleByMessageID(String * groupName, String * messageID, ErrorCode * pError)
+{
+ int r;
+ char * msgID;
+ char * content;
+ size_t content_len;
+
+ MCLog("fetch article at message-id %s", messageID->UTF8Characters());
+
+ loginIfNeeded(pError);
+ if (* pError != ErrorNone) {
+ return NULL;
+ }
+
+ selectGroup(groupName, pError);
+ if (* pError != ErrorNone) {
+ return NULL;
+ }
+
+ msgID = strdup(messageID->UTF8Characters());
+
+ r = newsnntp_article_by_message_id(mNNTP, msgID, &content, &content_len);
+ if (r == NEWSNNTP_ERROR_STREAM) {
+ * pError = ErrorConnection;
+ return NULL;
+ }
+ else if (r != NEWSNNTP_NO_ERROR) {
+ * pError = ErrorFetchMessageList;
+ return NULL;
+ }
+
+ Data * result;
+ result = Data::dataWithBytes(content, (unsigned int) content_len);
+ newsnntp_article_free(content);
+ * pError = ErrorNone;
+
+ return result;
+}
+
+time_t NNTPSession::fetchServerClock(ErrorCode * pError) {
+ int r;
+ struct tm time;
+ time_t result;
+
+ loginIfNeeded(pError);
+ if (* pError != ErrorNone) {
+ return NULL;
+ }
+
+ r = newsnntp_date(mNNTP, &time);
+
+ if (r == NEWSNNTP_ERROR_STREAM) {
+ * pError = ErrorConnection;
+ return NULL;
+ }
+ else if (r != NEWSNNTP_NO_ERROR) {
+ * pError = ErrorBadResponse;
+ return NULL;
+ }
+
+ result = timegm(&time);
+ * pError = ErrorNone;
+
+ return result;
+}
+
IndexSet * NNTPSession::fetchAllArticles(String * groupName, ErrorCode * pError)
{
int r;
@@ -515,7 +583,7 @@ Array * NNTPSession::fetchOverArticlesInRange(Range range, String * groupName, E
if (* pError != ErrorNone) {
return NULL;
}
- r = newsnntp_xover_range(mNNTP, range.location, range.location + range.length, &msg_list);
+ r = newsnntp_xover_range(mNNTP, (uint32_t) range.location, (uint32_t) (range.location + range.length), &msg_list);
if (r == NEWSNNTP_ERROR_STREAM) {
* pError = ErrorConnection;
return NULL;
@@ -525,17 +593,30 @@ Array * NNTPSession::fetchOverArticlesInRange(Range range, String * groupName, E
return NULL;
}
+ Array * result = Array::array();
clistiter * iter;
for(iter = clist_begin(msg_list) ;iter != NULL ; iter = clist_next(iter)) {
struct newsnntp_xover_resp_item * item;
+ struct mailimf_fields * fields = NULL;
- item = clist_content(cur);
- if (!msg_info) {
+ item = (struct newsnntp_xover_resp_item *) clist_content(iter);
+ if (!item) {
continue;
}
- result->addIndex(*msg_info);
+ r = xover_resp_to_fields(item, &fields);
+ if (r == MAIL_NO_ERROR) {
+ MessageHeader * header = new MessageHeader();
+ header->importIMFFields(fields);
+ result->addObject(header);
+ header->release();
+ }
}
+
+ newsnntp_xover_resp_list_free(msg_list);
+ * pError = ErrorNone;
+
+ return result;
}
void NNTPSession::selectGroup(String * folder, ErrorCode * pError)
@@ -577,3 +658,241 @@ ConnectionLogger * NNTPSession::connectionLogger()
{
return mConnectionLogger;
}
+
+// Taken from nntp/nntpdriver.c
+static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, struct mailimf_fields ** result)
+{
+ size_t cur_token;
+ clist * list;
+ struct mailimf_fields * fields;
+ int r;
+
+ list = clist_new();
+ if (list == NULL) {
+ r = MAIL_ERROR_MEMORY;
+ goto err;
+ }
+
+ if (item->ovr_subject != NULL) {
+ char * subject_str;
+ struct mailimf_subject * subject;
+ struct mailimf_field * field;
+
+ subject_str = strdup(item->ovr_subject);
+ if (subject_str == NULL) {
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ subject = mailimf_subject_new(subject_str);
+ if (subject == NULL) {
+ free(subject_str);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ field = mailimf_field_new(MAILIMF_FIELD_SUBJECT,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, subject, NULL, NULL, NULL);
+ if (field == NULL) {
+ mailimf_subject_free(subject);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ r = clist_append(list, field);
+ if (r < 0) {
+ mailimf_field_free(field);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+ }
+
+ if (item->ovr_author != NULL) {
+ struct mailimf_mailbox_list * mb_list;
+ struct mailimf_from * from;
+ struct mailimf_field * field;
+
+ cur_token = 0;
+ r = mailimf_mailbox_list_parse(item->ovr_author, strlen(item->ovr_author),
+ &cur_token, &mb_list);
+ switch (r) {
+ case MAILIMF_NO_ERROR:
+ from = mailimf_from_new(mb_list);
+ if (from == NULL) {
+ mailimf_mailbox_list_free(mb_list);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ field = mailimf_field_new(MAILIMF_FIELD_FROM,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, from,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL);
+ if (field == NULL) {
+ mailimf_from_free(from);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ r = clist_append(list, field);
+ if (r < 0) {
+ mailimf_field_free(field);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+ break;
+
+ case MAILIMF_ERROR_PARSE:
+ break;
+
+ default:
+ goto free_list;
+ }
+ }
+
+ if (item->ovr_date != NULL) {
+ struct mailimf_date_time * date_time;
+ struct mailimf_orig_date * orig_date;
+ struct mailimf_field * field;
+
+ cur_token = 0;
+ r = mailimf_date_time_parse(item->ovr_date, strlen(item->ovr_date),
+ &cur_token, &date_time);
+ switch (r) {
+ case MAILIMF_NO_ERROR:
+ orig_date = mailimf_orig_date_new(date_time);
+ if (orig_date == NULL) {
+ mailimf_date_time_free(date_time);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ field = mailimf_field_new(MAILIMF_FIELD_ORIG_DATE,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, orig_date, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL);
+ if (field == NULL) {
+ mailimf_orig_date_free(orig_date);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ r = clist_append(list, field);
+ if (r < 0) {
+ mailimf_field_free(field);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+ break;
+
+ case MAILIMF_ERROR_PARSE:
+ break;
+
+ default:
+ goto free_list;
+ }
+ }
+
+ if (item->ovr_message_id != NULL) {
+ char * msgid_str;
+ struct mailimf_message_id * msgid;
+ struct mailimf_field * field;
+
+ cur_token = 0;
+ r = mailimf_msg_id_parse(item->ovr_message_id, strlen(item->ovr_message_id),
+ &cur_token, &msgid_str);
+
+ switch (r) {
+ case MAILIMF_NO_ERROR:
+ msgid = mailimf_message_id_new(msgid_str);
+ if (msgid == NULL) {
+ mailimf_msg_id_free(msgid_str);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ field = mailimf_field_new(MAILIMF_FIELD_MESSAGE_ID,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, msgid, NULL,
+ NULL, NULL, NULL, NULL, NULL);
+
+ r = clist_append(list, field);
+ if (r < 0) {
+ mailimf_field_free(field);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+ break;
+
+ case MAILIMF_ERROR_PARSE:
+ break;
+
+ default:
+ goto free_list;
+ }
+ }
+
+ if (item->ovr_references != NULL) {
+ clist * msgid_list;
+ struct mailimf_references * references;
+ struct mailimf_field * field;
+
+ cur_token = 0;
+
+ r = mailimf_msg_id_list_parse(item->ovr_references, strlen(item->ovr_references),
+ &cur_token, &msgid_list);
+
+ switch (r) {
+ case MAILIMF_NO_ERROR:
+ references = mailimf_references_new(msgid_list);
+ if (references == NULL) {
+ clist_foreach(msgid_list,
+ (clist_func) mailimf_msg_id_free, NULL);
+ clist_free(msgid_list);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ field = mailimf_field_new(MAILIMF_FIELD_REFERENCES,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ references, NULL, NULL, NULL, NULL);
+
+ r = clist_append(list, field);
+ if (r < 0) {
+ mailimf_field_free(field);
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ case MAILIMF_ERROR_PARSE:
+ break;
+
+ default:
+ goto free_list;
+ }
+ }
+
+ fields = mailimf_fields_new(list);
+ if (fields == NULL) {
+ r = MAIL_ERROR_MEMORY;
+ goto free_list;
+ }
+
+ * result = fields;
+
+ return MAIL_NO_ERROR;
+
+free_list:
+ clist_foreach(list, (clist_func) mailimf_field_free, NULL);
+ clist_free(list);
+err:
+ return r;
+}
diff --git a/src/core/nntp/MCNNTPSession.h b/src/core/nntp/MCNNTPSession.h
index e5ebbd91..84a6fb4e 100644
--- a/src/core/nntp/MCNNTPSession.h
+++ b/src/core/nntp/MCNNTPSession.h
@@ -47,13 +47,15 @@ namespace mailcore {
virtual Array * /* NNTPGroupInfo */ listAllNewsgroups(ErrorCode * pError);
virtual Array * listDefaultNewsgroups(ErrorCode * pError);
- virtual MessageHeader * fetchHeader(String *groupName, unsigned int index, ErrorCode * pError);
-
+ virtual MessageHeader * fetchHeader(String * groupName, unsigned int index, ErrorCode * pError);
+ virtual Array /*MessageHeader*/ * fetchOverArticlesInRange(Range range, String * groupname, ErrorCode * pError);
+
virtual IndexSet * fetchAllArticles(String * groupname, ErrorCode * pError);
+
+ virtual Data * fetchArticle(String *groupName, unsigned int index, NNTPProgressCallback * callback, ErrorCode * pError);
+ virtual Data * fetchArticleByMessageID(String * groupname, String * messageID, ErrorCode * pError);
- virtual Array * fetchOverArticlesInRange(Range range, String * groupname, ErrorCode * pError);
-
- Data * fetchArticle(String *groupName, unsigned int index, NNTPProgressCallback * callback, ErrorCode * pError);
+ virtual time_t fetchServerClock(ErrorCode * pError);
virtual void setConnectionLogger(ConnectionLogger * logger);
virtual ConnectionLogger * connectionLogger();
diff --git a/src/objc/nntp/MCONNTPFetchOverviewOperation.h b/src/objc/nntp/MCONNTPFetchOverviewOperation.h
new file mode 100644
index 00000000..d63668e8
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchOverviewOperation.h
@@ -0,0 +1,32 @@
+//
+// MCONNTPFetchOverviewOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 10/21/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPFETCHOVERVIEWOPERATION_H
+
+#define MAILCORE_MCONNTPFETCHOVERVIEWOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+@interface MCONNTPFetchOverviewOperation : 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 MCOMessageHeaders
+
+ - 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 * /* MCOMessageHeader */ messages))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPFetchOverviewOperation.mm b/src/objc/nntp/MCONNTPFetchOverviewOperation.mm
new file mode 100644
index 00000000..60bf2161
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchOverviewOperation.mm
@@ -0,0 +1,69 @@
+//
+// MCONNTPFetchOverviewOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 10/21/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPFetchOverviewOperation.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOUtils.h"
+#import "MCOOperation+Private.h"
+
+typedef void (^CompletionType)(NSError *error, NSArray * groups);
+
+@implementation MCONNTPFetchOverviewOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::NNTPFetchOverviewOperation
+
++ (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->articles()));
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end \ No newline at end of file
diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h
index 8b632647..c5fb04cc 100644
--- a/src/objc/nntp/MCONNTPSession.h
+++ b/src/objc/nntp/MCONNTPSession.h
@@ -20,7 +20,9 @@
@class MCONNTPFetchHeaderOperation;
@class MCONNTPFetchArticleOperation;
@class MCONNTPListNewsgroupsOperation;
+@class MCONNTPFetchOverviewOperation;
@class MCONNTPOperation;
+@class MCOIndexSet;
/** This class implements asynchronous access to the NNTP protocol.*/
@@ -85,6 +87,16 @@
- (MCONNTPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index inGroup:(NSString *)group;
/**
+ Returns an operation that will fetch an overview (headers) for a set of messages.
+
+ MCONNTPFetchHeaderOperation * op = [session fetchOverviewOperationWithIndexes:indexes inGroup:@"Group"];
+ [op start:^(NSError * error, NSArray * headers) {
+ // headers are the parsed headers of each part of the overview.
+ }];
+ */
+- (MCONNTPFetchOverviewOperation *)fetchOverviewOperationWithIndexes:(MCOIndexSet *)indexes inGroup:(NSString *)group;
+
+/**
Returns an operation that will fetch the content of the given message.
MCONNTPFetchArticleOperation * op = [session fetchArticleOperationWithIndex:idx inGroup:@"Group"];
@@ -95,6 +107,16 @@
- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithIndex:(unsigned int)index inGroup:(NSString *)group;
/**
+ Returns an operation that will fetch the content of a message with the given messageID.
+
+ MCONNTPFetchArticleOperation * op = [session fetchArticleOperationWithMessageID:@"<26>" inGroup:@"Group"];
+ [op start:^(NSError * error, NSData * messageData) {
+ // messageData is the RFC 822 formatted message data.
+ }];
+ */
+- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithMessageID:(NSString *)messageID inGroup:(NSString *)group;
+
+/**
Returns an operation that will list all available newsgroups.
MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation];
diff --git a/src/objc/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm
index ed5bd81d..094c5886 100644
--- a/src/objc/nntp/MCONNTPSession.mm
+++ b/src/objc/nntp/MCONNTPSession.mm
@@ -124,7 +124,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
- (MCONNTPFetchArticlesOperation *) fetchAllArticlesOperation:(NSString *)group
{
- mailcore::MCNNTPFetchArticlesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchAllArticlesOperation(MCO_FROM_OBJC(mailcore::String, group));
+ mailcore::NNTPFetchArticlesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchAllArticlesOperation(MCO_FROM_OBJC(mailcore::String, group));
return MCO_TO_OBJC_OP(coreOp);
}
@@ -140,6 +140,16 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return MCO_TO_OBJC_OP(coreOp);
}
+- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithMessageID:(NSString *)messageID inGroup:(NSString *)group {
+ mailcore::NNTPFetchArticleOperation * coreOp = MCO_NATIVE_INSTANCE->fetchArticleByMessageIDOperation(MCO_FROM_OBJC(mailcore::String, group), MCO_FROM_OBJC(mailcore::String, messageID));
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCONNTPFetchOverviewOperation *)fetchOverviewOperationWithIndexes:(MCOIndexSet *)indexes inGroup:(NSString *)group {
+ mailcore::NNTPFetchOverviewOperation * coreOp = MCO_NATIVE_INSTANCE->fetchOverviewOperationWithIndexes(MCO_FROM_OBJC(mailcore::String, group), MCO_FROM_OBJC(mailcore::IndexSet, indexes));
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
- (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation {
mailcore::NNTPListNewsgroupsOperation * coreOp = MCO_NATIVE_INSTANCE->listAllNewsgroupsOperation();
return MCO_TO_OBJC_OP(coreOp);