struct mailmime_content * mailmime_content_new_with_str(const char * str) { int r; size_t cur_token; struct mailmime_content * content; cur_token = 0; r = mailmime_content_parse(str, strlen(str), &cur_token, &content); if (r != MAILIMF_NO_ERROR) return NULL; return content; }
struct mailmime_content * mailmime_get_content(char * mime_type) { struct mailmime_content *content; int r; size_t cur_token; cur_token = 0; r = mailmime_content_parse(mime_type, strlen(mime_type), &cur_token, &content); if (r != MAILIMF_NO_ERROR) return NULL; return content; }
LIBETPAN_EXPORT int mailmime_field_parse(struct mailimf_optional_field * field, struct mailmime_field ** result) { char * name; char * value; int guessed_type; size_t cur_token; struct mailmime_content * content; struct mailmime_mechanism * encoding; char * id; char * description; uint32_t version; struct mailmime_field * mime_field; struct mailmime_language * language; struct mailmime_disposition * disposition; char * location; int res; int r; name = field->fld_name; value = field->fld_value; cur_token = 0; content = NULL; encoding = NULL; id = NULL; description = NULL; version = 0; disposition = NULL; language = NULL; location = NULL; guessed_type = guess_field_type(name); switch (guessed_type) { case MAILMIME_FIELD_TYPE: if (strcasecmp(name, "Content-Type") != 0) return MAILIMF_ERROR_PARSE; { size_t cur_token = 0; char * decoded_value; r = mailmime_encoded_phrase_parse("us-ascii", value, strlen(value), &cur_token, "utf-8", &decoded_value); if (r != MAILIMF_NO_ERROR) { cur_token = 0; r = mailmime_content_parse(value, strlen(value), &cur_token, &content); } else { cur_token = 0; r = mailmime_content_parse(decoded_value, strlen(decoded_value), &cur_token, &content); free(decoded_value); } if (r != MAILIMF_NO_ERROR) return r; } break; case MAILMIME_FIELD_TRANSFER_ENCODING: if (strcasecmp(name, "Content-Transfer-Encoding") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_encoding_parse(value, strlen(value), &cur_token, &encoding); if (r != MAILIMF_NO_ERROR) return r; break; case MAILMIME_FIELD_ID: if (strcasecmp(name, "Content-ID") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_id_parse(value, strlen(value), &cur_token, &id); if (r != MAILIMF_NO_ERROR) return r; break; case MAILMIME_FIELD_DESCRIPTION: if (strcasecmp(name, "Content-Description") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_description_parse(value, strlen(value), &cur_token, &description); if (r != MAILIMF_NO_ERROR) return r; break; case MAILMIME_FIELD_VERSION: if (strcasecmp(name, "MIME-Version") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_version_parse(value, strlen(value), &cur_token, &version); if (r != MAILIMF_NO_ERROR) return r; break; case MAILMIME_FIELD_DISPOSITION: if (strcasecmp(name, "Content-Disposition") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_disposition_parse(value, strlen(value), &cur_token, &disposition); if (r != MAILIMF_NO_ERROR) return r; break; case MAILMIME_FIELD_LANGUAGE: if (strcasecmp(name, "Content-Language") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_language_parse(value, strlen(value), &cur_token, &language); if (r != MAILIMF_NO_ERROR) return r; break; case MAILMIME_FIELD_LOCATION: if (strcasecmp(name, "Content-Location") != 0) return MAILIMF_ERROR_PARSE; r = mailmime_location_parse(value, strlen(value), &cur_token, &location); if (r != MAILIMF_NO_ERROR) return r; break; default: return MAILIMF_ERROR_PARSE; } mime_field = mailmime_field_new(guessed_type, content, encoding, id, description, version, disposition, language, location); if (mime_field == NULL) { res = MAILIMF_ERROR_MEMORY; goto free; } * result = mime_field; return MAILIMF_NO_ERROR; free: if (location != NULL) mailmime_location_free(location); if (language != NULL) mailmime_language_free(language); if (content != NULL) mailmime_content_free(content); if (encoding != NULL) mailmime_encoding_free(encoding); if (id != NULL) mailmime_id_free(id); if (description != NULL) mailmime_description_free(description); return res; }
int mailmime_new_with_content(const char * content_type, struct mailmime_fields * mime_fields, struct mailmime ** result) { int r; size_t cur_token; struct mailmime_content * content; struct mailmime * build_info; #if 0 int mime_type; #endif int res; cur_token = 0; r = mailmime_content_parse(content_type, strlen(content_type), &cur_token, &content); if (r != MAILIMF_NO_ERROR) { res = r; goto err; } #if 0 switch (content->type->type) { case MAILMIME_TYPE_DISCRETE_TYPE: mime_type = MAILMIME_SINGLE; break; case MAILMIME_TYPE_COMPOSITE_TYPE: switch (content->type->composite_type->type) { case MAILMIME_COMPOSITE_TYPE_MULTIPART: mime_type = MAILMIME_MULTIPLE; break; case MAILMIME_COMPOSITE_TYPE_MESSAGE: if (strcasecmp(content->subtype, "rfc822") == 0) mime_type = MAILMIME_MESSAGE; else mime_type = MAILMIME_SINGLE; break; default: res = MAILIMF_ERROR_INVAL; goto free; } break; default: res = MAILIMF_ERROR_INVAL; goto free; } #endif build_info = mailmime_new_empty(content, mime_fields); if (build_info == NULL) { res = MAILIMF_ERROR_MEMORY; goto free; } * result = build_info; return MAILIMF_NO_ERROR; free: mailmime_content_free(content); err: return res; }