aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/imap/MCOIMAPFetchContentToFileOperation.mm
diff options
context:
space:
mode:
authorGravatar Dmitry Isaikin <isaikin-dmitry@yandex.ru>2016-06-06 04:28:53 +0400
committerGravatar HoĆ  V. DINH <dinh.viet.hoa@gmail.com>2016-06-05 17:28:53 -0700
commiteeed76e48c830fe742eadd435682f3b1e6036f83 (patch)
tree36bad63fccde47e6cdecb7033f65a3d75e1bbb71 /src/objc/imap/MCOIMAPFetchContentToFileOperation.mm
parent6dbe79ccf3f085da9a195ee3f9a59cb4449f6505 (diff)
Add possibility of fetching message attachment by chunks and store it to file. (#1438)
Diffstat (limited to 'src/objc/imap/MCOIMAPFetchContentToFileOperation.mm')
-rw-r--r--src/objc/imap/MCOIMAPFetchContentToFileOperation.mm103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/objc/imap/MCOIMAPFetchContentToFileOperation.mm b/src/objc/imap/MCOIMAPFetchContentToFileOperation.mm
new file mode 100644
index 00000000..4f2bbfcf
--- /dev/null
+++ b/src/objc/imap/MCOIMAPFetchContentToFileOperation.mm
@@ -0,0 +1,103 @@
+//
+// MCOIMAPFetchContentToFileOperation.mm
+// mailcore2
+//
+// Created by Dmitry Isaikin on 2/08/16.
+// Copyright (c) 2016 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPFetchContentToFileOperation.h"
+
+#include "MCAsyncIMAP.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSError *error);
+
+@implementation MCOIMAPFetchContentToFileOperation {
+ CompletionType _completionBlock;
+ MCOIMAPBaseOperationProgressBlock _progress;
+}
+
+@synthesize progress = _progress;
+
+#define nativeType mailcore::IMAPFetchContentToFileOperation
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ nativeType * op = (nativeType *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+- (void)setLoadingByChunksEnabled:(BOOL)loadingByChunksEnabled {
+ MCO_NATIVE_INSTANCE->setLoadingByChunksEnabled(loadingByChunksEnabled);
+}
+
+- (BOOL)isLoadingByChunksEnabled {
+ return MCO_NATIVE_INSTANCE->isLoadingByChunksEnabled();
+}
+
+- (void)setChunksSize:(uint32_t)chunksSize {
+ MCO_NATIVE_INSTANCE->setChunksSize(chunksSize);
+}
+
+- (uint32_t)chunksSize {
+ return MCO_NATIVE_INSTANCE->chunksSize();
+}
+
+- (void)setEstimatedSize:(uint32_t)estimatedSize {
+ MCO_NATIVE_INSTANCE->setEstimatedSize(estimatedSize);
+}
+
+- (uint32_t)estimatedSize {
+ return MCO_NATIVE_INSTANCE->estimatedSize();
+}
+
+- (void) dealloc
+{
+ [_progress release];
+ [_completionBlock release];
+ [super dealloc];
+}
+
+- (void) start:(void (^)(NSError *error))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);
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()]);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum
+{
+ if (_progress != NULL) {
+ _progress(current, maximum);
+ }
+}
+
+@end