aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/rfc822/MCAttachment.cc73
-rw-r--r--src/core/rfc822/MCAttachment.h8
-rw-r--r--src/core/rfc822/MCMessageBuilder.cc47
-rw-r--r--src/objc/rfc822/MCOAttachment.h14
-rw-r--r--src/objc/rfc822/MCOAttachment.mm19
5 files changed, 151 insertions, 10 deletions
diff --git a/src/core/rfc822/MCAttachment.cc b/src/core/rfc822/MCAttachment.cc
index 331d7d28..9369ebe1 100644
--- a/src/core/rfc822/MCAttachment.cc
+++ b/src/core/rfc822/MCAttachment.cc
@@ -211,6 +211,8 @@ Attachment * Attachment::attachmentWithText(String * text)
void Attachment::init()
{
mData = NULL;
+ mExtraParameters = NULL;
+ mlcExtraParameters = NULL;
setMimeType(MCSTR("application/octet-stream"));
}
@@ -223,11 +225,14 @@ Attachment::Attachment(Attachment * other) : AbstractPart(other)
{
init();
MC_SAFE_REPLACE_RETAIN(Data, mData, other->mData);
+ setExtraParameters(other->mExtraParameters);
}
Attachment::~Attachment()
{
MC_SAFE_RELEASE(mData);
+ MC_SAFE_RELEASE(mExtraParameters);
+ MC_SAFE_RELEASE(mlcExtraParameters);
}
String * Attachment::description()
@@ -256,6 +261,11 @@ String * Attachment::description()
else {
result->appendUTF8Format("no data\n");
}
+ if (mExtraParameters != NULL) {
+ mc_foreachhashmapKeyAndValue(String, header, String, value, mExtraParameters) {
+ result->appendUTF8Format("%s: %s\n", header->UTF8Characters(), value->UTF8Characters());
+ }
+ }
result->appendUTF8Format(">");
return result;
@@ -286,6 +296,55 @@ String * Attachment::decodedString()
}
}
+void Attachment::setExtraParameters(HashMap * parameters)
+{
+ MC_SAFE_REPLACE_COPY(HashMap, mExtraParameters, parameters);
+ MC_SAFE_RELEASE(mlcExtraParameters);
+ if (mExtraParameters != NULL) {
+ mlcExtraParameters = new HashMap();
+ mc_foreachhashmapKeyAndValue(String, key, String, value, mExtraParameters) {
+ mlcExtraParameters->setObjectForKey(key->lowercaseString(), value);
+ }
+ }
+}
+
+Array * Attachment::allExtraParametersNames()
+{
+ if (mExtraParameters == NULL)
+ return Array::array();
+ return mExtraParameters->allKeys();
+}
+
+void Attachment::setExtraParameter(String * name, String * object)
+{
+ if (mExtraParameters == NULL) {
+ mExtraParameters = new HashMap();
+ }
+ if (mlcExtraParameters == NULL) {
+ mlcExtraParameters = new HashMap();
+ }
+ if (object == NULL) {
+ removeExtraParameter(name);
+ return;
+ }
+ mExtraParameters->setObjectForKey(name, object);
+ mlcExtraParameters->setObjectForKey(name->lowercaseString(), object);
+}
+
+void Attachment::removeExtraParameter(String * name)
+{
+ if (mExtraParameters == NULL)
+ return;
+ mExtraParameters->removeObjectForKey(name);
+ mlcExtraParameters->removeObjectForKey(name);
+}
+
+String * Attachment::extraParameterValueForName(String * name)
+{
+ if (mlcExtraParameters == NULL)
+ return NULL;
+ return (String *) mlcExtraParameters->objectForKey(name->lowercaseString());
+}
AbstractPart * Attachment::attachmentsWithMIME(struct mailmime * mime)
{
@@ -495,6 +554,7 @@ Attachment * Attachment::attachmentWithSingleMIME(struct mailmime * mime)
char * description;
char * loc;
Encoding encoding;
+ clist * ct_parameters;
MCAssert(mime->mm_type == MAILMIME_SINGLE);
@@ -523,6 +583,7 @@ Attachment * Attachment::attachmentWithSingleMIME(struct mailmime * mime)
content_id = single_fields.fld_id;
description = single_fields.fld_description;
loc = single_fields.fld_location;
+ ct_parameters = single_fields.fld_content->ct_parameters;
if (filename != NULL) {
result->setFilename(String::stringByDecodingMIMEHeaderValue(filename));
@@ -543,6 +604,18 @@ Attachment * Attachment::attachmentWithSingleMIME(struct mailmime * mime)
result->setContentLocation(String::stringWithUTF8Characters(loc));
}
+ if (ct_parameters != NULL) {
+ clistiter * iter = clist_begin(ct_parameters);
+ struct mailmime_parameter * param;
+ while (iter != NULL) {
+ param = (struct mailmime_parameter *) clist_content(iter);
+ if (param != NULL) {
+ result->setExtraParameter(String::stringWithUTF8Characters(param->pa_name), String::stringWithUTF8Characters(param->pa_value));
+ }
+ iter = clist_next(iter);
+ }
+ }
+
if (single_fields.fld_disposition != NULL) {
if (single_fields.fld_disposition->dsp_type != NULL) {
if (single_fields.fld_disposition->dsp_type->dsp_type == MAILMIME_DISPOSITION_TYPE_INLINE) {
diff --git a/src/core/rfc822/MCAttachment.h b/src/core/rfc822/MCAttachment.h
index 7dd15b89..33dbf942 100644
--- a/src/core/rfc822/MCAttachment.h
+++ b/src/core/rfc822/MCAttachment.h
@@ -29,6 +29,11 @@ namespace mailcore {
virtual Data * data();
virtual String * decodedString();
+ virtual void setExtraParameter(String * name, String * value);
+ virtual void removeExtraParameter(String * name);
+ virtual String * extraParameterValueForName(String *name);
+ virtual Array * allExtraParametersNames();
+
public: // subclass behavior
Attachment(Attachment * other);
virtual String * description();
@@ -39,6 +44,8 @@ namespace mailcore {
private:
Data * mData;
+ HashMap * mExtraParameters;
+ HashMap * mlcExtraParameters;
void init();
static void fillMultipartSubAttachments(AbstractMultipart * multipart, struct mailmime * mime);
static AbstractPart * attachmentsWithMIMEWithMain(struct mailmime * mime, bool isMain);
@@ -46,6 +53,7 @@ namespace mailcore {
static MessagePart * attachmentWithMessageMIME(struct mailmime * mime);
static Encoding encodingForMIMEEncoding(struct mailmime_mechanism * mechanism, int defaultMimeEncoding);
static HashMap * readMimeTypesFile(String * filename);
+ void setExtraParameters(HashMap * parameters);
};
}
diff --git a/src/core/rfc822/MCMessageBuilder.cc b/src/core/rfc822/MCMessageBuilder.cc
index cd87009e..390d268b 100644
--- a/src/core/rfc822/MCMessageBuilder.cc
+++ b/src/core/rfc822/MCMessageBuilder.cc
@@ -134,7 +134,7 @@ err:
static struct mailmime * get_text_part(const char * mime_type, const char * charset, const char * content_id,
const char * description,
- const char * text, size_t length, int encoding_type)
+ const char * text, size_t length, int encoding_type, Array * extraParameters)
{
struct mailmime_fields * mime_fields;
struct mailmime * mime;
@@ -165,6 +165,11 @@ static struct mailmime * get_text_part(const char * mime_type, const char * char
param = mailmime_param_new_with_data((char *) "charset", (char *) charset);
}
clist_append(content->ct_parameters, param);
+
+ mc_foreacharray(Value, extraParam, extraParameters) {
+ clist_append(content->ct_parameters, extraParam->pointerValue());
+ }
+
mime = part_new_empty(content, mime_fields, NULL, 1);
mailmime_set_body_text(mime, (char *) text, length);
@@ -173,7 +178,7 @@ static struct mailmime * get_text_part(const char * mime_type, const char * char
static struct mailmime * get_plain_text_part(const char * mime_type, const char * charset, const char * content_id,
const char * description,
- const char * text, size_t length)
+ const char * text, size_t length, Array * extraParameters)
{
bool needsQuotedPrintable;
int mechanism;
@@ -189,20 +194,20 @@ static struct mailmime * get_plain_text_part(const char * mime_type, const char
if (needsQuotedPrintable) {
mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
}
- return get_text_part(mime_type, charset, content_id, description, text, length, mechanism);
+ return get_text_part(mime_type, charset, content_id, description, text, length, mechanism, extraParameters);
}
static struct mailmime * get_other_text_part(const char * mime_type, const char * charset, const char * content_id,
const char * description,
- const char * text, size_t length)
+ const char * text, size_t length, Array * extraParameters)
{
- return get_text_part(mime_type, charset, content_id, description, text, length, MAILMIME_MECHANISM_QUOTED_PRINTABLE);
+ return get_text_part(mime_type, charset, content_id, description, text, length, MAILMIME_MECHANISM_QUOTED_PRINTABLE, extraParameters);
}
static struct mailmime * get_file_part(const char * filename, const char * mime_type, int is_inline,
const char * content_id,
const char * content_description,
- const char * text, size_t length)
+ const char * text, size_t length, Array * extraParameters)
{
char * disposition_name;
int encoding_type;
@@ -238,6 +243,11 @@ static struct mailmime * get_file_part(const char * filename, const char * mime_
dup_content_description = strdup(content_description);
mime_fields = mailmime_fields_new_with_data(encoding,
dup_content_id, dup_content_description, disposition, NULL);
+
+ mc_foreacharray(Value, extraParam, extraParameters) {
+ clist_append(content->ct_parameters, extraParam->pointerValue());
+ }
+
mime = part_new_empty(content, mime_fields, NULL, 1);
mailmime_set_body_text(mime, (char *) text, length);
@@ -246,6 +256,22 @@ static struct mailmime * get_file_part(const char * filename, const char * mime_
#define MIME_ENCODED_STR(str) (str != NULL ? str->encodedMIMEHeaderValue()->bytes() : NULL)
+static Array * extraParameters_from_attachment(Attachment * att)
+{
+ Array * extraParamters = new Array();
+ struct mailmime_parameter * param;
+ Value * paramValue;
+
+ mc_foreacharray(String, name, att->allExtraParametersNames()) {
+ String * value = att->extraParameterValueForName(name);
+ param = mailmime_param_new_with_data((char *)name->UTF8Characters(), (char *)value->UTF8Characters());
+ paramValue = Value::valueWithPointerValue(param);
+ extraParamters->addObject(paramValue);
+ }
+
+ return (Array *)extraParamters->autorelease();
+}
+
static struct mailmime * mime_from_attachment(Attachment * att)
{
struct mailmime * mime;
@@ -266,20 +292,23 @@ static struct mailmime * mime_from_attachment(Attachment * att)
mime = get_plain_text_part(MCUTF8(att->mimeType()), MCUTF8(att->charset()),
MCUTF8(att->contentID()),
MIME_ENCODED_STR(att->contentDescription()),
- data->bytes(), data->length());
+ data->bytes(), data->length(),
+ extraParameters_from_attachment(att));
}
else if (att->isInlineAttachment() && att->mimeType()->lowercaseString()->hasPrefix(MCSTR("text/"))) {
mime = get_other_text_part(MCUTF8(att->mimeType()), MCUTF8(att->charset()),
MCUTF8(att->contentID()),
MIME_ENCODED_STR(att->contentDescription()),
- data->bytes(), data->length());
+ data->bytes(), data->length(),
+ extraParameters_from_attachment(att));
}
else {
mime = get_file_part(MIME_ENCODED_STR(att->filename()),
MCUTF8(att->mimeType()), att->isInlineAttachment(),
MCUTF8(att->contentID()),
MIME_ENCODED_STR(att->contentDescription()),
- data->bytes(), data->length());
+ data->bytes(), data->length(),
+ extraParameters_from_attachment(att));
}
return mime;
}
diff --git a/src/objc/rfc822/MCOAttachment.h b/src/objc/rfc822/MCOAttachment.h
index 8094d474..03ccbeab 100644
--- a/src/objc/rfc822/MCOAttachment.h
+++ b/src/objc/rfc822/MCOAttachment.h
@@ -41,7 +41,19 @@
/** Returns string representation according to charset*/
- (NSString *) decodedString;
-
+
+/** Adds a custom parameter.*/
+- (void) setExtraParameterValue:(NSString *)value forName:(NSString *)name;
+
+/** Remove a given custom parameter.*/
+- (void) removeExtraParameterForName:(NSString *)name;
+
+/** Returns the value of a given custom parameter.*/
+- (NSString *) extraParameterValueForName:(NSString *)name;
+
+/** Returns an array with the names of all custom headers.*/
+- (NSArray * /* NSString */) allExtraParametersNames;
+
@end
#endif
diff --git a/src/objc/rfc822/MCOAttachment.mm b/src/objc/rfc822/MCOAttachment.mm
index afaf96af..3892ee78 100644
--- a/src/objc/rfc822/MCOAttachment.mm
+++ b/src/objc/rfc822/MCOAttachment.mm
@@ -90,4 +90,23 @@ MCO_OBJC_SYNTHESIZE_DATA(setData, data)
return [NSString mco_stringWithMCString:result];
}
+- (void) setExtraParameterValue:(NSString *)value forName:(NSString *)name
+{
+ MCO_NATIVE_INSTANCE->setExtraParameter(MCO_FROM_OBJC(mailcore::String, name), MCO_FROM_OBJC(mailcore::String, value));
+}
+
+- (NSString *) extraParameterValueForName:(NSString *)name
+{
+ return MCO_TO_OBJC(MCO_NATIVE_INSTANCE->extraParameterValueForName((MCO_FROM_OBJC(mailcore::String, name))));
+}
+- (void) removeExtraParameterForName:(NSString *)name
+{
+ MCO_NATIVE_INSTANCE->removeExtraParameter(MCO_FROM_OBJC(mailcore::String, name));
+}
+
+- (NSArray * /* NSString */) allExtraParametersNames
+{
+ return MCO_TO_OBJC(MCO_NATIVE_INSTANCE->allExtraParametersNames());
+}
+
@end