diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/abstract/MCMessageConstants.h | 1 | ||||
-rw-r--r-- | src/core/basetypes/MCMainThread.h | 11 | ||||
-rw-r--r-- | src/core/basetypes/MCMainThread.mm | 9 | ||||
-rw-r--r-- | src/core/basetypes/MCObject.cc | 71 | ||||
-rw-r--r-- | src/core/basetypes/MCObject.h | 1 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueue.cc | 24 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueue.h | 65 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueueCallback.h | 23 | ||||
-rw-r--r-- | src/core/imap/MCIMAPMessage.cc | 11 | ||||
-rw-r--r-- | src/core/imap/MCIMAPMessage.h | 72 | ||||
-rw-r--r-- | src/core/imap/MCIMAPSession.cc | 36 | ||||
-rw-r--r-- | src/core/imap/MCIMAPSession.h | 269 | ||||
-rw-r--r-- | src/core/smtp/MCSMTPSession.cc | 6 | ||||
-rw-r--r-- | src/core/smtp/MCSMTPSession.h | 3 |
14 files changed, 389 insertions, 213 deletions
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(); }; } |