aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/rfc822
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2016-05-01 22:54:40 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2016-05-01 22:54:40 -0700
commit5b9afdca3c850e7b33ac9555e8dc3e5e77d4e241 (patch)
treeed5a01295758618b4e96b5017cbadccf59154c5a /src/core/rfc822
parent7f4125a9f28c9509c7cc2735c844a50e433501b2 (diff)
Added partID to RFC 822 messages, provided a way to retrieve data for serialized MessageParser
Diffstat (limited to 'src/core/rfc822')
-rw-r--r--src/core/rfc822/MCAttachment.cpp15
-rw-r--r--src/core/rfc822/MCAttachment.h5
-rw-r--r--src/core/rfc822/MCMessageParser.cpp102
-rw-r--r--src/core/rfc822/MCMessageParser.h15
-rw-r--r--src/core/rfc822/MCMessagePart.cpp19
-rw-r--r--src/core/rfc822/MCMessagePart.h10
-rw-r--r--src/core/rfc822/MCMultipart.cpp19
-rw-r--r--src/core/rfc822/MCMultipart.h10
8 files changed, 191 insertions, 4 deletions
diff --git a/src/core/rfc822/MCAttachment.cpp b/src/core/rfc822/MCAttachment.cpp
index cdee201b..e6ebc9c9 100644
--- a/src/core/rfc822/MCAttachment.cpp
+++ b/src/core/rfc822/MCAttachment.cpp
@@ -223,6 +223,7 @@ Attachment * Attachment::attachmentWithText(String * text)
void Attachment::init()
{
mData = NULL;
+ mPartID = NULL;
setMimeType(MCSTR("application/octet-stream"));
}
@@ -234,11 +235,13 @@ Attachment::Attachment()
Attachment::Attachment(Attachment * other) : AbstractPart(other)
{
init();
- MC_SAFE_REPLACE_RETAIN(Data, mData, other->mData);
+ setData(other->data());
+ setPartID(other->partID());
}
Attachment::~Attachment()
{
+ MC_SAFE_RELEASE(mPartID);
MC_SAFE_RELEASE(mData);
}
@@ -278,6 +281,16 @@ Object * Attachment::copy()
return new Attachment(this);
}
+void Attachment::setPartID(String * partID)
+{
+ MC_SAFE_REPLACE_COPY(String, mPartID, partID);
+}
+
+String * Attachment::partID()
+{
+ return mPartID;
+}
+
void Attachment::setData(Data * data)
{
MC_SAFE_REPLACE_RETAIN(Data, mData, data);
diff --git a/src/core/rfc822/MCAttachment.h b/src/core/rfc822/MCAttachment.h
index deacf75e..ae02d256 100644
--- a/src/core/rfc822/MCAttachment.h
+++ b/src/core/rfc822/MCAttachment.h
@@ -25,6 +25,9 @@ namespace mailcore {
Attachment();
virtual ~Attachment();
+ virtual void setPartID(String * partID);
+ virtual String * partID();
+
virtual void setData(Data * data);
virtual Data * data();
virtual String * decodedString();
@@ -39,6 +42,8 @@ namespace mailcore {
private:
Data * mData;
+ String * mPartID;
+
void init();
static void fillMultipartSubAttachments(AbstractMultipart * multipart, struct mailmime * mime);
static AbstractPart * attachmentsWithMIMEWithMain(struct mailmime * mime, bool isMain);
diff --git a/src/core/rfc822/MCMessageParser.cpp b/src/core/rfc822/MCMessageParser.cpp
index beddeebc..e68d701b 100644
--- a/src/core/rfc822/MCMessageParser.cpp
+++ b/src/core/rfc822/MCMessageParser.cpp
@@ -71,6 +71,8 @@ void MessageParser::setBytes(char * dataBytes, unsigned int dataLength)
mailimf_fields_free(fields);
}
mailmessage_free(msg);
+
+ setupPartID();
}
MessageParser::MessageParser()
@@ -91,6 +93,7 @@ MessageParser::MessageParser(MessageParser * other) : AbstractMessage(other)
init();
MC_SAFE_REPLACE_RETAIN(Data, mData, other->mData);
MC_SAFE_REPLACE_RETAIN(AbstractPart, mMainPart, other->mMainPart);
+ setupPartID();
}
MessageParser::~MessageParser()
@@ -148,6 +151,7 @@ void MessageParser::importSerializable(HashMap * serializable)
if (mMainPart != NULL) {
mMainPart->applyUniquePartID();
}
+ setupPartID();
}
Object * MessageParser::copy()
@@ -173,7 +177,13 @@ AbstractPart * MessageParser::partForUniqueID(String * uniqueID)
String * MessageParser::htmlRendering(HTMLRendererTemplateCallback * htmlCallback)
{
- return HTMLRenderer::htmlForRFC822Message(this, htmlCallback);
+ return HTMLRenderer::htmlForRFC822Message(this, NULL, htmlCallback);
+}
+
+String * MessageParser::htmlRenderingWithDataCallback(HTMLRendererTemplateCallback * htmlCallback,
+ HTMLRendererRFC822Callback * dataCallback)
+{
+ return HTMLRenderer::htmlForRFC822Message(this, dataCallback, htmlCallback);
}
String * MessageParser::htmlBodyRendering()
@@ -201,6 +211,96 @@ String * MessageParser::plainTextBodyRendering(bool stripWhitespace)
return plainTextBodyString;
}
+void MessageParser::setupPartID()
+{
+ if (mMainPart == NULL) {
+ return;
+ }
+ recursiveSetupPartIDWithPart(mMainPart, MCSTR(""));
+}
+
+void MessageParser::recursiveSetupPartIDWithPart(mailcore::AbstractPart * part,
+ mailcore::String * partIDPrefix)
+{
+ switch (part->partType()) {
+ case PartTypeSingle:
+ {
+ String * partID = NULL;
+ if (partIDPrefix->length() == 0) {
+ partID = MCSTR("1");
+ }
+ else {
+ partID = partIDPrefix;
+ }
+ return recursiveSetupPartIDWithSinglePart((Attachment *) part, partID);
+ }
+ case PartTypeMessage:
+ {
+ String * partID = NULL;
+ if (partIDPrefix->length() == 0) {
+ partID = MCSTR("1");
+ }
+ else {
+ partID = partIDPrefix;
+ }
+ return recursiveSetupPartIDWithMessagePart((MessagePart *) part, partID);
+ }
+ case PartTypeMultipartMixed:
+ case PartTypeMultipartRelated:
+ case PartTypeMultipartAlternative:
+ case PartTypeMultipartSigned:
+ return recursiveSetupPartIDWithMultipart((Multipart *) part, partIDPrefix);
+ default:
+ MCAssert(0);
+ }
+}
+
+void MessageParser::recursiveSetupPartIDWithSinglePart(mailcore::Attachment * part,
+ mailcore::String * partIDPrefix)
+{
+ part->setPartID(partIDPrefix);
+}
+
+void MessageParser::recursiveSetupPartIDWithMessagePart(mailcore::MessagePart * part,
+ mailcore::String * partIDPrefix)
+{
+ part->setPartID(partIDPrefix);
+ String * partID = NULL;
+ switch (part->mainPart()->partType()) {
+ case PartTypeSingle:
+ case PartTypeMessage:
+ {
+ if (partIDPrefix->length() == 0) {
+ partID = MCSTR("1");
+ }
+ else {
+ partID = partIDPrefix->stringByAppendingUTF8Characters(".1");
+ }
+ break;
+ }
+ default:
+ partID = partIDPrefix;
+ break;
+ }
+ recursiveSetupPartIDWithPart(part->mainPart(), partID);
+}
+
+void MessageParser::recursiveSetupPartIDWithMultipart(mailcore::Multipart * part,
+ mailcore::String * partIDPrefix)
+{
+ part->setPartID(partIDPrefix);
+ mc_foreacharrayIndex(idx, AbstractPart, subpart, part->parts()) {
+ String * partID = NULL;
+ if (partIDPrefix->length() == 0) {
+ partID = String::stringWithUTF8Format("%u", idx + 1);
+ }
+ else {
+ partID = partIDPrefix->stringByAppendingUTF8Format(".%u", idx + 1);
+ }
+ recursiveSetupPartIDWithPart(subpart, partID);
+ }
+}
+
static void * createObject()
{
return new MessageParser();
diff --git a/src/core/rfc822/MCMessageParser.h b/src/core/rfc822/MCMessageParser.h
index 9682bfce..4541b41c 100644
--- a/src/core/rfc822/MCMessageParser.h
+++ b/src/core/rfc822/MCMessageParser.h
@@ -14,6 +14,10 @@
namespace mailcore {
class HTMLRendererTemplateCallback;
+ class HTMLRendererRFC822Callback;
+ class Multipart;
+ class MessagePart;
+ class Attachment;
class MAILCORE_EXPORT MessageParser : public AbstractMessage {
public:
@@ -28,6 +32,8 @@ namespace mailcore {
virtual Data * data();
virtual String * htmlRendering(HTMLRendererTemplateCallback * htmlCallback = NULL);
+ virtual String * htmlRenderingWithDataCallback(HTMLRendererTemplateCallback * htmlCallback,
+ HTMLRendererRFC822Callback * dataCallback);
virtual String * htmlBodyRendering();
virtual String * plainTextRendering();
@@ -61,6 +67,15 @@ namespace mailcore {
private:
void setBytes(char * bytes, unsigned int length);
Data * dataFromNSData();
+ void setupPartID();
+ void recursiveSetupPartIDWithPart(mailcore::AbstractPart * part,
+ mailcore::String * partIDPrefix);
+ void recursiveSetupPartIDWithSinglePart(mailcore::Attachment * part,
+ mailcore::String * partIDPrefix);
+ void recursiveSetupPartIDWithMessagePart(mailcore::MessagePart * part,
+ mailcore::String * partIDPrefix);
+ void recursiveSetupPartIDWithMultipart(mailcore::Multipart * part,
+ mailcore::String * partIDPrefix);
};
};
diff --git a/src/core/rfc822/MCMessagePart.cpp b/src/core/rfc822/MCMessagePart.cpp
index abd98ac2..9862bc29 100644
--- a/src/core/rfc822/MCMessagePart.cpp
+++ b/src/core/rfc822/MCMessagePart.cpp
@@ -6,14 +6,33 @@ using namespace mailcore;
MessagePart::MessagePart()
{
+ init();
}
MessagePart::MessagePart(MessagePart * other) : AbstractMessagePart(other)
{
+ init();
+ setPartID(other->partID());
+}
+
+void MessagePart::init()
+{
+ mPartID = NULL;
}
MessagePart::~MessagePart()
{
+ MC_SAFE_RELEASE(mPartID);
+}
+
+void MessagePart::setPartID(String * partID)
+{
+ MC_SAFE_REPLACE_COPY(String, mPartID, partID);
+}
+
+String * MessagePart::partID()
+{
+ return mPartID;
}
Object * MessagePart::copy()
diff --git a/src/core/rfc822/MCMessagePart.h b/src/core/rfc822/MCMessagePart.h
index 894cd3e5..04879ba3 100644
--- a/src/core/rfc822/MCMessagePart.h
+++ b/src/core/rfc822/MCMessagePart.h
@@ -13,10 +13,18 @@ namespace mailcore {
public:
MessagePart();
virtual ~MessagePart();
-
+
+ virtual void setPartID(String * partID);
+ virtual String * partID();
+
public: // subclass behavior
MessagePart(MessagePart * other);
virtual Object * copy();
+
+ private:
+ String * mPartID;
+
+ void init();
};
}
diff --git a/src/core/rfc822/MCMultipart.cpp b/src/core/rfc822/MCMultipart.cpp
index 0be76430..0e3ee1ab 100644
--- a/src/core/rfc822/MCMultipart.cpp
+++ b/src/core/rfc822/MCMultipart.cpp
@@ -6,14 +6,33 @@ using namespace mailcore;
Multipart::Multipart()
{
+ init();
}
Multipart::Multipart(Multipart * other) : AbstractMultipart(other)
{
+ init();
+ setPartID(other->partID());
+}
+
+void Multipart::init()
+{
+ mPartID = NULL;
}
Multipart::~Multipart()
{
+ MC_SAFE_RELEASE(mPartID);
+}
+
+void Multipart::setPartID(String * partID)
+{
+ MC_SAFE_REPLACE_COPY(String, mPartID, partID);
+}
+
+String * Multipart::partID()
+{
+ return mPartID;
}
Object * Multipart::copy()
diff --git a/src/core/rfc822/MCMultipart.h b/src/core/rfc822/MCMultipart.h
index 40b0a48b..d389f522 100644
--- a/src/core/rfc822/MCMultipart.h
+++ b/src/core/rfc822/MCMultipart.h
@@ -13,10 +13,18 @@ namespace mailcore {
public:
Multipart();
virtual ~Multipart();
-
+
+ virtual void setPartID(String * partID);
+ virtual String * partID();
+
public: // subclass behavior
Multipart(Multipart * other);
virtual Object * copy();
+
+ private:
+ String * mPartID;
+
+ void init();
};
}