diff options
Diffstat (limited to 'src/objc')
-rw-r--r-- | src/objc/imap/MCOIMAPFetchContentOperation.mm | 2 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTP.h | 4 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchAllArticlesOperation.h (renamed from src/objc/nntp/MCONNTPFetchArticlesOperation.h) | 4 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchAllArticlesOperation.mm (renamed from src/objc/nntp/MCONNTPFetchArticlesOperation.mm) | 8 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchOverviewOperation.h | 32 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchOverviewOperation.mm | 69 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchServerTimeOperation.h | 35 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchServerTimeOperation.mm | 70 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPSession.h | 50 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPSession.mm | 25 |
10 files changed, 277 insertions, 22 deletions
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); } |