diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-07-31 23:35:08 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-07-31 23:35:08 -0700 |
commit | 85a26f97fefac157bb3d310f444f7c86a8b07204 (patch) | |
tree | e8fd7d161b72b4b425b9f1dfaee80c0205602903 /src/core/abstract | |
parent | a722d215582e295d9e8fe5fb876d61a7a93cf494 (diff) |
Serialization of IMAP data. Implemented base64.
Diffstat (limited to 'src/core/abstract')
-rw-r--r-- | src/core/abstract/MCAbstractMessage.cc | 13 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractMessage.h | 30 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractMessagePart.cc | 19 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractMessagePart.h | 46 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractMultipart.cc | 14 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractMultipart.h | 36 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractPart.cc | 84 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractPart.h | 96 | ||||
-rw-r--r-- | src/core/abstract/MCAddress.cc | 29 | ||||
-rw-r--r-- | src/core/abstract/MCAddress.h | 88 | ||||
-rw-r--r-- | src/core/abstract/MCMessageHeader.cc | 105 | ||||
-rw-r--r-- | src/core/abstract/MCMessageHeader.h | 11 |
12 files changed, 401 insertions, 170 deletions
diff --git a/src/core/abstract/MCAbstractMessage.cc b/src/core/abstract/MCAbstractMessage.cc index a7e73992..cf3fd6c4 100644 --- a/src/core/abstract/MCAbstractMessage.cc +++ b/src/core/abstract/MCAbstractMessage.cc @@ -80,3 +80,16 @@ Array * AbstractMessage::htmlInlineAttachments() return HTMLRenderer::htmlInlineAttachmentsForMessage(this); } +HashMap * AbstractMessage::serializable() +{ + HashMap * result = Object::serializable(); + if (header() != NULL) { + result->setObjectForKey(MCSTR("header"), mHeader->serializable()); + } + return result; +} + +void AbstractMessage::importSerializable(HashMap * hashmap) +{ + setHeader((MessageHeader *) Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("header")))); +} diff --git a/src/core/abstract/MCAbstractMessage.h b/src/core/abstract/MCAbstractMessage.h index d7384b36..2c7766f8 100644 --- a/src/core/abstract/MCAbstractMessage.h +++ b/src/core/abstract/MCAbstractMessage.h @@ -8,15 +8,15 @@ namespace mailcore { class AbstractPart; - class MessageHeader; + class MessageHeader; - class AbstractMessage : public Object { - public: - AbstractMessage(); - virtual ~AbstractMessage(); + class AbstractMessage : public Object { + public: + AbstractMessage(); + virtual ~AbstractMessage(); - virtual MessageHeader * header(); - virtual void setHeader(MessageHeader * header); + virtual MessageHeader * header(); + virtual void setHeader(MessageHeader * header); virtual AbstractPart * partForContentID(String * contentID); virtual AbstractPart * partForUniqueID(String * uniqueID); @@ -25,15 +25,17 @@ namespace mailcore { virtual Array * /* AbstractPart */ htmlInlineAttachments(); public: //subclass behavior - AbstractMessage(AbstractMessage * other); - virtual String * description(); - virtual Object * copy(); + AbstractMessage(AbstractMessage * other); + virtual String * description(); + virtual Object * copy(); + virtual HashMap * serializable(); + virtual void importSerializable(HashMap * hashmap); - private: - MessageHeader * mHeader; - void init(); + private: + MessageHeader * mHeader; + void init(); - }; + }; } #endif diff --git a/src/core/abstract/MCAbstractMessagePart.cc b/src/core/abstract/MCAbstractMessagePart.cc index be6e8e9b..65d7b8cc 100644 --- a/src/core/abstract/MCAbstractMessagePart.cc +++ b/src/core/abstract/MCAbstractMessagePart.cc @@ -77,3 +77,22 @@ AbstractPart * AbstractMessagePart::partForUniqueID(String * contentID) { return mainPart()->partForUniqueID(contentID); } + +HashMap * AbstractMessagePart::serializable() +{ + HashMap * result = (HashMap *) AbstractPart::serializable(); + if (mainPart() != NULL) { + result->setObjectForKey(MCSTR("mainPart"), mainPart()->serializable()); + } + if (header() != NULL) { + result->setObjectForKey(MCSTR("header"), header()->serializable()); + } + return result; +} + +void AbstractMessagePart::importSerializable(HashMap * serializable) +{ + AbstractPart::importSerializable(serializable); + setMainPart((AbstractPart *) Object::objectWithSerializable((HashMap *) serializable->objectForKey(MCSTR("mainPart")))); + setHeader((MessageHeader *) Object::objectWithSerializable((HashMap *) serializable->objectForKey(MCSTR("header")))); +} diff --git a/src/core/abstract/MCAbstractMessagePart.h b/src/core/abstract/MCAbstractMessagePart.h index bd2ac4e0..1d975d62 100644 --- a/src/core/abstract/MCAbstractMessagePart.h +++ b/src/core/abstract/MCAbstractMessagePart.h @@ -8,33 +8,35 @@ #ifdef __cplusplus namespace mailcore { - - class MessageHeader; - - class AbstractMessagePart : public AbstractPart { - public: - AbstractMessagePart(); - virtual ~AbstractMessagePart(); - - virtual MessageHeader * header(); - virtual void setHeader(MessageHeader * header); - - virtual AbstractPart * mainPart(); - virtual void setMainPart(AbstractPart * mainPart); - + + class MessageHeader; + + class AbstractMessagePart : public AbstractPart { + public: + AbstractMessagePart(); + virtual ~AbstractMessagePart(); + + virtual MessageHeader * header(); + virtual void setHeader(MessageHeader * header); + + virtual AbstractPart * mainPart(); + virtual void setMainPart(AbstractPart * mainPart); + public: //subclass behavior - AbstractMessagePart(AbstractMessagePart * other); - virtual String * description(); - virtual Object * copy(); + AbstractMessagePart(AbstractMessagePart * other); + virtual String * description(); + virtual Object * copy(); + virtual HashMap * serializable(); + virtual void importSerializable(HashMap * serializable); virtual AbstractPart * partForContentID(String * contentID); virtual AbstractPart * partForUniqueID(String * uniqueID); - private: - AbstractPart * mMainPart; - MessageHeader * mHeader; - void init(); - }; + private: + AbstractPart * mMainPart; + MessageHeader * mHeader; + void init(); + }; } #endif diff --git a/src/core/abstract/MCAbstractMultipart.cc b/src/core/abstract/MCAbstractMultipart.cc index d70b2974..e3a2f9f7 100644 --- a/src/core/abstract/MCAbstractMultipart.cc +++ b/src/core/abstract/MCAbstractMultipart.cc @@ -92,3 +92,17 @@ AbstractPart * AbstractMultipart::partForUniqueID(String * uniqueID) return NULL; } +HashMap * AbstractMultipart::serializable() +{ + HashMap * result = (HashMap *) AbstractPart::serializable(); + if (mParts != NULL) { + result->setObjectForKey(MCSTR("parts"), mParts->serializable()); + } + return result; +} + +void AbstractMultipart::importSerializable(HashMap * serializable) +{ + AbstractPart::importSerializable(serializable); + setParts((Array *) Object::objectWithSerializable((HashMap *) serializable->objectForKey(MCSTR("parts")))); +} diff --git a/src/core/abstract/MCAbstractMultipart.h b/src/core/abstract/MCAbstractMultipart.h index 11d33666..b499f848 100644 --- a/src/core/abstract/MCAbstractMultipart.h +++ b/src/core/abstract/MCAbstractMultipart.h @@ -8,27 +8,29 @@ #ifdef __cplusplus namespace mailcore { - - class AbstractMultipart : public AbstractPart { - public: - AbstractMultipart(); - virtual ~AbstractMultipart(); - - virtual Array * parts(); - virtual void setParts(Array * parts); - + + class AbstractMultipart : public AbstractPart { + public: + AbstractMultipart(); + virtual ~AbstractMultipart(); + + virtual Array * parts(); + virtual void setParts(Array * parts); + public: //subclass behavior - AbstractMultipart(AbstractMultipart * other); - virtual String * description(); - virtual Object * copy(); + AbstractMultipart(AbstractMultipart * other); + virtual String * description(); + virtual Object * copy(); + virtual HashMap * serializable(); + virtual void importSerializable(HashMap * serializable); virtual AbstractPart * partForContentID(String * contentID); virtual AbstractPart * partForUniqueID(String * uniqueID); - - private: - Array * mParts; - void init(); - }; + + private: + Array * mParts; + void init(); + }; } #endif diff --git a/src/core/abstract/MCAbstractPart.cc b/src/core/abstract/MCAbstractPart.cc index 6991e5fc..d7b57544 100644 --- a/src/core/abstract/MCAbstractPart.cc +++ b/src/core/abstract/MCAbstractPart.cc @@ -282,3 +282,87 @@ void AbstractPart::applyUniquePartID() } queue->release(); } + +HashMap * AbstractPart::serializable() +{ + HashMap * result = Object::serializable(); + + if (uniqueID() != NULL) { + result->setObjectForKey(MCSTR("uniqueID"), uniqueID()); + } + if (filename() != NULL) { + result->setObjectForKey(MCSTR("filename"), filename()); + } + if (mimeType() != NULL) { + result->setObjectForKey(MCSTR("mimeType"), mimeType()); + } + if (charset() != NULL) { + result->setObjectForKey(MCSTR("charset"), charset()); + } + if (contentID() != NULL) { + result->setObjectForKey(MCSTR("contentID"), contentID()); + } + if (contentLocation() != NULL) { + result->setObjectForKey(MCSTR("contentLocation"), contentLocation()); + } + if (mInlineAttachment) { + result->setObjectForKey(MCSTR("inlineAttachment"), MCSTR("1")); + } + String * partTypeStr; + switch (mPartType) { + default: + case PartTypeSingle: + partTypeStr = MCSTR("single"); + break; + case PartTypeMessage: + partTypeStr = MCSTR("message"); + break; + case PartTypeMultipartMixed: + partTypeStr = MCSTR("multipart/mixed"); + break; + case PartTypeMultipartRelated: + partTypeStr = MCSTR("multipart/related"); + break; + case PartTypeMultipartAlternative: + partTypeStr = MCSTR("multipart/alternative"); + break; + } + result->setObjectForKey(MCSTR("partType"), partTypeStr); + + return result; +} + +void AbstractPart::importSerializable(HashMap * serializable) +{ + setUniqueID((String *) serializable->objectForKey(MCSTR("uniqueID"))); + setFilename((String *) serializable->objectForKey(MCSTR("filename"))); + setMimeType((String *) serializable->objectForKey(MCSTR("mimeType"))); + setCharset((String *) serializable->objectForKey(MCSTR("charset"))); + setContentID((String *) serializable->objectForKey(MCSTR("contentID"))); + setContentLocation((String *) serializable->objectForKey(MCSTR("contentLocation"))); + String * value = (String *) serializable->objectForKey(MCSTR("inlineAttachment")); + if (value != NULL) { + if (value->intValue()) { + setInlineAttachment(true); + } + } + value = (String *) serializable->objectForKey(MCSTR("partType")); + if (value != NULL) { + if (value->isEqual(MCSTR("single"))) { + setPartType(PartTypeSingle); + } + else if (value->isEqual(MCSTR("message"))) { + setPartType(PartTypeMessage); + } + else if (value->isEqual(MCSTR("multipart/mixed"))) { + setPartType(PartTypeMultipartMixed); + } + else if (value->isEqual(MCSTR("multipart/related"))) { + setPartType(PartTypeMultipartRelated); + } + else if (value->isEqual(MCSTR("multipart/alternative"))) { + setPartType(PartTypeMultipartAlternative); + } + } + PartType mPartType; +} diff --git a/src/core/abstract/MCAbstractPart.h b/src/core/abstract/MCAbstractPart.h index b38c1b38..e4f68666 100644 --- a/src/core/abstract/MCAbstractPart.h +++ b/src/core/abstract/MCAbstractPart.h @@ -9,64 +9,66 @@ namespace mailcore { - class AbstractMessage; + class AbstractMessage; - class AbstractPart : public Object { - public: - AbstractPart(); - virtual ~AbstractPart(); - - virtual PartType partType(); - virtual void setPartType(PartType type); - - virtual String * filename(); - virtual void setFilename(String * filename); - - virtual String * mimeType(); - virtual void setMimeType(String * mimeType); - - virtual String * charset(); - virtual void setCharset(String * charset); - - virtual String * uniqueID(); - virtual void setUniqueID(String * uniqueID); + class AbstractPart : public Object { + public: + AbstractPart(); + virtual ~AbstractPart(); + + virtual PartType partType(); + virtual void setPartType(PartType type); + + virtual String * filename(); + virtual void setFilename(String * filename); + + virtual String * mimeType(); + virtual void setMimeType(String * mimeType); + + virtual String * charset(); + virtual void setCharset(String * charset); + + virtual String * uniqueID(); + virtual void setUniqueID(String * uniqueID); + + virtual String * contentID(); + virtual void setContentID(String * contentID); + + virtual String * contentLocation(); + virtual void setContentLocation(String * contentLocation); + + virtual bool isInlineAttachment(); + virtual void setInlineAttachment(bool inlineAttachment); - virtual String * contentID(); - virtual void setContentID(String * contentID); - - virtual String * contentLocation(); - virtual void setContentLocation(String * contentLocation); - - virtual bool isInlineAttachment(); - virtual void setInlineAttachment(bool inlineAttachment); - virtual AbstractPart * partForContentID(String * contentID); virtual AbstractPart * partForUniqueID(String * uniqueID); - virtual String * decodedStringForData(Data * data); - + virtual String * decodedStringForData(Data * data); + public: // subclass behavior - AbstractPart(AbstractPart * other); - virtual String * description(); - virtual Object * copy(); + AbstractPart(AbstractPart * other); + virtual String * description(); + virtual Object * copy(); + virtual HashMap * serializable(); + virtual void importSerializable(HashMap * serializable); public: // private - virtual void importIMAPFields(struct mailimap_body_fields * fields, + virtual void importIMAPFields(struct mailimap_body_fields * fields, struct mailimap_body_ext_1part * extension); virtual void applyUniquePartID(); - private: - String * mUniqueID; - String * mFilename; - String * mMimeType; - String * mCharset; - String * mContentID; - String * mContentLocation; - bool mInlineAttachment; - PartType mPartType; - void init(); - }; - + private: + String * mUniqueID; + String * mFilename; + String * mMimeType; + String * mCharset; + String * mContentID; + String * mContentLocation; + bool mInlineAttachment; + PartType mPartType; + void init(); + }; + } #endif diff --git a/src/core/abstract/MCAddress.cc b/src/core/abstract/MCAddress.cc index ebfc8f0d..213f6e65 100644 --- a/src/core/abstract/MCAddress.cc +++ b/src/core/abstract/MCAddress.cc @@ -494,3 +494,32 @@ static Array * lep_address_list_from_lep_addr(struct mailimf_address_list * addr return result; } +static void * createObject() +{ + return new Address(); +} + +HashMap * Address::serializable() +{ + HashMap * result = Object::serializable(); + if (mailbox() != NULL) { + result->setObjectForKey(MCSTR("mailbox"), mailbox()); + } + if (displayName() != NULL) { + result->setObjectForKey(MCSTR("displayName"), displayName()); + } + return result; +} + +void Address::importSerializable(HashMap * serializable) +{ + setMailbox((String *) serializable->objectForKey(MCSTR("mailbox"))); + setDisplayName((String *) serializable->objectForKey(MCSTR("mailbox"))); +} + +__attribute__((constructor)) +static void initialize() +{ + Object::registerObjectConstructor("mailcore::Address", &createObject); +} + diff --git a/src/core/abstract/MCAddress.h b/src/core/abstract/MCAddress.h index ad8a36f6..867ee02d 100644 --- a/src/core/abstract/MCAddress.h +++ b/src/core/abstract/MCAddress.h @@ -8,53 +8,55 @@ namespace mailcore { - class Address : public Object { - public: - Address(); - virtual ~Address(); - - static Address * addressWithDisplayName(String * displayName, String * mailbox); - static Address * addressWithMailbox(String * mailbox); - static Address * addressWithRFC822String(String * RFC822String); - static Address * addressWithNonEncodedRFC822String(String * nonEncodedRFC822String); - - static Array * addressesWithRFC822String(String * string); - static Array * addressesWithNonEncodedRFC822String(String * string); - - static String * RFC822StringForAddresses(Array * addresses); - static String * nonEncodedRFC822StringForAddresses(Array * addresses); - - virtual void setDisplayName(String * displayName); - virtual String * displayName(); - - virtual void setMailbox(String * address); - virtual String * mailbox(); - - virtual String * RFC822String(); - virtual String * nonEncodedRFC822String(); - + class Address : public Object { + public: + Address(); + virtual ~Address(); + + static Address * addressWithDisplayName(String * displayName, String * mailbox); + static Address * addressWithMailbox(String * mailbox); + static Address * addressWithRFC822String(String * RFC822String); + static Address * addressWithNonEncodedRFC822String(String * nonEncodedRFC822String); + + static Array * addressesWithRFC822String(String * string); + static Array * addressesWithNonEncodedRFC822String(String * string); + + static String * RFC822StringForAddresses(Array * addresses); + static String * nonEncodedRFC822StringForAddresses(Array * addresses); + + virtual void setDisplayName(String * displayName); + virtual String * displayName(); + + virtual void setMailbox(String * address); + virtual String * mailbox(); + + virtual String * RFC822String(); + virtual String * nonEncodedRFC822String(); + public: // subclass behavior. - Address(Address * other); - virtual String * description(); - virtual bool isEqual(Object * otherObject); - virtual unsigned int hash(); - virtual Object * copy(); + Address(Address * other); + virtual String * description(); + virtual bool isEqual(Object * otherObject); + virtual unsigned int hash(); + virtual Object * copy(); + virtual HashMap * serializable(); + virtual void importSerializable(HashMap * serializable); public: // private - // Must be released - virtual struct mailimf_address * createIMFAddress(); - virtual struct mailimf_mailbox * createIMFMailbox(); + // Must be released + virtual struct mailimf_address * createIMFAddress(); + virtual struct mailimf_mailbox * createIMFMailbox(); + + // Additions + static Address * addressWithIMFMailbox(struct mailimf_mailbox * mb); + static Address * addressWithNonEncodedIMFMailbox(struct mailimf_mailbox * mb); + static Address * addressWithIMAPAddress(struct mailimap_address * imap_addr); - // Additions - static Address * addressWithIMFMailbox(struct mailimf_mailbox * mb); - static Address * addressWithNonEncodedIMFMailbox(struct mailimf_mailbox * mb); - static Address * addressWithIMAPAddress(struct mailimap_address * imap_addr); - - private: - String * mDisplayName; - String * mMailbox; - void init(); - }; + private: + String * mDisplayName; + String * mMailbox; + void init(); + }; } diff --git a/src/core/abstract/MCMessageHeader.cc b/src/core/abstract/MCMessageHeader.cc index abb20fc4..6808899d 100644 --- a/src/core/abstract/MCMessageHeader.cc +++ b/src/core/abstract/MCMessageHeader.cc @@ -44,7 +44,6 @@ MessageHeader::MessageHeader(MessageHeader * other) setSubject(other->mSubject); setDate(other->date()); setReceivedDate(other->receivedDate()); - setUserAgent(other->mUserAgent); setExtraHeaders(other->mExtraHeaders); } @@ -62,7 +61,6 @@ void MessageHeader::init(bool generateDate, bool generateMessageID) mSubject = NULL; mDate = (time_t) -1; mReceivedDate = (time_t) -1; - mUserAgent = NULL; mExtraHeaders = NULL; if (generateDate) { @@ -114,7 +112,6 @@ MessageHeader::~MessageHeader() MC_SAFE_RELEASE(mBcc); MC_SAFE_RELEASE(mReplyTo); MC_SAFE_RELEASE(mSubject); - MC_SAFE_RELEASE(mUserAgent); MC_SAFE_RELEASE(mExtraHeaders); } @@ -152,11 +149,8 @@ String * MessageHeader::description() if (mSubject != NULL) { result->appendUTF8Format("Subject: %s\n", mSubject->UTF8Characters()); } - if (mUserAgent != NULL) { - result->appendUTF8Format("X-Mailer: %s\n", mUserAgent->UTF8Characters()); - } if (mExtraHeaders != NULL) { - mc_foreachdictionaryKeyAndValue(String, header, String, value, mExtraHeaders) { + mc_foreachhashmapKeyAndValue(String, header, String, value, mExtraHeaders) { result->appendUTF8Format("%s: %s\n", header->UTF8Characters(), value->UTF8Characters()); } } @@ -292,12 +286,12 @@ String * MessageHeader::subject() void MessageHeader::setUserAgent(String * userAgent) { - MC_SAFE_REPLACE_COPY(String, mUserAgent, userAgent); + setExtraHeader(MCSTR("X-Mailer"), userAgent); } String * MessageHeader::userAgent() { - return mUserAgent; + return extraHeaderValueForName(MCSTR("X-Mailer")); } void MessageHeader::setExtraHeaders(HashMap * headers) @@ -312,21 +306,25 @@ Array * MessageHeader::allExtraHeadersNames() return mExtraHeaders->allKeys(); } -void MessageHeader::addHeader(String * name, String * object) +void MessageHeader::setExtraHeader(String * name, String * object) { if (mExtraHeaders == NULL) mExtraHeaders = new HashMap(); + if (object == NULL) { + removeExtraHeader(name); + return; + } mExtraHeaders->setObjectForKey(name, object); } -void MessageHeader::removeHeader(String * name) +void MessageHeader::removeExtraHeader(String * name) { if (mExtraHeaders == NULL) return; mExtraHeaders->removeObjectForKey(name); } -String * MessageHeader::headerValueForName(String * name) +String * MessageHeader::extraHeaderValueForName(String * name) { if (mExtraHeaders == NULL) return NULL; @@ -498,13 +496,13 @@ void MessageHeader::importIMFFields(struct mailimf_fields * fields) fieldName = field->fld_data.fld_optional_field->fld_name; fieldNameStr = String::stringWithUTF8Characters(fieldName); // Set only if this optional-field is not set - if (headerValueForName(fieldNameStr) == NULL) { + if (extraHeaderValueForName(fieldNameStr) == NULL) { char * fieldValue; String * fieldValueStr; fieldValue = field->fld_data.fld_optional_field->fld_value; fieldValueStr = String::stringWithUTF8Characters(fieldValue); - addHeader(fieldNameStr, fieldValueStr); + setExtraHeader(fieldNameStr, fieldValueStr); } } } @@ -883,15 +881,8 @@ struct mailimf_fields * MessageHeader::createIMFFieldsAndFilterBcc(bool filterBc imfReferences, imfSubject); - if (mUserAgent != NULL) { - struct mailimf_field * field; - - field = mailimf_field_new_custom(strdup("X-Mailer"), strdup(mUserAgent->UTF8Characters())); - mailimf_fields_add(fields, field); - } - if (mExtraHeaders != NULL) { - mc_foreachdictionaryKeyAndValue(String, header, String, value, mExtraHeaders) { + mc_foreachhashmapKeyAndValue(String, header, String, value, mExtraHeaders) { struct mailimf_field * field; field = mailimf_field_new_custom(strdup(header->UTF8Characters()), strdup(value->UTF8Characters())); @@ -1347,3 +1338,73 @@ MessageHeader * MessageHeader::forwardHeader() return result; } +HashMap * MessageHeader::serializable() +{ + HashMap * result = Object::serializable(); + + if (messageID() != NULL) { + result->setObjectForKey(MCSTR("messageID"), messageID()); + } + if (references() != NULL) { + result->setObjectForKey(MCSTR("references"), references()); + } + if (inReplyTo() != NULL) { + result->setObjectForKey(MCSTR("inReplyTo"), inReplyTo()); + } + if (sender() != NULL) { + result->setObjectForKey(MCSTR("sender"), sender()->serializable()); + } + if (from() != NULL) { + result->setObjectForKey(MCSTR("from"), from()->serializable()); + } + if (to() != NULL) { + result->setObjectForKey(MCSTR("to"), to()->serializable()); + } + if (cc() != NULL) { + result->setObjectForKey(MCSTR("cc"), cc()->serializable()); + } + if (bcc() != NULL) { + result->setObjectForKey(MCSTR("bcc"), bcc()->serializable()); + } + if (replyTo() != NULL) { + result->setObjectForKey(MCSTR("replyTo"), replyTo()->serializable()); + } + if (subject() != NULL) { + result->setObjectForKey(MCSTR("subject"), subject()); + } + result->setObjectForKey(MCSTR("date"), String::stringWithUTF8Format("%lld", (unsigned long long) date())); + result->setObjectForKey(MCSTR("receivedDate"), String::stringWithUTF8Format("%lld", (unsigned long long) receivedDate())); + if (mExtraHeaders != NULL) { + result->setObjectForKey(MCSTR("extraHeaders"), mExtraHeaders); + } + + return result; +} + +void MessageHeader::importSerializable(HashMap * hashmap) +{ + setMessageID((String *) hashmap->objectForKey(MCSTR("messageID"))); + setReferences((Array *) hashmap->objectForKey(MCSTR("references"))); + setInReplyTo((Array *) hashmap->objectForKey(MCSTR("inReplyTo"))); + setSender((Address *) Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("sender")))); + setFrom((Address *) Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("from")))); + setTo((Array *) Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("to")))); + setCc((Array *)Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("cc")))); + setBcc((Array *)Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("bcc")))); + setReplyTo((Array *)Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("replyTo")))); + setSubject((String *) hashmap->objectForKey(MCSTR("subject"))); + setDate((time_t) ((String *) hashmap->objectForKey(MCSTR("date")))->unsignedLongLongValue()); + setReceivedDate((time_t) ((String *) hashmap->objectForKey(MCSTR("receivedDate")))->unsignedLongLongValue()); + setExtraHeaders((HashMap *) hashmap->objectForKey(MCSTR("extraHeaders"))); +} + +static void * createObject() +{ + return new MessageHeader(); +} + +__attribute__((constructor)) +static void initialize() +{ + Object::registerObjectConstructor("mailcore::MessageHeader", &createObject); +} diff --git a/src/core/abstract/MCMessageHeader.h b/src/core/abstract/MCMessageHeader.h index 8da5f980..828d3a47 100644 --- a/src/core/abstract/MCMessageHeader.h +++ b/src/core/abstract/MCMessageHeader.h @@ -15,7 +15,7 @@ namespace mailcore { public: MessageHeader(); virtual ~MessageHeader(); - + virtual void setMessageID(String * messageID); virtual String * messageID(); @@ -55,9 +55,9 @@ namespace mailcore { virtual void setUserAgent(String * userAgent); virtual String * userAgent(); - virtual void addHeader(String *name, String * value); - virtual void removeHeader(String *name); - virtual String * headerValueForName(String *name); + virtual void setExtraHeader(String *name, String * value); + virtual void removeExtraHeader(String *name); + virtual String * extraHeaderValueForName(String *name); virtual Array * allExtraHeadersNames(); String * extractedSubject(); @@ -71,6 +71,8 @@ namespace mailcore { MessageHeader(MessageHeader * other); virtual String * description(); virtual Object * copy(); + virtual HashMap * serializable(); + virtual void importSerializable(HashMap * serializable); public: // private virtual void importIMAPEnvelope(struct mailimap_envelope * env); @@ -93,7 +95,6 @@ namespace mailcore { String * mSubject; time_t mDate; time_t mReceivedDate; - String * mUserAgent; HashMap * mExtraHeaders; void init(bool generateDate, bool generateMessageID); void setExtraHeaders(HashMap *headers); |