Attachment * Attachment::attachmentWithRFC822Message(Data * messageData) { Attachment * attachment; attachment = new Attachment(); attachment->setMimeType(MCSTR("message/rfc822")); attachment->setData(messageData); return (Attachment *) attachment->autorelease(); }
Attachment * Attachment::attachmentWithText(String * text) { Data * data; Attachment * attachment; attachment = new Attachment(); attachment->setInlineAttachment(true); attachment->setMimeType(MCSTR("text/plain")); data = text->dataUsingEncoding("utf-8"); attachment->setData(data); return (Attachment *) attachment->autorelease(); }
Attachment * Attachment::attachmentWithHTMLString(String * htmlString) { Data * data; Attachment * attachment; attachment = new Attachment(); attachment->setInlineAttachment(true); attachment->setMimeType(MCSTR("text/html")); data = htmlString->dataUsingEncoding("utf-8"); attachment->setData(data); return (Attachment *) attachment->autorelease(); }
Attachment * Attachment::attachmentWithData(String * filename, Data * data) { Attachment * attachment; String * mimeType; attachment = new Attachment(); mimeType = Attachment::mimeTypeForFilename(filename); if (mimeType != NULL) { attachment->setMimeType(mimeType); } if (filename != NULL) { attachment->setFilename(filename->lastPathComponent()); } attachment->setData(data); return (Attachment *) attachment->autorelease(); }
Attachment * Attachment::attachmentWithSingleMIME(struct mailmime * mime) { struct mailmime_data * data; const char * bytes; size_t length; Attachment * result; struct mailmime_single_fields single_fields; char * str; char * name; char * filename; char * content_id; char * description; char * loc; Encoding encoding; clist * ct_parameters; MCAssert(mime->mm_type == MAILMIME_SINGLE); result = new Attachment(); result->setUniqueID(mailcore::String::uuidString()); data = mime->mm_data.mm_single; bytes = data->dt_data.dt_text.dt_data; length = data->dt_data.dt_text.dt_length; mailmime_single_fields_init(&single_fields, mime->mm_mime_fields, mime->mm_content_type); encoding = encodingForMIMEEncoding(single_fields.fld_encoding, data->dt_encoding); Data * mimeData; mimeData = Data::dataWithBytes(bytes, (unsigned int) length); mimeData = mimeData->decodedDataUsingEncoding(encoding); result->setData(mimeData); str = get_content_type_str(mime->mm_content_type); result->setMimeType(String::stringWithUTF8Characters(str)); free(str); name = single_fields.fld_content_name; filename = single_fields.fld_disposition_filename; 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)); } else if (name != NULL) { result->setFilename(String::stringByDecodingMIMEHeaderValue(name)); } if (content_id != NULL) { result->setContentID(String::stringWithUTF8Characters(content_id)); } if (description != NULL) { result->setContentDescription(String::stringWithUTF8Characters(description)); } if (single_fields.fld_content_charset != NULL) { result->setCharset(String::stringByDecodingMIMEHeaderValue(single_fields.fld_content_charset)); } if (loc != NULL) { 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) { if ((strcasecmp("name", param->pa_name) != 0) && (strcasecmp("charset", param->pa_name) != 0)) { result->setContentTypeParameter(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) { result->setInlineAttachment(true); } else if (single_fields.fld_disposition->dsp_type->dsp_type == MAILMIME_DISPOSITION_TYPE_ATTACHMENT) { result->setAttachment(true); } } } return (Attachment *) result->autorelease(); }