struct mailmime * mailmime_new_message_data(struct mailmime * msg_mime) { struct mailmime_content * content; struct mailmime * build_info; struct mailmime_fields * mime_fields; content = mailmime_get_content_message(); if (content == NULL) goto err; mime_fields = mailmime_fields_new_with_version(NULL, NULL, NULL, NULL, NULL); if (mime_fields == NULL) goto free_content; build_info = mailmime_new(MAILMIME_MESSAGE, NULL, 0, mime_fields, content, NULL, NULL, NULL, NULL, NULL, msg_mime); if (build_info == NULL) goto free_fields; return build_info; free_fields: mailmime_fields_free(mime_fields); free_content: mailmime_content_free(content); err: return NULL; }
struct mailmime * mailmime_new_message_text(char * data_str, size_t length) { struct mailmime_content * content; struct mailmime * build_info; struct mailmime_data * msg_content; struct mailmime_fields * mime_fields; content = mailmime_get_content_message(); if (content == NULL) { goto err; } mime_fields = mailmime_fields_new_with_version(NULL, NULL, NULL, NULL, NULL); if (mime_fields == NULL) goto free_fields; msg_content = mailmime_data_new(MAILMIME_DATA_TEXT, MAILMIME_MECHANISM_8BIT, 1, data_str, length, NULL); if (msg_content == NULL) goto free_content; build_info = mailmime_new(MAILMIME_MESSAGE, NULL, 0, mime_fields, content, msg_content, NULL, NULL, NULL, NULL, NULL); if (build_info == NULL) goto free_msg_content; return build_info; free_msg_content: mailmime_data_free(msg_content); free_fields: mailmime_fields_free(mime_fields); free_content: mailmime_content_free(content); err: return NULL; }
static int imap_get_bodystructure(mailmessage * msg_info, struct mailmime ** result) { int r; struct mailimap_set * set; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; clist * fetch_result; struct mailimap_msg_att * msg_att; struct mailimap_body * imap_body; struct mailmime * body; int res; struct mailimf_fields * fields; struct mailmime * new_body; struct mailmime_content * content_message; struct mailimap_envelope * envelope; uint32_t uid; char * references; size_t ref_size; clistiter * cur; if (msg_info->msg_mime != NULL) { * result = msg_info->msg_mime; return MAIL_NO_ERROR; } set = mailimap_set_new_single(msg_info->msg_index); if (set == NULL) { res = MAIL_ERROR_MEMORY; goto err; } fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); if (fetch_type == NULL) { res = MAIL_ERROR_MEMORY; goto free_set; } fetch_att = mailimap_fetch_att_new_uid(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); if (r != MAILIMAP_NO_ERROR) { mailimap_fetch_att_free(fetch_att); res = MAIL_ERROR_MEMORY; goto free_fetch_type; } fetch_att = mailimap_fetch_att_new_bodystructure(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); if (r != MAILIMAP_NO_ERROR) { mailimap_fetch_att_free(fetch_att); res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = imap_add_envelope_fetch_att(fetch_type); if (r != MAIL_NO_ERROR) { res = r; goto free_fetch_type; } r = mailimap_uid_fetch(get_imap_session(msg_info), set, fetch_type, &fetch_result); mailimap_fetch_type_free(fetch_type); mailimap_set_free(set); switch (r) { case MAILIMAP_NO_ERROR: break; default: return imap_error_to_mail_error(r); } cur = clist_begin(fetch_result); if (cur == NULL) { mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; } msg_att = clist_content(cur); uid = 0; references = NULL; ref_size = 0; imap_body = NULL; envelope = NULL; r = imap_get_msg_att_info(msg_att, &uid, &envelope, &references, &ref_size, NULL, &imap_body); if (r != MAIL_NO_ERROR) { mailimap_fetch_list_free(fetch_result); res = r; goto err; } if (uid != msg_info->msg_index) { mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MSG_NOT_FOUND; goto err; } if (imap_body == NULL) { mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_FETCH; goto err; } r = imap_body_to_body(imap_body, &body); if (r != MAIL_NO_ERROR) { mailimap_fetch_list_free(fetch_result); res = r; goto err; } fields = NULL; if (envelope != NULL) { r = imap_env_to_fields(envelope, references, ref_size, &fields); if (r != MAIL_NO_ERROR) { mailmime_free(body); mailimap_fetch_list_free(fetch_result); res = r; goto err; } } content_message = mailmime_get_content_message(); if (content_message == NULL) { if (fields != NULL) mailimf_fields_free(fields); mailmime_free(body); mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MEMORY; goto err; } new_body = mailmime_new(MAILMIME_MESSAGE, NULL, 0, NULL, content_message, NULL, NULL, NULL, NULL, fields, body); if (new_body == NULL) { mailmime_content_free(content_message); if (fields != NULL) mailimf_fields_free(fields); mailmime_free(body); mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MEMORY; goto err; } msg_info->msg_mime = new_body; mailimap_fetch_list_free(fetch_result); * result = new_body; return MAIL_NO_ERROR; free_fetch_type: mailimap_fetch_type_free(fetch_type); free_set: mailimap_set_free(set); err: return res; }
static struct mailmime * part_new_empty(struct mailmime_content * content, struct mailmime_fields * mime_fields, const char * boundary_prefix, int force_single) { struct mailmime * build_info; clist * list; int r; int mime_type; list = NULL; if (force_single) { mime_type = MAILMIME_SINGLE; } else { switch (content->ct_type->tp_type) { case MAILMIME_TYPE_DISCRETE_TYPE: mime_type = MAILMIME_SINGLE; break; case MAILMIME_TYPE_COMPOSITE_TYPE: switch (content->ct_type->tp_data.tp_composite_type->ct_type) { case MAILMIME_COMPOSITE_TYPE_MULTIPART: mime_type = MAILMIME_MULTIPLE; break; case MAILMIME_COMPOSITE_TYPE_MESSAGE: if (strcasecmp(content->ct_subtype, "rfc822") == 0) mime_type = MAILMIME_MESSAGE; else mime_type = MAILMIME_SINGLE; break; default: goto err; } break; default: goto err; } } if (mime_type == MAILMIME_MULTIPLE) { char * attr_name; char * attr_value; struct mailmime_parameter * param; clist * parameters; char * boundary; list = clist_new(); if (list == NULL) goto err; attr_name = strdup("boundary"); boundary = generate_boundary(boundary_prefix); attr_value = boundary; if (attr_name == NULL) { free(attr_name); goto free_list; } param = mailmime_parameter_new(attr_name, attr_value); if (param == NULL) { free(attr_value); free(attr_name); goto free_list; } if (content->ct_parameters == NULL) { parameters = clist_new(); if (parameters == NULL) { mailmime_parameter_free(param); goto free_list; } } else parameters = content->ct_parameters; r = clist_append(parameters, param); if (r != 0) { clist_free(parameters); mailmime_parameter_free(param); goto free_list; } if (content->ct_parameters == NULL) content->ct_parameters = parameters; } build_info = mailmime_new(mime_type, NULL, 0, mime_fields, content, NULL, NULL, NULL, list, NULL, NULL); if (build_info == NULL) { clist_free(list); return NULL; } return build_info; free_list: clist_free(list); err: return NULL; }