diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-10-25 15:36:53 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-10-25 15:36:53 -0700 |
commit | 22caaf22182c2ece9a368bace9e31efa52ca567a (patch) | |
tree | e8970adc63cad779c77d79918bed661680f716dd /src | |
parent | cd37682217b0dafacfe02a3a3d64e2c80a329cce (diff) | |
parent | 8caeae6e162faed40eb3ae2dce1a654789eff01c (diff) |
Merge branch 'master' into removing-icu-dependency
Diffstat (limited to 'src')
-rwxr-xr-x | src/async/imap/MCAsyncIMAP.h | 1 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncConnection.cc | 36 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncConnection.h | 1 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncSession.cc | 32 | ||||
-rwxr-xr-x | src/async/imap/MCIMAPAsyncSession.h | 4 | ||||
-rw-r--r-- | src/async/imap/MCIMAPFetchParsedContentOperation.cc | 79 | ||||
-rw-r--r-- | src/async/imap/MCIMAPFetchParsedContentOperation.h | 53 | ||||
-rw-r--r-- | src/cmake/async.cmake | 1 | ||||
-rw-r--r-- | src/cmake/objc.cmake | 3 | ||||
-rw-r--r-- | src/cmake/public-headers.cmake | 2 | ||||
-rw-r--r-- | src/core/basetypes/MCData.cc | 36 | ||||
-rw-r--r-- | src/core/basetypes/MCData.h | 4 | ||||
-rw-r--r-- | src/core/basetypes/MCString.cc | 34 | ||||
-rw-r--r-- | src/core/basetypes/MCString.h | 2 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAP.h | 1 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFetchParsedContentOperation.h | 44 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFetchParsedContentOperation.mm | 84 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.h | 119 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.mm | 28 |
19 files changed, 482 insertions, 82 deletions
diff --git a/src/async/imap/MCAsyncIMAP.h b/src/async/imap/MCAsyncIMAP.h index da032c73..15c9e482 100755 --- a/src/async/imap/MCAsyncIMAP.h +++ b/src/async/imap/MCAsyncIMAP.h @@ -17,6 +17,7 @@ #include <MailCore/MCIMAPCopyMessagesOperation.h> #include <MailCore/MCIMAPFetchMessagesOperation.h> #include <MailCore/MCIMAPFetchContentOperation.h> +#include <MailCore/MCIMAPFetchParsedContentOperation.h> #include <MailCore/MCIMAPIdleOperation.h> #include <MailCore/MCIMAPFolderInfoOperation.h> #include <MailCore/MCIMAPFolderStatusOperation.h> diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc index 3a6508d6..b2fc24c3 100755 --- a/src/async/imap/MCIMAPAsyncConnection.cc +++ b/src/async/imap/MCIMAPAsyncConnection.cc @@ -21,7 +21,7 @@ #include "MCIMAPCopyMessagesOperation.h" #include "MCIMAPFetchMessagesOperation.h" #include "MCIMAPFetchContentOperation.h" -#include "MCIMAPFetchContentOperation.h" +#include "MCIMAPFetchParsedContentOperation.h" #include "MCIMAPStoreFlagsOperation.h" #include "MCIMAPStoreLabelsOperation.h" #include "MCIMAPSearchOperation.h" @@ -43,51 +43,51 @@ using namespace mailcore; namespace mailcore { - + class IMAPOperationQueueCallback : public Object, public OperationQueueCallback { public: IMAPOperationQueueCallback(IMAPAsyncConnection * connection) { mConnection = connection; } - + virtual ~IMAPOperationQueueCallback() { } - + virtual void queueStartRunning() { mConnection->setQueueRunning(true); mConnection->owner()->operationRunningStateChanged(); mConnection->queueStartRunning(); } - + virtual void queueStoppedRunning() { mConnection->setQueueRunning(false); mConnection->tryAutomaticDisconnect(); mConnection->owner()->operationRunningStateChanged(); mConnection->queueStoppedRunning(); } - + private: IMAPAsyncConnection * mConnection; }; - + class IMAPConnectionLogger : public Object, public ConnectionLogger { public: IMAPConnectionLogger(IMAPAsyncConnection * connection) { mConnection = connection; } - + virtual ~IMAPConnectionLogger() { } - + virtual void log(void * sender, ConnectionLogType logType, Data * buffer) { mConnection->logConnection(logType, buffer); } - + private: IMAPAsyncConnection * mConnection; }; - + } IMAPAsyncConnection::IMAPAsyncConnection() @@ -292,7 +292,7 @@ void IMAPAsyncConnection::tryAutomaticDisconnect() if (mSession->isDisconnected()) { return; } - + bool scheduledAutomaticDisconnect = mScheduledAutomaticDisconnect; if (scheduledAutomaticDisconnect) { #if __APPLE__ @@ -301,7 +301,7 @@ void IMAPAsyncConnection::tryAutomaticDisconnect() cancelDelayedPerformMethod((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL); #endif } - + mOwner->retain(); mScheduledAutomaticDisconnect = true; #if __APPLE__ @@ -309,7 +309,7 @@ void IMAPAsyncConnection::tryAutomaticDisconnect() #else performMethodAfterDelay((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL, 30); #endif - + if (scheduledAutomaticDisconnect) { mOwner->release(); } @@ -318,10 +318,10 @@ void IMAPAsyncConnection::tryAutomaticDisconnect() void IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay(void * context) { mScheduledAutomaticDisconnect = false; - + IMAPOperation * op = disconnectOperation(); op->start(); - + mOwner->release(); } @@ -373,11 +373,11 @@ void IMAPAsyncConnection::setConnectionLogger(ConnectionLogger * logger) ConnectionLogger * IMAPAsyncConnection::connectionLogger() { ConnectionLogger * result; - + pthread_mutex_lock(&mConnectionLoggerLock); result = mConnectionLogger; pthread_mutex_unlock(&mConnectionLoggerLock); - + return result; } diff --git a/src/async/imap/MCIMAPAsyncConnection.h b/src/async/imap/MCIMAPAsyncConnection.h index 50d1409a..b267f7c7 100755 --- a/src/async/imap/MCIMAPAsyncConnection.h +++ b/src/async/imap/MCIMAPAsyncConnection.h @@ -15,6 +15,7 @@ namespace mailcore { class IMAPCopyMessagesOperation; class IMAPFetchMessagesOperation; class IMAPFetchContentOperation; + class IMAPFetchParsedContentOperation; class IMAPIdleOperation; class IMAPFolderInfoOperation; class IMAPFolderStatusOperation; diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc index ef3bb621..f3a55a5e 100755 --- a/src/async/imap/MCIMAPAsyncSession.cc +++ b/src/async/imap/MCIMAPAsyncSession.cc @@ -28,7 +28,7 @@ #include "MCIMAPCopyMessagesOperation.h" #include "MCIMAPFetchMessagesOperation.h" #include "MCIMAPFetchContentOperation.h" -#include "MCIMAPFetchContentOperation.h" +#include "MCIMAPFetchParsedContentOperation.h" #include "MCIMAPStoreFlagsOperation.h" #include "MCIMAPStoreLabelsOperation.h" #include "MCIMAPSearchOperation.h" @@ -52,7 +52,7 @@ IMAPAsyncSession::IMAPAsyncSession() mSessions = new Array(); mMaximumConnections = DEFAULT_MAX_CONNECTIONS; mAllowsFolderConcurrentAccessEnabled = true; - + mHostname = NULL; mPort = 0; mUsername = NULL; @@ -244,7 +244,7 @@ IMAPAsyncConnection * IMAPAsyncSession::session() session->setConnectionLogger(mConnectionLogger); session->setOwner(this); session->autorelease(); - + session->setHostname(mHostname); session->setPort(mPort); session->setUsername(mUsername); @@ -265,7 +265,7 @@ IMAPAsyncConnection * IMAPAsyncSession::session() session->setAutomaticConfigurationEnabled(false); } #endif - + return session; } @@ -283,7 +283,7 @@ IMAPAsyncConnection * IMAPAsyncSession::sessionForFolder(String * folder, bool u return s; } } - + s = matchingSessionForFolder(folder); s->setLastFolder(folder); return s; @@ -549,6 +549,28 @@ IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageAttachmentByNumberOper return op; } +IMAPFetchParsedContentOperation * IMAPAsyncSession::fetchParsedMessageByUIDOperation(String * folder, uint32_t uid, bool urgent) +{ + IMAPFetchParsedContentOperation * op = new IMAPFetchParsedContentOperation(); + op->setMainSession(this); + op->setFolder(folder); + op->setUid(uid); + op->setUrgent(urgent); + op->autorelease(); + return op; +} + +IMAPFetchParsedContentOperation * IMAPAsyncSession::fetchParsedMessageByNumberOperation(String * folder, uint32_t number, bool urgent) +{ + IMAPFetchParsedContentOperation * op = new IMAPFetchParsedContentOperation(); + op->setMainSession(this); + op->setFolder(folder); + op->setNumber(number); + op->setUrgent(urgent); + op->autorelease(); + return op; +} + IMAPOperation * IMAPAsyncSession::storeFlagsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags) { IMAPStoreFlagsOperation * op = new IMAPStoreFlagsOperation(); diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h index a7ec90a0..05b1967c 100755 --- a/src/async/imap/MCIMAPAsyncSession.h +++ b/src/async/imap/MCIMAPAsyncSession.h @@ -23,6 +23,7 @@ namespace mailcore { class IMAPCopyMessagesOperation; class IMAPFetchMessagesOperation; class IMAPFetchContentOperation; + class IMAPFetchParsedContentOperation; class IMAPIdleOperation; class IMAPFolderInfoOperation; class IMAPFolderStatusOperation; @@ -137,6 +138,9 @@ namespace mailcore { virtual IMAPFetchContentOperation * fetchMessageAttachmentByNumberOperation(String * folder, uint32_t number, String * partID, Encoding encoding, bool urgent = false); + virtual IMAPFetchParsedContentOperation * fetchParsedMessageByUIDOperation(String * folder, uint32_t uid, bool urgent = false); + virtual IMAPFetchParsedContentOperation * fetchParsedMessageByNumberOperation(String * folder, uint32_t number, bool urgent = false); + virtual IMAPOperation * storeFlagsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags = NULL); virtual IMAPOperation * storeFlagsByNumberOperation(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags = NULL); virtual IMAPOperation * storeLabelsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels); diff --git a/src/async/imap/MCIMAPFetchParsedContentOperation.cc b/src/async/imap/MCIMAPFetchParsedContentOperation.cc new file mode 100644 index 00000000..e32112e6 --- /dev/null +++ b/src/async/imap/MCIMAPFetchParsedContentOperation.cc @@ -0,0 +1,79 @@ +// +// IMAPFetchParsedContentOperation.cc +// mailcore2 +// +// Created by DINH Viêt Hoà on 1/12/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#include "MCIMAPFetchParsedContentOperation.h" + +#include "MCIMAPSession.h" +#include "MCIMAPAsyncConnection.h" + +using namespace mailcore; + +IMAPFetchParsedContentOperation::IMAPFetchParsedContentOperation() +{ + mUid = 0; + mNumber = 0; + mEncoding = Encoding7Bit; + mParser = NULL; +} + +IMAPFetchParsedContentOperation::~IMAPFetchParsedContentOperation() +{ + MC_SAFE_RELEASE(mParser); +} + +void IMAPFetchParsedContentOperation::setUid(uint32_t uid) +{ + mUid = uid; +} + +uint32_t IMAPFetchParsedContentOperation::uid() +{ + return mUid; +} + +void IMAPFetchParsedContentOperation::setNumber(uint32_t value) +{ + mNumber = value; +} + +uint32_t IMAPFetchParsedContentOperation::number() +{ + return mNumber; +} + +void IMAPFetchParsedContentOperation::setEncoding(Encoding encoding) +{ + mEncoding = encoding; +} + +Encoding IMAPFetchParsedContentOperation::encoding() +{ + return mEncoding; +} + +MessageParser * IMAPFetchParsedContentOperation::parser() +{ + return mParser; +} + +void IMAPFetchParsedContentOperation::main() +{ + ErrorCode error; + Data * data; + if (mUid != 0) { + data = session()->session()->fetchMessageByUID(folder(), mUid, this, &error); + } + else { + data = session()->session()->fetchMessageByNumber(folder(), mNumber, this, &error); + } + if (data) { + mParser = new mailcore::MessageParser(data); + } + setError(error); +} + diff --git a/src/async/imap/MCIMAPFetchParsedContentOperation.h b/src/async/imap/MCIMAPFetchParsedContentOperation.h new file mode 100644 index 00000000..0262a35b --- /dev/null +++ b/src/async/imap/MCIMAPFetchParsedContentOperation.h @@ -0,0 +1,53 @@ +// +// IMAPFetchParsedContentOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 1/12/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef MAILCORE_IMAPFETCHPARSEDCONTENTOPERATION_H + +#define MAILCORE_IMAPFETCHPARSEDCONTENTOPERATION_H + +#include <MailCore/MCIMAPOperation.h> + +#include <MailCore/MCRFC822.h> + +#ifdef __cplusplus + +namespace mailcore { + + class IMAPFetchParsedContentOperation : public IMAPOperation { + public: + IMAPFetchParsedContentOperation(); + virtual ~IMAPFetchParsedContentOperation(); + + virtual void setUid(uint32_t uid); + virtual uint32_t uid(); + + virtual void setNumber(uint32_t value); + virtual uint32_t number(); + + virtual void setEncoding(Encoding encoding); + virtual Encoding encoding(); + + // Result. + virtual MessageParser * parser(); + + public: // subclass behavior + virtual void main(); + + private: + uint32_t mUid; + uint32_t mNumber; + Encoding mEncoding; + MessageParser * mParser; + + }; + +} + +#endif + +#endif diff --git a/src/cmake/async.cmake b/src/cmake/async.cmake index 58f410d4..947a69ee 100644 --- a/src/cmake/async.cmake +++ b/src/cmake/async.cmake @@ -13,6 +13,7 @@ set(async_imap_files async/imap/MCIMAPDisconnectOperation.cc async/imap/MCIMAPExpungeOperation.cc async/imap/MCIMAPFetchContentOperation.cc + async/imap/MCIMAPFetchParsedContentOperation.cc async/imap/MCIMAPFetchFoldersOperation.cc async/imap/MCIMAPFetchMessagesOperation.cc async/imap/MCIMAPFetchNamespaceOperation.cc diff --git a/src/cmake/objc.cmake b/src/cmake/objc.cmake index de4d8d06..cdf09dd6 100644 --- a/src/cmake/objc.cmake +++ b/src/cmake/objc.cmake @@ -16,6 +16,7 @@ set(objc_imap_files objc/imap/MCOIMAPCapabilityOperation.mm objc/imap/MCOIMAPCopyMessagesOperation.mm objc/imap/MCOIMAPFetchContentOperation.mm + objc/imap/MCOIMAPFetchParsedContentOperation.mm objc/imap/MCOIMAPFetchFoldersOperation.mm objc/imap/MCOIMAPFetchMessagesOperation.mm objc/imap/MCOIMAPFetchNamespaceOperation.mm @@ -84,7 +85,7 @@ set(objc_nntp_files objc/nntp/MCONNTPFetchOverviewOperation.mm objc/nntp/MCONNTPFetchServerTimeOperation.mm objc/nntp/MCONNTPOperation.mm - objc/nntp/MCONNTPSession.mm + objc/nntp/MCONNTPSession.mm ) set(objc_utils_files diff --git a/src/cmake/public-headers.cmake b/src/cmake/public-headers.cmake index 8b55c15e..65be3be7 100644 --- a/src/cmake/public-headers.cmake +++ b/src/cmake/public-headers.cmake @@ -86,6 +86,7 @@ async/imap/MCIMAPAppendMessageOperation.h async/imap/MCIMAPCopyMessagesOperation.h async/imap/MCIMAPFetchMessagesOperation.h async/imap/MCIMAPFetchContentOperation.h +async/imap/MCIMAPFetchParsedContentOperation.h async/imap/MCIMAPIdleOperation.h async/imap/MCIMAPFolderInfoOperation.h async/imap/MCIMAPFolderStatusOperation.h @@ -160,6 +161,7 @@ objc/imap/MCOIMAPAppendMessageOperation.h objc/imap/MCOIMAPCopyMessagesOperation.h objc/imap/MCOIMAPFetchMessagesOperation.h objc/imap/MCOIMAPFetchContentOperation.h +objc/imap/MCOIMAPFetchParsedContentOperation.h objc/imap/MCOIMAPSearchOperation.h objc/imap/MCOIMAPIdleOperation.h objc/imap/MCOIMAPFetchNamespaceOperation.h diff --git a/src/core/basetypes/MCData.cc b/src/core/basetypes/MCData.cc index 5f2282d9..9845d77a 100644 --- a/src/core/basetypes/MCData.cc +++ b/src/core/basetypes/MCData.cc @@ -27,17 +27,29 @@ using namespace mailcore; -void Data::allocate(unsigned int length) +static int isPowerOfTwo (unsigned int x) { - length ++; - if (length < mAllocated) + return ((x != 0) && !(x & (x - 1))); +} + +void Data::allocate(unsigned int length, bool force) +{ + if (length <= mAllocated) return; - - if (mAllocated == 0) { - mAllocated = 4; + + if (force) { + mAllocated = length; } - while (length > mAllocated) { - mAllocated *= 2; + else { + if (!isPowerOfTwo(mAllocated)) { + mAllocated = 0; + } + if (mAllocated == 0) { + mAllocated = 4; + } + while (length > mAllocated) { + mAllocated *= 2; + } } mBytes = (char *) realloc(mBytes, mAllocated); @@ -68,7 +80,7 @@ Data::Data(const char * bytes, unsigned int length) { mBytes = NULL; reset(); - allocate(length); + allocate(length, true); appendBytes(bytes, length); } @@ -76,7 +88,7 @@ Data::Data(int capacity) { mBytes = NULL; reset(); - allocate(capacity); + allocate(capacity, true); } Data::~Data() @@ -483,7 +495,7 @@ String * Data::charsetWithFilteredHTML(bool filterHTML, String * hintCharset) #endif } -void Data::replaceWithAllocatedBytes(char * bytes, unsigned int length) +void Data::takeBytesOwnership(char * bytes, unsigned int length) { free(mBytes); mBytes = (char *) bytes; @@ -520,7 +532,7 @@ Data * Data::dataWithContentsOfFile(String * filename) } data = Data::data(); - data->replaceWithAllocatedBytes(buf, (unsigned int) stat_buf.st_size); + data->takeBytesOwnership(buf, (unsigned int) stat_buf.st_size); fclose(f); diff --git a/src/core/basetypes/MCData.h b/src/core/basetypes/MCData.h index 131cb722..43ffb30f 100644 --- a/src/core/basetypes/MCData.h +++ b/src/core/basetypes/MCData.h @@ -62,10 +62,10 @@ namespace mailcore { char * mBytes; unsigned int mLength; unsigned int mAllocated; - void allocate(unsigned int length); + void allocate(unsigned int length, bool force = false); void reset(); String * charsetWithFilteredHTMLWithoutHint(bool filterHTML); - void replaceWithAllocatedBytes(char * bytes, unsigned int length); + void takeBytesOwnership(char * bytes, unsigned int length); }; diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc index a122c1e6..88c61a99 100644 --- a/src/core/basetypes/MCString.cc +++ b/src/core/basetypes/MCString.cc @@ -754,7 +754,7 @@ String::String(const UChar * unicodeChars) mUnicodeChars = NULL; reset(); if (unicodeChars != NULL) { - allocate(u_strlen(unicodeChars)); + allocate(u_strlen(unicodeChars), true); } appendCharacters(unicodeChars); } @@ -763,7 +763,7 @@ String::String(const UChar * unicodeChars, unsigned int length) { mUnicodeChars = NULL; reset(); - allocate(length); + allocate(length, true); appendCharactersLength(unicodeChars, length); } @@ -771,6 +771,7 @@ String::String(const char * UTF8Characters) { mUnicodeChars = NULL; reset(); + allocate((unsigned int) strlen(UTF8Characters), true); appendUTF8Characters(UTF8Characters); } @@ -792,7 +793,7 @@ String::String(const char * bytes, unsigned int length, const char * charset) { mUnicodeChars = NULL; reset(); - allocate(length); + allocate(length, true); if (charset == NULL) { appendUTF8CharactersLength(bytes, length); } @@ -806,17 +807,30 @@ String::~String() reset(); } -void String::allocate(unsigned int length) +static int isPowerOfTwo (unsigned int x) +{ + return ((x != 0) && !(x & (x - 1))); +} + +void String::allocate(unsigned int length, bool force) { length ++; - if (length < mAllocated) + if (length <= mAllocated) return; - - if (mAllocated == 0) { - mAllocated = 4; + + if (force) { + mAllocated = length; } - while (length > mAllocated) { - mAllocated *= 2; + else { + if (!isPowerOfTwo(mAllocated)) { + mAllocated = 0; + } + if (mAllocated == 0) { + mAllocated = 4; + } + while (length > mAllocated) { + mAllocated *= 2; + } } mUnicodeChars = (UChar *) realloc(mUnicodeChars, mAllocated * sizeof(* mUnicodeChars)); diff --git a/src/core/basetypes/MCString.h b/src/core/basetypes/MCString.h index 25439cf2..cad79c21 100644 --- a/src/core/basetypes/MCString.h +++ b/src/core/basetypes/MCString.h @@ -130,7 +130,7 @@ namespace mailcore { UChar * mUnicodeChars; unsigned int mLength; unsigned int mAllocated; - void allocate(unsigned int length); + void allocate(unsigned int length, bool force = false); void reset(); int compareWithCaseSensitive(String * otherString, bool caseSensitive); void appendBytes(const char * bytes, unsigned int length, const char * charset); diff --git a/src/objc/imap/MCOIMAP.h b/src/objc/imap/MCOIMAP.h index 7acffcef..1957afd8 100755 --- a/src/objc/imap/MCOIMAP.h +++ b/src/objc/imap/MCOIMAP.h @@ -29,6 +29,7 @@ #import <MailCore/MCOIMAPCopyMessagesOperation.h> #import <MailCore/MCOIMAPFetchMessagesOperation.h> #import <MailCore/MCOIMAPFetchContentOperation.h> +#import <MailCore/MCOIMAPFetchParsedContentOperation.h> #import <MailCore/MCOIMAPSearchOperation.h> #import <MailCore/MCOIMAPIdleOperation.h> #import <MailCore/MCOIMAPFetchNamespaceOperation.h> diff --git a/src/objc/imap/MCOIMAPFetchParsedContentOperation.h b/src/objc/imap/MCOIMAPFetchParsedContentOperation.h new file mode 100644 index 00000000..de2b1663 --- /dev/null +++ b/src/objc/imap/MCOIMAPFetchParsedContentOperation.h @@ -0,0 +1,44 @@ +// +// MCOIMAPFetchParsedContentOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/25/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef MAILCORE_MCOIMAPFETCHPARSEDCONTENTOPERATION_H + +#define MAILCORE_MCOIMAPFETCHPARSEDCONTENTOPERATION_H + +/** + This class implements an operation to fetch the parsed content of a message. +*/ + +#import <MailCore/MCOIMAPBaseOperation.h> +#import <MailCore/MCOConstants.h> + +@class MCOMessageParser; + +@interface MCOIMAPFetchParsedContentOperation : MCOIMAPBaseOperation + +/** + This block will be called as bytes are received from the network +*/ +@property (nonatomic, copy) MCOIMAPBaseOperationProgressBlock progress; + +/** + Starts the asynchronous fetch operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil and `parser` will contain the requested message + + - On failure, `error` will be set with `MCOErrorDomain` as domain and an + error code available in `MCOConstants.h`, `data` will be nil +*/ + +- (void) start:(void (^)(NSError * error, MCOMessageParser * parser))completionBlock; + +@end + +#endif diff --git a/src/objc/imap/MCOIMAPFetchParsedContentOperation.mm b/src/objc/imap/MCOIMAPFetchParsedContentOperation.mm new file mode 100644 index 00000000..5c1ebde3 --- /dev/null +++ b/src/objc/imap/MCOIMAPFetchParsedContentOperation.mm @@ -0,0 +1,84 @@ +// +// MCOIMAPFetchParsedContentOperation.m +// mailcore2 +// +// Created by DINH Viêt Hoà on 3/25/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOIMAPFetchParsedContentOperation.h" + +#include "MCAsyncIMAP.h" + +#import "MCOMessageParser.h" +#import "MCOOperation+Private.h" +#import "MCOUtils.h" + +typedef void (^CompletionType)(NSError *error, NSData * data); + +@implementation MCOIMAPFetchParsedContentOperation { + CompletionType _completionBlock; + MCOIMAPBaseOperationProgressBlock _progress; +} + +@synthesize progress = _progress; + +#define nativeType mailcore::IMAPFetchParsedContentOperation + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + nativeType * op = (nativeType *) object; + return [[[self alloc] initWithMCOperation:op] autorelease]; +} + +- (void) dealloc +{ + [_progress release]; + [_completionBlock release]; + [super dealloc]; +} + +- (void) start:(void (^)(NSError *error, MCOMessageParser * parser))completionBlock { + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void) cancel +{ + [_completionBlock release]; + _completionBlock = nil; + [super cancel]; +} + +- (void) operationCompleted +{ + if (_completionBlock == NULL) + return; + + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + if (op->parser()) { + _completionBlock(nil, MCO_TO_OBJC(op->parser())); + } else { + _completionBlock(nil, nil); + } + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } + [_completionBlock release]; + _completionBlock = nil; +} + +- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum +{ + if (_progress != NULL) { + _progress(current, maximum); + } +} + +@end diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index a6034e9a..660c896d 100755 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -23,6 +23,7 @@ @class MCOIndexSet; @class MCOIMAPFetchMessagesOperation; @class MCOIMAPFetchContentOperation; +@class MCOIMAPFetchParsedContentOperation; @class MCOIMAPSearchOperation; @class MCOIMAPIdleOperation; @class MCOIMAPFetchNamespaceOperation; @@ -35,7 +36,7 @@ @class MCOIMAPIdentity; /** - This is the main IMAP class from which all operations are created + This is the main IMAP class from which all operations are created After calling a method that returns an operation you must call start: on the instance to begin the operation. @@ -58,7 +59,7 @@ /** This is the OAuth2 token. */ @property (nonatomic, copy) NSString *OAuth2Token; -/** +/** This is the authentication type to use to connect. `MCOAuthTypeSASLNone` means that it uses the clear-text is used (and is the default). @warning *Important*: Over an encrypted connection like TLS, the password will still be secure @@ -105,7 +106,7 @@ /** Sets logger callback. The network traffic will be sent to this block. - + [session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) { NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]); // ... @@ -130,7 +131,7 @@ /** Sets operation running callback. It will be called when operations start or stop running. - + [session setOperationQueueRunningChangeBlock:^{ if ([session isOperationQueueRunning]) { ... @@ -165,7 +166,7 @@ /** Returns an operation that retrieves folder status (like UIDNext - Unseen -) - + MCOIMAPFolderStatusOperation * op = [session folderStatusOperation:@"INBOX"]; [op start:^(NSError *error, MCOIMAPFolderStatus * info) { NSLog(@"UIDNEXT: %lu", (unsigned long) [info uidNext]); @@ -178,7 +179,7 @@ /** Returns an operation that gets the list of subscribed folders. - + MCOIMAPFetchFoldersOperation * op = [session fetchSubscribedFoldersOperation]; [op start:^(NSError * error, NSArray * folders) { ... @@ -225,7 +226,7 @@ [op start:^(NSError * error) { ... }]; -*/ +*/ - (MCOIMAPOperation *) createFolderOperation:(NSString *)folder; /** @@ -282,7 +283,7 @@ /** Returns an operation to add a message with custom flags to a folder. - + MCOIMAPOperation * op = [session appendMessageOperationWithFolder:@"Sent Mail" messageData:rfc822Data flags:MCOMessageFlagNone customFlags:@[@"$CNS-Greeting-On"]]; [op start:^(NSError * error, uint32_t createdUID) { if (error == nil) { @@ -329,9 +330,9 @@ /** Returns an operation to change flags of messages, using IMAP sequence number. - + For example: Adds the seen flag to the message with the sequence number number 42. - + MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX" numbers:[MCOIndexSet indexSetWithIndex:42] kind:MCOIMAPStoreFlagsRequestKindAdd @@ -347,9 +348,9 @@ /** Returns an operation to change flags and custom flags of messages. - + For example: Adds the seen flag and $CNS-Greeting-On flag to the message with UID 456. - + MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX" uids:[MCOIndexSet indexSetWithIndex:456] kind:MCOIMAPStoreFlagsRequestKindAdd @@ -368,9 +369,9 @@ /** Returns an operation to change flags and custom flags of messages, using IMAP sequence number. - + For example: Adds the seen flag and $CNS-Greeting-On flag to the message with the sequence number 42. - + MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX" numbers:[MCOIndexSet indexSetWithIndex:42] kind:MCOIMAPStoreFlagsRequestKindAdd @@ -461,16 +462,16 @@ For example: show 50 most recent uids. NSString *folder = @"INBOX"; MCOIMAPFolderInfoOperation *folderInfo = [session folderInfoOperation:folder]; - + [folderInfo start:^(NSError *error, MCOIMAPFolderInfo *info) { int numberOfMessages = 50; numberOfMessages -= 1; MCOIndexSet *numbers = [MCOIndexSet indexSetWithRange:MCORangeMake([info messageCount] - numberOfMessages, numberOfMessages)]; - + MCOIMAPFetchMessagesOperation *fetchOperation = [session fetchMessagesByNumberOperationWithFolder:folder requestKind:MCOIMAPMessagesRequestKindUid numbers:numbers]; - + [fetchOperation start:^(NSError *error, NSArray *messages, MCOIndexSet *vanishedMessages) { for (MCOIMAPMessage * message in messages) { NSLog(@"%u", [message uid]); @@ -600,6 +601,58 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 - (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder number:(uint32_t)number; +/** + Returns an operation to fetch the parsed content of a message. + @param urgent is set to YES, an additional connection to the same folder might be opened to fetch the content. + + MCOIMAPFetchParsedContentOperation * op = [session fetchParsedMessageOperationWithFolder:@"INBOX" uid:456 urgent:NO]; + [op start:^(NSError * error, MCOMessageParser * parser) { + + ... + }]; + */ +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + uid:(uint32_t)uid + urgent:(BOOL)urgent; + +/** + Returns an operation to fetch the parsed content of a message. + + MCOIMAPFetchParsedContentOperation * op = [session fetchParsedMessageOperationWithFolder:@"INBOX" uid:456]; + [op start:^(NSError * error, MCOMessageParser * parser) { + + ... + }]; + */ +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + uid:(uint32_t)uid; + +/** + Returns an operation to fetch the parsed content of a message, using IMAP sequence number. + @param urgent is set to YES, an additional connection to the same folder might be opened to fetch the content. + + MCOIMAPFetchParsedContentOperation * op = [session fetchParsedMessageOperationWithFolder:@"INBOX" number:42 urgent:NO]; + [op start:^(NSError * error, MCOMessageParser * parser) { + + ... + }]; + */ +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + number:(uint32_t)number + urgent:(BOOL)urgent; + +/** + Returns an operation to fetch the parsed content of a message, using IMAP sequence number. + + MCOIMAPFetchParsedContentOperation * op = [session fetchParsedMessageOperationWithFolder:@"INBOX" number:42]; + [op start:^(NSError * error, MCOMessageParser * parser) { + + ... + }]; + */ +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + number:(uint32_t)number; + /** @name Fetching Attachment Operations */ /** @@ -633,7 +686,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 [op start:^(NSError * error, NSData * partData) { ... }]; - + Example 2: MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX" @@ -680,7 +733,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 [op start:^(NSError * error, NSData * partData) { ... }]; - + Example 2: MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX" @@ -727,7 +780,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 [op start:^(NSError * error, NSData * partData) { ... }]; - + Example 2: MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX" @@ -758,7 +811,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 - (MCOIMAPIdleOperation *) idleOperationWithFolder:(NSString *)folder lastKnownUID:(uint32_t)lastKnownUID; -/** +/** Returns an operation to fetch the list of namespaces. MCOIMAPFetchNamespaceOperation * op = [session fetchNamespaceOperation]; @@ -789,7 +842,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 /** Returns an operation that will connect to the given IMAP server without authenticating. Useful for checking initial server capabilities. - + MCOIMAPOperation * op = [session connectOperation]; [op start:^(NSError * error) { ... @@ -799,7 +852,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 /** Returns an operation that will perform a No-Op operation on the given IMAP server. - + MCOIMAPOperation * op = [session noopOperation]; [op start:^(NSError * error) { ... @@ -867,10 +920,10 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 /** Returns an operation to render the HTML version of a message to be displayed in a web view. - + MCOIMAPMessageRenderingOperation * op = [session htmlRenderingOperationWithMessage:msg folder:@"INBOX"]; - + [op start:^(NSString * htmlString, NSError * error) { ... }]; @@ -880,10 +933,10 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 /** Returns an operation to render the HTML body of a message to be displayed in a web view. - + MCOIMAPMessageRenderingOperation * op = [session htmlBodyRenderingOperationWithMessage:msg folder:@"INBOX"]; - + [op start:^(NSString * htmlString, NSError * error) { ... }]; @@ -893,7 +946,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 /** Returns an operation to render the plain text version of a message. - + MCOIMAPMessageRenderingOperation * op = [session plainTextRenderingOperationWithMessage:msg folder:@"INBOX"]; @@ -908,11 +961,11 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 Returns an operation to render the plain text body of a message. All end of line will be removed and white spaces cleaned up if requested. This method can be used to generate the summary of the message. - + MCOIMAPMessageRenderingOperation * op = [session plainTextBodyRenderingOperationWithMessage:msg folder:@"INBOX" stripWhitespace:YES]; - + [op start:^(NSString * htmlString, NSError * error) { ... }]; @@ -925,10 +978,10 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 Returns an operation to render the plain text body of a message. All end of line will be removed and white spaces cleaned up. This method can be used to generate the summary of the message. - + MCOIMAPMessageRenderingOperation * op = [session plainTextBodyRenderingOperationWithMessage:msg folder:@"INBOX"]; - + [op start:^(NSString * htmlString, NSError * error) { ... }]; @@ -939,7 +992,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162 /** Returns an operation to disconnect the session. It will disconnect all the sockets created by the session. - + MCOIMAPOperation * op = [session disconnectOperation]; [op start:^(NSError * error) { ... diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index c7c389a4..d22efbc9 100755 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -369,6 +369,34 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue, return [self fetchMessageOperationWithFolder:folder number:number urgent:NO]; } +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + uid:(uint32_t)uid + urgent:(BOOL)urgent +{ + IMAPFetchParsedContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchParsedMessageByUIDOperation([folder mco_mcString], uid, urgent); + return MCO_TO_OBJC_OP(coreOp); +} + +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + uid:(uint32_t)uid +{ + return [self fetchParsedMessageOperationWithFolder:folder uid:uid urgent:NO]; +} + +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + number:(uint32_t)number + urgent:(BOOL)urgent +{ + IMAPFetchParsedContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchParsedMessageByNumberOperation([folder mco_mcString], number, urgent); + return MCO_TO_OBJC_OP(coreOp); +} + +- (MCOIMAPFetchParsedContentOperation *) fetchParsedMessageOperationWithFolder:(NSString *)folder + number:(uint32_t)number +{ + return [self fetchParsedMessageOperationWithFolder:folder number:number urgent:NO]; +} + - (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder uid:(uint32_t)uid partID:(NSString *)partID |