aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar libec <libor.huspenina@gmail.com>2015-11-04 10:27:51 +0100
committerGravatar libec <libor.huspenina@gmail.com>2015-11-04 10:27:51 +0100
commit6a4a30034edc7d7b3f0a824e9b38f43d4b9910df (patch)
tree24b1fa27ba31a06c95817fbd22f0123f6452b6e9 /src
parente3a1b98d0ed520683f4e13a734d4a397ab761f5f (diff)
adds support to send custom IMAP command
Diffstat (limited to 'src')
-rwxr-xr-xsrc/async/imap/MCAsyncIMAP.h1
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.cpp12
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.h2
-rw-r--r--src/async/imap/MCIMAPCustomCommandOperation.cpp36
-rw-r--r--src/async/imap/MCIMAPCustomCommandOperation.h37
-rwxr-xr-xsrc/core/imap/MCIMAPSession.cpp10
-rwxr-xr-xsrc/core/imap/MCIMAPSession.h1
-rwxr-xr-xsrc/objc/imap/MCOIMAP.h1
-rw-r--r--src/objc/imap/MCOIMAPCustomCommandOperation.h24
-rw-r--r--src/objc/imap/MCOIMAPCustomCommandOperation.mm69
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.h3
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.mm5
12 files changed, 201 insertions, 0 deletions
diff --git a/src/async/imap/MCAsyncIMAP.h b/src/async/imap/MCAsyncIMAP.h
index 8a490aa8..aa6d6b68 100755
--- a/src/async/imap/MCAsyncIMAP.h
+++ b/src/async/imap/MCAsyncIMAP.h
@@ -33,5 +33,6 @@
#include <MailCore/MCIMAPQuotaOperation.h>
#include <MailCore/MCIMAPOperationCallback.h>
#include <MailCore/MCIMAPMessageRenderingOperation.h>
+#include <MailCore/MCIMAPCustomCommandOperation.h>
#endif
diff --git a/src/async/imap/MCIMAPAsyncSession.cpp b/src/async/imap/MCIMAPAsyncSession.cpp
index ab1bbd95..15d546d5 100755
--- a/src/async/imap/MCIMAPAsyncSession.cpp
+++ b/src/async/imap/MCIMAPAsyncSession.cpp
@@ -42,6 +42,7 @@
#include "MCIMAPDisconnectOperation.h"
#include "MCIMAPNoopOperation.h"
#include "MCIMAPMessageRenderingOperation.h"
+#include "MCIMAPCustomCommandOperation.h"
#define DEFAULT_MAX_CONNECTIONS 3
@@ -536,6 +537,17 @@ IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageByNumberOperation(Stri
return op;
}
+IMAPCustomCommandOperation * IMAPAsyncSession::sendCustomCommand(String *command, bool urgent)
+{
+
+ IMAPCustomCommandOperation *op = new IMAPCustomCommandOperation();
+ op->setMainSession(this);
+ op->setCustomCommand(command);
+ op->setUrgent(urgent);
+ op->autorelease();
+ return op;
+}
+
IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageAttachmentByNumberOperation(String * folder, uint32_t number, String * partID,
Encoding encoding, bool urgent)
{
diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h
index 86378926..42fedcfb 100755
--- a/src/async/imap/MCIMAPAsyncSession.h
+++ b/src/async/imap/MCIMAPAsyncSession.h
@@ -40,6 +40,7 @@ namespace mailcore {
class IMAPSession;
class IMAPIdentity;
class OperationQueueCallback;
+ class IMAPCustomCommandOperation;
class MAILCORE_EXPORT IMAPAsyncSession : public Object {
public:
@@ -135,6 +136,7 @@ namespace mailcore {
Encoding encoding, bool urgent = false);
virtual IMAPFetchContentOperation * fetchMessageByNumberOperation(String * folder, uint32_t number, bool urgent = false);
+ virtual IMAPCustomCommandOperation * sendCustomCommand(String *command, bool urgent);
virtual IMAPFetchContentOperation * fetchMessageAttachmentByNumberOperation(String * folder, uint32_t number, String * partID,
Encoding encoding, bool urgent = false);
diff --git a/src/async/imap/MCIMAPCustomCommandOperation.cpp b/src/async/imap/MCIMAPCustomCommandOperation.cpp
new file mode 100644
index 00000000..692c8f7d
--- /dev/null
+++ b/src/async/imap/MCIMAPCustomCommandOperation.cpp
@@ -0,0 +1,36 @@
+//
+// MCIMAPCustomCommandOperation.cpp
+// mailcore2
+//
+// Created by Libor Huspenina on 18/10/2015.
+// Copyright © 2015 MailCore. All rights reserved.
+//
+
+#include "MCIMAPCustomCommandOperation.h"
+
+#include "MCIMAPSession.h"
+#include "MCIMAPAsyncConnection.h"
+
+using namespace mailcore;
+
+IMAPCustomCommandOperation::IMAPCustomCommandOperation()
+{
+ mCustomCommand = NULL;
+}
+
+IMAPCustomCommandOperation::~IMAPCustomCommandOperation()
+{
+ MC_SAFE_RELEASE(mCustomCommand);
+}
+
+void IMAPCustomCommandOperation::setCustomCommand(mailcore::String * command)
+{
+ mCustomCommand = command;
+}
+
+void IMAPCustomCommandOperation::main()
+{
+
+ session()->session()->sendCustomCommand(mCustomCommand);
+
+}
diff --git a/src/async/imap/MCIMAPCustomCommandOperation.h b/src/async/imap/MCIMAPCustomCommandOperation.h
new file mode 100644
index 00000000..83e6c11f
--- /dev/null
+++ b/src/async/imap/MCIMAPCustomCommandOperation.h
@@ -0,0 +1,37 @@
+//
+// MCIMAPCustomCommandOperation.h
+// mailcore2
+//
+// Created by Libor Huspenina on 18/10/2015.
+// Copyright © 2015 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCIMAPCUSTOMCOMMANDOPERATION_H
+
+#define MAILCORE_MCIMAPCUSTOMCOMMANDOPERATION_H
+
+#include <MailCore/MCIMAPOperation.h>
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class MAILCORE_EXPORT IMAPCustomCommandOperation : public IMAPOperation {
+ public:
+ IMAPCustomCommandOperation();
+ virtual ~IMAPCustomCommandOperation();
+
+ virtual void setCustomCommand(String *command);
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ String * mCustomCommand;
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp
index 45501b8c..6c8dd43e 100755
--- a/src/core/imap/MCIMAPSession.cpp
+++ b/src/core/imap/MCIMAPSession.cpp
@@ -996,6 +996,16 @@ static uint64_t get_mod_sequence_value(mailimap * session)
return mod_sequence_value;
}
+void IMAPSession::sendCustomCommand(String * command)
+{
+ int r;
+
+ MCLog("custom command");
+ MCAssert(mState == STATE_LOGGEDIN);
+
+ mailimap_custom_command(mImap, MCUTF8(command));
+}
+
void IMAPSession::select(String * folder, ErrorCode * pError)
{
int r;
diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h
index da46e0a7..0447e372 100755
--- a/src/core/imap/MCIMAPSession.h
+++ b/src/core/imap/MCIMAPSession.h
@@ -107,6 +107,7 @@ namespace mailcore {
IndexSet * numbers,
IMAPProgressCallback * progressCallback,
Array * extraHeaders, ErrorCode * pError);
+ virtual void sendCustomCommand(String * command);
virtual Data * fetchMessageByUID(String * folder, uint32_t uid,
IMAPProgressCallback * progressCallback, ErrorCode * pError);
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..87124533
--- /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(^)(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..a9193477
--- /dev/null
+++ b/src/objc/imap/MCOIMAPCustomCommandOperation.mm
@@ -0,0 +1,69 @@
+//
+// MCOIMAPCustomCommandOperation.m
+// mailcore2
+//
+// Created by Libor Huspenina on 29/10/2015.
+// Copyright © 2015 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPCustomCommandOperation.h"
+
+#include "MCAsyncIMAP.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSError *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(^)(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) {
+ _completionBlock(nil);
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()]);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index 454def4a..6b3b071e 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
@@ -680,6 +681,8 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
encoding:(MCOEncoding)encoding
urgent:(BOOL)urgent DEPRECATED_ATTRIBUTE;
+- (MCOIMAPCustomCommandOperation *) customCommandOperation:(NSString *)command;
+
/**
Returns an operation to fetch an attachment.
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index 97673518..07e140b5 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->sendCustomCommand([command mco_mcString], false);
+ return MCO_TO_OBJC_OP(customOp);
+}
+
- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
uid:(uint32_t)uid
partID:(NSString *)partID