diff options
Diffstat (limited to 'src')
40 files changed, 870 insertions, 286 deletions
diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc index 5b1269da..ed40932c 100644 --- a/src/async/imap/MCIMAPAsyncConnection.cc +++ b/src/async/imap/MCIMAPAsyncConnection.cc @@ -30,9 +30,36 @@ #include "MCIMAPIdleOperation.h" #include "MCIMAPIdentityOperation.h" #include "MCIMAPCapabilityOperation.h" +#include "MCOperationQueueCallback.h" +#include "MCIMAPDisconnectOperation.h" +#include "MCIMAPAsyncSession.h" using namespace mailcore; +namespace mailcore { + class IMAPOperationQueueCallback : public Object, public OperationQueueCallback { + public: + IMAPOperationQueueCallback(IMAPAsyncConnection * connection) { + mConnection = connection; + } + + virtual ~IMAPOperationQueueCallback() { + } + + virtual void queueStartRunning() { + mConnection->queueStartRunning(); + } + + virtual void queueStoppedRunning() { + mConnection->tryAutomaticDisconnect(); + mConnection->queueStoppedRunning(); + } + + private: + IMAPAsyncConnection * mConnection; + }; +} + IMAPAsyncConnection::IMAPAsyncConnection() { mSession = new IMAPSession(); @@ -40,10 +67,15 @@ IMAPAsyncConnection::IMAPAsyncConnection() mDefaultNamespace = NULL; mDelimiter = 0; mLastFolder = NULL; + mQueueCallback = new IMAPOperationQueueCallback(this); + mQueue->setCallback(mQueueCallback); + mOwner = NULL; } IMAPAsyncConnection::~IMAPAsyncConnection() { + cancelDelayedPerformMethod((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL); + MC_SAFE_RELEASE(mQueueCallback); MC_SAFE_RELEASE(mLastFolder); MC_SAFE_RELEASE(mDefaultNamespace); MC_SAFE_RELEASE(mQueue); @@ -439,10 +471,40 @@ unsigned int IMAPAsyncConnection::operationsCount() void IMAPAsyncConnection::runOperation(IMAPOperation * operation) { -#warning disconnect after delay + cancelDelayedPerformMethod((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL); mQueue->addOperation(operation); } +void IMAPAsyncConnection::tryAutomaticDisconnect() +{ + // It's safe since no thread is running when this function is called. + if (mSession->isDisconnected()) { + return; + } + + performMethodAfterDelay((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL, 30); +} + +void IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay(void * context) +{ + IMAPDisconnectOperation * op = new IMAPDisconnectOperation(); + op->setSession(this); + op->autorelease(); + op->start(); +} + +void IMAPAsyncConnection::queueStartRunning() +{ + this->retain(); + mOwner->retain(); +} + +void IMAPAsyncConnection::queueStoppedRunning() +{ + mOwner->release(); + this->release(); +} + void IMAPAsyncConnection::setLastFolder(String * folder) { MC_SAFE_REPLACE_COPY(String, mLastFolder, folder); @@ -453,3 +515,14 @@ String * IMAPAsyncConnection::lastFolder() return mLastFolder; } +void IMAPAsyncConnection::setOwner(IMAPAsyncSession * owner) +{ + mOwner = owner; +} + +IMAPAsyncSession * IMAPAsyncConnection::owner() +{ + return mOwner; +} + + diff --git a/src/async/imap/MCIMAPAsyncConnection.h b/src/async/imap/MCIMAPAsyncConnection.h index 4843702b..d6ef6a91 100644 --- a/src/async/imap/MCIMAPAsyncConnection.h +++ b/src/async/imap/MCIMAPAsyncConnection.h @@ -25,6 +25,8 @@ namespace mailcore { class IMAPFetchNamespaceOperation; class IMAPIdentityOperation; class IMAPCapabilityOperation; + class IMAPOperationQueueCallback; + class IMAPAsyncSession; class IMAPAsyncConnection : public Object { public: @@ -116,8 +118,10 @@ namespace mailcore { char mDelimiter; IMAPNamespace * mDefaultNamespace; String * mLastFolder; - - void queue(IMAPOperation * op); + IMAPOperationQueueCallback * mQueueCallback; + IMAPAsyncSession * mOwner; + + virtual void tryAutomaticDisconnectAfterDelay(void * context); public: // private virtual void runOperation(IMAPOperation * operation); @@ -127,6 +131,13 @@ namespace mailcore { virtual void setLastFolder(String * folder); virtual String * lastFolder(); + + virtual void tryAutomaticDisconnect(); + virtual void queueStartRunning(); + virtual void queueStoppedRunning(); + + virtual void setOwner(IMAPAsyncSession * owner); + virtual IMAPAsyncSession * owner(); }; } diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc index 766b6fe6..7c085e4a 100644 --- a/src/async/imap/MCIMAPAsyncSession.cc +++ b/src/async/imap/MCIMAPAsyncSession.cc @@ -10,6 +10,7 @@ #include "MCIMAPAsyncConnection.h" #include "MCIMAPNamespace.h" +#include "MCOperationQueueCallback.h" #define DEFAULT_MAX_CONNECTIONS 3 @@ -173,6 +174,7 @@ unsigned int IMAPAsyncSession::maximumConnections() IMAPAsyncConnection * IMAPAsyncSession::session() { IMAPAsyncConnection * session = new IMAPAsyncConnection(); + session->setOwner(this); session->autorelease(); session->setHostname(mHostname); diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h index a2bc05f8..390fdab8 100644 --- a/src/async/imap/MCIMAPAsyncSession.h +++ b/src/async/imap/MCIMAPAsyncSession.h @@ -142,10 +142,10 @@ namespace mailcore { bool mAllowsFolderConcurrentAccessEnabled; unsigned int mMaximumConnections; - IMAPAsyncConnection * sessionForFolder(String * folder, bool urgent = false); - IMAPAsyncConnection * session(); - IMAPAsyncConnection * matchingSessionForFolder(String * folder); - IMAPAsyncConnection * availableSession(); + virtual IMAPAsyncConnection * sessionForFolder(String * folder, bool urgent = false); + virtual IMAPAsyncConnection * session(); + virtual IMAPAsyncConnection * matchingSessionForFolder(String * folder); + virtual IMAPAsyncConnection * availableSession(); }; } diff --git a/src/async/imap/MCIMAPDisconnectOperation.cc b/src/async/imap/MCIMAPDisconnectOperation.cc new file mode 100644 index 00000000..070eeaae --- /dev/null +++ b/src/async/imap/MCIMAPDisconnectOperation.cc @@ -0,0 +1,28 @@ +// +// MCIMAPDisconnectOperation.cc +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#include "MCIMAPDisconnectOperation.h" + +#include "MCIMAPAsyncConnection.h" +#include "MCIMAPSession.h" + +using namespace mailcore; + +IMAPDisconnectOperation::IMAPDisconnectOperation() +{ +} + +IMAPDisconnectOperation::~IMAPDisconnectOperation() +{ +} + +void IMAPDisconnectOperation::main() +{ + session()->session()->disconnect(); + setError(ErrorCode::ErrorNone); +} diff --git a/src/async/imap/MCIMAPDisconnectOperation.h b/src/async/imap/MCIMAPDisconnectOperation.h new file mode 100644 index 00000000..5d572def --- /dev/null +++ b/src/async/imap/MCIMAPDisconnectOperation.h @@ -0,0 +1,32 @@ +// +// MCIMAPDisconnectOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCIMAPDISCONNECTOPERATION_H_ +#define __MAILCORE_MCIMAPDISCONNECTOPERATION_H_ + +#include <MailCore/MCBaseTypes.h> +#include <MailCore/MCAbstract.h> +#include <MailCore/MCIMAPOperation.h> + +#ifdef __cplusplus + +namespace mailcore { + + class IMAPDisconnectOperation : public IMAPOperation { + public: + IMAPDisconnectOperation(); + virtual ~IMAPDisconnectOperation(); + + public: // subclass behavior + virtual void main(); + }; +} + +#endif + +#endif
\ No newline at end of file diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc index 39f356db..1269a34b 100644 --- a/src/async/pop/MCPOPAsyncSession.cc +++ b/src/async/pop/MCPOPAsyncSession.cc @@ -14,17 +14,44 @@ #include "MCPOPDeleteMessagesOperation.h" #include "MCPOPFetchMessagesOperation.h" #include "MCPOPCheckAccountOperation.h" +#include "MCOperationQueueCallback.h" using namespace mailcore; +namespace mailcore { + class POPOperationQueueCallback : public Object, public OperationQueueCallback { + public: + POPOperationQueueCallback(POPAsyncSession * session) { + mSession = session; + } + + virtual ~POPOperationQueueCallback() { + } + + virtual void queueStartRunning() { + mSession->retain(); + } + + virtual void queueStoppedRunning() { + mSession->release(); + } + + private: + POPAsyncSession * mSession; + }; +} + POPAsyncSession::POPAsyncSession() { mSession = new POPSession(); mQueue = new OperationQueue(); + mQueueCallback = new POPOperationQueueCallback(this); + mQueue->setCallback(mQueueCallback); } POPAsyncSession::~POPAsyncSession() { + MC_SAFE_RELEASE(mQueueCallback); MC_SAFE_RELEASE(mSession); MC_SAFE_RELEASE(mQueue); } @@ -164,6 +191,5 @@ POPSession * POPAsyncSession::session() void POPAsyncSession::runOperation(POPOperation * operation) { -#warning disconnect after delay mQueue->addOperation(operation); } diff --git a/src/async/pop/MCPOPAsyncSession.h b/src/async/pop/MCPOPAsyncSession.h index 166675e0..452d4d75 100644 --- a/src/async/pop/MCPOPAsyncSession.h +++ b/src/async/pop/MCPOPAsyncSession.h @@ -22,7 +22,8 @@ namespace mailcore { class POPFetchMessageOperation; class POPDeleteMessagesOperation; class POPFetchMessagesOperation; - + class POPOperationQueueCallback; + class POPAsyncSession : public Object { public: POPAsyncSession(); @@ -68,6 +69,7 @@ namespace mailcore { private: POPSession * mSession; OperationQueue * mQueue; + POPOperationQueueCallback * mQueueCallback; public: // private virtual void runOperation(POPOperation * operation); diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index 95101a50..73bc2a54 100644 --- a/src/async/smtp/MCSMTPAsyncSession.cc +++ b/src/async/smtp/MCSMTPAsyncSession.cc @@ -1,22 +1,50 @@ #include "MCSMTPAsyncSession.h" #include "MCSMTPSession.h" -//#include "MCSMTPSendWithRecipientOperation.h" #include "MCSMTPSendWithDataOperation.h" -//#include "MCSMTPSendWithBuilderOperation.h" #include "MCSMTPCheckAccountOperation.h" +#include "MCSMTPDisconnectOperation.h" #include "MCSMTPOperation.h" +#include "MCOperationQueueCallback.h" using namespace mailcore; +namespace mailcore { + class SMTPOperationQueueCallback : public Object, public OperationQueueCallback { + public: + SMTPOperationQueueCallback(SMTPAsyncSession * session) { + mSession = session; + } + + virtual ~SMTPOperationQueueCallback() { + } + + virtual void queueStartRunning() { + mSession->retain(); + } + + virtual void queueStoppedRunning() { + mSession->tryAutomaticDisconnect(); + mSession->release(); + } + + private: + SMTPAsyncSession * mSession; + }; +} + SMTPAsyncSession::SMTPAsyncSession() { mSession = new SMTPSession(); mQueue = new OperationQueue(); + mQueueCallback = new SMTPOperationQueueCallback(this); + mQueue->setCallback(mQueueCallback); } SMTPAsyncSession::~SMTPAsyncSession() { + cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL); + MC_SAFE_RELEASE(mQueueCallback); MC_SAFE_RELEASE(mQueue); MC_SAFE_RELEASE(mSession); } @@ -113,7 +141,7 @@ bool SMTPAsyncSession::useHeloIPEnabled() void SMTPAsyncSession::runOperation(SMTPOperation * operation) { -#warning disconnect after delay + cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL); mQueue->addOperation(operation); } @@ -122,35 +150,31 @@ SMTPSession * SMTPAsyncSession::session() return mSession; } -#if 0 -SMTPOperation * SMTPAsyncSession::sendMessageOperationWithFromAndRecipient(Address * from, Array * recipients, Data * messageData) +void SMTPAsyncSession::tryAutomaticDisconnect() { - SMTPSendWithRecipientOperation * op = new SMTPSendWithRecipientOperation(); - op->setSession(this); - op->setFrom(from); - op->setRecipients(recipients); - op->setMessageData(messageData); - return (SMTPOperation *) op->autorelease(); + // It's safe since no thread is running when this function is called. + if (mSession->isDisconnected()) { + return; + } + + performMethodAfterDelay((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL, 30); } -#endif -SMTPOperation * SMTPAsyncSession::sendMessageOperation(Data * messageData) +void SMTPAsyncSession::tryAutomaticDisconnectAfterDelay(void * context) { - SMTPSendWithDataOperation * op = new SMTPSendWithDataOperation(); + SMTPDisconnectOperation * op = new SMTPDisconnectOperation(); op->setSession(this); - op->setMessageData(messageData); - return (SMTPOperation *) op->autorelease(); + op->autorelease(); + op->start(); } -#if 0 -SMTPOperation * SMTPAsyncSession::sendMessageOperation(MessageBuilder * msg) +SMTPOperation * SMTPAsyncSession::sendMessageOperation(Data * messageData) { - SMTPSendWithBuilderOperation * op = new SMTPSendWithBuilderOperation(); + SMTPSendWithDataOperation * op = new SMTPSendWithDataOperation(); op->setSession(this); - op->setBuilder(msg); + op->setMessageData(messageData); return (SMTPOperation *) op->autorelease(); } -#endif SMTPOperation * SMTPAsyncSession::checkAccountOperation(Address * from) { @@ -159,4 +183,3 @@ SMTPOperation * SMTPAsyncSession::checkAccountOperation(Address * from) op->setSession(this); return (SMTPOperation *) op->autorelease(); } - diff --git a/src/async/smtp/MCSMTPAsyncSession.h b/src/async/smtp/MCSMTPAsyncSession.h index 0be287af..9cd7a8f0 100644 --- a/src/async/smtp/MCSMTPAsyncSession.h +++ b/src/async/smtp/MCSMTPAsyncSession.h @@ -13,6 +13,7 @@ namespace mailcore { class SMTPOperation; class SMTPSession; class Address; + class SMTPOperationQueueCallback; class SMTPAsyncSession : public Object { public: @@ -52,13 +53,14 @@ namespace mailcore { public: // private virtual void runOperation(SMTPOperation * operation); virtual SMTPSession * session(); + virtual void tryAutomaticDisconnect(); private: - SMTPSession * mSession; - OperationQueue * mQueue; - - void queue(SMTPOperation * op); - + SMTPSession * mSession; + OperationQueue * mQueue; + SMTPOperationQueueCallback * mQueueCallback; + + virtual void tryAutomaticDisconnectAfterDelay(void * context); }; } diff --git a/src/async/smtp/MCSMTPDisconnectOperation.cc b/src/async/smtp/MCSMTPDisconnectOperation.cc new file mode 100644 index 00000000..592ceb48 --- /dev/null +++ b/src/async/smtp/MCSMTPDisconnectOperation.cc @@ -0,0 +1,28 @@ +// +// SMTPDisconnectOperation.cpp +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#include "MCSMTPDisconnectOperation.h" + +#include "MCSMTPAsyncSession.h" +#include "MCSMTPSession.h" + +using namespace mailcore; + +SMTPDisconnectOperation::SMTPDisconnectOperation() +{ +} + +SMTPDisconnectOperation::~SMTPDisconnectOperation() +{ +} + +void SMTPDisconnectOperation::main() +{ + session()->session()->disconnect(); + setError(ErrorCode::ErrorNone); +} diff --git a/src/async/smtp/MCSMTPDisconnectOperation.h b/src/async/smtp/MCSMTPDisconnectOperation.h new file mode 100644 index 00000000..dacf72a6 --- /dev/null +++ b/src/async/smtp/MCSMTPDisconnectOperation.h @@ -0,0 +1,32 @@ +// +// SMTPDisconnectOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCSMTPDISCONNECTOPERATION_H_ +#define __MAILCORE_MCSMTPDISCONNECTOPERATION_H_ + +#include <MailCore/MCBaseTypes.h> +#include <MailCore/MCAbstract.h> +#include <MailCore/MCSMTPOperation.h> + +#ifdef __cplusplus + +namespace mailcore { + + class SMTPDisconnectOperation : public SMTPOperation { + public: + SMTPDisconnectOperation(); + virtual ~SMTPDisconnectOperation(); + + public: // subclass behavior + virtual void main(); + }; +} + +#endif + +#endif
\ No newline at end of file diff --git a/src/async/smtp/MCSMTPOperation.cc b/src/async/smtp/MCSMTPOperation.cc index 532c6ab4..e8211a24 100644 --- a/src/async/smtp/MCSMTPOperation.cc +++ b/src/async/smtp/MCSMTPOperation.cc @@ -82,4 +82,3 @@ void SMTPOperation::bodyProgressOnMainThread(void * ctx) } free(context); } - diff --git a/src/core/abstract/MCMessageConstants.h b/src/core/abstract/MCMessageConstants.h index c06acd06..eb9e80f4 100644 --- a/src/core/abstract/MCMessageConstants.h +++ b/src/core/abstract/MCMessageConstants.h @@ -65,6 +65,7 @@ namespace mailcore { IMAPMessagesRequestKindFullHeaders = 1 << 4, IMAPMessagesRequestKindHeaderSubject = 1 << 5, IMAPMessagesRequestKindGmailLabels = 1 << 6, + IMAPMessagesRequestKindGmailThreadID = 1 << 7, }; enum IMAPFetchRequestType { diff --git a/src/core/basetypes/MCMainThread.h b/src/core/basetypes/MCMainThread.h index 31819a29..c9fe4e8d 100644 --- a/src/core/basetypes/MCMainThread.h +++ b/src/core/basetypes/MCMainThread.h @@ -5,9 +5,14 @@ #ifdef __cplusplus namespace mailcore { - void callOnMainThread(void (*)(void *), void * context); - void callOnMainThreadAndWait(void (*)(void *), void * context); - void callAfterDelay(void (*)(void *), void * context, double time); + void callOnMainThread(void (*)(void *), void * context); + void callOnMainThreadAndWait(void (*)(void *), void * context); + + // Returns a "call" object. + void * callAfterDelay(void (*)(void *), void * context, double time); + + // Pass the pointer returns by callAfterDelay() to cancel a delayed call. + void cancelDelayedCall(void * call); } #endif diff --git a/src/core/basetypes/MCMainThread.mm b/src/core/basetypes/MCMainThread.mm index 0bdc2ce1..4e9c6fc7 100644 --- a/src/core/basetypes/MCMainThread.mm +++ b/src/core/basetypes/MCMainThread.mm @@ -52,13 +52,18 @@ void mailcore::callOnMainThreadAndWait(void (* function)(void *), void * context [caller release]; } -void mailcore::callAfterDelay(void (* function)(void *), void * context, double time) +void * mailcore::callAfterDelay(void (* function)(void *), void * context, double time) { LEPPPMainThreadCaller * caller; caller = [[LEPPPMainThreadCaller alloc] init]; [caller setFunction:function]; [caller setContext:context]; [caller performSelector:@selector(call) withObject:nil afterDelay:time]; - [caller release]; + return [caller autorelease]; } +void mailcore::cancelDelayedCall(void * delayedCall) +{ + LEPPPMainThreadCaller * caller = (LEPPPMainThreadCaller *) delayedCall; + [NSObject cancelPreviousPerformRequestsWithTarget:caller selector:@selector(call) object:nil]; +} diff --git a/src/core/basetypes/MCObject.cc b/src/core/basetypes/MCObject.cc index 32d51fc4..879c194f 100644 --- a/src/core/basetypes/MCObject.cc +++ b/src/core/basetypes/MCObject.cc @@ -3,6 +3,7 @@ #include <stdlib.h> #include <typeinfo> #include <cxxabi.h> +#include <libetpan/libetpan.h> #include "MCAutoreleasePool.h" #include "MCString.h" @@ -115,6 +116,26 @@ struct mainThreadCallData { Object * obj; void * context; Object::Method method; + void * caller; +}; + +static pthread_once_t delayedPerformOnce = PTHREAD_ONCE_INIT; +static chash * delayedPerformHash = NULL; + +static void reallyInitDelayedPerform() +{ + delayedPerformHash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY); +} + +static void initDelayedPerform() +{ + pthread_once(&delayedPerformOnce, reallyInitDelayedPerform); +} + +struct mainThreadCallKeyData { + Object * obj; + void * context; + Object::Method method; }; static void performOnMainThread(void * info) @@ -134,7 +155,7 @@ static void performOnMainThread(void * info) free(data); } -static void callAfterDelay(void * info) +static void performAfterDelay(void * info) { struct mainThreadCallData * data; void * context; @@ -146,6 +167,15 @@ static void callAfterDelay(void * info) context = data->context; method = data->method; + chashdatum key; + struct mainThreadCallKeyData keyData; + keyData.obj = obj; + keyData.context = context; + keyData.method = method; + key.data = &keyData; + key.len = sizeof(keyData); + chash_delete(delayedPerformHash, &key, NULL); + (obj->*method)(context); free(data); @@ -159,6 +189,7 @@ void Object::performMethodOnMainThread(Method method, void * context, bool waitU data->obj = this; data->context = context; data->method = method; + data->caller = NULL; if (waitUntilDone) { callOnMainThreadAndWait(performOnMainThread, data); @@ -170,12 +201,48 @@ void Object::performMethodOnMainThread(Method method, void * context, bool waitU void Object::performMethodAfterDelay(Method method, void * context, double delay) { + initDelayedPerform(); + struct mainThreadCallData * data; data = (struct mainThreadCallData *) calloc(sizeof(* data), 1); data->obj = this; data->context = context; data->method = method; + data->caller = callAfterDelay(performAfterDelay, data, delay); + + chashdatum key; + chashdatum value; + struct mainThreadCallKeyData keyData; + keyData.obj = this; + keyData.context = context; + keyData.method = method; + key.data = &keyData; + key.len = sizeof(keyData); + value.data = (void *) data; + value.len = 0; + chash_set(delayedPerformHash, &key, &value, NULL); +} + +void Object::cancelDelayedPerformMethod(Method method, void * context) +{ + initDelayedPerform(); - callAfterDelay(performOnMainThread, data, delay); + int r; + chashdatum key; + chashdatum value; + struct mainThreadCallKeyData keyData; + keyData.obj = this; + keyData.context = context; + keyData.method = method; + key.data = &keyData; + key.len = sizeof(keyData); + r = chash_get(delayedPerformHash, &key, &value); + if (r < 0) + return; + + chash_delete(delayedPerformHash, &key, NULL); + struct mainThreadCallData * data = (struct mainThreadCallData *) value.data; + cancelDelayedCall(data->caller); + free(data); } diff --git a/src/core/basetypes/MCObject.h b/src/core/basetypes/MCObject.h index 0fd65d09..01812191 100644 --- a/src/core/basetypes/MCObject.h +++ b/src/core/basetypes/MCObject.h @@ -38,6 +38,7 @@ namespace mailcore { virtual void performMethod(Method method, void * context); virtual void performMethodOnMainThread(Method method, void * context, bool waitUntilDone = false); virtual void performMethodAfterDelay(Method method, void * context, double delay); + virtual void cancelDelayedPerformMethod(Method method, void * context); private: pthread_mutex_t mLock; diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index 72d0041d..e448c237 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -1,13 +1,15 @@ #include "MCOperationQueue.h" +#include <libetpan/libetpan.h> + #include "MCOperation.h" #include "MCOperationCallback.h" +#include "MCOperationQueueCallback.h" #include "MCMainThread.h" #include "MCUtils.h" #include "MCArray.h" #include "MCLog.h" #include "MCAutoreleasePool.h" -#include <libetpan/libetpan.h> using namespace mailcore; @@ -21,6 +23,8 @@ OperationQueue::OperationQueue() mStartSem = mailsem_new(); mStopSem = mailsem_new(); mWaitingFinishedSem = mailsem_new(); + mQuitting = false; + mCallback = NULL; } OperationQueue::~OperationQueue() @@ -153,6 +157,10 @@ void OperationQueue::stoppedOnMainThread(void * context) mailsem_down(mStopSem); mStarted = false; + if (mCallback) { + mCallback->queueStoppedRunning(); + } + release(); // (2) release(); // (3) @@ -163,6 +171,10 @@ void OperationQueue::startThread() if (mStarted) return; + if (mCallback) { + mCallback->queueStartRunning(); + } + retain(); // (3) mQuitting = false; mStarted = true; @@ -181,6 +193,16 @@ unsigned int OperationQueue::count() return count; } +void OperationQueue::setCallback(OperationQueueCallback * callback) +{ + mCallback = callback; +} + +OperationQueueCallback * OperationQueue::callback() +{ + return mCallback; +} + #if 0 void OperationQueue::waitUntilAllOperationsAreFinished() { diff --git a/src/core/basetypes/MCOperationQueue.h b/src/core/basetypes/MCOperationQueue.h index b9323dea..ddfe9de2 100644 --- a/src/core/basetypes/MCOperationQueue.h +++ b/src/core/basetypes/MCOperationQueue.h @@ -10,41 +10,46 @@ #ifdef __cplusplus namespace mailcore { - - class Operation; - class Array; - class OperationQueue : public Object { - public: - OperationQueue(); - virtual ~OperationQueue(); - - virtual void addOperation(Operation * op); - + class Operation; + class OperationQueueCallback; + class Array; + + class OperationQueue : public Object { + public: + OperationQueue(); + virtual ~OperationQueue(); + + virtual void addOperation(Operation * op); + virtual unsigned int count(); - private: - Array * mOperations; - pthread_t mThreadID; - bool mStarted; - struct mailsem * mOperationSem; - struct mailsem * mStartSem; - struct mailsem * mStopSem; - pthread_mutex_t mLock; - bool mWaiting; - struct mailsem * mWaitingFinishedSem; - bool mQuitting; + virtual void setCallback(OperationQueueCallback * callback); + virtual OperationQueueCallback * callback(); - void startThread(); - static void runOperationsOnThread(OperationQueue * queue); - void runOperations(); - void callbackOnMainThread(Operation * op); - void checkRunningOnMainThread(void * context); - void checkRunningAfterDelay(void * context); + private: + Array * mOperations; + pthread_t mThreadID; + bool mStarted; + struct mailsem * mOperationSem; + struct mailsem * mStartSem; + struct mailsem * mStopSem; + pthread_mutex_t mLock; + bool mWaiting; + struct mailsem * mWaitingFinishedSem; + bool mQuitting; + OperationQueueCallback * mCallback; + + void startThread(); + static void runOperationsOnThread(OperationQueue * queue); + void runOperations(); + void callbackOnMainThread(Operation * op); + void checkRunningOnMainThread(void * context); + void checkRunningAfterDelay(void * context); void stoppedOnMainThread(void * context); - - }; - + + }; + } #endif diff --git a/src/core/basetypes/MCOperationQueueCallback.h b/src/core/basetypes/MCOperationQueueCallback.h new file mode 100644 index 00000000..367888bb --- /dev/null +++ b/src/core/basetypes/MCOperationQueueCallback.h @@ -0,0 +1,23 @@ +// +// MCOperationQueueCallback.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_OPERATIONQUEUECALLBACK_H_ +#define __MAILCORE_OPERATIONQUEUECALLBACK_H_ + +namespace mailcore { + + class OperationQueue; + + class OperationQueueCallback { + public: + virtual void queueStartRunning() {} + virtual void queueStoppedRunning() {} + }; +} + +#endif diff --git a/src/core/imap/MCIMAPMessage.cc b/src/core/imap/MCIMAPMessage.cc index 6f8a0dbb..f8b9f4e6 100644 --- a/src/core/imap/MCIMAPMessage.cc +++ b/src/core/imap/MCIMAPMessage.cc @@ -35,6 +35,7 @@ IMAPMessage::IMAPMessage(IMAPMessage * other) setOriginalFlags(other->originalFlags()); setMainPart((AbstractPart *) other->mainPart()->copy()->autorelease()); setGmailLabels(other->gmailLabels()); + setGmailThreadID(other->gmailThreadID()); } IMAPMessage::~IMAPMessage() @@ -121,6 +122,16 @@ Array * IMAPMessage::gmailLabels() return mLabels; } +void IMAPMessage::setGmailThreadID(uint64_t threadID) +{ + mThreadID = threadID; +} + +uint64_t IMAPMessage::gmailThreadID() +{ + return mThreadID; +} + AbstractPart * IMAPMessage::partForPartID(String * partID) { return partForPartIDInPart(mainPart(), partID); diff --git a/src/core/imap/MCIMAPMessage.h b/src/core/imap/MCIMAPMessage.h index 5a9cadcb..3c2ee9c0 100644 --- a/src/core/imap/MCIMAPMessage.h +++ b/src/core/imap/MCIMAPMessage.h @@ -10,33 +10,36 @@ #ifdef __cplusplus namespace mailcore { - + class IMAPPart; class HTMLRendererIMAPCallback; class HTMLRendererTemplateCallback; - class IMAPMessage : public AbstractMessage { - public: - IMAPMessage(); - ~IMAPMessage(); - - virtual uint32_t uid(); - virtual void setUid(uint32_t uid); - - virtual void setFlags(MessageFlag flags); - virtual MessageFlag flags(); - - virtual void setOriginalFlags(MessageFlag flags); - virtual MessageFlag originalFlags(); - - virtual uint64_t modSeqValue(); - virtual void setModSeqValue(uint64_t uid); + class IMAPMessage : public AbstractMessage { + public: + IMAPMessage(); + ~IMAPMessage(); + + virtual uint32_t uid(); + virtual void setUid(uint32_t uid); + + virtual void setFlags(MessageFlag flags); + virtual MessageFlag flags(); + + virtual void setOriginalFlags(MessageFlag flags); + virtual MessageFlag originalFlags(); - virtual void setMainPart(AbstractPart * mainPart); - virtual AbstractPart * mainPart(); - - virtual void setGmailLabels(Array * /* String */ labels); - virtual Array * /* String */ gmailLabels(); + virtual uint64_t modSeqValue(); + virtual void setModSeqValue(uint64_t uid); + + virtual void setMainPart(AbstractPart * mainPart); + virtual AbstractPart * mainPart(); + + virtual void setGmailLabels(Array * /* String */ labels); + virtual Array * /* String */ gmailLabels(); + + virtual void setGmailThreadID(uint64_t threadID); + virtual uint64_t gmailThreadID(); virtual AbstractPart * partForPartID(String * partID); @@ -48,20 +51,21 @@ namespace mailcore { HTMLRendererTemplateCallback * htmlCallback = NULL); public: // subclass behavior - IMAPMessage(IMAPMessage * other); - virtual Object * copy(); - virtual String * description(); + IMAPMessage(IMAPMessage * other); + virtual Object * copy(); + virtual String * description(); - private: + private: uint64_t mModSeqValue; - uint32_t mUid; - MessageFlag mFlags; - MessageFlag mOriginalFlags; - AbstractPart * mMainPart; - Array * /* String */ mLabels; - void init(); - }; - + uint32_t mUid; + MessageFlag mFlags; + MessageFlag mOriginalFlags; + AbstractPart * mMainPart; + Array * /* String */ mLabels; + uint64_t mThreadID; + void init(); + }; + } #endif diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index 52e819d9..254f9865 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -514,6 +514,8 @@ void IMAPSession::unsetup() mailimap_free(imap); imap = NULL; } + + mState = STATE_DISCONNECTED; } void IMAPSession::connect(ErrorCode * pError) @@ -1582,6 +1584,7 @@ struct msg_att_handler_data { bool needsBody; bool needsFlags; bool needsGmailLabels; + bool needsGmailThreadID; uint32_t startUid; }; @@ -1594,6 +1597,7 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) bool hasBody; bool hasFlags; bool hasGmailLabels; + bool hasGmailThreadID; struct msg_att_handler_data * msg_att_context; // struct IMAPSession * self; @@ -1607,6 +1611,7 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) bool needsBody; bool needsFlags; bool needsGmailLabels; + bool needsGmailThreadID; uint32_t startUid; msg_att_context = (struct msg_att_handler_data *) context; @@ -1621,13 +1626,15 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) needsBody = msg_att_context->needsBody; needsFlags = msg_att_context->needsFlags; needsGmailLabels = msg_att_context->needsGmailLabels; + needsGmailThreadID = msg_att_context->needsGmailThreadID; startUid = msg_att_context->startUid; hasHeader = false; hasBody = false; hasFlags = false; hasGmailLabels = false; - + hasGmailThreadID = false; + msg = new IMAPMessage(); uid = 0; @@ -1718,6 +1725,13 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) } labels->release(); } + else if (ext_data->ext_extension == &mailimap_extension_xgmthrid) { + uint64_t * threadID; + + threadID = (uint64_t *) ext_data->ext_data; + msg->setGmailThreadID(*threadID); + hasGmailThreadID = true; + } } } for(item_iter = clist_begin(msg_att->att_list) ; item_iter != NULL ; item_iter = clist_next(item_iter)) { @@ -1752,7 +1766,10 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) msg->release(); return; } - + if (needsGmailThreadID && !hasGmailThreadID) { + msg->release(); + return; + } if (uid != 0) { msg->setUid(uid); } @@ -1780,6 +1797,7 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest bool needsBody; bool needsFlags; bool needsGmailLabels; + bool needsGmailThreadID; Array * messages; IndexSet * vanishedMessages; @@ -1803,7 +1821,8 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest needsBody = false; needsFlags = false; needsGmailLabels = false; - + needsGmailThreadID = false; + fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); fetch_att = mailimap_fetch_att_new_uid(); mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); @@ -1819,6 +1838,11 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); needsGmailLabels = true; } + if ((requestKind & IMAPMessagesRequestKindGmailThreadID) != 0) { + fetch_att = mailimap_fetch_att_new_xgmthrid(); + mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); + needsGmailThreadID = true; + } if ((requestKind & IMAPMessagesRequestKindFullHeaders) != 0) { clist * hdrlist; char * header; @@ -1908,7 +1932,7 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest msg_att_data.needsFlags = needsFlags; msg_att_data.needsGmailLabels = needsGmailLabels; msg_att_data.startUid = startUid; - + msg_att_data.needsGmailThreadID = needsGmailThreadID; mailimap_set_msg_att_handler(mImap, msg_att_handler, &msg_att_data); mBodyProgressEnabled = false; @@ -2912,3 +2936,7 @@ bool IMAPSession::isIdentityEnabled() return mIdentityEnabled; } +bool IMAPSession::isDisconnected() +{ + return mState == STATE_DISCONNECTED; +} diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h index 8531b050..c21c36cd 100644 --- a/src/core/imap/MCIMAPSession.h +++ b/src/core/imap/MCIMAPSession.h @@ -5,92 +5,90 @@ #include <MailCore/MCBaseTypes.h> #include <MailCore/MCMessageConstants.h> - - #ifdef __cplusplus namespace mailcore { - extern String * IMAPNamespacePersonal; - extern String * IMAPNamespaceOther; - extern String * IMAPNamespaceShared; + extern String * IMAPNamespacePersonal; + extern String * IMAPNamespaceOther; + extern String * IMAPNamespaceShared; - class IMAPNamespace; - class IMAPSearchExpression; - class IMAPFolder; - class IMAPProgressCallback; + class IMAPNamespace; + class IMAPSearchExpression; + class IMAPFolder; + class IMAPProgressCallback; class IMAPSyncResult; class IMAPFolderStatus; - - class IMAPSession : public Object { - public: - IMAPSession(); - virtual ~IMAPSession(); - - virtual void setHostname(String * hostname); - virtual String * hostname(); + + class IMAPSession : public Object { + public: + IMAPSession(); + virtual ~IMAPSession(); + + virtual void setHostname(String * hostname); + virtual String * hostname(); - virtual void setPort(unsigned int port); - virtual unsigned int port(); + virtual void setPort(unsigned int port); + virtual unsigned int port(); - virtual void setUsername(String * username); - virtual String * username(); + virtual void setUsername(String * username); + virtual String * username(); - virtual void setPassword(String * password); - virtual String * password(); + virtual void setPassword(String * password); + virtual String * password(); - virtual void setAuthType(AuthType authType); - virtual AuthType authType(); + virtual void setAuthType(AuthType authType); + virtual AuthType authType(); - virtual void setConnectionType(ConnectionType connectionType); - virtual ConnectionType connectionType(); + virtual void setConnectionType(ConnectionType connectionType); + virtual ConnectionType connectionType(); - virtual void setTimeout(time_t timeout); - virtual time_t timeout(); - - virtual void setCheckCertificateEnabled(bool enabled); - virtual bool isCheckCertificateEnabled(); + virtual void setTimeout(time_t timeout); + virtual time_t timeout(); - virtual void setVoIPEnabled(bool enabled); - virtual bool isVoIPEnabled(); + virtual void setCheckCertificateEnabled(bool enabled); + virtual bool isCheckCertificateEnabled(); + + virtual void setVoIPEnabled(bool enabled); + virtual bool isVoIPEnabled(); // Needed for fetchSubscribedFolders() and fetchAllFolders(). - virtual void setDelimiter(char delimiter); - virtual char delimiter(); + virtual void setDelimiter(char delimiter); + virtual char delimiter(); // Needed for fetchSubscribedFolders() and fetchAllFolders(). - virtual void setDefaultNamespace(IMAPNamespace * ns); - virtual IMAPNamespace * defaultNamespace(); + virtual void setDefaultNamespace(IMAPNamespace * ns); + virtual IMAPNamespace * defaultNamespace(); - virtual void select(String * folder, ErrorCode * pError); + virtual void select(String * folder, ErrorCode * pError); virtual IMAPFolderStatus * folderStatus(String * folder, ErrorCode * pError); - - virtual Array * /* IMAPFolder */ fetchSubscribedFolders(ErrorCode * pError); - virtual Array * /* IMAPFolder */ fetchAllFolders(ErrorCode * pError); // will use xlist if available - virtual void renameFolder(String * folder, String * otherName, ErrorCode * pError); - virtual void deleteFolder(String * folder, ErrorCode * pError); - virtual void createFolder(String * folder, ErrorCode * pError); + virtual Array * /* IMAPFolder */ fetchSubscribedFolders(ErrorCode * pError); + virtual Array * /* IMAPFolder */ fetchAllFolders(ErrorCode * pError); // will use xlist if available + + virtual void renameFolder(String * folder, String * otherName, ErrorCode * pError); + virtual void deleteFolder(String * folder, ErrorCode * pError); + virtual void createFolder(String * folder, ErrorCode * pError); - virtual void subscribeFolder(String * folder, ErrorCode * pError); - virtual void unsubscribeFolder(String * folder, ErrorCode * pError); + virtual void subscribeFolder(String * folder, ErrorCode * pError); + virtual void unsubscribeFolder(String * folder, ErrorCode * pError); - virtual void appendMessage(String * folder, Data * messageData, MessageFlag flags, + virtual void appendMessage(String * folder, Data * messageData, MessageFlag flags, IMAPProgressCallback * progressCallback, uint32_t * createdUID, ErrorCode * pError); - - virtual void copyMessages(String * folder, IndexSet * uidSet, String * destFolder, + + virtual void copyMessages(String * folder, IndexSet * uidSet, String * destFolder, IndexSet ** pDestUIDs, ErrorCode * pError); - - virtual void expunge(String * folder, ErrorCode * pError); - - virtual Array * /* IMAPMessage */ fetchMessagesByUID(String * folder, IMAPMessagesRequestKind requestKind, + + virtual void expunge(String * folder, ErrorCode * pError); + + virtual Array * /* IMAPMessage */ fetchMessagesByUID(String * folder, IMAPMessagesRequestKind requestKind, IndexSet * uids, IMAPProgressCallback * progressCallback, ErrorCode * pError); - virtual Array * /* IMAPMessage */ fetchMessagesByNumber(String * folder, IMAPMessagesRequestKind requestKind, + virtual Array * /* IMAPMessage */ fetchMessagesByNumber(String * folder, IMAPMessagesRequestKind requestKind, IndexSet * numbers, IMAPProgressCallback * progressCallback, ErrorCode * pError); - virtual Data * fetchMessageByUID(String * folder, uint32_t uid, + virtual Data * fetchMessageByUID(String * folder, uint32_t uid, IMAPProgressCallback * progressCallback, ErrorCode * pError); - virtual Data * fetchMessageAttachmentByUID(String * folder, uint32_t uid, String * partID, + virtual Data * fetchMessageAttachmentByUID(String * folder, uint32_t uid, String * partID, Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError); virtual HashMap * fetchMessageNumberUIDMapping(String * folder, uint32_t fromUID, uint32_t toUID, ErrorCode * pError); @@ -100,94 +98,95 @@ namespace mailcore { IndexSet * uids, uint64_t modseq, IMAPProgressCallback * progressCallback, ErrorCode * pError); - virtual void storeFlags(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError); - virtual void storeLabels(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError); - - virtual IndexSet * search(String * folder, IMAPSearchKind kind, String * searchString, ErrorCode * pError); - virtual IndexSet * search(String * folder, IMAPSearchExpression * expression, ErrorCode * pError); - - virtual bool setupIdle(); - virtual void idle(String * folder, uint32_t lastKnownUID, ErrorCode * pError); - virtual void interruptIdle(); - virtual void unsetupIdle(); - - virtual void connect(ErrorCode * pError); - virtual void disconnect(); - - virtual HashMap * fetchNamespace(ErrorCode * pError); - - virtual void login(ErrorCode * pError); - - virtual HashMap * identity(String * vendor, String * name, String * version, ErrorCode * pError); + virtual void storeFlags(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError); + virtual void storeLabels(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError); + + virtual IndexSet * search(String * folder, IMAPSearchKind kind, String * searchString, ErrorCode * pError); + virtual IndexSet * search(String * folder, IMAPSearchExpression * expression, ErrorCode * pError); + + virtual bool setupIdle(); + virtual void idle(String * folder, uint32_t lastKnownUID, ErrorCode * pError); + virtual void interruptIdle(); + virtual void unsetupIdle(); + + virtual void connect(ErrorCode * pError); + virtual void disconnect(); + + virtual HashMap * fetchNamespace(ErrorCode * pError); + + virtual void login(ErrorCode * pError); + + virtual HashMap * identity(String * vendor, String * name, String * version, ErrorCode * pError); virtual IndexSet * capability(ErrorCode * pError); - virtual uint32_t uidValidity(); - virtual uint32_t uidNext(); + virtual uint32_t uidValidity(); + virtual uint32_t uidNext(); virtual uint64_t modSequenceValue(); - virtual unsigned int lastFolderMessageCount(); + virtual unsigned int lastFolderMessageCount(); virtual uint32_t firstUnseenUid(); - virtual bool isIdleEnabled(); - virtual bool isXListEnabled(); - virtual bool isCondstoreEnabled(); - virtual bool isQResyncEnabled(); - virtual bool isIdentityEnabled(); + virtual bool isIdleEnabled(); + virtual bool isXListEnabled(); + virtual bool isCondstoreEnabled(); + virtual bool isQResyncEnabled(); + virtual bool isIdentityEnabled(); public: // private - virtual void loginIfNeeded(ErrorCode * pError); - virtual void connectIfNeeded(ErrorCode * pError); - - private: - String * mHostname; - unsigned int mPort; - String * mUsername; - String * mPassword; - AuthType mAuthType; - ConnectionType mConnectionType; - bool mCheckCertificateEnabled; - bool mVoIPEnabled; - char mDelimiter; - IMAPNamespace * mDefaultNamespace; - time_t mTimeout; - - bool mBodyProgressEnabled; - bool mIdleEnabled; - bool mXListEnabled; - bool mCondstoreEnabled; - bool mQResyncEnabled; - bool mIdentityEnabled; - String * mWelcomeString; - bool mNeedsMboxMailWorkaround; - uint32_t mUIDValidity; - uint32_t mUIDNext; - uint64_t mModSequenceValue; - unsigned int mFolderMsgCount; - uint32_t mFirstUnseenUid; - - unsigned int mLastFetchedSequenceNumber; - String * mCurrentFolder; - pthread_mutex_t mIdleLock; - bool mCanIdle; - int mState; - mailimap * mImap; - IMAPProgressCallback * mProgressCallback; - unsigned int mProgressItemsCount; - - void init(); - void bodyProgress(unsigned int current, unsigned int maximum); - void itemsProgress(unsigned int current, unsigned int maximum); - bool checkCertificate(); - static void body_progress(size_t current, size_t maximum, void * context); - static void items_progress(size_t current, size_t maximum, void * context); - void setup(); - void unsetup(); - void selectIfNeeded(String * folder, ErrorCode * pError); - char fetchDelimiterIfNeeded(char defaultDelimiter, ErrorCode * pError); - IMAPSyncResult * fetchMessages(String * folder, IMAPMessagesRequestKind requestKind, bool fetchByUID, + virtual void loginIfNeeded(ErrorCode * pError); + virtual void connectIfNeeded(ErrorCode * pError); + virtual bool isDisconnected(); + + private: + String * mHostname; + unsigned int mPort; + String * mUsername; + String * mPassword; + AuthType mAuthType; + ConnectionType mConnectionType; + bool mCheckCertificateEnabled; + bool mVoIPEnabled; + char mDelimiter; + IMAPNamespace * mDefaultNamespace; + time_t mTimeout; + + bool mBodyProgressEnabled; + bool mIdleEnabled; + bool mXListEnabled; + bool mCondstoreEnabled; + bool mQResyncEnabled; + bool mIdentityEnabled; + String * mWelcomeString; + bool mNeedsMboxMailWorkaround; + uint32_t mUIDValidity; + uint32_t mUIDNext; + uint64_t mModSequenceValue; + unsigned int mFolderMsgCount; + uint32_t mFirstUnseenUid; + + unsigned int mLastFetchedSequenceNumber; + String * mCurrentFolder; + pthread_mutex_t mIdleLock; + bool mCanIdle; + int mState; + mailimap * mImap; + IMAPProgressCallback * mProgressCallback; + unsigned int mProgressItemsCount; + + void init(); + void bodyProgress(unsigned int current, unsigned int maximum); + void itemsProgress(unsigned int current, unsigned int maximum); + bool checkCertificate(); + static void body_progress(size_t current, size_t maximum, void * context); + static void items_progress(size_t current, size_t maximum, void * context); + void setup(); + void unsetup(); + void selectIfNeeded(String * folder, ErrorCode * pError); + char fetchDelimiterIfNeeded(char defaultDelimiter, ErrorCode * pError); + IMAPSyncResult * fetchMessages(String * folder, IMAPMessagesRequestKind requestKind, bool fetchByUID, struct mailimap_set * imapset, uint64_t modseq, HashMap * mapping, uint32_t startUid, IMAPProgressCallback * progressCallback, ErrorCode * pError); - }; + }; } #endif diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc index fd5832f3..ee225b16 100644 --- a/src/core/smtp/MCSMTPSession.cc +++ b/src/core/smtp/MCSMTPSession.cc @@ -44,12 +44,10 @@ SMTPSession::SMTPSession() SMTPSession::~SMTPSession() { - MCLog("dealloc"); MC_SAFE_RELEASE(mLastSMTPResponse); MC_SAFE_RELEASE(mHostname); MC_SAFE_RELEASE(mUsername); MC_SAFE_RELEASE(mPassword); - MCLog("dealloc4"); } void SMTPSession::setHostname(String * hostname) @@ -679,3 +677,7 @@ void SMTPSession::sendMessage(MessageBuilder * msg, SMTPProgressCallback * callb recipients->release(); } +bool SMTPSession::isDisconnected() +{ + return mState == STATE_DISCONNECTED; +} diff --git a/src/core/smtp/MCSMTPSession.h b/src/core/smtp/MCSMTPSession.h index 70237c16..57c6e0ce 100644 --- a/src/core/smtp/MCSMTPSession.h +++ b/src/core/smtp/MCSMTPSession.h @@ -85,6 +85,9 @@ namespace mailcore { void sendMessage(Address * from, Array * /* Address */ recipients, Data * messageData, SMTPProgressCallback * callback, ErrorCode * pError); void sendMessage(MessageBuilder * msg, SMTPProgressCallback * callback, ErrorCode * pError); + + public: // private + virtual bool isDisconnected(); }; } diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index 6f9dd446..8b73aeaf 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -134,6 +134,8 @@ typedef enum { MCOIMAPMessagesRequestKindHeaderSubject = 1 << 5, /** Gmail Labels.*/ MCOIMAPMessagesRequestKindGmailLabels = 1 << 6, + /** Gmail Thread ID.*/ + MCOIMAPMessagesRequestKindGmailThreadID = 1 << 7, } MCOIMAPMessagesRequestKind; /** It defines the behavior of the STORE flags request.*/ diff --git a/src/objc/imap/MCOIMAPBaseOperation+Private.h b/src/objc/imap/MCOIMAPBaseOperation+Private.h new file mode 100644 index 00000000..e744355a --- /dev/null +++ b/src/objc/imap/MCOIMAPBaseOperation+Private.h @@ -0,0 +1,20 @@ +// +// Header.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOIMAPBASEOPERATION_PRIVATE_H_ +#define __MAILCORE_MCOIMAPBASEOPERATION_PRIVATE_H_ + +@class MCOIMAPSession; + +@interface MCOIMAPBaseOperation (Private) + +@property (nonatomic, retain) MCOIMAPSession * session; + +@end + +#endif diff --git a/src/objc/imap/MCOIMAPBaseOperation.mm b/src/objc/imap/MCOIMAPBaseOperation.mm index be398ece..ed67e34e 100644 --- a/src/objc/imap/MCOIMAPBaseOperation.mm +++ b/src/objc/imap/MCOIMAPBaseOperation.mm @@ -7,10 +7,12 @@ // #import "MCOIMAPBaseOperation.h" +#import "MCOIMAPBaseOperation+Private.h" #import "MCOOperation+Private.h" #import "MCAsyncIMAP.h" +#import "MCOIMAPSession.h" class MCOIMAPBaseOperationIMAPCallback : public mailcore::IMAPOperationCallback { public: @@ -33,6 +35,7 @@ private: @implementation MCOIMAPBaseOperation { MCOIMAPBaseOperationIMAPCallback * _imapCallback; + MCOIMAPSession * _session; } - (id) initWithMCOperation:(mailcore::Operation *)op @@ -47,10 +50,22 @@ private: - (void) dealloc { + [_session release]; delete _imapCallback; [super dealloc]; } +- (void) setSession:(MCOIMAPSession *)session +{ + [_session release]; + _session = [session retain]; +} + +- (MCOIMAPSession *) session +{ + return _session; +} + - (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum { } diff --git a/src/objc/imap/MCOIMAPMessage.h b/src/objc/imap/MCOIMAPMessage.h index c6d8595b..ab9771ca 100644 --- a/src/objc/imap/MCOIMAPMessage.h +++ b/src/objc/imap/MCOIMAPMessage.h @@ -49,6 +49,9 @@ /** All Gmail labels of the message */ @property (nonatomic, copy) NSArray * /* NSString */ gmailLabels; +/** Gmail thread iD of the message */ +@property (nonatomic, assign) uint64_t gmailThreadID; + /** Returns the part with the given part identifier. @param partID A part identifier looks like 1.2.1 diff --git a/src/objc/imap/MCOIMAPMessage.mm b/src/objc/imap/MCOIMAPMessage.mm index 9984443e..b5845bc2 100644 --- a/src/objc/imap/MCOIMAPMessage.mm +++ b/src/objc/imap/MCOIMAPMessage.mm @@ -47,6 +47,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(MCOMessageFlag, mailcore::MessageFlag, setOriginalFla MCO_OBJC_SYNTHESIZE_SCALAR(uint64_t, uint64_t, setModSeqValue, modSeqValue) MCO_OBJC_SYNTHESIZE(AbstractPart, setMainPart, mainPart) MCO_OBJC_SYNTHESIZE_ARRAY(setGmailLabels, gmailLabels) +MCO_OBJC_SYNTHESIZE_SCALAR(uint64_t, uint64_t, setGmailThreadID, gmailThreadID) - (MCOAbstractPart *) partForPartID:(NSString *)partID { diff --git a/src/objc/imap/MCOIMAPOperation.h b/src/objc/imap/MCOIMAPOperation.h index b8ee37e4..6f286596 100644 --- a/src/objc/imap/MCOIMAPOperation.h +++ b/src/objc/imap/MCOIMAPOperation.h @@ -12,9 +12,9 @@ /** This class implements a generic IMAP operation */ -#import <MailCore/MCOOperation.h> +#import <MailCore/MCOIMAPBaseOperation.h> -@interface MCOIMAPOperation : MCOOperation +@interface MCOIMAPOperation : MCOIMAPBaseOperation /** Starts the asynchronous append operation. diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index a13724ae..a8df8aed 100644 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -13,6 +13,7 @@ #import "MCOObjectWrapper.h" #import "MCOIMAPOperation.h" #import "MCOIMAPFetchFoldersOperation.h" +#import "MCOIMAPBaseOperation+Private.h" #import "MCOUtils.h" @@ -60,57 +61,74 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma #pragma mark - Operations +#define MCO_TO_OBJC_OP(op) [self _objcOperationFromNativeOp:op]; +#define OPAQUE_OPERATION(op) [self _objcOpaqueOperationFromNativeOp:op] + +- (id) _objcOperationFromNativeOp:(IMAPOperation *)op +{ + MCOIMAPBaseOperation * result = MCO_TO_OBJC(op); + [result setSession:self]; + return result; +} + +- (id) _objcOpaqueOperationFromNativeOp:(IMAPOperation *)op +{ + MCOIMAPOperation * result = [[[MCOIMAPOperation alloc] initWithMCOperation:op] autorelease]; + [result setSession:self]; + return result; +} + - (MCOIMAPFolderInfoOperation *) folderInfoOperation:(NSString *)folder { IMAPFolderInfoOperation * coreOp = MCO_NATIVE_INSTANCE->folderInfoOperation([folder mco_mcString]); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFolderStatusOperation *) folderStatusOperation:(NSString *)folder { IMAPFolderStatusOperation * coreOp = MCO_NATIVE_INSTANCE->folderStatusOperation([folder mco_mcString]); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchFoldersOperation *) fetchSubscribedFoldersOperation { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->fetchSubscribedFoldersOperation(); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchFoldersOperation *)fetchAllFoldersOperation { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->fetchAllFoldersOperation(); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPOperation *) renameFolderOperation:(NSString *)folder otherName:(NSString *)otherName { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->renameFolderOperation([folder mco_mcString], [otherName mco_mcString]); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPOperation *) deleteFolderOperation:(NSString *)folder { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->deleteFolderOperation([folder mco_mcString]); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPOperation *) createFolderOperation:(NSString *)folder { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->createFolderOperation([folder mco_mcString]); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPOperation *) subscribeFolderOperation:(NSString *)folder { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->subscribeFolderOperation([folder mco_mcString]); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPOperation *) unsubscribeFolderOperation:(NSString *)folder { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->unsubscribeFolderOperation([folder mco_mcString]); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPAppendMessageOperation *)appendMessageOperationWithFolder:(NSString *)folder @@ -120,7 +138,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma IMAPAppendMessageOperation * coreOp = MCO_NATIVE_INSTANCE->appendMessageOperation([folder mco_mcString], [messageData mco_mcData], (MessageFlag) flags); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPCopyMessagesOperation *)copyMessagesOperationWithFolder:(NSString *)folder @@ -130,14 +148,14 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma IMAPCopyMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->copyMessagesOperation([folder mco_mcString], MCO_FROM_OBJC(IndexSet, uids), [destFolder mco_mcString]); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPOperation *) expungeOperation:(NSString *)folder { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->expungeOperation([folder mco_mcString]); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPFetchMessagesOperation *) fetchMessagesByUIDOperationWithFolder:(NSString *)folder @@ -147,7 +165,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma IMAPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessagesByUIDOperation([folder mco_mcString], (IMAPMessagesRequestKind) requestKind, MCO_FROM_OBJC(IndexSet, uids)); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchMessagesOperation *) fetchMessagesByNumberOperationWithFolder:(NSString *)folder @@ -157,7 +175,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma IMAPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessagesByNumberOperation([folder mco_mcString], (IMAPMessagesRequestKind) requestKind, MCO_FROM_OBJC(IndexSet, numbers)); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchMessagesOperation *) syncMessagesByUIDWithFolder:(NSString *)folder @@ -169,7 +187,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma (IMAPMessagesRequestKind) requestKind, MCO_FROM_OBJC(IndexSet, uids), modSeq); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder @@ -177,7 +195,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma urgent:(BOOL)urgent { IMAPFetchContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageByUIDOperation([folder mco_mcString], uid, urgent); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder @@ -197,7 +215,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma [partID mco_mcString], (Encoding) encoding, urgent); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder @@ -217,7 +235,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma MCO_FROM_OBJC(IndexSet, uids), (IMAPStoreFlagsRequestKind) kind, (MessageFlag) flags); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPOperation *) storeLabelsOperationWithFolder:(NSString *)folder @@ -229,7 +247,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma MCO_FROM_OBJC(IndexSet, uids), (IMAPStoreFlagsRequestKind) kind, MCO_FROM_OBJC(Array, labels)); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPSearchOperation *) searchOperationWithFolder:(NSString *)folder @@ -239,7 +257,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma IMAPSearchOperation * coreOp = MCO_NATIVE_INSTANCE->searchOperation([folder mco_mcString], (IMAPSearchKind) kind, [searchString mco_mcString]); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPSearchOperation *) searchExpressionOperationWithFolder:(NSString *)folder @@ -247,20 +265,20 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma { IMAPSearchOperation * coreOp = MCO_NATIVE_INSTANCE->searchOperation([folder mco_mcString], MCO_FROM_OBJC(IMAPSearchExpression, expression)); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPIdleOperation *) idleOperationWithFolder:(NSString *)folder lastKnownUID:(uint32_t)lastKnownUID { IMAPIdleOperation * coreOp = MCO_NATIVE_INSTANCE->idleOperation([folder mco_mcString], lastKnownUID); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPFetchNamespaceOperation *) fetchNamespaceOperation { IMAPFetchNamespaceOperation * coreOp = MCO_NATIVE_INSTANCE->fetchNamespaceOperation(); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPIdentityOperation *) identityOperationWithVendor:(NSString *)vendor @@ -270,19 +288,19 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma IMAPIdentityOperation * coreOp = MCO_NATIVE_INSTANCE->identityOperation([vendor mco_mcString], [name mco_mcString], [version mco_mcString]); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOIMAPOperation *)checkAccountOperation { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation(); - return [[[MCOIMAPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOIMAPCapabilityOperation *) capabilityOperation { IMAPCapabilityOperation * coreOp = MCO_NATIVE_INSTANCE->capabilityOperation(); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } @end diff --git a/src/objc/pop/MCOPOPOperation+Private.h b/src/objc/pop/MCOPOPOperation+Private.h new file mode 100644 index 00000000..1d888f08 --- /dev/null +++ b/src/objc/pop/MCOPOPOperation+Private.h @@ -0,0 +1,20 @@ +// +// MCOPOPOperation+Private.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPOPERATION_PRIVATE_H_ +#define __MAILCORE_MCOPOPOPERATION_PRIVATE_H_ + +@class MCOPOPSession; + +@interface MCOPOPOperation (Private) + +@property (nonatomic, retain) MCOPOPSession * session; + +@end + +#endif diff --git a/src/objc/pop/MCOPOPOperation.mm b/src/objc/pop/MCOPOPOperation.mm index 7bb17bb8..9b58f84d 100644 --- a/src/objc/pop/MCOPOPOperation.mm +++ b/src/objc/pop/MCOPOPOperation.mm @@ -12,17 +12,20 @@ #import "MCOUtils.h" #import "MCOOperation+Private.h" +#import "MCOPOPSession.h" typedef void (^CompletionType)(NSError *error); @implementation MCOPOPOperation { CompletionType _completionBlock; + MCOPOPSession * _session; } #define nativeType mailcore::POPOperation - (void) dealloc { + [_session release]; [_completionBlock release]; [super dealloc]; } @@ -40,5 +43,15 @@ typedef void (^CompletionType)(NSError *error); _completionBlock(error); } +- (void) setSession:(MCOPOPSession *)session +{ + [_session release]; + _session = [session retain]; +} + +- (MCOPOPSession *) session +{ + return _session; +} @end diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm index 10806937..11f7cad6 100644 --- a/src/objc/pop/MCOPOPSession.mm +++ b/src/objc/pop/MCOPOPSession.mm @@ -14,6 +14,7 @@ #import "MCOPOPOperation.h" #import "MCOOperation+Private.h" #import "MCOPOPFetchMessagesOperation.h" +#import "MCOPOPOperation+Private.h" @implementation MCOPOPSession { mailcore::POPAsyncSession * _session; @@ -55,41 +56,59 @@ MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled) #pragma mark - Operations + +#define MCO_TO_OBJC_OP(op) [self _objcOperationFromNativeOp:op]; +#define OPAQUE_OPERATION(op) [self _objcOpaqueOperationFromNativeOp:op] + +- (id) _objcOperationFromNativeOp:(mailcore::POPOperation *)op +{ + MCOPOPOperation * result = MCO_TO_OBJC(op); + [result setSession:self]; + return result; +} + +- (id) _objcOpaqueOperationFromNativeOp:(mailcore::POPOperation *)op +{ + MCOPOPOperation * result = [[[MCOPOPOperation alloc] initWithMCOperation:op] autorelease]; + [result setSession:self]; + return result; +} + - (MCOPOPFetchMessagesOperation *) fetchMessagesOperation { mailcore::POPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessagesOperation(); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOPOPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index { mailcore::POPFetchHeaderOperation * coreOp = MCO_NATIVE_INSTANCE->fetchHeaderOperation(index); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } - (MCOPOPFetchMessageOperation *) fetchMessageOperationWithIndex:(unsigned int)index; { mailcore::POPFetchMessageOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageOperation(index); - return MCO_TO_OBJC(coreOp); + return MCO_TO_OBJC_OP(coreOp); } // Will disconnect. - (MCOPOPOperation *) deleteMessagesOperationWithIndexes:(MCOIndexSet *)indexes { mailcore::POPOperation * coreOp = MCO_NATIVE_INSTANCE->deleteMessagesOperation(MCO_FROM_OBJC(mailcore::IndexSet, indexes)); - return [[[MCOPOPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOPOPOperation *) disconnectOperation { mailcore::POPOperation * coreOp = MCO_NATIVE_INSTANCE->disconnectOperation(); - return [[[MCOPOPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } - (MCOPOPOperation *) checkAccountOperation { mailcore::POPOperation * coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation(); - return [[[MCOPOPOperation alloc] initWithMCOperation:coreOp] autorelease]; + return OPAQUE_OPERATION(coreOp); } @end diff --git a/src/objc/smtp/MCOSMTPOperation+Private.h b/src/objc/smtp/MCOSMTPOperation+Private.h new file mode 100644 index 00000000..5b9b5ee9 --- /dev/null +++ b/src/objc/smtp/MCOSMTPOperation+Private.h @@ -0,0 +1,20 @@ +// +// MCOSMTPOperation+Private.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOSMTPOPERATION_PRIVATE_H_ +#define __MAILCORE_MCOSMTPOPERATION_PRIVATE_H_ + +@class MCOSMTPSession; + +@interface MCOSMTPOperation (Private) + +@property (nonatomic, retain) MCOSMTPSession * session; + +@end + +#endif diff --git a/src/objc/smtp/MCOSMTPOperation.mm b/src/objc/smtp/MCOSMTPOperation.mm index d95c434d..cd52ad13 100644 --- a/src/objc/smtp/MCOSMTPOperation.mm +++ b/src/objc/smtp/MCOSMTPOperation.mm @@ -12,17 +12,20 @@ #import "MCOUtils.h" #import "MCOOperation+Private.h" +#import "MCOSMTPSession.h" typedef void (^CompletionType)(NSError *error); @implementation MCOSMTPOperation { CompletionType _completionBlock; + MCOSMTPSession * _session; } #define nativeType mailcore::SMTPOperation - (void) dealloc { + [_session release]; [_completionBlock release]; [super dealloc]; } @@ -40,4 +43,15 @@ typedef void (^CompletionType)(NSError *error); _completionBlock(error); } +- (void) setSession:(MCOSMTPSession *)session +{ + [_session release]; + _session = [session retain]; +} + +- (MCOSMTPSession *) session +{ + return _session; +} + @end diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm index ad8f212e..de6b54cd 100644 --- a/src/objc/smtp/MCOSMTPSession.mm +++ b/src/objc/smtp/MCOSMTPSession.mm @@ -15,6 +15,7 @@ #import "MCOSMTPOperation.h" #import "MCOOperation+Private.h" #import "MCOAddress.h" +#import "MCOSMTPOperation+Private.h" @implementation MCOSMTPSession { mailcore::SMTPAsyncSession * _session; @@ -55,13 +56,17 @@ MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled) - (MCOSMTPSendOperation *) sendOperationWithData:(NSData *)messageData { mailcore::SMTPOperation * coreOp = MCO_NATIVE_INSTANCE->sendMessageOperation([messageData mco_mcData]); - return [[[MCOSMTPSendOperation alloc] initWithMCOperation:coreOp] autorelease]; + MCOSMTPSendOperation * result = [[[MCOSMTPSendOperation alloc] initWithMCOperation:coreOp] autorelease]; + [result setSession:self]; + return result; } - (MCOOperation *) checkAccountOperationWithFrom:(MCOAddress *)from { mailcore::SMTPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation(MCO_FROM_OBJC(mailcore::Address, from)); - return [[[MCOSMTPOperation alloc] initWithMCOperation:coreOp] autorelease]; + MCOSMTPOperation * result = [[[MCOSMTPOperation alloc] initWithMCOperation:coreOp] autorelease]; + [result setSession:self]; + return result; } @end |