diff options
-rwxr-xr-x | build-mac/mailcore2.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | src/cmake/core.cmake | 1 | ||||
-rw-r--r-- | src/core/basetypes/MCData.cc | 11 | ||||
-rw-r--r-- | src/core/basetypes/MCData.h | 1 | ||||
-rw-r--r-- | src/core/rfc822/MCMessageParser.cc | 49 | ||||
-rw-r--r-- | src/core/rfc822/MCMessageParser.h | 15 |
6 files changed, 67 insertions, 16 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index 64b8a727..e4763f82 100755 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -1260,6 +1260,8 @@ C6D4FD3619FA9F4F001F7E01 /* MCNNTPFetchServerTimeOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84CFA98E19F724E500FE35D2 /* MCNNTPFetchServerTimeOperation.h */; }; C6D4FD3719FA9F55001F7E01 /* MCNNTPFetchServerTimeOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84CFA98E19F724E500FE35D2 /* MCNNTPFetchServerTimeOperation.h */; }; C6D4FD3819FA9F57001F7E01 /* MCONNTPFetchServerTimeOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84CFA99319F725CB00FE35D2 /* MCONNTPFetchServerTimeOperation.h */; }; + C6D4FD3F19FB7534001F7E01 /* MCMessageParserMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6D4FD3E19FB7534001F7E01 /* MCMessageParserMac.mm */; }; + C6D4FD4019FB7786001F7E01 /* MCMessageParserMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6D4FD3E19FB7534001F7E01 /* MCMessageParserMac.mm */; }; C6D6F7F9171E595D006F5B28 /* MCJSON.cc in Sources */ = {isa = PBXBuildFile; fileRef = C6D6F7F7171E595D006F5B28 /* MCJSON.cc */; }; C6D6F7FA171E595D006F5B28 /* MCJSON.cc in Sources */ = {isa = PBXBuildFile; fileRef = C6D6F7F7171E595D006F5B28 /* MCJSON.cc */; }; C6D6F954171E5CB8006F5B28 /* MCMD5.cc in Sources */ = {isa = PBXBuildFile; fileRef = C6D6F950171E5CB8006F5B28 /* MCMD5.cc */; }; @@ -2255,6 +2257,7 @@ C6D42C1A16AE03D6002BB4F9 /* NSData+MCO.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSData+MCO.mm"; sourceTree = "<group>"; }; C6D42C1B16AE03D6002BB4F9 /* NSString+MCO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MCO.h"; sourceTree = "<group>"; }; C6D42C1C16AE03D6002BB4F9 /* NSString+MCO.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSString+MCO.mm"; sourceTree = "<group>"; }; + C6D4FD3E19FB7534001F7E01 /* MCMessageParserMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCMessageParserMac.mm; sourceTree = "<group>"; }; C6D6F7F7171E595D006F5B28 /* MCJSON.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCJSON.cc; sourceTree = "<group>"; }; C6D6F7F8171E595D006F5B28 /* MCJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCJSON.h; sourceTree = "<group>"; }; C6D6F950171E5CB8006F5B28 /* MCMD5.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCMD5.cc; sourceTree = "<group>"; }; @@ -2909,6 +2912,7 @@ C64EA6E3169E847800778456 /* MCMessageBuilder.h */, C64EA6E4169E847800778456 /* MCMessageParser.cc */, C64EA6E5169E847800778456 /* MCMessageParser.h */, + C6D4FD3E19FB7534001F7E01 /* MCMessageParserMac.mm */, C64EA6E6169E847800778456 /* MCMessagePart.cc */, C64EA6E7169E847800778456 /* MCMessagePart.h */, C64EA6E8169E847800778456 /* MCMultipart.cc */, @@ -4184,6 +4188,7 @@ C6E665BB1796500C0063F2CF /* unzip.c in Sources */, C6F61F9917016B460073032E /* MCOIMAPSearchExpression.mm in Sources */, C6F61F9F17016EA10073032E /* MCOIMAPFolderInfo.m in Sources */, + C6D4FD3F19FB7534001F7E01 /* MCMessageParserMac.mm in Sources */, C6F61FB51702AB340073032E /* MCOIMAPBaseOperation.mm in Sources */, C608167517759967001F1018 /* MCSMTPDisconnectOperation.cc in Sources */, C6A81BBF17068E5E00882C15 /* MCOSMTPSession.mm in Sources */, @@ -4420,6 +4425,7 @@ C6BA2C111705F4E6003F0E9E /* MCOIMAPCapabilityOperation.mm in Sources */, C6E665BC1796500C0063F2CF /* unzip.c in Sources */, C6BA2C121705F4E6003F0E9E /* MCOIMAPSearchExpression.mm in Sources */, + C6D4FD4019FB7786001F7E01 /* MCMessageParserMac.mm in Sources */, C6BA2C131705F4E6003F0E9E /* MCOIMAPFolderInfo.m in Sources */, C6BA2C141705F4E6003F0E9E /* MCOIMAPBaseOperation.mm in Sources */, C608167617759968001F1018 /* MCSMTPDisconnectOperation.cc in Sources */, diff --git a/src/cmake/core.cmake b/src/cmake/core.cmake index e69e4fc0..59139908 100644 --- a/src/cmake/core.cmake +++ b/src/cmake/core.cmake @@ -14,6 +14,7 @@ IF(APPLE) core/basetypes/MCAutoreleasePoolMac.mm core/basetypes/MCMainThread.mm core/basetypes/MCObjectMac.mm + core/rfc822/MCMessageParserMac.mm ) ENDIF() diff --git a/src/core/basetypes/MCData.cc b/src/core/basetypes/MCData.cc index b851ed22..a4426e49 100644 --- a/src/core/basetypes/MCData.cc +++ b/src/core/basetypes/MCData.cc @@ -403,6 +403,13 @@ String * Data::charsetWithFilteredHTML(bool filterHTML, String * hintCharset) return result; } +void Data::replaceWithAllocatedBytes(char * bytes, unsigned int length) +{ + free(mBytes); + mBytes = (char *) bytes; + mLength = length; +} + Data * Data::dataWithContentsOfFile(String * filename) { int r; @@ -432,8 +439,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..e7363644 100644 --- a/src/core/basetypes/MCData.h +++ b/src/core/basetypes/MCData.h @@ -58,6 +58,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/rfc822/MCMessageParser.cc b/src/core/rfc822/MCMessageParser.cc index 4eb6046e..f8a25bda 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,7 +105,12 @@ AbstractPart * MessageParser::mainPart() Data * MessageParser::data() { - return mData; + if (mNSData != NULL) { + return dataFromNSData(); + } + else { + return mData; + } } String * MessageParser::description() diff --git a/src/core/rfc822/MCMessageParser.h b/src/core/rfc822/MCMessageParser.h index bf4687cb..3b34ab9e 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 __OBJC__ +#import <Foundation/Foundation.h> +#endif #ifdef __cplusplus @@ -39,11 +42,23 @@ namespace mailcore { virtual HashMap * serializable(); +#ifdef __OBJC__ + public: + static MessageParser * messageParserWithData(NSData * data); + MessageParser(NSData * data); +#endif + private: Data * mData; AbstractPart * mMainPart; void init(); +#if __APPLE__ + void * mNSData; +#endif + private: + void setBytes(char * bytes, unsigned int length); + Data * dataFromNSData(); }; }; |