diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-09-22 22:13:31 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-09-22 22:13:31 -0700 |
commit | de2b44501bf3da0eed83905f44eed75059e9e401 (patch) | |
tree | 9b9029c69d07ba19a9257550a4ab79871819a312 /src/core/abstract | |
parent | c001526075610a35a05573da749b8ecdde3077ba (diff) |
Simplified extra headers implementation and content-types parameters
Diffstat (limited to 'src/core/abstract')
-rw-r--r-- | src/core/abstract/MCAbstractPart.cc | 51 | ||||
-rw-r--r-- | src/core/abstract/MCAbstractPart.h | 7 | ||||
-rw-r--r-- | src/core/abstract/MCMessageHeader.cc | 35 | ||||
-rw-r--r-- | src/core/abstract/MCMessageHeader.h | 1 |
4 files changed, 71 insertions, 23 deletions
diff --git a/src/core/abstract/MCAbstractPart.cc b/src/core/abstract/MCAbstractPart.cc index 50f12249..5b7a1c9a 100644 --- a/src/core/abstract/MCAbstractPart.cc +++ b/src/core/abstract/MCAbstractPart.cc @@ -27,6 +27,7 @@ AbstractPart::AbstractPart(AbstractPart * other) setContentDescription(other->mContentDescription); setInlineAttachment(other->mInlineAttachment); setPartType(other->mPartType); + setContentTypeParameters(other->mContentTypeParameters); } void AbstractPart::init() @@ -40,6 +41,7 @@ void AbstractPart::init() mContentDescription = NULL; mInlineAttachment = false; mPartType = PartTypeSingle; + mContentTypeParameters = NULL; } AbstractPart::~AbstractPart() @@ -51,6 +53,7 @@ AbstractPart::~AbstractPart() MC_SAFE_RELEASE(mContentID); MC_SAFE_RELEASE(mContentLocation); MC_SAFE_RELEASE(mContentDescription); + MC_SAFE_RELEASE(mContentTypeParameters); } String * AbstractPart::description() @@ -76,6 +79,11 @@ String * AbstractPart::description() result->appendUTF8Format("content-description: %s\n", mContentDescription->UTF8Characters()); } result->appendUTF8Format("inline: %i\n", mInlineAttachment); + if (mContentTypeParameters != NULL) { + mc_foreachhashmapKeyAndValue(String, key, String, value, mContentTypeParameters) { + result->appendUTF8Format("%s: %s\n", key->UTF8Characters(), value->UTF8Characters()); + } + } result->appendUTF8Format(">"); return result; @@ -395,3 +403,46 @@ void AbstractPart::importSerializable(HashMap * serializable) } } } + +void AbstractPart::setContentTypeParameters(HashMap * parameters) +{ + MC_SAFE_REPLACE_COPY(HashMap, mContentTypeParameters, parameters); +} + +Array * AbstractPart::allContentTypeParametersNames() +{ + if (mContentTypeParameters == NULL) + return Array::array(); + return mContentTypeParameters->allKeys(); +} + +void AbstractPart::setContentTypeParameter(String * name, String * object) +{ + if (mContentTypeParameters == NULL) { + mContentTypeParameters = new HashMap(); + } + removeContentTypeParameter(name); + mContentTypeParameters->setObjectForKey(name, object); +} + +void AbstractPart::removeContentTypeParameter(String * name) +{ + if (mContentTypeParameters == NULL) + return; + mc_foreachhashmapKey(String, key, mContentTypeParameters) { + if (key->isEqualCaseInsensitive(name)) { + mContentTypeParameters->removeObjectForKey(key); + break; + } + } +} + +String * AbstractPart::contentTypeParameterValueForName(String * name) +{ + mc_foreachhashmapKey(String, key, mContentTypeParameters) { + if (key->isEqualCaseInsensitive(name)) { + return (String *) mContentTypeParameters->objectForKey(key); + } + } + return NULL; +} diff --git a/src/core/abstract/MCAbstractPart.h b/src/core/abstract/MCAbstractPart.h index 7f641205..0fcbf279 100644 --- a/src/core/abstract/MCAbstractPart.h +++ b/src/core/abstract/MCAbstractPart.h @@ -48,6 +48,12 @@ namespace mailcore { virtual String * decodedStringForData(Data * data); + void setContentTypeParameters(HashMap * parameters); + Array * allContentTypeParametersNames(); + void setContentTypeParameter(String * name, String * object); + void removeContentTypeParameter(String * name); + String * contentTypeParameterValueForName(String * name); + public: // subclass behavior AbstractPart(AbstractPart * other); virtual String * description(); @@ -70,6 +76,7 @@ namespace mailcore { String * mContentDescription; bool mInlineAttachment; PartType mPartType; + HashMap * mContentTypeParameters; void init(); }; diff --git a/src/core/abstract/MCMessageHeader.cc b/src/core/abstract/MCMessageHeader.cc index 6e8d2c09..89dec15c 100644 --- a/src/core/abstract/MCMessageHeader.cc +++ b/src/core/abstract/MCMessageHeader.cc @@ -62,7 +62,6 @@ void MessageHeader::init(bool generateDate, bool generateMessageID) mDate = (time_t) -1; mReceivedDate = (time_t) -1; mExtraHeaders = NULL; - mlcExtraHeaders = NULL; if (generateDate) { time_t date; @@ -116,7 +115,6 @@ MessageHeader::~MessageHeader() MC_SAFE_RELEASE(mReplyTo); MC_SAFE_RELEASE(mSubject); MC_SAFE_RELEASE(mExtraHeaders); - MC_SAFE_RELEASE(mlcExtraHeaders); } String * MessageHeader::description() @@ -307,13 +305,6 @@ String * MessageHeader::userAgent() void MessageHeader::setExtraHeaders(HashMap * headers) { MC_SAFE_REPLACE_COPY(HashMap, mExtraHeaders, headers); - MC_SAFE_RELEASE(mlcExtraHeaders); - if (mExtraHeaders != NULL) { - mlcExtraHeaders = new HashMap(); - mc_foreachhashmapKeyAndValue(String, key, String, value, mExtraHeaders) { - mlcExtraHeaders->setObjectForKey(key->lowercaseString(), value); - } - } } Array * MessageHeader::allExtraHeadersNames() @@ -328,30 +319,30 @@ void MessageHeader::setExtraHeader(String * name, String * object) if (mExtraHeaders == NULL) { mExtraHeaders = new HashMap(); } - if (mlcExtraHeaders == NULL) { - mlcExtraHeaders = new HashMap(); - } - if (object == NULL) { - removeExtraHeader(name); - return; - } + removeExtraHeader(name); mExtraHeaders->setObjectForKey(name, object); - mlcExtraHeaders->setObjectForKey(name->lowercaseString(), object); } void MessageHeader::removeExtraHeader(String * name) { if (mExtraHeaders == NULL) return; - mExtraHeaders->removeObjectForKey(name); - mlcExtraHeaders->removeObjectForKey(name); + mc_foreachhashmapKey(String, key, mExtraHeaders) { + if (key->isEqualCaseInsensitive(name)) { + mExtraHeaders->removeObjectForKey(key); + break; + } + } } String * MessageHeader::extraHeaderValueForName(String * name) { - if (mlcExtraHeaders == NULL) - return NULL; - return (String *) mlcExtraHeaders->objectForKey(name->lowercaseString()); + mc_foreachhashmapKey(String, key, mExtraHeaders) { + if (key->isEqualCaseInsensitive(name)) { + return (String *) mExtraHeaders->objectForKey(key); + } + } + return NULL; } String * MessageHeader::extractedSubject() diff --git a/src/core/abstract/MCMessageHeader.h b/src/core/abstract/MCMessageHeader.h index 51b1e2f7..4018343c 100644 --- a/src/core/abstract/MCMessageHeader.h +++ b/src/core/abstract/MCMessageHeader.h @@ -99,7 +99,6 @@ namespace mailcore { time_t mDate; time_t mReceivedDate; HashMap * mExtraHeaders; - HashMap * mlcExtraHeaders; void init(bool generateDate, bool generateMessageID); void setExtraHeaders(HashMap *headers); Array * recipientWithReplyAll(bool replyAll, bool includeTo, bool includeCc, Array * senderEmails); |