Skip to content

Commit 2f65b64

Browse files
committed
Improve serialization of messages
1 parent cfc147c commit 2f65b64

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

src/core/rfc822/MCAttachment.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "MCAttachment.h"
44

5+
#include "MCDefines.h"
56
#include "MCMultipart.h"
67
#include "MCMessagePart.h"
78
#include "MCMessageHeader.h"
@@ -610,3 +611,13 @@ MessagePart * Attachment::attachmentWithMessageMIME(struct mailmime * mime)
610611

611612
return (MessagePart *) attachment->autorelease();
612613
}
614+
615+
static void * createObject()
616+
{
617+
return new Attachment();
618+
}
619+
620+
INITIALIZE(Attachment)
621+
{
622+
Object::registerObjectConstructor("mailcore::Attachment", &createObject);
623+
}

src/core/rfc822/MCMessageParser.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <CoreFoundation/CoreFoundation.h>
66
#endif
77

8+
#include "MCDefines.h"
89
#include "MCAttachment.h"
910
#include "MCMessageHeader.h"
1011
#include "MCHTMLRenderer.h"
@@ -140,6 +141,15 @@ HashMap * MessageParser::serializable()
140141
return result;
141142
}
142143

144+
void MessageParser::importSerializable(HashMap * serializable)
145+
{
146+
AbstractMessage::importSerializable(serializable);
147+
MC_SAFE_REPLACE_RETAIN(AbstractPart, mMainPart, Object::objectWithSerializable((HashMap *) serializable->objectForKey(MCSTR("mainPart"))));
148+
if (mMainPart != NULL) {
149+
mMainPart->applyUniquePartID();
150+
}
151+
}
152+
143153
Object * MessageParser::copy()
144154
{
145155
return new MessageParser(this);
@@ -190,3 +200,13 @@ String * MessageParser::plainTextBodyRendering(bool stripWhitespace)
190200
}
191201
return plainTextBodyString;
192202
}
203+
204+
static void * createObject()
205+
{
206+
return new MessageParser();
207+
}
208+
209+
INITIALIZE(MessageParser)
210+
{
211+
Object::registerObjectConstructor("mailcore::MessageParser", &createObject);
212+
}

src/core/rfc822/MCMessageParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace mailcore {
4242
virtual AbstractPart * partForUniqueID(String * uniqueID);
4343

4444
virtual HashMap * serializable();
45-
45+
virtual void importSerializable(HashMap * serializable);
46+
4647
#ifdef __APPLE__
4748
public:
4849
static MessageParser * messageParserWithData(CFDataRef data);

src/core/rfc822/MCMessagePart.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "MCMessagePart.h"
22

3+
#include "MCDefines.h"
4+
35
using namespace mailcore;
46

57
MessagePart::MessagePart()
@@ -18,3 +20,13 @@ Object * MessagePart::copy()
1820
{
1921
return new MessagePart(this);
2022
}
23+
24+
static void * createObject()
25+
{
26+
return new MessagePart();
27+
}
28+
29+
INITIALIZE(MessagePart)
30+
{
31+
Object::registerObjectConstructor("mailcore::MessagePart", &createObject);
32+
}

src/core/rfc822/MCMultipart.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "MCMultipart.h"
22

3+
#include "MCDefines.h"
4+
35
using namespace mailcore;
46

57
Multipart::Multipart()
@@ -19,3 +21,12 @@ Object * Multipart::copy()
1921
return new Multipart(this);
2022
}
2123

24+
static void * createObject()
25+
{
26+
return new Multipart();
27+
}
28+
29+
INITIALIZE(Multipart)
30+
{
31+
Object::registerObjectConstructor("mailcore::Multipart", &createObject);
32+
}

0 commit comments

Comments
 (0)