diff options
author | Hoà V. DINH <dinh.viet.hoa@gmail.com> | 2015-11-09 15:45:08 -0800 |
---|---|---|
committer | Hoà V. DINH <dinh.viet.hoa@gmail.com> | 2015-11-09 15:45:08 -0800 |
commit | c41ed58043f57e05d0e6fe20b2e4f95dae1e95cb (patch) | |
tree | 137701edd4c7ac52146679c0ff8132a0738868f7 | |
parent | 859fde854dbfc29f65533fe85db6d6b43f80aa98 (diff) | |
parent | 1aeb24a13bea39fb8ac430b2cdf8da629da17e14 (diff) |
Merge pull request #1266 from libec/master
Adds support for sending custom IMAP command
-rwxr-xr-x | build-mac/mailcore2.xcodeproj/project.pbxproj | 24 | ||||
-rwxr-xr-x | src/async/imap/MCAsyncIMAP.h | 1 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncConnection.cpp | 1 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncSession.cpp | 12 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncSession.h | 2 | ||||
-rw-r--r-- | src/async/imap/MCIMAPCustomCommandOperation.cpp | 44 | ||||
-rw-r--r-- | src/async/imap/MCIMAPCustomCommandOperation.h | 39 | ||||
-rw-r--r-- | src/cmake/async.cmake | 1 | ||||
-rw-r--r-- | src/cmake/objc.cmake | 1 | ||||
-rw-r--r-- | src/cmake/public-headers.cmake | 2 | ||||
-rw-r--r-- | src/core/abstract/MCMessageConstants.h | 1 | ||||
-rwxr-xr-x | src/core/imap/MCIMAPSession.cpp | 23 | ||||
-rwxr-xr-x | src/core/imap/MCIMAPSession.h | 1 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAP.h | 1 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPCustomCommandOperation.h | 24 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPCustomCommandOperation.mm | 72 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.h | 13 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.mm | 5 |
18 files changed, 267 insertions, 0 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index cb26cb7b..66f6e1a6 100755 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -7,6 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 1820E7D51BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1820E7D31BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp */; }; + 1820E7D61BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1820E7D31BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp */; }; + 184535701BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1845356F1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm */; }; + 184535711BE23FCF000B0D87 /* MCOIMAPCustomCommandOperation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1845356F1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm */; }; + 184805441BE751AF001B80AA /* MCOIMAPCustomCommandOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1845356E1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.h */; }; + 184805451BE751BD001B80AA /* MCOIMAPCustomCommandOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1845356E1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.h */; }; + 18707E211BE24DEA00B494C3 /* MCIMAPCustomCommandOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1820E7D41BD403ED00835D1E /* MCIMAPCustomCommandOperation.h */; }; + 18707E221BE24E0800B494C3 /* MCIMAPCustomCommandOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1820E7D41BD403ED00835D1E /* MCIMAPCustomCommandOperation.h */; }; 2744B16A1A7A4637009E9E67 /* MCMXRecordResolverOperation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2744B1681A7A4637009E9E67 /* MCMXRecordResolverOperation.cpp */; }; 2744B16B1A7A4637009E9E67 /* MCMXRecordResolverOperation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2744B1681A7A4637009E9E67 /* MCMXRecordResolverOperation.cpp */; }; 27478E801A764698004AE621 /* MCAccountValidator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27478E7E1A764698004AE621 /* MCAccountValidator.cpp */; }; @@ -1022,8 +1030,10 @@ C6D4FD3419FA9EB6001F7E01 /* MCONNTPFetchOverviewOperation.h in CopyFiles */, C6D4FD3119FA9E80001F7E01 /* MCNNTPFetchOverviewOperation.h in CopyFiles */, 849189A318C94023002063A3 /* MCNNTP.h in CopyFiles */, + 18707E211BE24DEA00B494C3 /* MCIMAPCustomCommandOperation.h in CopyFiles */, 849189A418C94023002063A3 /* MCNNTPSession.h in CopyFiles */, 84B639F317F2839C003B5BA2 /* MCOPOPNoopOperation.h in CopyFiles */, + 184805451BE751BD001B80AA /* MCOIMAPCustomCommandOperation.h in CopyFiles */, 84B639F417F2839C003B5BA2 /* MCIMAPNoopOperation.h in CopyFiles */, 84D7377B199C00F5005124E5 /* MCONNTP.h in CopyFiles */, 84B639F517F2839C003B5BA2 /* MCPOPNoopOperation.h in CopyFiles */, @@ -1257,7 +1267,9 @@ 849F53D817F28443002D417F /* MCOPOPNoopOperation.h in CopyFiles */, 849F53D917F28443002D417F /* MCIMAPNoopOperation.h in CopyFiles */, 849F53DA17F28443002D417F /* MCPOPNoopOperation.h in CopyFiles */, + 184805441BE751AF001B80AA /* MCOIMAPCustomCommandOperation.h in CopyFiles */, 849F53DB17F28443002D417F /* MCSMTPNoopOperation.h in CopyFiles */, + 18707E221BE24E0800B494C3 /* MCIMAPCustomCommandOperation.h in CopyFiles */, 84915BB8199C4B0400EDDED9 /* MCNNTP.h in CopyFiles */, 84D7377C199C00F7005124E5 /* MCONNTP.h in CopyFiles */, 84D7374A199BFB92005124E5 /* MCAsyncNNTP.h in CopyFiles */, @@ -1464,6 +1476,10 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1820E7D31BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCIMAPCustomCommandOperation.cpp; sourceTree = "<group>"; }; + 1820E7D41BD403ED00835D1E /* MCIMAPCustomCommandOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCIMAPCustomCommandOperation.h; sourceTree = "<group>"; }; + 1845356E1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOIMAPCustomCommandOperation.h; sourceTree = "<group>"; }; + 1845356F1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPCustomCommandOperation.mm; sourceTree = "<group>"; }; 2744B1681A7A4637009E9E67 /* MCMXRecordResolverOperation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCMXRecordResolverOperation.cpp; sourceTree = "<group>"; }; 2744B1691A7A4637009E9E67 /* MCMXRecordResolverOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCMXRecordResolverOperation.h; sourceTree = "<group>"; }; 27478E7E1A764698004AE621 /* MCAccountValidator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCAccountValidator.cpp; sourceTree = "<group>"; }; @@ -2513,6 +2529,8 @@ 943F1A9917D964F600F0C798 /* MCIMAPConnectOperation.h */, C64EA7FA16A2959700778456 /* MCIMAPFetchFoldersOperation.cpp */, C64EA7FB16A2959700778456 /* MCIMAPFetchFoldersOperation.h */, + 1820E7D31BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp */, + 1820E7D41BD403ED00835D1E /* MCIMAPCustomCommandOperation.h */, C64EA80016A295E200778456 /* MCIMAPRenameFolderOperation.cpp */, C64EA80116A295E300778456 /* MCIMAPRenameFolderOperation.h */, C64EA80316A2997B00778456 /* MCIMAPDeleteFolderOperation.cpp */, @@ -3089,6 +3107,8 @@ C63D316117C92D8300A4D993 /* MCOIMAPIdentity.mm */, C6EFFBCA1833334900CFF656 /* MCOIMAPMultiDisconnectOperation.h */, C6EFFBCB1833334900CFF656 /* MCOIMAPMultiDisconnectOperation.mm */, + 1845356E1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.h */, + 1845356F1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm */, ); path = imap; sourceTree = "<group>"; @@ -3565,6 +3585,7 @@ C63CD69116BE566E00DB18F1 /* MCHTMLCleaner.cpp in Sources */, C64BB22116E34DCB000DB34C /* MCIMAPSyncResult.cpp in Sources */, C64BB22B16E5C0A4000DB34C /* MCIMAPCapabilityOperation.cpp in Sources */, + 1820E7D51BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp in Sources */, C64BB22E16E5C1EE000DB34C /* MCIndexSet.cpp in Sources */, 84D73764199BFFC7005124E5 /* MCONNTPSession.mm in Sources */, C64BB23516EDAA17000DB34C /* MCOAbstractMessage.mm in Sources */, @@ -3593,6 +3614,7 @@ C6F5B9E816FEA28600D9DABD /* MCOIMAPMultipart.mm in Sources */, C6F5B9EB16FEA3B500D9DABD /* MCOIMAPNamespace.mm in Sources */, C6F5B9EE16FEA3C400D9DABD /* MCOIMAPNamespaceItem.mm in Sources */, + 184535701BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm in Sources */, C6F5B9F116FEA3D700D9DABD /* MCOIMAPPart.mm in Sources */, C6F5B9F416FEAC6C00D9DABD /* MCOIndexSet.mm in Sources */, 849189AB18C94986002063A3 /* MCNNTPGroupInfo.cpp in Sources */, @@ -3773,6 +3795,7 @@ C6BA2BC51705F4E6003F0E9E /* MCIMAPFetchFoldersOperation.cpp in Sources */, C6BA2BC61705F4E6003F0E9E /* MCIMAPRenameFolderOperation.cpp in Sources */, BD49963819FEC6DD000945BC /* ConvertUTF.c in Sources */, + 184535711BE23FCF000B0D87 /* MCOIMAPCustomCommandOperation.mm in Sources */, C6BA2BC71705F4E6003F0E9E /* MCIMAPDeleteFolderOperation.cpp in Sources */, C63D315D17C9155C00A4D993 /* MCIMAPIdentity.cpp in Sources */, 84D73743199BF963005124E5 /* MCNNTPFetchAllArticlesOperation.cpp in Sources */, @@ -3837,6 +3860,7 @@ C6BA2BEB1705F4E6003F0E9E /* MCHTMLRendererCallback.cpp in Sources */, C6BA2BEC1705F4E6003F0E9E /* MCHTMLCleaner.cpp in Sources */, C6BA2BED1705F4E6003F0E9E /* MCIMAPSyncResult.cpp in Sources */, + 1820E7D61BD403ED00835D1E /* MCIMAPCustomCommandOperation.cpp in Sources */, C6BA2BEE1705F4E6003F0E9E /* MCIMAPCapabilityOperation.cpp in Sources */, C6BA2BEF1705F4E6003F0E9E /* MCIndexSet.cpp in Sources */, 84D73765199BFFC7005124E5 /* MCONNTPSession.mm in Sources */, 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 |