aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc
diff options
context:
space:
mode:
authorGravatar Hoà V. DINH <dinh.viet.hoa@gmail.com>2015-11-09 15:45:08 -0800
committerGravatar Hoà V. DINH <dinh.viet.hoa@gmail.com>2015-11-09 15:45:08 -0800
commitc41ed58043f57e05d0e6fe20b2e4f95dae1e95cb (patch)
tree137701edd4c7ac52146679c0ff8132a0738868f7 /src/objc
parent859fde854dbfc29f65533fe85db6d6b43f80aa98 (diff)
parent1aeb24a13bea39fb8ac430b2cdf8da629da17e14 (diff)
Merge pull request #1266 from libec/master
Adds support for sending custom IMAP command
Diffstat (limited to 'src/objc')
-rwxr-xr-xsrc/objc/imap/MCOIMAP.h1
-rw-r--r--src/objc/imap/MCOIMAPCustomCommandOperation.h24
-rw-r--r--src/objc/imap/MCOIMAPCustomCommandOperation.mm72
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.h13
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.mm5
5 files changed, 115 insertions, 0 deletions
diff --git a/src/objc/imap/MCOIMAP.h b/src/objc/imap/MCOIMAP.h
index 1957afd8..9483a36b 100755
--- a/src/objc/imap/MCOIMAP.h
+++ b/src/objc/imap/MCOIMAP.h
@@ -41,5 +41,6 @@
#import <MailCore/MCOIMAPQuotaOperation.h>
#import <MailCore/MCOIMAPSearchExpression.h>
#import <MailCore/MCOIMAPMessageRenderingOperation.h>
+#import <MailCore/MCOIMAPCustomCommandOperation.h>
#endif
diff --git a/src/objc/imap/MCOIMAPCustomCommandOperation.h b/src/objc/imap/MCOIMAPCustomCommandOperation.h
new file mode 100644
index 00000000..e23d29e7
--- /dev/null
+++ b/src/objc/imap/MCOIMAPCustomCommandOperation.h
@@ -0,0 +1,24 @@
+//
+// MCOIMAPCustomCommandOperation.h
+// mailcore2
+//
+// Created by Libor Huspenina on 29/10/2015.
+// Copyright © 2015 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCOIMAPCUSTOMCOMMANDOPERATION_H
+
+#define MAILCORE_MCOIMAPCUSTOMCOMMANDOPERATION_H
+
+#import <MailCore/MCOIMAPBaseOperation.h>
+#import <MailCore/MCOConstants.h>
+
+NS_ASSUME_NONNULL_BEGIN
+@interface MCOIMAPCustomCommandOperation : MCOIMAPBaseOperation
+
+- (void)start:(void(^)(NSString * __nullable response, NSError * __nullable error))completionBlock;
+
+@end
+NS_ASSUME_NONNULL_END
+
+#endif
diff --git a/src/objc/imap/MCOIMAPCustomCommandOperation.mm b/src/objc/imap/MCOIMAPCustomCommandOperation.mm
new file mode 100644
index 00000000..b4fb15a6
--- /dev/null
+++ b/src/objc/imap/MCOIMAPCustomCommandOperation.mm
@@ -0,0 +1,72 @@
+//
+// MCOIMAPCustomCommandOperation.m
+// mailcore2
+//
+// Created by Libor Huspenina on 29/10/2015.
+// Copyright © 2015 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPCustomCommandOperation.h"
+
+#include "MCAsyncIMAP.h"
+#include "MCIMAPCustomCommandOperation.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSString * __nullable response, NSError * __nullable error);
+
+@implementation MCOIMAPCustomCommandOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::IMAPCustomCommandOperation
+
++ (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(^)(NSString * __nullable response, NSError * __nullable 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) {
+ NSString *response = [NSString mco_stringWithMCString:op->response()];
+ _completionBlock(response, nil);
+ } else {
+ NSError *error = [NSError mco_errorWithErrorCode:op->error()];
+ _completionBlock(nil, error);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index 454def4a..add9a428 100755
--- a/src/objc/imap/MCOIMAPSession.h
+++ b/src/objc/imap/MCOIMAPSession.h
@@ -34,6 +34,7 @@
@class MCOIMAPMessageRenderingOperation;
@class MCOIMAPMessage;
@class MCOIMAPIdentity;
+@class MCOIMAPCustomCommandOperation;
/**
This is the main IMAP class from which all operations are created
@@ -681,6 +682,18 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
urgent:(BOOL)urgent DEPRECATED_ATTRIBUTE;
/**
+ Returns an operation for custom command.
+ @param command is the text representation of the command to be send.
+
+
+ MCOIMAPCustomCommandOperation * op = [session customCommandOperation:@"ACTIVATE SERVICE"];
+ [op start: ^(NSString * __nullable response, NSError * __nullable error) {
+ ...
+ }];
+ */
+- (MCOIMAPCustomCommandOperation *) customCommandOperation:(NSString *)command;
+
+/**
Returns an operation to fetch an attachment.
Example 1:
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index 97673518..362227f6 100755
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -435,6 +435,11 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return MCO_TO_OBJC_OP(coreOp);
}
+- (MCOIMAPCustomCommandOperation *) customCommandOperation:(NSString *)command {
+ IMAPCustomCommandOperation *customOp = MCO_NATIVE_INSTANCE->customCommand([command mco_mcString], false);
+ return MCO_TO_OBJC_OP(customOp);
+}
+
- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
uid:(uint32_t)uid
partID:(NSString *)partID