From 6a4a30034edc7d7b3f0a824e9b38f43d4b9910df Mon Sep 17 00:00:00 2001 From: libec Date: Wed, 4 Nov 2015 10:27:51 +0100 Subject: adds support to send custom IMAP command --- src/async/imap/MCAsyncIMAP.h | 1 + src/async/imap/MCIMAPAsyncSession.cpp | 12 +++++ src/async/imap/MCIMAPAsyncSession.h | 2 + src/async/imap/MCIMAPCustomCommandOperation.cpp | 36 +++++++++++++ src/async/imap/MCIMAPCustomCommandOperation.h | 37 +++++++++++++ src/core/imap/MCIMAPSession.cpp | 10 ++++ src/core/imap/MCIMAPSession.h | 1 + src/objc/imap/MCOIMAP.h | 1 + src/objc/imap/MCOIMAPCustomCommandOperation.h | 24 +++++++++ src/objc/imap/MCOIMAPCustomCommandOperation.mm | 69 +++++++++++++++++++++++++ src/objc/imap/MCOIMAPSession.h | 3 ++ src/objc/imap/MCOIMAPSession.mm | 5 ++ 12 files changed, 201 insertions(+) create mode 100644 src/async/imap/MCIMAPCustomCommandOperation.cpp create mode 100644 src/async/imap/MCIMAPCustomCommandOperation.h create mode 100644 src/objc/imap/MCOIMAPCustomCommandOperation.h create mode 100644 src/objc/imap/MCOIMAPCustomCommandOperation.mm 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 #include #include +#include #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 + +#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 #import #import +#import #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 +#import + +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 -- cgit v1.2.3 From 47d97200574028cce13c4025ed9140d650eba1e9 Mon Sep 17 00:00:00 2001 From: libec Date: Wed, 4 Nov 2015 10:36:24 +0100 Subject: adds custom imap command files to xcodeproj --- build-mac/mailcore2.xcodeproj/project.pbxproj | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 = ""; }; + 1820E7D41BD403ED00835D1E /* MCIMAPCustomCommandOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCIMAPCustomCommandOperation.h; sourceTree = ""; }; + 1845356E1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOIMAPCustomCommandOperation.h; sourceTree = ""; }; + 1845356F1BE23FBD000B0D87 /* MCOIMAPCustomCommandOperation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPCustomCommandOperation.mm; sourceTree = ""; }; 2744B1681A7A4637009E9E67 /* MCMXRecordResolverOperation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCMXRecordResolverOperation.cpp; sourceTree = ""; }; 2744B1691A7A4637009E9E67 /* MCMXRecordResolverOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCMXRecordResolverOperation.h; sourceTree = ""; }; 27478E7E1A764698004AE621 /* MCAccountValidator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCAccountValidator.cpp; sourceTree = ""; }; @@ -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 = ""; @@ -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 */, -- cgit v1.2.3 From b331a5bfe5e26f68099ecb5e02041b0260da24eb Mon Sep 17 00:00:00 2001 From: libec Date: Thu, 5 Nov 2015 08:10:29 +0100 Subject: Removes assert on loggedIn in custom command --- src/core/imap/MCIMAPSession.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index 6c8dd43e..656168fa 100755 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -1001,7 +1001,6 @@ void IMAPSession::sendCustomCommand(String * command) int r; MCLog("custom command"); - MCAssert(mState == STATE_LOGGEDIN); mailimap_custom_command(mImap, MCUTF8(command)); } -- cgit v1.2.3 From d0408d75fd7ead8f36acc60155d49e236850f7ce Mon Sep 17 00:00:00 2001 From: libec Date: Fri, 6 Nov 2015 08:45:37 +0100 Subject: Adds imap response string to custom command operation --- src/async/imap/MCIMAPAsyncConnection.cpp | 1 + src/async/imap/MCIMAPCustomCommandOperation.cpp | 16 +++++++++++----- src/async/imap/MCIMAPCustomCommandOperation.h | 2 ++ src/core/imap/MCIMAPSession.cpp | 8 +++----- src/core/imap/MCIMAPSession.h | 2 +- src/objc/imap/MCOIMAPCustomCommandOperation.h | 2 +- src/objc/imap/MCOIMAPCustomCommandOperation.mm | 11 +++++++---- 7 files changed, 26 insertions(+), 16 deletions(-) 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/MCIMAPCustomCommandOperation.cpp b/src/async/imap/MCIMAPCustomCommandOperation.cpp index 692c8f7d..61e0e655 100644 --- a/src/async/imap/MCIMAPCustomCommandOperation.cpp +++ b/src/async/imap/MCIMAPCustomCommandOperation.cpp @@ -16,21 +16,27 @@ using namespace mailcore; IMAPCustomCommandOperation::IMAPCustomCommandOperation() { mCustomCommand = NULL; + mResponse = NULL; } IMAPCustomCommandOperation::~IMAPCustomCommandOperation() { MC_SAFE_RELEASE(mCustomCommand); + MC_SAFE_RELEASE(mResponse); } -void IMAPCustomCommandOperation::setCustomCommand(mailcore::String * command) +void IMAPCustomCommandOperation::setCustomCommand(String * command) { - mCustomCommand = command; + MC_SAFE_REPLACE_COPY(String, mCustomCommand, command); } -void IMAPCustomCommandOperation::main() +String * IMAPCustomCommandOperation::response() { + return mResponse; +} - session()->session()->sendCustomCommand(mCustomCommand); - +void IMAPCustomCommandOperation::main() +{ + mResponse = session()->session()->sendCustomCommand(mCustomCommand); + MC_SAFE_RETAIN(mResponse); } diff --git a/src/async/imap/MCIMAPCustomCommandOperation.h b/src/async/imap/MCIMAPCustomCommandOperation.h index 83e6c11f..a2ce20fe 100644 --- a/src/async/imap/MCIMAPCustomCommandOperation.h +++ b/src/async/imap/MCIMAPCustomCommandOperation.h @@ -22,12 +22,14 @@ namespace mailcore { virtual ~IMAPCustomCommandOperation(); virtual void setCustomCommand(String *command); + virtual String * response(); public: // subclass behavior virtual void main(); private: String * mCustomCommand; + String * mResponse; }; } diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index 656168fa..69d80cc7 100755 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -996,13 +996,11 @@ static uint64_t get_mod_sequence_value(mailimap * session) return mod_sequence_value; } -void IMAPSession::sendCustomCommand(String * command) +String * IMAPSession::sendCustomCommand(String * command) { - int r; - - MCLog("custom command"); - mailimap_custom_command(mImap, MCUTF8(command)); + String *response = String::stringWithUTF8Characters(mImap->imap_response); + return response; } void IMAPSession::select(String * folder, ErrorCode * pError) diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h index 0447e372..8b1db9cb 100755 --- a/src/core/imap/MCIMAPSession.h +++ b/src/core/imap/MCIMAPSession.h @@ -107,7 +107,7 @@ namespace mailcore { IndexSet * numbers, IMAPProgressCallback * progressCallback, Array * extraHeaders, ErrorCode * pError); - virtual void sendCustomCommand(String * command); + virtual String * sendCustomCommand(String * command); virtual Data * fetchMessageByUID(String * folder, uint32_t uid, IMAPProgressCallback * progressCallback, ErrorCode * pError); diff --git a/src/objc/imap/MCOIMAPCustomCommandOperation.h b/src/objc/imap/MCOIMAPCustomCommandOperation.h index 87124533..e23d29e7 100644 --- a/src/objc/imap/MCOIMAPCustomCommandOperation.h +++ b/src/objc/imap/MCOIMAPCustomCommandOperation.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MCOIMAPCustomCommandOperation : MCOIMAPBaseOperation -- (void)start:(void(^)(NSError * __nullable error))completionBlock; +- (void)start:(void(^)(NSString * __nullable response, NSError * __nullable error))completionBlock; @end NS_ASSUME_NONNULL_END diff --git a/src/objc/imap/MCOIMAPCustomCommandOperation.mm b/src/objc/imap/MCOIMAPCustomCommandOperation.mm index a9193477..b4fb15a6 100644 --- a/src/objc/imap/MCOIMAPCustomCommandOperation.mm +++ b/src/objc/imap/MCOIMAPCustomCommandOperation.mm @@ -9,11 +9,12 @@ #import "MCOIMAPCustomCommandOperation.h" #include "MCAsyncIMAP.h" +#include "MCIMAPCustomCommandOperation.h" #import "MCOOperation+Private.h" #import "MCOUtils.h" -typedef void (^CompletionType)(NSError *error); +typedef void (^CompletionType)(NSString * __nullable response, NSError * __nullable error); @implementation MCOIMAPCustomCommandOperation { CompletionType _completionBlock; @@ -38,7 +39,7 @@ typedef void (^CompletionType)(NSError *error); [super dealloc]; } -- (void)start:(void(^)(NSError * __nullable error))completionBlock +- (void)start:(void(^)(NSString * __nullable response, NSError * __nullable error))completionBlock { _completionBlock = [completionBlock copy]; [self start]; @@ -58,9 +59,11 @@ typedef void (^CompletionType)(NSError *error); nativeType *op = MCO_NATIVE_INSTANCE; if (op->error() == mailcore::ErrorNone) { - _completionBlock(nil); + NSString *response = [NSString mco_stringWithMCString:op->response()]; + _completionBlock(response, nil); } else { - _completionBlock([NSError mco_errorWithErrorCode:op->error()]); + NSError *error = [NSError mco_errorWithErrorCode:op->error()]; + _completionBlock(nil, error); } [_completionBlock release]; _completionBlock = nil; -- cgit v1.2.3 From e8e41511e27e9b9f5d757bf2ac33871edd676ec4 Mon Sep 17 00:00:00 2001 From: libec Date: Fri, 6 Nov 2015 09:03:30 +0100 Subject: Comment with usage of custom IMAP operation --- src/objc/imap/MCOIMAPSession.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index 6b3b071e..add9a428 100755 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -681,6 +681,16 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 encoding:(MCOEncoding)encoding 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; /** -- cgit v1.2.3 From 703a580f1fe599f2dde7fec6c6e9a51ca47da34d Mon Sep 17 00:00:00 2001 From: libec Date: Sat, 7 Nov 2015 21:02:04 +0100 Subject: Adds error code to IMAPSession::customCommand. Renames sendCustomCommand to customCommand. --- src/async/imap/MCIMAPAsyncSession.cpp | 2 +- src/async/imap/MCIMAPAsyncSession.h | 2 +- src/async/imap/MCIMAPCustomCommandOperation.cpp | 4 +++- src/core/imap/MCIMAPSession.cpp | 11 +++++++++-- src/core/imap/MCIMAPSession.h | 2 +- src/objc/imap/MCOIMAPSession.mm | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/async/imap/MCIMAPAsyncSession.cpp b/src/async/imap/MCIMAPAsyncSession.cpp index 15d546d5..a8cccea5 100755 --- a/src/async/imap/MCIMAPAsyncSession.cpp +++ b/src/async/imap/MCIMAPAsyncSession.cpp @@ -537,7 +537,7 @@ IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageByNumberOperation(Stri return op; } -IMAPCustomCommandOperation * IMAPAsyncSession::sendCustomCommand(String *command, bool urgent) +IMAPCustomCommandOperation * IMAPAsyncSession::customCommand(String *command, bool urgent) { IMAPCustomCommandOperation *op = new IMAPCustomCommandOperation(); diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h index 42fedcfb..62577a6e 100755 --- a/src/async/imap/MCIMAPAsyncSession.h +++ b/src/async/imap/MCIMAPAsyncSession.h @@ -136,7 +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 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 index 61e0e655..3995d6aa 100644 --- a/src/async/imap/MCIMAPCustomCommandOperation.cpp +++ b/src/async/imap/MCIMAPCustomCommandOperation.cpp @@ -37,6 +37,8 @@ String * IMAPCustomCommandOperation::response() void IMAPCustomCommandOperation::main() { - mResponse = session()->session()->sendCustomCommand(mCustomCommand); + ErrorCode error; + mResponse = session()->session()->customCommand(mCustomCommand, &error); MC_SAFE_RETAIN(mResponse); + setError(error); } diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index 69d80cc7..cbd94a2b 100755 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -996,9 +996,16 @@ static uint64_t get_mod_sequence_value(mailimap * session) return mod_sequence_value; } -String * IMAPSession::sendCustomCommand(String * command) +String * IMAPSession::customCommand(String * command, ErrorCode * pError) { - mailimap_custom_command(mImap, MCUTF8(command)); + int r; + + r = mailimap_custom_command(mImap, MCUTF8(command)); + if (r == MAILIMAP_ERROR_CUSTOM_COMMAND) { + * pError = ErrorCustomCommand; + return NULL; + } + String *response = String::stringWithUTF8Characters(mImap->imap_response); return response; } diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h index 8b1db9cb..5ee6bc1c 100755 --- a/src/core/imap/MCIMAPSession.h +++ b/src/core/imap/MCIMAPSession.h @@ -107,7 +107,7 @@ namespace mailcore { IndexSet * numbers, IMAPProgressCallback * progressCallback, Array * extraHeaders, ErrorCode * pError); - virtual String * sendCustomCommand(String * command); + 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/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index 07e140b5..362227f6 100755 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -436,7 +436,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue, } - (MCOIMAPCustomCommandOperation *) customCommandOperation:(NSString *)command { - IMAPCustomCommandOperation *customOp = MCO_NATIVE_INSTANCE->sendCustomCommand([command mco_mcString], false); + IMAPCustomCommandOperation *customOp = MCO_NATIVE_INSTANCE->customCommand([command mco_mcString], false); return MCO_TO_OBJC_OP(customOp); } -- cgit v1.2.3 From b2878046fb591c31090591f32507cb3a7e035c74 Mon Sep 17 00:00:00 2001 From: libec Date: Sat, 7 Nov 2015 21:11:55 +0100 Subject: Adds custom command files to cmake --- src/cmake/async.cmake | 1 + src/cmake/objc.cmake | 1 + src/cmake/public-headers.cmake | 2 ++ 3 files changed, 4 insertions(+) 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 -- cgit v1.2.3 From a5d3ebb7a5cfa386869b1f569538249883c5b6db Mon Sep 17 00:00:00 2001 From: libec Date: Sat, 7 Nov 2015 22:45:44 +0100 Subject: Added ErrorCustomCommand --- src/core/abstract/MCMessageConstants.h | 1 + 1 file changed, 1 insertion(+) 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 { -- cgit v1.2.3 From 1aeb24a13bea39fb8ac430b2cdf8da629da17e14 Mon Sep 17 00:00:00 2001 From: libec Date: Mon, 9 Nov 2015 08:11:31 +0100 Subject: Proper error handling in IMAPSession::customCommand --- src/core/imap/MCIMAPSession.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index cbd94a2b..e8603114 100755 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -1001,8 +1001,17 @@ String * IMAPSession::customCommand(String * command, ErrorCode * pError) int r; r = mailimap_custom_command(mImap, MCUTF8(command)); - if (r == MAILIMAP_ERROR_CUSTOM_COMMAND) { - * pError = ErrorCustomCommand; + 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; } -- cgit v1.2.3