aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-05-04 10:31:00 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-05-04 10:31:29 -0700
commit7b03eb79d8d097f50f5eb4767850b3993a3b2d2d (patch)
treef8ccd206acc35dce79bf2a07741171d295f305b7
parente9ccd70a6dd9d17dec75e6c35189a0a2ae0f3cac (diff)
consistent uniqueID for MIME parts
-rw-r--r--src/core/abstract/MCAbstractPart.cc30
-rw-r--r--src/core/abstract/MCAbstractPart.h2
-rw-r--r--src/core/imap/MCIMAPPart.cc8
-rw-r--r--src/core/rfc822/MCMessageParser.cc1
4 files changed, 37 insertions, 4 deletions
diff --git a/src/core/abstract/MCAbstractPart.cc b/src/core/abstract/MCAbstractPart.cc
index f0446167..a1cf57b0 100644
--- a/src/core/abstract/MCAbstractPart.cc
+++ b/src/core/abstract/MCAbstractPart.cc
@@ -4,6 +4,9 @@
#include <stdlib.h>
#include <libetpan/libetpan.h>
#include "MCData.h"
+#include "MCAbstractMessagePart.h"
+#include "MCAbstractMultipart.h"
+#include "MCArray.h"
using namespace mailcore;
@@ -262,3 +265,30 @@ String * AbstractPart::decodedStringForData(Data * data)
return NULL;
}
}
+
+void AbstractPart::applyUniquePartID()
+{
+ Array * queue = new Array();
+ queue->addObject(this);
+ unsigned int queueIndex = 0;
+ unsigned int identifier = 0;
+ while (queueIndex < queue->count()) {
+ AbstractPart * part = (AbstractPart *) queue->objectAtIndex(queueIndex);
+ switch (part->partType()) {
+ case PartTypeSingle:
+ part->setUniqueID(String::stringWithUTF8Format("%u", identifier));
+ identifier ++;
+ break;
+ case PartTypeMessage:
+ queue->addObject(((AbstractMessagePart *) part)->mainPart());
+ break;
+ case PartTypeMultipartMixed:
+ case PartTypeMultipartRelated:
+ case PartTypeMultipartAlternative:
+ queue->addObjectsFromArray(((AbstractMultipart *) part)->parts());
+ break;
+ }
+ queueIndex ++;
+ }
+ queue->release();
+}
diff --git a/src/core/abstract/MCAbstractPart.h b/src/core/abstract/MCAbstractPart.h
index b01ba4f4..fe8a57d5 100644
--- a/src/core/abstract/MCAbstractPart.h
+++ b/src/core/abstract/MCAbstractPart.h
@@ -56,7 +56,7 @@ namespace mailcore {
public: // private
virtual void importIMAPFields(struct mailimap_body_fields * fields,
struct mailimap_body_ext_1part * extension);
-
+ virtual void applyUniquePartID();
private:
String * mUniqueID;
diff --git a/src/core/imap/MCIMAPPart.cc b/src/core/imap/MCIMAPPart.cc
index 9596533e..14b23c3a 100644
--- a/src/core/imap/MCIMAPPart.cc
+++ b/src/core/imap/MCIMAPPart.cc
@@ -83,12 +83,16 @@ unsigned int IMAPPart::decodedSize()
AbstractPart * IMAPPart::attachmentWithIMAPBody(struct mailimap_body * body)
{
String * partID;
+ AbstractPart * result;
partID = NULL;
if (body->bd_type == MAILIMAP_BODY_1PART) {
partID = MCSTR("1");
}
- return attachmentWithIMAPBodyInternal(body, partID);
+ result = attachmentWithIMAPBodyInternal(body, partID);
+ result->applyUniquePartID();
+
+ return result;
}
AbstractPart * IMAPPart::attachmentWithIMAPBodyInternal(struct mailimap_body * body, String * partID)
@@ -198,7 +202,6 @@ IMAPPart * IMAPPart::attachmentWithIMAPBody1PartBasic(struct mailimap_body_type_
attachment = new IMAPPart();
attachment->importIMAPFields(basic->bd_fields, extension);
- attachment->setUniqueID(mailcore::String::uuidString());
mimeType = NULL;
switch (basic->bd_media_basic->med_type) {
@@ -232,7 +235,6 @@ IMAPPart * IMAPPart::attachmentWithIMAPBody1PartText(struct mailimap_body_type_t
IMAPPart * attachment;
attachment = new IMAPPart();
- attachment->setUniqueID(mailcore::String::uuidString());
attachment->importIMAPFields(text->bd_fields, extension);
attachment->setMimeType(String::stringWithUTF8Format("text/%s", text->bd_media_text));
diff --git a/src/core/rfc822/MCMessageParser.cc b/src/core/rfc822/MCMessageParser.cc
index 98982e93..2a892e6b 100644
--- a/src/core/rfc822/MCMessageParser.cc
+++ b/src/core/rfc822/MCMessageParser.cc
@@ -38,6 +38,7 @@ MessageParser::MessageParser(Data * data)
mailmessage_get_bodystructure(msg, &mime);
mMainPart = (AbstractPart *) Attachment::attachmentsWithMIME(msg->msg_mime)->retain();
mMainPart->setMessage(this);
+ mMainPart->applyUniquePartID();
header()->importIMFFields(msg->msg_fields);
mailmessage_free(msg);
}