aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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
parent859fde854dbfc29f65533fe85db6d6b43f80aa98 (diff)
parent1aeb24a13bea39fb8ac430b2cdf8da629da17e14 (diff)
Merge pull request #1266 from libec/master
Adds support for sending custom IMAP command
Diffstat (limited to 'src')
-rwxr-xr-xsrc/async/imap/MCAsyncIMAP.h1
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncConnection.cpp1
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.cpp12
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.h2
-rw-r--r--src/async/imap/MCIMAPCustomCommandOperation.cpp44
-rw-r--r--src/async/imap/MCIMAPCustomCommandOperation.h39
-rw-r--r--src/cmake/async.cmake1
-rw-r--r--src/cmake/objc.cmake1
-rw-r--r--src/cmake/public-headers.cmake2
-rw-r--r--src/core/abstract/MCMessageConstants.h1
-rwxr-xr-xsrc/core/imap/MCIMAPSession.cpp23
-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.mm72
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.h13
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.mm5
17 files changed, 243 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/MCIMAPAsyncConnection.cpp b/src/async/imap/MCIMAPAsyncConnection.cpp
index c03422ff..0dc29ee0 100755
--- a/src/async/imap/MCIMAPAsyncConnection.cpp
+++ b/src/async/imap/MCIMAPAsyncConnection.cpp
@@ -38,6 +38,7 @@
#include "MCIMAPAsyncSession.h"
#include "MCConnectionLogger.h"
#include "MCIMAPMessageRenderingOperation.h"
+#include "MCIMAPCustomCommandOperation.h"
#include "MCIMAPIdentity.h"
using namespace mailcore;
diff --git a/src/async/imap/MCIMAPAsyncSession.cpp b/src/async/imap/MCIMAPAsyncSession.cpp
index ab1bbd95..a8cccea5 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::customCommand(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..62577a6e 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 * customCommand(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..3995d6aa
--- /dev/null
+++ b/src/async/imap/MCIMAPCustomCommandOperation.cpp
@@ -0,0 +1,44 @@
+//
+// 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;
+ mResponse = NULL;
+}
+
+IMAPCustomCommandOperation::~IMAPCustomCommandOperation()
+{
+ MC_SAFE_RELEASE(mCustomCommand);
+ MC_SAFE_RELEASE(mResponse);
+}
+
+void IMAPCustomCommandOperation::setCustomCommand(String * command)
+{
+ MC_SAFE_REPLACE_COPY(String, mCustomCommand, command);
+}
+
+String * IMAPCustomCommandOperation::response()
+{
+ return mResponse;
+}
+
+void IMAPCustomCommandOperation::main()
+{
+ ErrorCode error;
+ mResponse = session()->session()->customCommand(mCustomCommand, &error);
+ MC_SAFE_RETAIN(mResponse);
+ setError(error);
+}
diff --git a/src/async/imap/MCIMAPCustomCommandOperation.h b/src/async/imap/MCIMAPCustomCommandOperation.h
new file mode 100644
index 00000000..a2ce20fe
--- /dev/null
+++ b/src/async/imap/MCIMAPCustomCommandOperation.h
@@ -0,0 +1,39 @@
+//
+// 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);
+ virtual String * response();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ String * mCustomCommand;
+ String * mResponse;
+ };
+
+}
+
+#endif
+
+#endif
diff --git a/src/cmake/async.cmake b/src/cmake/async.cmake
index c1eb3faf..79c97f5d 100644
--- a/src/cmake/async.cmake
+++ b/src/cmake/async.cmake
@@ -32,6 +32,7 @@ set(async_imap_files
async/imap/MCIMAPStoreLabelsOperation.cpp
async/imap/MCIMAPSubscribeFolderOperation.cpp
async/imap/MCIMAPNoopOperation.cpp
+ async/imap/MCIMAPCustomCommandOperation.cpp
)
set(async_pop_files
diff --git a/src/cmake/objc.cmake b/src/cmake/objc.cmake
index dfca7aee..328ceb24 100644
--- a/src/cmake/objc.cmake
+++ b/src/cmake/objc.cmake
@@ -41,6 +41,7 @@ set(objc_imap_files
objc/imap/MCOIMAPSearchExpression.mm
objc/imap/MCOIMAPSearchOperation.mm
objc/imap/MCOIMAPNoopOperation.mm
+ objc/imap/MCOIMAPCustomCommandOperation.mm
objc/imap/MCOIMAPSession.mm
)
diff --git a/src/cmake/public-headers.cmake b/src/cmake/public-headers.cmake
index ecd17a61..7677a5aa 100644
--- a/src/cmake/public-headers.cmake
+++ b/src/cmake/public-headers.cmake
@@ -100,6 +100,7 @@ async/imap/MCIMAPCapabilityOperation.h
async/imap/MCIMAPQuotaOperation.h
async/imap/MCIMAPOperationCallback.h
async/imap/MCIMAPMessageRenderingOperation.h
+async/imap/MCIMAPCustomCommandOperation.h
async/pop/MCAsyncPOP.h
async/pop/MCPOPAsyncSession.h
async/pop/MCPOPOperation.h
@@ -171,6 +172,7 @@ objc/imap/MCOIMAPCapabilityOperation.h
objc/imap/MCOIMAPQuotaOperation.h
objc/imap/MCOIMAPSearchExpression.h
objc/imap/MCOIMAPMessageRenderingOperation.h
+objc/imap/MCOIMAPCustomCommandOperation.h
objc/rfc822/MCORFC822.h
objc/rfc822/MCOAttachment.h
objc/rfc822/MCOMessageBuilder.h
diff --git a/src/core/abstract/MCMessageConstants.h b/src/core/abstract/MCMessageConstants.h
index 449d7e84..7d7403da 100644
--- a/src/core/abstract/MCMessageConstants.h
+++ b/src/core/abstract/MCMessageConstants.h
@@ -252,6 +252,7 @@ namespace mailcore {
ErrorGmailApplicationSpecificPasswordRequired, // 40
ErrorServerDate,
ErrorNoValidServerFound,
+ ErrorCustomCommand,
};
enum PartType {
diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp
index 45501b8c..e8603114 100755
--- a/src/core/imap/MCIMAPSession.cpp
+++ b/src/core/imap/MCIMAPSession.cpp
@@ -996,6 +996,29 @@ static uint64_t get_mod_sequence_value(mailimap * session)
return mod_sequence_value;
}
+String * IMAPSession::customCommand(String * command, ErrorCode * pError)
+{
+ int r;
+
+ r = mailimap_custom_command(mImap, MCUTF8(command));
+ if (r == MAILIMAP_ERROR_STREAM) {
+ mShouldDisconnect = true;
+ * pError = ErrorConnection;
+ return NULL;
+ }
+ else if (r == MAILIMAP_ERROR_PARSE) {
+ * pError = ErrorParse;
+ return NULL;
+ }
+ else if (hasError(r)) {
+ * pError = ErrorDelete;
+ return NULL;
+ }
+
+ String *response = String::stringWithUTF8Characters(mImap->imap_response);
+ return response;
+}
+
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..5ee6bc1c 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 String * customCommand(String * command, ErrorCode * pError);
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..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