diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-10-25 09:12:24 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-10-25 09:12:24 -0700 |
commit | cd37682217b0dafacfe02a3a3d64e2c80a329cce (patch) | |
tree | f241bc5de3a9855d1a94d9be80b8798b7ad37a69 /src/core | |
parent | 128a11a36103c3a57372cf72a51e52744524d827 (diff) | |
parent | 386f84abe048c4b37cef42195d612b480021df3f (diff) |
Merge branch 'master' into removing-icu-dependency
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/abstract/MCAbstractPart.cc | 5 | ||||
-rw-r--r-- | src/core/abstract/MCMessageConstants.h | 1 | ||||
-rw-r--r-- | src/core/abstract/MCMessageHeader.cc | 5 | ||||
-rw-r--r-- | src/core/basetypes/MCData.cc | 12 | ||||
-rw-r--r-- | src/core/basetypes/MCData.h | 8 | ||||
-rw-r--r-- | src/core/basetypes/MCDataMac.mm | 22 | ||||
-rw-r--r-- | src/core/basetypes/MCString.cc | 6 | ||||
-rw-r--r-- | src/core/nntp/MCNNTPSession.cc | 366 | ||||
-rw-r--r-- | src/core/nntp/MCNNTPSession.h | 14 | ||||
-rw-r--r-- | src/core/rfc822/MCMessageParser.cc | 47 | ||||
-rw-r--r-- | src/core/rfc822/MCMessageParser.h | 15 | ||||
-rw-r--r-- | src/core/rfc822/MCMessageParserMac.mm | 34 |
12 files changed, 500 insertions, 35 deletions
diff --git a/src/core/abstract/MCAbstractPart.cc b/src/core/abstract/MCAbstractPart.cc index 5b7a1c9a..04e99e4d 100644 --- a/src/core/abstract/MCAbstractPart.cc +++ b/src/core/abstract/MCAbstractPart.cc @@ -439,10 +439,11 @@ void AbstractPart::removeContentTypeParameter(String * name) String * AbstractPart::contentTypeParameterValueForName(String * name) { + String * result = NULL; mc_foreachhashmapKey(String, key, mContentTypeParameters) { if (key->isEqualCaseInsensitive(name)) { - return (String *) mContentTypeParameters->objectForKey(key); + result = (String *) mContentTypeParameters->objectForKey(key); } } - return NULL; + return result; } diff --git a/src/core/abstract/MCMessageConstants.h b/src/core/abstract/MCMessageConstants.h index c81f8360..1b45ea69 100644 --- a/src/core/abstract/MCMessageConstants.h +++ b/src/core/abstract/MCMessageConstants.h @@ -249,6 +249,7 @@ namespace mailcore { ErrorNoRecipient, ErrorNoop, ErrorGmailApplicationSpecificPasswordRequired, + ErrorServerDate, }; enum PartType { diff --git a/src/core/abstract/MCMessageHeader.cc b/src/core/abstract/MCMessageHeader.cc index 89dec15c..08b0f045 100644 --- a/src/core/abstract/MCMessageHeader.cc +++ b/src/core/abstract/MCMessageHeader.cc @@ -337,12 +337,13 @@ void MessageHeader::removeExtraHeader(String * name) String * MessageHeader::extraHeaderValueForName(String * name) { + String * result = NULL; mc_foreachhashmapKey(String, key, mExtraHeaders) { if (key->isEqualCaseInsensitive(name)) { - return (String *) mExtraHeaders->objectForKey(key); + result = (String *) mExtraHeaders->objectForKey(key); } } - return NULL; + return result; } String * MessageHeader::extractedSubject() diff --git a/src/core/basetypes/MCData.cc b/src/core/basetypes/MCData.cc index 13c5fd61..5f2282d9 100644 --- a/src/core/basetypes/MCData.cc +++ b/src/core/basetypes/MCData.cc @@ -68,6 +68,7 @@ Data::Data(const char * bytes, unsigned int length) { mBytes = NULL; reset(); + allocate(length); appendBytes(bytes, length); } @@ -482,6 +483,13 @@ String * Data::charsetWithFilteredHTML(bool filterHTML, String * hintCharset) #endif } +void Data::replaceWithAllocatedBytes(char * bytes, unsigned int length) +{ + free(mBytes); + mBytes = (char *) bytes; + mLength = length; +} + Data * Data::dataWithContentsOfFile(String * filename) { int r; @@ -511,8 +519,8 @@ Data * Data::dataWithContentsOfFile(String * filename) return NULL; } - data = Data::dataWithBytes(buf, (unsigned int) stat_buf.st_size); - free(buf); + data = Data::data(); + data->replaceWithAllocatedBytes(buf, (unsigned int) stat_buf.st_size); fclose(f); diff --git a/src/core/basetypes/MCData.h b/src/core/basetypes/MCData.h index 6ba056e7..131cb722 100644 --- a/src/core/basetypes/MCData.h +++ b/src/core/basetypes/MCData.h @@ -5,6 +5,10 @@ #include <MailCore/MCObject.h> #include <MailCore/MCMessageConstants.h> +#ifdef __APPLE__ +#import <CoreFoundation/CoreFoundation.h> +#endif + #ifdef __cplusplus namespace mailcore { @@ -41,6 +45,9 @@ namespace mailcore { public: // private virtual String * charsetWithFilteredHTML(bool filterHTML, String * hintCharset = NULL); +#ifdef __APPLE__ + virtual CFDataRef destructiveNSData(); +#endif public: // subclass behavior Data(Data * otherData); @@ -58,6 +65,7 @@ namespace mailcore { void allocate(unsigned int length); void reset(); String * charsetWithFilteredHTMLWithoutHint(bool filterHTML); + void replaceWithAllocatedBytes(char * bytes, unsigned int length); }; diff --git a/src/core/basetypes/MCDataMac.mm b/src/core/basetypes/MCDataMac.mm new file mode 100644 index 00000000..8081b1f9 --- /dev/null +++ b/src/core/basetypes/MCDataMac.mm @@ -0,0 +1,22 @@ +// +// MCDataMac.m +// mailcore2 +// +// Created by Hoa V. DINH on 10/24/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include "MCData.h" + +#import <Foundation/Foundation.h> + +using namespace mailcore; + +CFDataRef Data::destructiveNSData() +{ + NSData * result = [NSData dataWithBytesNoCopy:(void *) mBytes length:mLength]; + mBytes = NULL; + mAllocated = 0; + mLength = 0; + return (CFDataRef) result; +} diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc index de975d44..a122c1e6 100644 --- a/src/core/basetypes/MCString.cc +++ b/src/core/basetypes/MCString.cc @@ -753,6 +753,9 @@ String::String(const UChar * unicodeChars) { mUnicodeChars = NULL; reset(); + if (unicodeChars != NULL) { + allocate(u_strlen(unicodeChars)); + } appendCharacters(unicodeChars); } @@ -760,6 +763,7 @@ String::String(const UChar * unicodeChars, unsigned int length) { mUnicodeChars = NULL; reset(); + allocate(length); appendCharactersLength(unicodeChars, length); } @@ -788,6 +792,7 @@ String::String(const char * bytes, unsigned int length, const char * charset) { mUnicodeChars = NULL; reset(); + allocate(length); if (charset == NULL) { appendUTF8CharactersLength(bytes, length); } @@ -1966,6 +1971,7 @@ String * String::stripWhitespace() /* do nothing */ } + str->autorelease(); return str; } diff --git a/src/core/nntp/MCNNTPSession.cc b/src/core/nntp/MCNNTPSession.cc index 02db197e..3c7ea7a3 100644 --- a/src/core/nntp/MCNNTPSession.cc +++ b/src/core/nntp/MCNNTPSession.cc @@ -21,6 +21,8 @@ using namespace mailcore; +static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, struct mailimf_fields ** result); + enum { STATE_DISCONNECTED, STATE_CONNECTED, @@ -359,16 +361,17 @@ Array * NNTPSession::listAllNewsgroups(ErrorCode * pError) return result; } -Array * NNTPSession::listSubscribedNewsgroups(ErrorCode * pError) +Array * NNTPSession::listDefaultNewsgroups(ErrorCode * pError) { int r; clist * subd_groups; MCLog("fetch subscribed"); loginIfNeeded(pError); - if (* pError != ErrorNone) + if (* pError != ErrorNone) { return NULL; - + } + r = newsnntp_list_subscriptions(mNNTP, &subd_groups); MCLog("fetch subscribed %u", r); @@ -390,10 +393,11 @@ Array * NNTPSession::listSubscribedNewsgroups(ErrorCode * pError) } newsnntp_list_subscriptions_free(subd_groups); * pError = ErrorNone; - + return result; } + MessageHeader * NNTPSession::fetchHeader(String *groupName, unsigned int index, ErrorCode * pError) { int r; @@ -401,10 +405,6 @@ MessageHeader * NNTPSession::fetchHeader(String *groupName, unsigned int index, size_t content_len; MCLog("fetch header at index %u", index); - loginIfNeeded(pError); - if (* pError != ErrorNone) { - return NULL; - } selectGroup(groupName, pError); if (* pError != ErrorNone) { @@ -438,17 +438,46 @@ Data * NNTPSession::fetchArticle(String *groupName, unsigned int index, NNTPProg MCLog("fetch article at index %u", index); - loginIfNeeded(pError); + selectGroup(groupName, pError); if (* pError != ErrorNone) { return NULL; } + r = newsnntp_article(mNNTP, index, &content, &content_len); + if (r == NEWSNNTP_ERROR_STREAM) { + * pError = ErrorConnection; + return NULL; + } + else if (r != NEWSNNTP_NO_ERROR) { + * pError = ErrorFetchMessageList; + return NULL; + } + + Data * result; + result = Data::dataWithBytes(content, (unsigned int) content_len); + newsnntp_article_free(content); + * pError = ErrorNone; + + return result; +} + +Data * NNTPSession::fetchArticleByMessageID(String * groupName, String * messageID, ErrorCode * pError) +{ + int r; + char * msgID; + char * content; + size_t content_len; + + MCLog("fetch article at message-id %s", messageID->UTF8Characters()); + selectGroup(groupName, pError); if (* pError != ErrorNone) { return NULL; } - r = newsnntp_article(mNNTP, index, &content, &content_len); + msgID = strdup(messageID->UTF8Characters()); + + r = newsnntp_article_by_message_id(mNNTP, msgID, &content, &content_len); if (r == NEWSNNTP_ERROR_STREAM) { * pError = ErrorConnection; return NULL; @@ -466,7 +495,34 @@ Data * NNTPSession::fetchArticle(String *groupName, unsigned int index, NNTPProg return result; } -IndexSet * NNTPSession::fetchArticles(String * groupName, ErrorCode * pError) +time_t NNTPSession::fetchServerDate(ErrorCode * pError) { + int r; + struct tm time; + time_t result; + + loginIfNeeded(pError); + if (* pError != ErrorNone) { + return NULL; + } + + r = newsnntp_date(mNNTP, &time); + + if (r == NEWSNNTP_ERROR_STREAM) { + * pError = ErrorConnection; + return NULL; + } + else if (r != NEWSNNTP_NO_ERROR) { + * pError = ErrorServerDate; + return NULL; + } + + result = timegm(&time); + * pError = ErrorNone; + + return result; +} + +IndexSet * NNTPSession::fetchAllArticles(String * groupName, ErrorCode * pError) { int r; clist * msg_list; @@ -506,11 +562,61 @@ IndexSet * NNTPSession::fetchArticles(String * groupName, ErrorCode * pError) return result; } +Array * NNTPSession::fetchOverArticlesInRange(Range range, String * groupName, ErrorCode * pError) +{ + int r; + clist * msg_list; + + selectGroup(groupName, pError); + if (* pError != ErrorNone) { + return NULL; + } + r = newsnntp_xover_range(mNNTP, (uint32_t) range.location, (uint32_t) (range.location + range.length), &msg_list); + if (r == NEWSNNTP_ERROR_STREAM) { + * pError = ErrorConnection; + return NULL; + } + else if (r != NEWSNNTP_NO_ERROR) { + * pError = ErrorFetchMessageList; + return NULL; + } + + Array * result = Array::array(); + clistiter * iter; + for(iter = clist_begin(msg_list) ;iter != NULL ; iter = clist_next(iter)) { + struct newsnntp_xover_resp_item * item; + struct mailimf_fields * fields = NULL; + + item = (struct newsnntp_xover_resp_item *) clist_content(iter); + if (!item) { + continue; + } + + r = xover_resp_to_fields(item, &fields); + if (r == MAIL_NO_ERROR) { + MessageHeader * header = new MessageHeader(); + header->importIMFFields(fields); + result->addObject(header); + header->release(); + } + } + + newsnntp_xover_resp_list_free(msg_list); + * pError = ErrorNone; + + return result; +} + void NNTPSession::selectGroup(String * folder, ErrorCode * pError) { int r; struct newsnntp_group_info * info; + loginIfNeeded(pError); + if (* pError != ErrorNone) { + return; + } + readerIfNeeded(pError); if (* pError != ErrorNone) { return; @@ -545,3 +651,241 @@ ConnectionLogger * NNTPSession::connectionLogger() { return mConnectionLogger; } + +// Taken from nntp/nntpdriver.c +static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, struct mailimf_fields ** result) +{ + size_t cur_token; + clist * list; + struct mailimf_fields * fields; + int r; + + list = clist_new(); + if (list == NULL) { + r = MAIL_ERROR_MEMORY; + goto err; + } + + if (item->ovr_subject != NULL) { + char * subject_str; + struct mailimf_subject * subject; + struct mailimf_field * field; + + subject_str = strdup(item->ovr_subject); + if (subject_str == NULL) { + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + subject = mailimf_subject_new(subject_str); + if (subject == NULL) { + free(subject_str); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + field = mailimf_field_new(MAILIMF_FIELD_SUBJECT, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, subject, NULL, NULL, NULL); + if (field == NULL) { + mailimf_subject_free(subject); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + r = clist_append(list, field); + if (r < 0) { + mailimf_field_free(field); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + } + + if (item->ovr_author != NULL) { + struct mailimf_mailbox_list * mb_list; + struct mailimf_from * from; + struct mailimf_field * field; + + cur_token = 0; + r = mailimf_mailbox_list_parse(item->ovr_author, strlen(item->ovr_author), + &cur_token, &mb_list); + switch (r) { + case MAILIMF_NO_ERROR: + from = mailimf_from_new(mb_list); + if (from == NULL) { + mailimf_mailbox_list_free(mb_list); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + field = mailimf_field_new(MAILIMF_FIELD_FROM, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, from, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL); + if (field == NULL) { + mailimf_from_free(from); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + r = clist_append(list, field); + if (r < 0) { + mailimf_field_free(field); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + break; + + case MAILIMF_ERROR_PARSE: + break; + + default: + goto free_list; + } + } + + if (item->ovr_date != NULL) { + struct mailimf_date_time * date_time; + struct mailimf_orig_date * orig_date; + struct mailimf_field * field; + + cur_token = 0; + r = mailimf_date_time_parse(item->ovr_date, strlen(item->ovr_date), + &cur_token, &date_time); + switch (r) { + case MAILIMF_NO_ERROR: + orig_date = mailimf_orig_date_new(date_time); + if (orig_date == NULL) { + mailimf_date_time_free(date_time); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + field = mailimf_field_new(MAILIMF_FIELD_ORIG_DATE, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, orig_date, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL); + if (field == NULL) { + mailimf_orig_date_free(orig_date); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + r = clist_append(list, field); + if (r < 0) { + mailimf_field_free(field); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + break; + + case MAILIMF_ERROR_PARSE: + break; + + default: + goto free_list; + } + } + + if (item->ovr_message_id != NULL) { + char * msgid_str; + struct mailimf_message_id * msgid; + struct mailimf_field * field; + + cur_token = 0; + r = mailimf_msg_id_parse(item->ovr_message_id, strlen(item->ovr_message_id), + &cur_token, &msgid_str); + + switch (r) { + case MAILIMF_NO_ERROR: + msgid = mailimf_message_id_new(msgid_str); + if (msgid == NULL) { + mailimf_msg_id_free(msgid_str); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + field = mailimf_field_new(MAILIMF_FIELD_MESSAGE_ID, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, msgid, NULL, + NULL, NULL, NULL, NULL, NULL); + + r = clist_append(list, field); + if (r < 0) { + mailimf_field_free(field); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + break; + + case MAILIMF_ERROR_PARSE: + break; + + default: + goto free_list; + } + } + + if (item->ovr_references != NULL) { + clist * msgid_list; + struct mailimf_references * references; + struct mailimf_field * field; + + cur_token = 0; + + r = mailimf_msg_id_list_parse(item->ovr_references, strlen(item->ovr_references), + &cur_token, &msgid_list); + + switch (r) { + case MAILIMF_NO_ERROR: + references = mailimf_references_new(msgid_list); + if (references == NULL) { + clist_foreach(msgid_list, + (clist_func) mailimf_msg_id_free, NULL); + clist_free(msgid_list); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + field = mailimf_field_new(MAILIMF_FIELD_REFERENCES, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + references, NULL, NULL, NULL, NULL); + + r = clist_append(list, field); + if (r < 0) { + mailimf_field_free(field); + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + case MAILIMF_ERROR_PARSE: + break; + + default: + goto free_list; + } + } + + fields = mailimf_fields_new(list); + if (fields == NULL) { + r = MAIL_ERROR_MEMORY; + goto free_list; + } + + * result = fields; + + return MAIL_NO_ERROR; + +free_list: + clist_foreach(list, (clist_func) mailimf_field_free, NULL); + clist_free(list); +err: + return r; +} diff --git a/src/core/nntp/MCNNTPSession.h b/src/core/nntp/MCNNTPSession.h index a6fb511c..d410fdcf 100644 --- a/src/core/nntp/MCNNTPSession.h +++ b/src/core/nntp/MCNNTPSession.h @@ -45,13 +45,17 @@ namespace mailcore { virtual void checkAccount(ErrorCode * pError); virtual Array * /* NNTPGroupInfo */ listAllNewsgroups(ErrorCode * pError); - virtual Array * listSubscribedNewsgroups(ErrorCode * pError); + virtual Array * /* NNTPGroupInfo */ listDefaultNewsgroups(ErrorCode * pError); - virtual MessageHeader * fetchHeader(String *groupName, unsigned int index, ErrorCode * pError); - - virtual IndexSet * fetchArticles(String * groupname, ErrorCode * pError); + virtual MessageHeader * fetchHeader(String * groupName, unsigned int index, ErrorCode * pError); + virtual Array /*MessageHeader*/ * fetchOverArticlesInRange(Range range, String * groupname, ErrorCode * pError); + + virtual IndexSet * fetchAllArticles(String * groupname, ErrorCode * pError); + + virtual Data * fetchArticle(String *groupName, unsigned int index, NNTPProgressCallback * callback, ErrorCode * pError); + virtual Data * fetchArticleByMessageID(String * groupname, String * messageID, ErrorCode * pError); - Data * fetchArticle(String *groupName, unsigned int index, NNTPProgressCallback * callback, ErrorCode * pError); + virtual time_t fetchServerDate(ErrorCode * pError); virtual void setConnectionLogger(ConnectionLogger * logger); virtual ConnectionLogger * connectionLogger(); diff --git a/src/core/rfc822/MCMessageParser.cc b/src/core/rfc822/MCMessageParser.cc index 4eb6046e..404bc862 100644 --- a/src/core/rfc822/MCMessageParser.cc +++ b/src/core/rfc822/MCMessageParser.cc @@ -1,6 +1,9 @@ #include "MCMessageParser.h" #include <libetpan/libetpan.h> +#if __APPLE__ +#include <CoreFoundation/CoreFoundation.h> +#endif #include "MCAttachment.h" #include "MCMessageHeader.h" @@ -25,43 +28,43 @@ void MessageParser::init() { mData = NULL; mMainPart = NULL; +#if __APPLE__ + mNSData = NULL; +#endif } -MessageParser::MessageParser(Data * data) +void MessageParser::setBytes(char * dataBytes, unsigned int dataLength) { - init(); - const char * start = NULL; unsigned int length = 0; - if (data->length() > 5) { - if (strncmp(data->bytes(), "From ", 5) == 0) { - start = data->bytes(); - for(unsigned int i = 0 ; i < data->length() ; i ++) { + if (dataLength > 5) { + if (strncmp(dataBytes, "From ", 5) == 0) { + start = dataBytes; + for(unsigned int i = 0 ; i < dataLength ; i ++) { if (start[i] == '\n') { start = start + i + 1; - length = data->length() - (i + 1); + length = dataLength - (i + 1); break; } } } } if (start != NULL) { - data = Data::dataWithBytes(start, length); + dataBytes = (char *) start; + dataLength = length; } - mData = (Data *) data->retain(); - mailmessage * msg; struct mailmime * mime; - msg = data_message_init(data->bytes(), data->length()); + msg = data_message_init(dataBytes, dataLength); mailmessage_get_bodystructure(msg, &mime); mMainPart = (AbstractPart *) Attachment::attachmentsWithMIME(msg->msg_mime)->retain(); mMainPart->applyUniquePartID(); size_t cur_token = 0; struct mailimf_fields * fields; - int r = mailimf_envelope_and_optional_fields_parse(data->bytes(), data->length(), &cur_token, &fields); + int r = mailimf_envelope_and_optional_fields_parse(dataBytes, dataLength, &cur_token, &fields); if (r == MAILIMAP_NO_ERROR) { header()->importIMFFields(fields); mailimf_fields_free(fields); @@ -69,6 +72,14 @@ MessageParser::MessageParser(Data * data) mailmessage_free(msg); } +MessageParser::MessageParser(Data * data) +{ + init(); + + setBytes(data->bytes(), data->length()); + mData = (Data *) data->retain(); +} + MessageParser::MessageParser(MessageParser * other) : AbstractMessage(other) { init(); @@ -80,6 +91,11 @@ MessageParser::~MessageParser() { MC_SAFE_RELEASE(mMainPart); MC_SAFE_RELEASE(mData); +#if __APPLE__ + if (mNSData != NULL) { + CFRelease(mNSData); + } +#endif } AbstractPart * MessageParser::mainPart() @@ -89,6 +105,11 @@ AbstractPart * MessageParser::mainPart() Data * MessageParser::data() { +#if __APPLE__ + if (mNSData != NULL) { + return dataFromNSData(); + } +#endif return mData; } diff --git a/src/core/rfc822/MCMessageParser.h b/src/core/rfc822/MCMessageParser.h index bf4687cb..eba0e052 100644 --- a/src/core/rfc822/MCMessageParser.h +++ b/src/core/rfc822/MCMessageParser.h @@ -5,6 +5,9 @@ #include <MailCore/MCBaseTypes.h> #include <MailCore/MCAbstractMessage.h> #include <MailCore/MCAbstractPart.h> +#ifdef __APPLE__ +#import <CoreFoundation/CoreFoundation.h> +#endif #ifdef __cplusplus @@ -39,11 +42,23 @@ namespace mailcore { virtual HashMap * serializable(); +#ifdef __APPLE__ + public: + static MessageParser * messageParserWithData(CFDataRef data); + MessageParser(CFDataRef data); +#endif + private: Data * mData; AbstractPart * mMainPart; void init(); +#if __APPLE__ + void * mNSData; +#endif + private: + void setBytes(char * bytes, unsigned int length); + Data * dataFromNSData(); }; }; diff --git a/src/core/rfc822/MCMessageParserMac.mm b/src/core/rfc822/MCMessageParserMac.mm new file mode 100644 index 00000000..6748ed1a --- /dev/null +++ b/src/core/rfc822/MCMessageParserMac.mm @@ -0,0 +1,34 @@ +// +// MCMessageParserMac.m +// mailcore2 +// +// Created by Hoa V. DINH on 10/24/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include "MCMessageParser.h" + +#import <Foundation/Foundation.h> + +#import "NSData+MCO.h" + +using namespace mailcore; + +MessageParser * MessageParser::messageParserWithData(CFDataRef data) +{ + MessageParser * parser = new MessageParser(data); + return (MessageParser *) parser->autorelease(); +} + +MessageParser::MessageParser(CFDataRef data) +{ + init(); + + setBytes((char *) [(NSData *) data bytes], (unsigned int) [(NSData *) data length]); + mNSData = [(NSData *) data retain]; +} + +Data * MessageParser::dataFromNSData() +{ + return [(NSData *) mNSData mco_mcData]; +} |