From: Sunghyun Kwon Date: Fri, 1 Feb 2013 08:32:52 +0000 (+0900) Subject: Fixed the prevent and attachment size missing error X-Git-Tag: submit/submit/20141001.115906~33^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ed2744b0eccf69bbfbf3ba44d367f247eb30d47;p=platform%2Fframework%2Fnative%2Fmessaging.git Fixed the prevent and attachment size missing error --- diff --git a/email-common-use/include/email-errors.h b/email-common-use/include/email-errors.h index 2110457..4499c09 100755 --- a/email-common-use/include/email-errors.h +++ b/email-common-use/include/email-errors.h @@ -167,6 +167,7 @@ #define EMAIL_ERROR_LOAD_ENGINE_FAILURE -1056 /* loading engine failed */ #define EMAIL_ERROR_CLOSE_FAILURE -1057 /* engine is still used */ #define EMAIL_ERROR_NULL_VALUE -1302 +#define EMAIL_ERROR_EMPTY_FILE -1304 /* Should be classified */ #define EMAIL_ERROR_SYSTEM_FAILURE -1050 /* There is a system error */ diff --git a/email-core/email-core-mail.c b/email-core/email-core-mail.c index 7379f9f..7106687 100755 --- a/email-core/email-core-mail.c +++ b/email-core/email-core-mail.c @@ -1327,8 +1327,6 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ ADDRESS *addr = NULL; char *address = NULL; char *temp_emailaddr = NULL; - int start_text_ascii = 2; - int end_text_ascii = 3; char *alias = NULL; int is_searched = false; int address_length = 0; @@ -1568,13 +1566,8 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ temp_emailaddr = NULL; } - if (contact_name != NULL) { - contact_info->contact_name = g_strdup(contact_name); - } - else { - contact_info->contact_name = g_strdup_printf("%c%d%c%s%c", start_text_ascii, 0, start_text_ascii, full_address, end_text_ascii); - contact_info->contact_id = -1; - } + + contact_info->contact_name = g_strdup(contact_name); /*prevent 40020*/ ret = true; @@ -5248,7 +5241,8 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a if (input_mail_data->preview_text == NULL) { if ( (err =emcore_get_preview_text_from_file(input_mail_data->file_path_plain, input_mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(input_mail_data->preview_text))) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file failed[%d]", err); - goto FINISH_OFF2; + if (err != EMAIL_ERROR_EMPTY_FILE) + goto FINISH_OFF2; } } diff --git a/email-core/email-core-mailbox-sync.c b/email-core/email-core-mailbox-sync.c index 24f6bf6..fb3ea4e 100755 --- a/email-core/email-core-mailbox-sync.c +++ b/email-core/email-core-mailbox-sync.c @@ -3187,7 +3187,7 @@ static void emcore_free_email_image_data(email_image_data **image_data, int coun static int emcore_parse_image_part_for_partial_body(char *header_start_string, char *start_header, char *boundary_string, char *bufsendforparse, email_image_data *image_data, int body_size) { - EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_FUNC_BEGIN("boundary_string : [%s]", boundary_string); int err = EMAIL_ERROR_NONE; char *multiple_image = NULL; @@ -3203,6 +3203,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c char *temp_cid1 = NULL; char *cid_end = NULL; char *temp_enc1 = NULL; + char *p_boundary_string = NULL; if(image_data == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -3225,7 +3226,10 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c memcpy(temp_image_boundary, image_boundary, image_boundary_end-image_boundary); if ((char *)strcasestr((const char *)temp_image_boundary, "Content-type:") == NULL) - boundary_string = temp_image_boundary; + p_boundary_string = temp_image_boundary; + else + p_boundary_string = boundary_string; + do { if (multiple_image != NULL){ p = multiple_image; @@ -3309,7 +3313,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c if (txt_image != NULL){ txt_image += 4; /* txt_image points at image content */ start = txt_image; - end = strstr(txt_image, boundary_string); + end = strstr(txt_image, p_boundary_string); if (end == NULL){ @@ -3318,7 +3322,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c end = txt_image + body_size - (txt_image-bufsendforparse); } else{ - boundarylen = EM_SAFE_STRLEN(boundary_string); + boundarylen = EM_SAFE_STRLEN(p_boundary_string); end -= 2; } @@ -3508,38 +3512,38 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c no_alternative_part_flag = 1; } else { EM_DEBUG_LOG(" Content-type: multipart/alternative "); - boundary_start = strstr(temp_alternative_plain_header, "--") + strlen("--"); + boundary_start = strstr(temp_alternative_plain_header, "--"); if(!boundary_start) goto FINISH_OFF; /*prevent 37946 */ boundary_end = strcasestr(boundary_start, "Content-type:"); if(!boundary_end) goto FINISH_OFF; /*prevent 37946 */ - boundary_string = em_malloc(boundary_end - boundary_start); + boundary_string = em_malloc(boundary_end - (boundary_start + strlen("--"))); if (boundary_string == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - memcpy(boundary_string, boundary_start, boundary_end - boundary_start); + memcpy(boundary_string, boundary_start, boundary_end - (boundary_start + strlen("--"))); } } } else no_alternative_part_flag = 1; if (no_alternative_part_flag) { - boundary_start = strstr(p_body_str, "--") + strlen("--"); + boundary_start = strstr(p_body_str, "--"); if(!boundary_start) goto FINISH_OFF; /*prevent 37946 */ boundary_end = strcasestr(boundary_start, "Content-type:"); if(!boundary_end) goto FINISH_OFF; /*prevent 37946 */ - boundary_string = em_malloc(boundary_end - boundary_start); + boundary_string = em_malloc(boundary_end - (boundary_start + strlen("--"))); if (boundary_string == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - memcpy(boundary_string, boundary_start, boundary_end - boundary_start); + memcpy(boundary_string, boundary_start, boundary_end - (boundary_start + strlen("--"))); } if (boundary_string && boundary_end) { /*prevent 37946 */ diff --git a/email-core/email-core-mime.c b/email-core/email-core-mime.c index 443795d..5d73272 100755 --- a/email-core/email-core-mime.c +++ b/email-core/email-core-mime.c @@ -453,28 +453,34 @@ FINISH_OFF: int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary_string, char *boundary_end_string, int *end_of_parsing, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_string[%s], boundary_end_string[%s], end_of_parsing[%p], err_code[%p]", stream, is_file, boundary_string, boundary_end_string, end_of_parsing, err_code); - char buf[MIME_LINE_LEN] = {0, }; + int err = EMAIL_ERROR_NONE; int local_end_of_parsing = 0; + char buf[MIME_LINE_LEN] = {0, }; if (!stream) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return false; } while (TRUE) { - if (!emcore_check_thread_status()) { - if (err_code != NULL) - *err_code = EMAIL_ERROR_CANCELLED; + if (!emcore_check_thread_status()) { EM_DEBUG_FUNC_END("EMAIL_ERROR_CANCELLED"); + if (err_code) + *err_code = EMAIL_ERROR_CANCELLED; return false; } - if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || - (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { - EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed"); - local_end_of_parsing = 0; + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &err)) || + (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, &err))) { + if (err != EMAIL_ERROR_NO_MORE_DATA) { + EM_DEBUG_EXCEPTION("file : [%d], emcore_mime_get_line_from_sock or emcore_mime_get_line_from_file failed", is_file); + local_end_of_parsing = 0; + break; + } + + local_end_of_parsing = 1; break; } @@ -495,6 +501,9 @@ int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary if (end_of_parsing) *end_of_parsing = local_end_of_parsing; + if (err_code) + *err_code = err; + EM_DEBUG_FUNC_END(); return true; } @@ -758,8 +767,15 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru { EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], mmsg[%p], cnt_info[%p], callback[%p], err_code[%p]", stream, is_file, mmsg, cnt_info, callback, err_code); + if (!mmsg->header) { + EM_DEBUG_EXCEPTION("Invalid paramter"); + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + char *content_type = NULL, *content_encoding = NULL, *holder = NULL, *attachment_name, *t = NULL; - int type = 0, end_of_parsing = 0, size, local_err_code = EMAIL_ERROR_NONE; + int type = 0, end_of_parsing = 0, size; + int err = EMAIL_ERROR_NONE; if (!emcore_check_thread_status()) { if (err_code != NULL) @@ -788,23 +804,24 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru switch (type) { case TYPE_MULTIPART: - if (mmsg->header && !emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_BOUNDARY, err_code)) { + if (mmsg->header && !emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_BOUNDARY, &err)) { EM_DEBUG_FUNC_END("false"); + if (err_code != NULL) + *err_code = err; return false; } - if (mmsg->header && !emcore_mime_parse_part(stream, is_file, mmsg->header->part_header, &mmsg->nested, cnt_info, &end_of_parsing, &local_err_code)) { + if (mmsg->header && !emcore_mime_parse_part(stream, is_file, mmsg->header->part_header, &mmsg->nested, cnt_info, &end_of_parsing, &err)) { EM_DEBUG_FUNC_END("false"); + if (err_code != NULL) + *err_code = err; return false; } /* after finishing body parsing, make stream empty to get next mail. (get line from sock or file until '.' is read */ - if (end_of_parsing == true && local_err_code != EMAIL_ERROR_NO_MORE_DATA) + if (end_of_parsing == true && err != EMAIL_ERROR_NO_MORE_DATA) emcore_mime_flush_receiving_buffer(stream, is_file, NULL, NULL, NULL, err_code); - if (err_code) - *err_code = local_err_code; - break; default: @@ -843,21 +860,17 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru EM_DEBUG_LOG("After emcore_mime_get_content_data"); char *charset = mmsg->header? emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_CHARSET, err_code) : NULL; /* prevent 27453 */ - EM_DEBUG_LOG(">>>> charset [%s]", charset); if (mmsg->header && mmsg->header->part_header && strstr((t = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code)) ? t : "", "HTML")) { if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) - cnt_info->text.plain_charset = strdup("UTF-8"); + cnt_info->text.html_charset = strdup("UTF-8"); else - cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); - - EM_DEBUG_LOG(">>>> cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset); + cnt_info->text.html_charset = EM_SAFE_STRDUP(charset); + EM_DEBUG_LOG(">>>> cnt_info->text.html_charset [%s]", cnt_info->text.html_charset); cnt_info->text.html = holder; - - EM_DEBUG_LOG(">>>> cnt_info->text.plain [%s]", cnt_info->text.html); - + EM_DEBUG_LOG(">>>> cnt_info->text.html [%s]", cnt_info->text.html); } else if (mmsg->header) { @@ -865,11 +878,9 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru cnt_info->text.plain_charset = strdup("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); - EM_DEBUG_LOG(">>>> cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset); cnt_info->text.plain = holder; - EM_DEBUG_LOG(">>>> cnt_info->text.plain [%s]", cnt_info->text.plain); } } @@ -896,7 +907,6 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par char *holder = NULL; char *attachment_name = NULL; char *content_disposition = NULL; - char *t = NULL; char *pTemp = NULL; int type = 0; int content_disposition_type = 0; @@ -1044,56 +1054,50 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par /* first check inline content */ /* if the content id or content location exis */ - t = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_TYPE, err_code); - EM_DEBUG_LOG("content_type : [%s]", t); + content_disposition = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_DISPOSITION, err_code); + EM_DEBUG_LOG("content_disposition : [%s]", content_disposition); - if (!strstr(t ? t : "", "HTML")) { - content_disposition = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_DISPOSITION, err_code); - EM_DEBUG_LOG("content_disposition : [%s]", content_disposition); + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_ID, err_code); + EM_DEBUG_LOG("content_id : [%s]", attachment_name); - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_ID, err_code); - EM_DEBUG_LOG("content_id : [%s]", attachment_name); + if (attachment_name) { + if (emcore_search_string_from_file(cnt_info->text.html, attachment_name, &result) == EMAIL_ERROR_NONE && result) { + content_disposition_type = INLINE_ATTACHMENT; + } else if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) { + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); - if (attachment_name) { - if (emcore_search_string_from_file(cnt_info->text.html, attachment_name, &result) == EMAIL_ERROR_NONE && result) { - content_disposition_type = INLINE_ATTACHMENT; - } else if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) { - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); + if (!attachment_name) + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); - if (!attachment_name) - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); + content_disposition_type = ATTACHMENT; - content_disposition_type = ATTACHMENT; - - } else { - EM_DEBUG_EXCEPTION("Unknown mime type"); - } } else { - if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) { - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); - - if (!attachment_name) - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); + EM_DEBUG_EXCEPTION("Unknown mime type"); + } + } else { + if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) { + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); - content_disposition_type = ATTACHMENT; + if (!attachment_name) + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); - } else if (!strcasecmp(content_disposition ? content_disposition : "", "inline")) { - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); + content_disposition_type = ATTACHMENT; - if (!attachment_name) - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); + } else if (!strcasecmp(content_disposition ? content_disposition : "", "inline")) { + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); - content_disposition_type = INLINE_ATTACHMENT; - } else if (strstr(content_type, "PKCS7")) { - attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); - EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name : NIL); + if (!attachment_name) + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); - content_disposition_type = ATTACHMENT; + content_disposition_type = INLINE_ATTACHMENT; + } else if (strstr(content_type ? content_type : "", "PKCS7")) { + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); + EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name : NIL); - } else { - EM_DEBUG_EXCEPTION("Unknown mime"); - } + content_disposition_type = ATTACHMENT; + } else { + EM_DEBUG_LOG("No attachment"); } } @@ -1119,36 +1123,36 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_LOG("After emcore_mime_get_content_data"); - if (cnt_info->grab_type & GRAB_TYPE_TEXT) { - if (tmp_body->part_header && strstr(t ? t : "", "HTML")) { - cnt_info->text.html = holder; + if (cnt_info->grab_type & GRAB_TYPE_TEXT) { + char *charset = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_CHARSET, err_code); + EM_DEBUG_LOG(" charset [%s]", charset); - EM_DEBUG_LOG(" cnt_info->text.html [%s]", cnt_info->text.html); - } - else { - char *charset = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_CHARSET, err_code); - EM_DEBUG_LOG(" charset [%s]", charset); + if (tmp_body->part_header && strstr(content_type ? content_type : "", "HTML")) { + if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) + cnt_info->text.html_charset = strdup("UTF-8"); + else + cnt_info->text.html_charset = EM_SAFE_STRDUP(charset); + EM_DEBUG_LOG(" cnt_info->text.html_charset [%s]", cnt_info->text.html_charset); + cnt_info->text.html = holder; + EM_DEBUG_LOG(" cnt_info->text.html [%s]", cnt_info->text.html); + } else { if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) cnt_info->text.plain_charset = strdup("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); - EM_DEBUG_LOG(" cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset); cnt_info->text.plain = holder; - EM_DEBUG_LOG(" cnt_info->text.plain [%s]", cnt_info->text.plain); } - } - else { - if (holder) { + } else { + if (holder) { free(holder); holder = NULL; } } - } - else { /* attachment */ + } else { /* attachment */ EM_DEBUG_LOG("attachment_name is not NULL. It's a attachment"); struct attachment_info *file = NULL; struct attachment_info *temp_file = cnt_info->file; @@ -1742,7 +1746,7 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b if (is_file) { EM_DEBUG_LOG("from file"); - error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, size); + error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, &sz); if (error != EMAIL_ERROR_NONE) { if (error != EMAIL_ERROR_NO_MORE_DATA) { EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_file failed : [%d]", error); @@ -2596,11 +2600,9 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int char *filename = NULL; int server_response_yn = 0; int write_flag = false; - char *write_buffer = NULL; unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0, }; unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0, }; int flag_first_write = true; - int max_write_buffer_size = MAX_WRITE_BUFFER_SIZE; if (!stream || !filepath || !section) { EM_DEBUG_EXCEPTION("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p]", stream, filepath, uid, section, encoding, decoded_total); @@ -2608,17 +2610,6 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } - EM_DEBUG_LOG(">>> WRITE BUFFER SIZE : %d KB", max_write_buffer_size); - - if (max_write_buffer_size > 0) { - max_write_buffer_size *= 1024; /* KB -> byte */ - if (!(write_buffer = em_malloc(sizeof(char) *max_write_buffer_size))) { - EM_DEBUG_EXCEPTION("em_malloc failed..."); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - } - FINISH_OFF_IF_CANCELED; if (!(fp = fopen(filepath, "wb+"))) { @@ -2937,8 +2928,6 @@ FINISH_OFF: if (fp != NULL) fclose(fp); - EM_SAFE_FREE(write_buffer); - if (ret == false) { /* delete temp fil */ struct stat temp_file_stat; if (filepath && stat(filepath, &temp_file_stat) == 0) @@ -3297,10 +3286,7 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a _imap4_received_body_size -= gap; _imap4_last_notified_body_size = _imap4_received_body_size; - if (body_size) - progress = 100*total/body_size; - else - progress = body_size; + progress = 100*total/body_size; /*prevent 40023*/ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, progress, total); EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress); @@ -4999,14 +4985,12 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str goto FINISH_OFF; } - if (cnt_info->text.plain_charset != NULL) { - SNPRINTF(html_body, MAX_PATH, "%s%s", cnt_info->text.plain_charset, HTML_EXTENSION_STRING); - } - else { + if (cnt_info->text.html_charset != NULL) { + SNPRINTF(html_body, MAX_PATH, "%s%s", cnt_info->text.html_charset, HTML_EXTENSION_STRING); + } else { strcpy(html_body, UNKNOWN_CHARSET_HTML_TEXT_FILE); } - if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, html_body, buf, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; @@ -5418,11 +5402,11 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco { EM_DEBUG_FUNC_BEGIN(); int error = EMAIL_ERROR_NONE; - int start_location = 0; - int end_location = 0; int p_size = 0; int partial_body = 0; int dec_len = 0; + long start_location = 0; + long end_location = 0; char boundary[BOUNDARY_LEN] = {0x00, }; char boundary_end[BOUNDARY_LEN] = {0x00, }; char buf[MIME_LINE_LEN] = {0x00, }; @@ -5506,7 +5490,14 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco } if (modified_body == NULL) { - modified_body = strdup(body); /*prevent 35585 */ + modified_body = em_malloc(dec_len + 1); + if (modified_body == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + memcpy(modified_body, body, dec_len); /*prevent 35585 */ modified_body_size = dec_len; } @@ -5525,6 +5516,9 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco FINISH_OFF: + if (size) + *size = modified_body_size; + EM_SAFE_FREE(modified_body); EM_SAFE_FREE(body); /*prevent 35585 */ return error; diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c index 96d7b75..96467e8 100755 --- a/email-core/email-core-smtp.c +++ b/email-core/email-core-smtp.c @@ -815,7 +815,9 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta if (mail_data->preview_text == NULL) { if ( (err = emcore_get_preview_text_from_file(mail_data->file_path_plain, mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail_data->preview_text))) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file failed[%d]", err); - goto FINISH_OFF; + + if (err != EMAIL_ERROR_EMPTY_FILE) + goto FINISH_OFF; } } @@ -1192,12 +1194,12 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai } /* get mail to send */ - if ( !emstorage_get_mail_by_id(mail_id, &mail_tbl_data, false, &err) || err != EMAIL_ERROR_NONE) { + if (!emstorage_get_mail_by_id(mail_id, &mail_tbl_data, false, &err) || err != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); goto FINISH_OFF; } - if ( (err = emstorage_get_attachment_list(mail_id, false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) { + if ((err = emstorage_get_attachment_list(mail_id, false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); goto FINISH_OFF; } @@ -1214,7 +1216,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai goto FINISH_OFF; } else { - if ( (err = em_verify_email_address_of_mail_tbl(mail_tbl_data, false)) != EMAIL_ERROR_NONE ) { + if ((err = em_verify_email_address_of_mail_tbl(mail_tbl_data, false)) != EMAIL_ERROR_NONE) { err = EMAIL_ERROR_INVALID_ADDRESS; EM_DEBUG_EXCEPTION("em_verify_email_address_of_mail_tbl failed [%d]", err); goto FINISH_OFF; @@ -1240,7 +1242,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai /*Update status flag to DB*/ /* get rfc822 data */ - if (!emcore_make_rfc822_file_from_mail(mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) { + if (!emcore_make_rfc822_file_from_mail(mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) { EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err); goto FINISH_OFF; } @@ -2639,7 +2641,7 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d envelope->from = rfc822_parse_mailbox(&p, NULL); EM_SAFE_FREE(p); - if (!envelope->from) { + if (!envelope->from) { EM_DEBUG_EXCEPTION("rfc822_parse_mailbox failed..."); error = EMAIL_ERROR_INVALID_ADDRESS; goto FINISH_OFF; @@ -2916,7 +2918,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ root_body->size.bytes = 0; root_body->parameter = param; - if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE) { + if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE && input_mail_tbl_data->file_path_plain && input_mail_tbl_data->file_path_html) { part_for_text = attach_mutipart_with_sub_type(root_body, "ALTERNATIVE", &error); if (!part_for_text) { @@ -2925,28 +2927,28 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } text_body = &part_for_text->body; - } - if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) { - EM_DEBUG_LOG("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - if (!attach_part(text_body, (unsigned char *)input_mail_tbl_data->file_path_plain, 0, NULL, NULL, false, &error)) { - EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); - goto FINISH_OFF; + if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) { + EM_DEBUG_LOG("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); + if (!attach_part(text_body, (unsigned char *)input_mail_tbl_data->file_path_plain, 0, NULL, NULL, false, &error)) { + EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); + goto FINISH_OFF; + } } - } - if (input_mail_tbl_data->file_path_html && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_html) > 0) { - EM_DEBUG_LOG("file_path_html[%s]", input_mail_tbl_data->file_path_html); + if (input_mail_tbl_data->file_path_html && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_html) > 0) { + EM_DEBUG_LOG("file_path_html[%s]", input_mail_tbl_data->file_path_html); - part_for_html = attach_mutipart_with_sub_type(text_body, "RELATED", &error); - if (!part_for_html) { - EM_DEBUG_EXCEPTION("attach_mutipart_with_sub_type [part_for_html] failed [%d]", error); - goto FINISH_OFF; - } + part_for_html = attach_mutipart_with_sub_type(text_body, "RELATED", &error); + if (!part_for_html) { + EM_DEBUG_EXCEPTION("attach_mutipart_with_sub_type [part_for_html] failed [%d]", error); + goto FINISH_OFF; + } - if (!attach_part(&(part_for_html->body) , (unsigned char *)input_mail_tbl_data->file_path_html, 0, NULL, "html", false, &error)) { - EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); - goto FINISH_OFF; + if (!attach_part(&(part_for_html->body) , (unsigned char *)input_mail_tbl_data->file_path_html, 0, NULL, "html", false, &error)) { + EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); + goto FINISH_OFF; + } } } @@ -2990,7 +2992,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } text_body = NULL; } - else { + else { text_body = mail_newbody(); if (text_body == NULL) { @@ -3028,7 +3030,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ if (part_for_html) html_body = &(part_for_html->body); - if (!emcore_write_rfc822(envelope, root_body ? root_body : text_body, html_body, input_mail_tbl_data->priority, input_mail_tbl_data->report_status, &fname, &error)) { + if (!emcore_write_rfc822(envelope, root_body ? root_body : text_body, html_body, input_mail_tbl_data->priority, input_mail_tbl_data->report_status, &fname, &error)) { EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error); goto FINISH_OFF; } diff --git a/email-core/email-core-utils.c b/email-core/email-core-utils.c index 75c77d9..570ccaa 100755 --- a/email-core/email-core-utils.c +++ b/email-core/email-core-utils.c @@ -1195,6 +1195,12 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } + if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) { + EM_DEBUG_LOG("input_html_file is empty size"); + err = EMAIL_ERROR_EMPTY_FILE; + goto FINISH_OFF; + } + if (!(local_preview_text = (char*)em_malloc(sizeof(char) * (st_buf.st_size + 1)))) { EM_DEBUG_EXCEPTION("em_malloc failed"); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -1226,12 +1232,25 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } + memset(&st_buf, 0, sizeof(struct stat)); + if (stat(input_plain_path, &st_buf) < 0) { + EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path); + err = EMAIL_ERROR_INVALID_MAIL; + goto FINISH_OFF; + } + if (!(fp_plain = fopen(input_plain_path, "r"))) { EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } + if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) { + EM_DEBUG_LOG("input_text_file is empty size"); + err = EMAIL_ERROR_EMPTY_FILE; + goto FINISH_OFF; + } + if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) { EM_DEBUG_EXCEPTION("em_malloc failed"); goto FINISH_OFF; diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index 85bce46..10e84ef 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -1113,7 +1113,7 @@ static int _get_stmt_field_data_time_t(DB_STMT hStmt, time_t *buf, int index) static int _get_stmt_field_data_string(DB_STMT hStmt, char **buf, int ucs2, int index) { - if ((hStmt < 0) || (buf == NULL) || (index < 0)) { + if (!hStmt || !buf || (index < 0)) { /*prevent 39619*/ EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], index[%d]", hStmt, buf, index); return false; } @@ -1144,7 +1144,7 @@ static int _get_stmt_field_data_string(DB_STMT hStmt, char **buf, int ucs2, int static void _get_stmt_field_data_blob(DB_STMT hStmt, void **buf, int index) { - if ((hStmt < 0) || (buf == NULL) || (index < 0)) { + if( !hStmt || !buf || (index < 0)) { /*prevent 39618*/ EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], index[%d]", hStmt, buf, index); return; } @@ -1167,7 +1167,7 @@ static void _get_stmt_field_data_blob(DB_STMT hStmt, void **buf, int index) static int _get_stmt_field_data_string_without_allocation(DB_STMT hStmt, char *buf, int buffer_size, int ucs2, int index) { - if ((hStmt < 0) || (buf == NULL) || (index < 0)) { + if (!hStmt || !buf || (index < 0)) { /*prevent 39620*/ EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], buffer_size[%d], index[%d]", hStmt, buf, buffer_size, index); return false; } @@ -9250,11 +9250,12 @@ FINISH_OFF: else if (p_data_tbl != NULL) emstorage_free_attachment(&p_data_tbl, *output_attachment_count, NULL); - rc = sqlite3_finalize(hStmt); - - if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc); - error = EMAIL_ERROR_DB_FAILURE; + if (hStmt) { + rc = sqlite3_finalize(hStmt); + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } } EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); diff --git a/email-core/include/email-core-mail.h b/email-core/include/email-core-mail.h index 667df78..e7c0f47 100755 --- a/email-core/include/email-core-mail.h +++ b/email-core/include/email-core-mail.h @@ -71,6 +71,7 @@ struct _m_content_info char *plain; /* body plain text */ char *plain_charset; /* charset of body text */ char *html; /* body html text */ + char *html_charset; /* charset of html text */ } text; struct attachment_info diff --git a/email-service.manifest b/email-service.manifest index dfbc76f..fec577f 100644 --- a/email-service.manifest +++ b/email-service.manifest @@ -6,13 +6,11 @@ - - diff --git a/packaging/email-service.spec b/packaging/email-service.spec index 4e4f537..ea51f9e 100755 --- a/packaging/email-service.spec +++ b/packaging/email-service.spec @@ -1,6 +1,6 @@ Name: email-service Summary: E-mail Framework Middleware package -Version: 0.10.82 +Version: 0.10.84 Release: 1 Group: System/Libraries License: TBD @@ -405,6 +405,11 @@ chgrp 6006 /opt/usr/data/email/.email_data/tmp mkdir -p /opt/share/cert-svc/certs/trusteduser/email chgrp 6006 /opt/share/cert-svc/certs/trusteduser/email +if [ -f /opt/usr/dbspace/.email-service.db ] +then + chsmack -a 'email-service::db' /opt/usr/dbspace/.email-service.db* +fi + systemctl daemon-reload if [ $1 == 1 ]; then systemctl restart email.service