diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-10-25 09:12:24 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-10-25 09:12:24 -0700 |
commit | cd37682217b0dafacfe02a3a3d64e2c80a329cce (patch) | |
tree | f241bc5de3a9855d1a94d9be80b8798b7ad37a69 /src | |
parent | 128a11a36103c3a57372cf72a51e52744524d827 (diff) | |
parent | 386f84abe048c4b37cef42195d612b480021df3f (diff) |
Merge branch 'master' into removing-icu-dependency
Diffstat (limited to 'src')
38 files changed, 1055 insertions, 89 deletions
diff --git a/src/async/nntp/MCAsyncNNTP.h b/src/async/nntp/MCAsyncNNTP.h index 56509ff8..914cc754 100644 --- a/src/async/nntp/MCAsyncNNTP.h +++ b/src/async/nntp/MCAsyncNNTP.h @@ -14,8 +14,10 @@ #include <MailCore/MCNNTPOperation.h> #include <MailCore/MCNNTPFetchHeaderOperation.h> #include <MailCore/MCNNTPFetchArticleOperation.h> -#include <MailCore/MCNNTPFetchArticlesOperation.h> +#include <MailCore/MCNNTPFetchAllArticlesOperation.h> #include <MailCore/MCNNTPListNewsgroupsOperation.h> +#include <MailCore/MCNNTPFetchOverviewOperation.h> +#include <MailCore/MCNNTPFetchServerTimeOperation.h> #include <MailCore/MCNNTPOperationCallback.h> #endif diff --git a/src/async/nntp/MCNNTPAsyncSession.cc b/src/async/nntp/MCNNTPAsyncSession.cc index 833bf4d5..a78a70b4 100644 --- a/src/async/nntp/MCNNTPAsyncSession.cc +++ b/src/async/nntp/MCNNTPAsyncSession.cc @@ -11,9 +11,11 @@ #include "MCNNTP.h" #include "MCNNTPFetchHeaderOperation.h" #include "MCNNTPFetchArticleOperation.h" -#include "MCNNTPFetchArticlesOperation.h" +#include "MCNNTPFetchAllArticlesOperation.h" #include "MCNNTPListNewsgroupsOperation.h" +#include "MCNNTPFetchOverviewOperation.h" #include "MCNNTPCheckAccountOperation.h" +#include "MCNNTPFetchServerTimeOperation.h" #include "MCNNTPDisconnectOperation.h" #include "MCOperationQueueCallback.h" #include "MCConnectionLogger.h" @@ -153,9 +155,9 @@ bool NNTPAsyncSession::isCheckCertificateEnabled() return mSession->isCheckCertificateEnabled(); } -MCNNTPFetchArticlesOperation * NNTPAsyncSession::fetchArticlesOperation(String * group) +NNTPFetchAllArticlesOperation * NNTPAsyncSession::fetchAllArticlesOperation(String * group) { - MCNNTPFetchArticlesOperation * op = new MCNNTPFetchArticlesOperation(); + NNTPFetchAllArticlesOperation * op = new NNTPFetchAllArticlesOperation(); op->setSession(this); op->setGroupName(group); op->autorelease(); @@ -182,6 +184,34 @@ 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; +} + +NNTPFetchServerTimeOperation * NNTPAsyncSession::fetchServerDateOperation() +{ + NNTPFetchServerTimeOperation * op = new NNTPFetchServerTimeOperation(); + op->setSession(this); + op->autorelease(); + return op; +} + NNTPListNewsgroupsOperation * NNTPAsyncSession::listAllNewsgroupsOperation() { NNTPListNewsgroupsOperation * op = new NNTPListNewsgroupsOperation(); @@ -191,7 +221,7 @@ NNTPListNewsgroupsOperation * NNTPAsyncSession::listAllNewsgroupsOperation() return op; } -NNTPListNewsgroupsOperation * NNTPAsyncSession::listSubscribedNewsgroupsOperation() +NNTPListNewsgroupsOperation * NNTPAsyncSession::listDefaultNewsgroupsOperation() { NNTPListNewsgroupsOperation * op = new NNTPListNewsgroupsOperation(); op->setSession(this); diff --git a/src/async/nntp/MCNNTPAsyncSession.h b/src/async/nntp/MCNNTPAsyncSession.h index 66f0cc0d..d18ea119 100644 --- a/src/async/nntp/MCNNTPAsyncSession.h +++ b/src/async/nntp/MCNNTPAsyncSession.h @@ -12,8 +12,10 @@ namespace mailcore { class NNTPSession; class NNTPFetchHeaderOperation; class NNTPFetchArticleOperation; - class MCNNTPFetchArticlesOperation; + class NNTPFetchAllArticlesOperation; + class NNTPFetchOverviewOperation; class NNTPListNewsgroupsOperation; + class NNTPFetchServerTimeOperation; class NNTPOperationQueueCallback; class NNTPConnectionLogger; @@ -51,14 +53,19 @@ namespace mailcore { virtual dispatch_queue_t dispatchQueue(); #endif - virtual MCNNTPFetchArticlesOperation * fetchArticlesOperation(String * group); + virtual NNTPFetchAllArticlesOperation * 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 NNTPFetchServerTimeOperation * fetchServerDateOperation(); virtual NNTPListNewsgroupsOperation * listAllNewsgroupsOperation(); - virtual NNTPListNewsgroupsOperation * listSubscribedNewsgroupsOperation(); + virtual NNTPListNewsgroupsOperation * listDefaultNewsgroupsOperation(); virtual NNTPOperation * disconnectOperation(); diff --git a/src/async/nntp/MCNNTPFetchArticlesOperation.cc b/src/async/nntp/MCNNTPFetchAllArticlesOperation.cc index 39446f35..044e9e5e 100644 --- a/src/async/nntp/MCNNTPFetchArticlesOperation.cc +++ b/src/async/nntp/MCNNTPFetchAllArticlesOperation.cc @@ -1,49 +1,49 @@ // -// MCMCNNTPFetchArticlesOperation.cpp +// MCNNTPFetchAllArticlesOperation.cpp // mailcore2 // // Created by Robert Widmann on 8/13/14. // Copyright (c) 2014 MailCore. All rights reserved. // -#include "MCNNTPFetchArticlesOperation.h" +#include "MCNNTPFetchAllArticlesOperation.h" #include "MCNNTPAsyncSession.h" #include "MCNNTPSession.h" using namespace mailcore; -MCNNTPFetchArticlesOperation::MCNNTPFetchArticlesOperation() +NNTPFetchAllArticlesOperation::NNTPFetchAllArticlesOperation() { mGroupName = NULL; mArticles = NULL; } -MCNNTPFetchArticlesOperation::~MCNNTPFetchArticlesOperation() +NNTPFetchAllArticlesOperation::~NNTPFetchAllArticlesOperation() { MC_SAFE_RELEASE(mGroupName); MC_SAFE_RELEASE(mArticles); } -void MCNNTPFetchArticlesOperation::setGroupName(String * groupname) +void NNTPFetchAllArticlesOperation::setGroupName(String * groupname) { MC_SAFE_REPLACE_COPY(String, mGroupName, groupname); } -String * MCNNTPFetchArticlesOperation::groupName() +String * NNTPFetchAllArticlesOperation::groupName() { return mGroupName; } -IndexSet * MCNNTPFetchArticlesOperation::articles() +IndexSet * NNTPFetchAllArticlesOperation::articles() { return mArticles; } -void MCNNTPFetchArticlesOperation::main() +void NNTPFetchAllArticlesOperation::main() { ErrorCode error; - mArticles = session()->session()->fetchArticles(mGroupName, &error); + mArticles = session()->session()->fetchAllArticles(mGroupName, &error); setError(error); MC_SAFE_RETAIN(mArticles); } diff --git a/src/async/nntp/MCNNTPFetchArticlesOperation.h b/src/async/nntp/MCNNTPFetchAllArticlesOperation.h index fa0037c8..88395dee 100644 --- a/src/async/nntp/MCNNTPFetchArticlesOperation.h +++ b/src/async/nntp/MCNNTPFetchAllArticlesOperation.h @@ -1,5 +1,5 @@ // -// MCMCNNTPFetchArticlesOperation.h +// MCNNTPFetchAllArticlesOperation.h // mailcore2 // // Created by Robert Widmann on 8/13/14. @@ -16,10 +16,10 @@ namespace mailcore { - class MCNNTPFetchArticlesOperation : public NNTPOperation { + class NNTPFetchAllArticlesOperation : public NNTPOperation { public: - MCNNTPFetchArticlesOperation(); - virtual ~MCNNTPFetchArticlesOperation(); + NNTPFetchAllArticlesOperation(); + virtual ~NNTPFetchAllArticlesOperation(); virtual void setGroupName(String * groupName); virtual String * groupName(); diff --git a/src/async/nntp/MCNNTPFetchArticleOperation.cc b/src/async/nntp/MCNNTPFetchArticleOperation.cc index a12f346f..1df0dc33 100644 --- a/src/async/nntp/MCNNTPFetchArticleOperation.cc +++ b/src/async/nntp/MCNNTPFetchArticleOperation.cc @@ -1,5 +1,5 @@ // -// MCMCNNTPFetchArticlesOperation.cpp +// MCNNTPFetchArticleOperation.cpp // mailcore2 // // Created by Robert Widmann on 8/13/14. @@ -32,6 +32,14 @@ String * NNTPFetchArticleOperation::groupName() { return mGroupName; } +void NNTPFetchArticleOperation::setMessageID(String * groupName) { + MC_SAFE_REPLACE_COPY(String, mMessageID, groupName); +} + +String * NNTPFetchArticleOperation::messageID() { + return mMessageID; +} + void NNTPFetchArticleOperation::setMessageIndex(unsigned int messageIndex) { mMessageIndex = messageIndex; @@ -50,7 +58,11 @@ Data * NNTPFetchArticleOperation::data() void NNTPFetchArticleOperation::main() { ErrorCode error; - mData = session()->session()->fetchArticle(mGroupName, mMessageIndex, this, &error); + if (mMessageID == NULL) { + mData = session()->session()->fetchArticle(mGroupName, mMessageIndex, this, &error); + } else { + mData = session()->session()->fetchArticleByMessageID(mGroupName, mMessageID, &error); + } MC_SAFE_RETAIN(mData); setError(error); } diff --git a/src/async/nntp/MCNNTPFetchArticleOperation.h b/src/async/nntp/MCNNTPFetchArticleOperation.h index 4f607c4f..7b11ae16 100644 --- a/src/async/nntp/MCNNTPFetchArticleOperation.h +++ b/src/async/nntp/MCNNTPFetchArticleOperation.h @@ -1,5 +1,5 @@ // -// MCMCNNTPFetchArticlesOperation.h +// MCNNTPFetchArticleOperation.h // mailcore2 // // Created by Robert Widmann on 8/13/14. @@ -23,6 +23,9 @@ namespace mailcore { virtual void setGroupName(String * groupName); virtual String * groupName(); + virtual void setMessageID(String * groupName); + virtual String * messageID(); + virtual void setMessageIndex(unsigned int messageIndex); virtual unsigned int messageIndex(); @@ -33,6 +36,7 @@ namespace mailcore { private: String * mGroupName; + String * mMessageID; unsigned int mMessageIndex; Data * mData; diff --git a/src/async/nntp/MCNNTPFetchOverviewOperation.cc b/src/async/nntp/MCNNTPFetchOverviewOperation.cc new file mode 100644 index 00000000..b05b29e6 --- /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]; + Array * articles = session()->session()->fetchOverArticlesInRange(range, mGroupName, &error); + if (error != ErrorNone) { + setError(error); + return; + } + mArticles->addObjectsFromArray(articles); + } + + setError(error); +} diff --git a/src/async/nntp/MCNNTPFetchOverviewOperation.h b/src/async/nntp/MCNNTPFetchOverviewOperation.h new file mode 100644 index 00000000..aab8d24b --- /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 * /* MessageHeader */ mArticles; + }; + +} + +#endif + +#endif diff --git a/src/async/nntp/MCNNTPFetchServerTimeOperation.cc b/src/async/nntp/MCNNTPFetchServerTimeOperation.cc new file mode 100644 index 00000000..86800733 --- /dev/null +++ b/src/async/nntp/MCNNTPFetchServerTimeOperation.cc @@ -0,0 +1,34 @@ +// +// MCNNTPFetchServerTimeOperation.cpp +// mailcore2 +// +// Created by Robert Widmann on 10/21/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include "MCNNTPFetchServerTimeOperation.h" + +#include "MCNNTPAsyncSession.h" +#include "MCNNTPSession.h" + +using namespace mailcore; + +NNTPFetchServerTimeOperation::NNTPFetchServerTimeOperation() +{ +} + +NNTPFetchServerTimeOperation::~NNTPFetchServerTimeOperation() +{ +} + +time_t NNTPFetchServerTimeOperation::time() +{ + return mTime; +} + +void NNTPFetchServerTimeOperation::main() +{ + ErrorCode error; + mTime = session()->session()->fetchServerDate(&error); + setError(error); +} diff --git a/src/async/nntp/MCNNTPFetchServerTimeOperation.h b/src/async/nntp/MCNNTPFetchServerTimeOperation.h new file mode 100644 index 00000000..22cebf25 --- /dev/null +++ b/src/async/nntp/MCNNTPFetchServerTimeOperation.h @@ -0,0 +1,37 @@ +// +// MCNNTPFetchServerTimeOperation.h +// mailcore2 +// +// Created by Robert Widmann on 10/21/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#ifndef MAILCORE_MCNNTPFETCHSERVERTIMEOPERATION_H + +#define MAILCORE_MCNNTPFETCHSERVERTIMEOPERATION_H + +#include <MailCore/MCNNTPOperation.h> + +#ifdef __cplusplus + +namespace mailcore { + + class NNTPFetchServerTimeOperation : public NNTPOperation { + public: + NNTPFetchServerTimeOperation(); + virtual ~NNTPFetchServerTimeOperation(); + + virtual time_t time(); + + public: // subclass behavior + virtual void main(); + + private: + time_t mTime; + }; + +} + +#endif + +#endif diff --git a/src/async/nntp/MCNNTPListNewsgroupsOperation.cc b/src/async/nntp/MCNNTPListNewsgroupsOperation.cc index 253b38d0..3747bacf 100644 --- a/src/async/nntp/MCNNTPListNewsgroupsOperation.cc +++ b/src/async/nntp/MCNNTPListNewsgroupsOperation.cc @@ -40,7 +40,7 @@ void NNTPListNewsgroupsOperation::main() ErrorCode error; if (mListsSuscribed) { - mGroups = session()->session()->listSubscribedNewsgroups(&error); + mGroups = session()->session()->listDefaultNewsgroups(&error); } else { mGroups = session()->session()->listAllNewsgroups(&error); } diff --git a/src/cmake/async.cmake b/src/cmake/async.cmake index e38bffe2..58f410d4 100644 --- a/src/cmake/async.cmake +++ b/src/cmake/async.cmake @@ -57,9 +57,11 @@ set(async_nntp_files async/nntp/MCNNTPCheckAccountOperation.cc async/nntp/MCNNTPDisconnectOperation.cc async/nntp/MCNNTPFetchArticleOperation.cc - async/nntp/MCNNTPFetchArticlesOperation.cc + async/nntp/MCNNTPFetchAllArticlesOperation.cc async/nntp/MCNNTPFetchHeaderOperation.cc async/nntp/MCNNTPListNewsgroupsOperation.cc + async/nntp/MCNNTPFetchOverviewOperation.cc + async/nntp/MCNNTPFetchServerTimeOperation.cc async/nntp/MCNNTPOperation.cc ) diff --git a/src/cmake/core.cmake b/src/cmake/core.cmake index e69e4fc0..4b0782cf 100644 --- a/src/cmake/core.cmake +++ b/src/cmake/core.cmake @@ -14,6 +14,8 @@ IF(APPLE) core/basetypes/MCAutoreleasePoolMac.mm core/basetypes/MCMainThread.mm core/basetypes/MCObjectMac.mm + core/basetypes/MCDataMac.mm + core/rfc822/MCMessageParserMac.mm ) ENDIF() diff --git a/src/cmake/objc.cmake b/src/cmake/objc.cmake index af1cfcf5..de4d8d06 100644 --- a/src/cmake/objc.cmake +++ b/src/cmake/objc.cmake @@ -77,10 +77,12 @@ set(objc_smtp_files set(objc_nntp_files objc/nntp/MCONNTPDisconnectOperation.mm objc/nntp/MCONNTPFetchArticleOperation.mm - objc/nntp/MCONNTPFetchArticlesOperation.mm + objc/nntp/MCONNTPFetchAllArticlesOperation.mm objc/nntp/MCONNTPFetchHeaderOperation.mm objc/nntp/MCONNTPGroupInfo.mm objc/nntp/MCONNTPListNewsgroupsOperation.mm + objc/nntp/MCONNTPFetchOverviewOperation.mm + objc/nntp/MCONNTPFetchServerTimeOperation.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..8b55c15e 100644 --- a/src/cmake/public-headers.cmake +++ b/src/cmake/public-headers.cmake @@ -108,11 +108,13 @@ async/nntp/MCNNTPAsyncSession.h async/nntp/MCNNTPCheckAccountOperation.h async/nntp/MCNNTPDisconnectOperation.h async/nntp/MCNNTPFetchArticleOperation.h -async/nntp/MCNNTPFetchArticlesOperation.h +async/nntp/MCNNTPFetchAllArticlesOperation.h async/nntp/MCNNTPFetchHeaderOperation.h async/nntp/MCNNTPListNewsgroupsOperation.h +async/nntp/MCNNTPFetchOverviewOperation.h async/nntp/MCNNTPOperation.h async/nntp/MCNNTPOperationCallback.h +async/nntp/MCNNTPFetchServerTimeOperation.h objc/MCObjC.h objc/utils/MCOUtils.h objc/utils/MCOObjectWrapper.h @@ -186,13 +188,12 @@ objc/smtp/MCOSMTPOperation.h objc/nntp/MCONNTP.h objc/nntp/MCONNTPDisconnectOperation.h objc/nntp/MCONNTPFetchArticleOperation.h -objc/nntp/MCONNTPFetchArticleOperation.mm -objc/nntp/MCONNTPFetchArticlesOperation.h -objc/nntp/MCONNTPFetchArticlesOperation.mm +objc/nntp/MCONNTPFetchAllArticlesOperation.h objc/nntp/MCONNTPFetchHeaderOperation.h -objc/nntp/MCONNTPFetchHeaderOperation.mm objc/nntp/MCONNTPGroupInfo.h objc/nntp/MCONNTPListNewsgroupsOperation.h +objc/nntp/MCONNTPFetchOverviewOperation.h +objc/nntp/MCONNTPFetchServerTimeOperation.h objc/nntp/MCONNTPOperation.h objc/nntp/MCONNTPSession.h objc/provider/MCOProvider.h diff --git a/src/core/abstract/MCAbstractPart.cc b/src/core/abstract/MCAbstractPart.cc index 5b7a1c9a..04e99e4d 100644 --- a/src/core/abstract/MCAbstractPart.cc +++ b/src/core/abstract/MCAbstractPart.cc @@ -439,10 +439,11 @@ void AbstractPart::removeContentTypeParameter(String * name) String * AbstractPart::contentTypeParameterValueForName(String * name) { + String * result = NULL; mc_foreachhashmapKey(String, key, mContentTypeParameters) { if (key->isEqualCaseInsensitive(name)) { - return (String *) mContentTypeParameters->objectForKey(key); + result = (String *) mContentTypeParameters->objectForKey(key); } } - return NULL; + return result; } diff --git a/src/core/abstract/MCMessageConstants.h b/src/core/abstract/MCMessageConstants.h index c81f8360..1b45ea69 100644 --- a/src/core/abstract/MCMessageConstants.h +++ b/src/core/abstract/MCMessageConstants.h @@ -249,6 +249,7 @@ namespace mailcore { ErrorNoRecipient, ErrorNoop, ErrorGmailApplicationSpecificPasswordRequired, + ErrorServerDate, }; enum PartType { diff --git a/src/core/abstract/MCMessageHeader.cc b/src/core/abstract/MCMessageHeader.cc index 89dec15c..08b0f045 100644 --- a/src/core/abstract/MCMessageHeader.cc +++ b/src/core/abstract/MCMessageHeader.cc @@ -337,12 +337,13 @@ void MessageHeader::removeExtraHeader(String * name) String * MessageHeader::extraHeaderValueForName(String * name) { + String * result = NULL; mc_foreachhashmapKey(String, key, mExtraHeaders) { if (key->isEqualCaseInsensitive(name)) { - return (String *) mExtraHeaders->objectForKey(key); + result = (String *) mExtraHeaders->objectForKey(key); } } - return NULL; + return result; } String * MessageHeader::extractedSubject() diff --git a/src/core/basetypes/MCData.cc b/src/core/basetypes/MCData.cc index 13c5fd61..5f2282d9 100644 --- a/src/core/basetypes/MCData.cc +++ b/src/core/basetypes/MCData.cc @@ -68,6 +68,7 @@ Data::Data(const char * bytes, unsigned int length) { mBytes = NULL; reset(); + allocate(length); appendBytes(bytes, length); } @@ -482,6 +483,13 @@ String * Data::charsetWithFilteredHTML(bool filterHTML, String * hintCharset) #endif } +void Data::replaceWithAllocatedBytes(char * bytes, unsigned int length) +{ + free(mBytes); + mBytes = (char *) bytes; + mLength = length; +} + Data * Data::dataWithContentsOfFile(String * filename) { int r; @@ -511,8 +519,8 @@ Data * Data::dataWithContentsOfFile(String * filename) return NULL; } - data = Data::dataWithBytes(buf, (unsigned int) stat_buf.st_size); - free(buf); + data = Data::data(); + data->replaceWithAllocatedBytes(buf, (unsigned int) stat_buf.st_size); fclose(f); diff --git a/src/core/basetypes/MCData.h b/src/core/basetypes/MCData.h index 6ba056e7..131cb722 100644 --- a/src/core/basetypes/MCData.h +++ b/src/core/basetypes/MCData.h @@ -5,6 +5,10 @@ #include <MailCore/MCObject.h> #include <MailCore/MCMessageConstants.h> +#ifdef __APPLE__ +#import <CoreFoundation/CoreFoundation.h> +#endif + #ifdef __cplusplus namespace mailcore { @@ -41,6 +45,9 @@ namespace mailcore { public: // private virtual String * charsetWithFilteredHTML(bool filterHTML, String * hintCharset = NULL); +#ifdef __APPLE__ + virtual CFDataRef destructiveNSData(); +#endif public: // subclass behavior Data(Data * otherData); @@ -58,6 +65,7 @@ namespace mailcore { void allocate(unsigned int length); void reset(); String * charsetWithFilteredHTMLWithoutHint(bool filterHTML); + void replaceWithAllocatedBytes(char * bytes, unsigned int length); }; diff --git a/src/core/basetypes/MCDataMac.mm b/src/core/basetypes/MCDataMac.mm new file mode 100644 index 00000000..8081b1f9 --- /dev/null +++ b/src/core/basetypes/MCDataMac.mm @@ -0,0 +1,22 @@ +// +// MCDataMac.m +// mailcore2 +// +// Created by Hoa V. DINH on 10/24/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include "MCData.h" + +#import <Foundation/Foundation.h> + +using namespace mailcore; + +CFDataRef Data::destructiveNSData() +{ + NSData * result = [NSData dataWithBytesNoCopy:(void *) mBytes length:mLength]; + mBytes = NULL; + mAllocated = 0; + mLength = 0; + return (CFDataRef) result; +} diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc index de975d44..a122c1e6 100644 --- a/src/core/basetypes/MCString.cc +++ b/src/core/basetypes/MCString.cc @@ -753,6 +753,9 @@ String::String(const UChar * unicodeChars) { mUnicodeChars = NULL; reset(); + if (unicodeChars != NULL) { + allocate(u_strlen(unicodeChars)); + } appendCharacters(unicodeChars); } @@ -760,6 +763,7 @@ String::String(const UChar * unicodeChars, unsigned int length) { mUnicodeChars = NULL; reset(); + allocate(length); appendCharactersLength(unicodeChars, length); } @@ -788,6 +792,7 @@ String::String(const char * bytes, unsigned int length, const char * charset) { mUnicodeChars = NULL; reset(); + allocate(length); if (charset == NULL) { appendUTF8CharactersLength(bytes, length); } @@ -1966,6 +1971,7 @@ String * String::stripWhitespace() /* do nothing */ } + str->autorelease(); return str; } diff --git a/src/core/nntp/MCNNTPSession.cc b/src/core/nntp/MCNNTPSession.cc index 02db197e..3c7ea7a3 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, @@ -359,16 +361,17 @@ Array * NNTPSession::listAllNewsgroups(ErrorCode * pError) return result; } -Array * NNTPSession::listSubscribedNewsgroups(ErrorCode * pError) +Array * NNTPSession::listDefaultNewsgroups(ErrorCode * pError) { int r; clist * subd_groups; MCLog("fetch subscribed"); loginIfNeeded(pError); - if (* pError != ErrorNone) + if (* pError != ErrorNone) { return NULL; - + } + r = newsnntp_list_subscriptions(mNNTP, &subd_groups); MCLog("fetch subscribed %u", r); @@ -390,10 +393,11 @@ Array * NNTPSession::listSubscribedNewsgroups(ErrorCode * pError) } newsnntp_list_subscriptions_free(subd_groups); * pError = ErrorNone; - + return result; } + MessageHeader * NNTPSession::fetchHeader(String *groupName, unsigned int index, ErrorCode * pError) { int r; @@ -401,10 +405,6 @@ MessageHeader * NNTPSession::fetchHeader(String *groupName, unsigned int index, size_t content_len; MCLog("fetch header at index %u", index); - loginIfNeeded(pError); - if (* pError != ErrorNone) { - return NULL; - } selectGroup(groupName, pError); if (* pError != ErrorNone) { @@ -438,17 +438,46 @@ Data * NNTPSession::fetchArticle(String *groupName, unsigned int index, NNTPProg MCLog("fetch article at index %u", index); - loginIfNeeded(pError); + selectGroup(groupName, pError); if (* pError != ErrorNone) { return NULL; } + r = newsnntp_article(mNNTP, index, &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; +} + +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()); + selectGroup(groupName, pError); if (* pError != ErrorNone) { return NULL; } - r = newsnntp_article(mNNTP, index, &content, &content_len); + msgID = strdup(messageID->UTF8Characters()); + + r = newsnntp_article_by_message_id(mNNTP, msgID, &content, &content_len); if (r == NEWSNNTP_ERROR_STREAM) { * pError = ErrorConnection; return NULL; @@ -466,7 +495,34 @@ Data * NNTPSession::fetchArticle(String *groupName, unsigned int index, NNTPProg return result; } -IndexSet * NNTPSession::fetchArticles(String * groupName, ErrorCode * pError) +time_t NNTPSession::fetchServerDate(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 = ErrorServerDate; + return NULL; + } + + result = timegm(&time); + * pError = ErrorNone; + + return result; +} + +IndexSet * NNTPSession::fetchAllArticles(String * groupName, ErrorCode * pError) { int r; clist * msg_list; @@ -506,11 +562,61 @@ IndexSet * NNTPSession::fetchArticles(String * groupName, ErrorCode * pError) return result; } +Array * NNTPSession::fetchOverArticlesInRange(Range range, String * groupName, ErrorCode * pError) +{ + int r; + clist * msg_list; + + selectGroup(groupName, pError); + if (* pError != ErrorNone) { + return NULL; + } + 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; + } + else if (r != NEWSNNTP_NO_ERROR) { + * pError = ErrorFetchMessageList; + 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 = (struct newsnntp_xover_resp_item *) clist_content(iter); + if (!item) { + continue; + } + + 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) { int r; struct newsnntp_group_info * info; + loginIfNeeded(pError); + if (* pError != ErrorNone) { + return; + } + readerIfNeeded(pError); if (* pError != ErrorNone) { return; @@ -545,3 +651,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 a6fb511c..d410fdcf 100644 --- a/src/core/nntp/MCNNTPSession.h +++ b/src/core/nntp/MCNNTPSession.h @@ -45,13 +45,17 @@ namespace mailcore { virtual void checkAccount(ErrorCode * pError); virtual Array * /* NNTPGroupInfo */ listAllNewsgroups(ErrorCode * pError); - virtual Array * listSubscribedNewsgroups(ErrorCode * pError); + virtual Array * /* NNTPGroupInfo */ listDefaultNewsgroups(ErrorCode * pError); - virtual MessageHeader * fetchHeader(String *groupName, unsigned int index, ErrorCode * pError); - - virtual IndexSet * fetchArticles(String * groupname, 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); - Data * fetchArticle(String *groupName, unsigned int index, NNTPProgressCallback * callback, ErrorCode * pError); + virtual time_t fetchServerDate(ErrorCode * pError); virtual void setConnectionLogger(ConnectionLogger * logger); virtual ConnectionLogger * connectionLogger(); diff --git a/src/core/rfc822/MCMessageParser.cc b/src/core/rfc822/MCMessageParser.cc index 4eb6046e..404bc862 100644 --- a/src/core/rfc822/MCMessageParser.cc +++ b/src/core/rfc822/MCMessageParser.cc @@ -1,6 +1,9 @@ #include "MCMessageParser.h" #include <libetpan/libetpan.h> +#if __APPLE__ +#include <CoreFoundation/CoreFoundation.h> +#endif #include "MCAttachment.h" #include "MCMessageHeader.h" @@ -25,43 +28,43 @@ void MessageParser::init() { mData = NULL; mMainPart = NULL; +#if __APPLE__ + mNSData = NULL; +#endif } -MessageParser::MessageParser(Data * data) +void MessageParser::setBytes(char * dataBytes, unsigned int dataLength) { - init(); - const char * start = NULL; unsigned int length = 0; - if (data->length() > 5) { - if (strncmp(data->bytes(), "From ", 5) == 0) { - start = data->bytes(); - for(unsigned int i = 0 ; i < data->length() ; i ++) { + if (dataLength > 5) { + if (strncmp(dataBytes, "From ", 5) == 0) { + start = dataBytes; + for(unsigned int i = 0 ; i < dataLength ; i ++) { if (start[i] == '\n') { start = start + i + 1; - length = data->length() - (i + 1); + length = dataLength - (i + 1); break; } } } } if (start != NULL) { - data = Data::dataWithBytes(start, length); + dataBytes = (char *) start; + dataLength = length; } - mData = (Data *) data->retain(); - mailmessage * msg; struct mailmime * mime; - msg = data_message_init(data->bytes(), data->length()); + msg = data_message_init(dataBytes, dataLength); mailmessage_get_bodystructure(msg, &mime); mMainPart = (AbstractPart *) Attachment::attachmentsWithMIME(msg->msg_mime)->retain(); mMainPart->applyUniquePartID(); size_t cur_token = 0; struct mailimf_fields * fields; - int r = mailimf_envelope_and_optional_fields_parse(data->bytes(), data->length(), &cur_token, &fields); + int r = mailimf_envelope_and_optional_fields_parse(dataBytes, dataLength, &cur_token, &fields); if (r == MAILIMAP_NO_ERROR) { header()->importIMFFields(fields); mailimf_fields_free(fields); @@ -69,6 +72,14 @@ MessageParser::MessageParser(Data * data) mailmessage_free(msg); } +MessageParser::MessageParser(Data * data) +{ + init(); + + setBytes(data->bytes(), data->length()); + mData = (Data *) data->retain(); +} + MessageParser::MessageParser(MessageParser * other) : AbstractMessage(other) { init(); @@ -80,6 +91,11 @@ MessageParser::~MessageParser() { MC_SAFE_RELEASE(mMainPart); MC_SAFE_RELEASE(mData); +#if __APPLE__ + if (mNSData != NULL) { + CFRelease(mNSData); + } +#endif } AbstractPart * MessageParser::mainPart() @@ -89,6 +105,11 @@ AbstractPart * MessageParser::mainPart() Data * MessageParser::data() { +#if __APPLE__ + if (mNSData != NULL) { + return dataFromNSData(); + } +#endif return mData; } diff --git a/src/core/rfc822/MCMessageParser.h b/src/core/rfc822/MCMessageParser.h index bf4687cb..eba0e052 100644 --- a/src/core/rfc822/MCMessageParser.h +++ b/src/core/rfc822/MCMessageParser.h @@ -5,6 +5,9 @@ #include <MailCore/MCBaseTypes.h> #include <MailCore/MCAbstractMessage.h> #include <MailCore/MCAbstractPart.h> +#ifdef __APPLE__ +#import <CoreFoundation/CoreFoundation.h> +#endif #ifdef __cplusplus @@ -39,11 +42,23 @@ namespace mailcore { virtual HashMap * serializable(); +#ifdef __APPLE__ + public: + static MessageParser * messageParserWithData(CFDataRef data); + MessageParser(CFDataRef data); +#endif + private: Data * mData; AbstractPart * mMainPart; void init(); +#if __APPLE__ + void * mNSData; +#endif + private: + void setBytes(char * bytes, unsigned int length); + Data * dataFromNSData(); }; }; diff --git a/src/core/rfc822/MCMessageParserMac.mm b/src/core/rfc822/MCMessageParserMac.mm new file mode 100644 index 00000000..6748ed1a --- /dev/null +++ b/src/core/rfc822/MCMessageParserMac.mm @@ -0,0 +1,34 @@ +// +// MCMessageParserMac.m +// mailcore2 +// +// Created by Hoa V. DINH on 10/24/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include "MCMessageParser.h" + +#import <Foundation/Foundation.h> + +#import "NSData+MCO.h" + +using namespace mailcore; + +MessageParser * MessageParser::messageParserWithData(CFDataRef data) +{ + MessageParser * parser = new MessageParser(data); + return (MessageParser *) parser->autorelease(); +} + +MessageParser::MessageParser(CFDataRef data) +{ + init(); + + setBytes((char *) [(NSData *) data bytes], (unsigned int) [(NSData *) data length]); + mNSData = [(NSData *) data retain]; +} + +Data * MessageParser::dataFromNSData() +{ + return [(NSData *) mNSData mco_mcData]; +} diff --git a/src/objc/imap/MCOIMAPFetchContentOperation.mm b/src/objc/imap/MCOIMAPFetchContentOperation.mm index 791307ca..9ca4c1c4 100644 --- a/src/objc/imap/MCOIMAPFetchContentOperation.mm +++ b/src/objc/imap/MCOIMAPFetchContentOperation.mm @@ -61,7 +61,7 @@ typedef void (^CompletionType)(NSError *error, NSData * data); nativeType *op = MCO_NATIVE_INSTANCE; if (op->error() == mailcore::ErrorNone) { - _completionBlock(nil, MCO_TO_OBJC(op->data())); + _completionBlock(nil, (NSData *) op->data()->destructiveNSData()); } else { _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); } diff --git a/src/objc/nntp/MCONNTP.h b/src/objc/nntp/MCONNTP.h index 980d0c39..71979dfa 100644 --- a/src/objc/nntp/MCONNTP.h +++ b/src/objc/nntp/MCONNTP.h @@ -14,8 +14,10 @@ #include <MailCore/MCONNTPOperation.h> #include <MailCore/MCONNTPFetchHeaderOperation.h> #include <MailCore/MCONNTPFetchArticleOperation.h> -#include <MailCore/MCONNTPFetchArticlesOperation.h> +#include <MailCore/MCONNTPFetchAllArticlesOperation.h> #include <MailCore/MCONNTPListNewsgroupsOperation.h> +#include <MailCore/MCONNTPFetchOverviewOperation.h> +#include <MailCore/MCONNTPFetchServerTimeOperation.h> #include <MailCore/MCONNTPGroupInfo.h> #endif diff --git a/src/objc/nntp/MCONNTPFetchArticlesOperation.h b/src/objc/nntp/MCONNTPFetchAllArticlesOperation.h index 35a0889d..34ccee7e 100644 --- a/src/objc/nntp/MCONNTPFetchArticlesOperation.h +++ b/src/objc/nntp/MCONNTPFetchAllArticlesOperation.h @@ -1,5 +1,5 @@ // -// MCONNTPFetchArticlesOperation.h +// MCONNTPFetchAllArticlesOperation.h // mailcore2 // // Created by Robert Widmann on 8/13/14. @@ -16,7 +16,7 @@ @class MCOIndexSet; /** This is an asynchronous operation that will fetch the list of a messages on the NNTP server. */ -@interface MCONNTPFetchArticlesOperation : MCONNTPOperation +@interface MCONNTPFetchAllArticlesOperation : MCONNTPOperation /** Starts the asynchronous fetch operation. diff --git a/src/objc/nntp/MCONNTPFetchArticlesOperation.mm b/src/objc/nntp/MCONNTPFetchAllArticlesOperation.mm index 6e13a5d2..947f0324 100644 --- a/src/objc/nntp/MCONNTPFetchArticlesOperation.mm +++ b/src/objc/nntp/MCONNTPFetchAllArticlesOperation.mm @@ -1,12 +1,12 @@ // -// MCONNTPFetchArticlesOperation.m +// MCONNTPFetchAllArticlesOperation.m // mailcore2 // // Created by Robert Widmann on 8/13/14. // Copyright (c) 2014 MailCore. All rights reserved. // -#import "MCONNTPFetchArticlesOperation.h" +#import "MCONNTPFetchAllArticlesOperation.h" #include "MCAsyncNNTP.h" @@ -15,11 +15,11 @@ typedef void (^CompletionType)(NSError *error, MCOIndexSet * articles); -@implementation MCONNTPFetchArticlesOperation { +@implementation MCONNTPFetchAllArticlesOperation { CompletionType _completionBlock; } -#define nativeType mailcore::MCNNTPFetchArticlesOperation +#define nativeType mailcore::NNTPFetchAllArticlesOperation + (void) load { 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/MCONNTPFetchServerTimeOperation.h b/src/objc/nntp/MCONNTPFetchServerTimeOperation.h new file mode 100644 index 00000000..a06dd746 --- /dev/null +++ b/src/objc/nntp/MCONNTPFetchServerTimeOperation.h @@ -0,0 +1,35 @@ +// +// MCONNTPFetchServerTimeOperation.h +// mailcore2 +// +// Created by Robert Widmann on 10/21/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#ifndef MAILCORE_MCONNTPFETCHSERVERTIMEOPERATION_H + +#define MAILCORE_MCONNTPFETCHSERVERTIMEOPERATION_H + +#import <Foundation/Foundation.h> +#import <MailCore/MCONNTPOperation.h> + +@class MCOIndexSet; + +/** This is an asynchronous operation that will fetch the list of a messages on the NNTP server. */ +@interface MCONNTPFetchServerTimeOperation : MCONNTPOperation + +/** + Starts the asynchronous fetch operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil and `date` will be the server's date and time as an NSDate. + + - 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, NSDate * date))completionBlock; + +@end + +#endif diff --git a/src/objc/nntp/MCONNTPFetchServerTimeOperation.mm b/src/objc/nntp/MCONNTPFetchServerTimeOperation.mm new file mode 100644 index 00000000..a2f51f91 --- /dev/null +++ b/src/objc/nntp/MCONNTPFetchServerTimeOperation.mm @@ -0,0 +1,70 @@ +// +// MCONNTPFetchServerTimeOperation.m +// mailcore2 +// +// Created by Robert Widmann on 10/21/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#import "MCONNTPFetchServerTimeOperation.h" + +#include "MCAsyncNNTP.h" + +#import "MCOOperation+Private.h" +#import "MCOUtils.h" + +typedef void (^CompletionType)(NSError *error, NSDate * date); + +@implementation MCONNTPFetchServerTimeOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::NNTPFetchServerTimeOperation + ++ (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, NSDate * date))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, [NSDate dateWithTimeIntervalSince1970:op->time()]); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } + [_completionBlock release]; + _completionBlock = nil; +} + + +@end diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h index 6712d9e4..413de507 100644 --- a/src/objc/nntp/MCONNTPSession.h +++ b/src/objc/nntp/MCONNTPSession.h @@ -16,11 +16,14 @@ #import <MailCore/MCOConstants.h> -@class MCONNTPFetchArticlesOperation; +@class MCONNTPFetchAllArticlesOperation; @class MCONNTPFetchHeaderOperation; @class MCONNTPFetchArticleOperation; @class MCONNTPListNewsgroupsOperation; +@class MCONNTPFetchOverviewOperation; +@class MCONNTPFetchServerTimeOperation; @class MCONNTPOperation; +@class MCOIndexSet; /** This class implements asynchronous access to the NNTP protocol.*/ @@ -68,16 +71,16 @@ /** Returns an operation that will fetch the list of article numbers. - MCONNTPFetchArticlesOperation * op = [session fetchArticlesOperation]; + MCONNTPFetchAllArticlesOperation * op = [session fetchAllArticlesOperation:@"comp.lang.c"]; [op start:^(NSError * error, MCOIndexSet * articles) { }]; */ -- (MCONNTPFetchArticlesOperation *) fetchArticlesOperation:(NSString *)group; +- (MCONNTPFetchAllArticlesOperation *) fetchAllArticlesOperation:(NSString *)group; /** Returns an operation that will fetch the header of the given message. - MCONNTPFetchHeaderOperation * op = [session fetchHeaderOperationWithIndex:idx inGroup:@"Group"]; + MCONNTPFetchHeaderOperation * op = [session fetchHeaderOperationWithIndex:idx inGroup:@"comp.lang.c"]; [op start:^(NSError * error, MCOMessageHeader * header) { // header is the parsed header of the message. }]; @@ -85,9 +88,19 @@ - (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:@"comp.lang.c"]; + [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"]; + MCONNTPFetchArticleOperation * op = [session fetchArticleOperationWithIndex:idx inGroup:@"comp.lang.c"]; [op start:^(NSError * error, NSData * messageData) { // messageData is the RFC 822 formatted message data. }]; @@ -95,6 +108,25 @@ - (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:@"<MessageID123@mail.google.com>" inGroup:@"comp.lang.c"]; + [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 fetch the server's date and time. + + MCONNTPFetchArticleOperation * op = [session fetchServerDateOperation]; + [op start:^(NSError * error, NSDate * serverDate) { + }]; + */ +- (MCONNTPFetchServerTimeOperation *) fetchServerDateOperation; + +/** Returns an operation that will list all available newsgroups. MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation]; @@ -104,13 +136,13 @@ - (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation; /** - Returns an operation that will list all newsgroups subscribed to by the user. + Returns an operation that will list server-suggested default newsgroups. - MCONNTPListNewsgroupsOperation * op = [session listSubscribedNewsgroupsOperation]; - [op start:^(NSError * error, NSArray * subscribedGroups) { + MCONNTPListNewsgroupsOperation * op = [session listDefaultNewsgroupsOperation]; + [op start:^(NSError * error, NSArray * defaultGroups) { }]; */ -- (MCONNTPListNewsgroupsOperation *) listSubscribedNewsgroupsOperation; +- (MCONNTPListNewsgroupsOperation *) listDefaultNewsgroupsOperation; /** Returns an operation that will disconnect the session. diff --git a/src/objc/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm index ead237ea..95c87364 100644 --- a/src/objc/nntp/MCONNTPSession.mm +++ b/src/objc/nntp/MCONNTPSession.mm @@ -13,7 +13,7 @@ #import "MCOUtils.h" #import "MCONNTPOperation.h" #import "MCOOperation+Private.h" -#import "MCONNTPFetchArticlesOperation.h" +#import "MCONNTPFetchAllArticlesOperation.h" #import "MCONNTPOperation+Private.h" using namespace mailcore; @@ -122,9 +122,9 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue, return result; } -- (MCONNTPFetchArticlesOperation *) fetchArticlesOperation:(NSString *)group +- (MCONNTPFetchAllArticlesOperation *) fetchAllArticlesOperation:(NSString *)group { - mailcore::MCNNTPFetchArticlesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchArticlesOperation(MCO_FROM_OBJC(mailcore::String, group)); + mailcore::NNTPFetchAllArticlesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchAllArticlesOperation(MCO_FROM_OBJC(mailcore::String, group)); return MCO_TO_OBJC_OP(coreOp); } @@ -140,13 +140,28 @@ 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); +} + +- (MCONNTPFetchServerTimeOperation *) fetchServerDateOperation { + mailcore::NNTPFetchServerTimeOperation * coreOp = MCO_NATIVE_INSTANCE->fetchServerDateOperation(); + 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(); +- (MCONNTPListNewsgroupsOperation *) listDefaultNewsgroupsOperation { + mailcore::NNTPListNewsgroupsOperation * coreOp = MCO_NATIVE_INSTANCE->listDefaultNewsgroupsOperation(); return MCO_TO_OBJC_OP(coreOp); } |