From: Sunghyun Kwon Date: Wed, 9 Jan 2013 07:46:26 +0000 (+0900) Subject: Fixed the prevent and Add the new feature X-Git-Tag: submit/submit/20141001.115906~33^2~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4e9c0072e430ba8572c7d78b9bcfefe2a1512084;p=platform%2Fframework%2Fnative%2Fmessaging.git Fixed the prevent and Add the new feature --- diff --git a/email-api/email-api-account.c b/email-api/email-api-account.c index f3d5e67..7127667 100755 --- a/email-api/email-api-account.c +++ b/email-api/email-api-account.c @@ -191,7 +191,7 @@ EXPORT_API int email_update_account(int account_id, email_account_t* new_account int with_validation = false; char* new_account_stream = NULL; - if ((account_id <= 0) || !new_account || (with_validation != false && with_validation != true)) { + if ( account_id <= 0 || !new_account ) { /*prevent 23138*/ EM_DEBUG_EXCEPTION("account_id[%d], new_account[%p], with_validation[%d]", account_id, new_account, with_validation); return EMAIL_ERROR_INVALID_PARAM; } @@ -434,7 +434,6 @@ EXPORT_API int email_add_account_with_validation(email_account_t* account, int * if(emstorage_check_duplicated_account(account, true, &err) == false) { EM_DEBUG_EXCEPTION("emstorage_check_duplicated_account failed (%d) ", err); - return err; } @@ -488,7 +487,7 @@ EXPORT_API int email_backup_accounts_into_secure_storage(const char *file_name) EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); /* file_name */ - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, strlen(file_name)+1)) { + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) { EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed "); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } @@ -528,7 +527,7 @@ EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); /* file_name */ - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, strlen(file_name)+1)) { + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) { EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed "); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } diff --git a/email-api/email-api-etc.c b/email-api/email-api-etc.c index fea7ceb..1a289ad 100755 --- a/email-api/email-api-etc.c +++ b/email-api/email-api-etc.c @@ -136,7 +136,7 @@ EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data, email_a goto FINISH_OFF; } - if (*output_file_path && (size = strlen(*output_file_path)) > 0) { + if (*output_file_path && (size = EM_SAFE_STRLEN(*output_file_path)) > 0) { EM_DEBUG_LOG("output_file_path : [%s] size : [%d]", *output_file_path, size); size = size + 1; } else { @@ -210,3 +210,5 @@ EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity) EM_DEBUG_FUNC_END(); return err; } + + diff --git a/email-api/email-api-mail.c b/email-api/email-api-mail.c index 9ac133c..7f03f4d 100755 --- a/email-api/email-api-mail.c +++ b/email-api/email-api-mail.c @@ -1223,56 +1223,6 @@ FINISH_OFF: return err; } -int execute_proxy_task(email_task_type_t input_task_type, void *input_task_parameter) -{ - EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_parameter [%p]", input_task_type, input_task_parameter); - - int err = EMAIL_ERROR_NONE; - int task_parameter_length = 0; - char *task_parameter_stream = NULL; - HIPC_API hAPI = NULL; - - if(input_task_parameter == NULL) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - if((err = emcore_encode_task_parameter(input_task_type, input_task_parameter, &task_parameter_stream, &task_parameter_length)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_encode_task_parameter failed [%d]", err); - goto FINISH_OFF; - } - - hAPI = emipc_create_email_api(input_task_type); - - if(!hAPI) { - EM_DEBUG_EXCEPTION("emipc_create_email_api failed"); - err = EMAIL_ERROR_NULL_VALUE; - goto FINISH_OFF; - } - - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)task_parameter_stream, task_parameter_length)) { - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed"); - err = EMAIL_ERROR_IPC_SOCKET_FAILURE; - goto FINISH_OFF; - } - - emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); - - FINISH_OFF: - if(hAPI) - emipc_destroy_email_api(hAPI); - - EM_DEBUG_FUNC_END("err [%d]", err); - return err; -} - EXPORT_API int email_move_mails_to_mailbox_of_another_account(int input_source_mailbox_id, int *input_mail_id_array, int input_mail_id_count, int input_target_mailbox_id, int *output_task_id) { EM_DEBUG_FUNC_BEGIN("input_source_mailbox_id[%d] input_mail_id_array[%p] input_mail_id_count[%d] input_target_mailbox_id[%d] output_task_id[%p]", input_source_mailbox_id, input_mail_id_array, input_mail_id_count, input_target_mailbox_id, output_task_id); @@ -1291,7 +1241,7 @@ EXPORT_API int email_move_mails_to_mailbox_of_another_account(int input_source_m task_parameter.mail_id_count = input_mail_id_count; task_parameter.target_mailbox_id = input_target_mailbox_id; - if((err = execute_proxy_task(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, &task_parameter)) != EMAIL_ERROR_NONE) { + if((err = emipc_execute_proxy_task(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, &task_parameter)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("execute_proxy_task failed [%d]", err); goto FINISH_OFF; } @@ -1314,7 +1264,7 @@ EXPORT_API int email_free_mail_data(email_mail_data_t** mail_list, int count) /* Convert Modified UTF-7 mailbox name to UTF-8 */ /* returns modified UTF-8 Name if success else NULL */ -EXPORT_API int email_cancel_sending_mail( int mail_id) +EXPORT_API int email_cancel_sending_mail(int mail_id) { EM_DEBUG_FUNC_BEGIN("Mail ID [ %d]", mail_id); EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM); @@ -1550,7 +1500,7 @@ FINISH_OFF: EXPORT_API int email_free_meeting_request(email_meeting_request_t** meeting_req, int count) { EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d]", meeting_req, count); - if( !meeting_req | !*meeting_req ) { + if( !meeting_req || !*meeting_req ) { EM_DEBUG_EXCEPTION("NULL PARAM"); return EMAIL_ERROR_INVALID_PARAM; } diff --git a/email-api/email-api-mailbox.c b/email-api/email-api-mailbox.c index f87a54f..790a6fe 100755 --- a/email-api/email-api-mailbox.c +++ b/email-api/email-api-mailbox.c @@ -193,12 +193,12 @@ EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_na EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, input_mailbox_name, strlen(input_mailbox_name)+1 )) { + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, input_mailbox_name, EM_SAFE_STRLEN(input_mailbox_name)+1 )) { EM_DEBUG_EXCEPTION(" emipc_add_parameter for input_mailbox_path failed"); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, input_mailbox_alias, strlen(input_mailbox_alias)+1 )) { + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, input_mailbox_alias, EM_SAFE_STRLEN(input_mailbox_alias)+1 )) { EM_DEBUG_EXCEPTION(" emipc_add_parameter for input_mailbox_alias failed"); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } @@ -316,6 +316,70 @@ FINISH_OFF: return err; } +EXPORT_API int email_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int *output_handle) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_on_server[%d] output_handle[%p]", input_mailbox_id_array, input_mailbox_id_array, input_mailbox_id_count, input_on_server, output_handle); + int err = EMAIL_ERROR_NONE; + email_account_server_t account_server_type; + task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX task_parameter; + + if(input_account_id == 0 || input_mailbox_id_count <= 0 || input_mailbox_id_array == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* check account bind type and branch off */ + if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, false, &err) == false ) { + EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err); + err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; + goto FINISH_OFF; + } + + if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_on_server) { + int as_handle; + ASNotiData as_noti_data; + + if ( em_get_handle_for_activesync(&as_handle, &err) == false ) { + EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err); + err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; + goto FINISH_OFF; + } + + /* noti to active sync */ + as_noti_data.delete_mailbox_ex.handle = as_handle; + as_noti_data.delete_mailbox_ex.account_id = input_account_id; + as_noti_data.delete_mailbox_ex.mailbox_id_array = input_mailbox_id_array; + as_noti_data.delete_mailbox_ex.mailbox_id_count = input_mailbox_id_count; + as_noti_data.delete_mailbox_ex.on_server = input_on_server; + + if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX, &as_noti_data) == false) { + EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed."); + err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; + goto FINISH_OFF; + } + + if(output_handle) + *output_handle = as_handle; + } + else { + task_parameter.account_id = input_account_id; + task_parameter.mailbox_id_array = input_mailbox_id_array; + task_parameter.mailbox_id_count = input_mailbox_id_count; + task_parameter.on_server = input_on_server; + + if((err = emipc_execute_proxy_task(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, &task_parameter)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("execute_proxy_task failed [%d]", err); + goto FINISH_OFF; + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type) { EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_type [%d]", input_mailbox_id, input_mailbox_type); @@ -587,7 +651,7 @@ EXPORT_API int email_set_mail_slot_size(int account_id, int mailbox_id, int new_ { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], new_slot_size[%d]", account_id, mailbox_id, new_slot_size); - int err = EMAIL_ERROR_NONE, *handle = NULL; + int err = EMAIL_ERROR_NONE; if(new_slot_size < 0) { EM_DEBUG_EXCEPTION("new_slot_size should be greater than 0 or should be equal to 0"); @@ -621,10 +685,11 @@ EXPORT_API int email_set_mail_slot_size(int account_id, int mailbox_id, int new_ emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); EM_DEBUG_LOG("email_set_mail_slot_size error VALUE [%d]", err); - if(handle) { + /*prevent 23139*/ +/* if(handle) { emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle); EM_DEBUG_LOG("email_set_mail_slot_size handle VALUE [%d]", handle); - } + } */ emipc_destroy_email_api(hAPI); hAPI = NULL; diff --git a/email-api/email-api-smime.c b/email-api/email-api-smime.c index 7ff8515..66b78b6 100755 --- a/email-api/email-api-smime.c +++ b/email-api/email-api-smime.c @@ -61,13 +61,13 @@ EXPORT_API int email_add_certificate(char *certificate_path, char *email_address goto FINISH_OFF; } - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, strlen(certificate_path)+1)) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, EM_SAFE_STRLEN(certificate_path)+1)) { EM_DEBUG_EXCEPTION("emipc_add_parameter certificate_path[%s] failed", certificate_path); err = EMAIL_ERROR_NULL_VALUE; goto FINISH_OFF; } - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, strlen(email_address)+1)) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) { EM_DEBUG_EXCEPTION("emipc_add_parameter certificate_path[%s] failed", email_address); err = EMAIL_ERROR_NULL_VALUE; goto FINISH_OFF; @@ -113,7 +113,7 @@ EXPORT_API int email_delete_certificate(char *email_address) goto FINISH_OFF; } - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, strlen(email_address)+1)) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) { EM_DEBUG_EXCEPTION("emipc_add_parameter email_address[%s] failed", email_address); err = EMAIL_ERROR_NULL_VALUE; goto FINISH_OFF; @@ -174,7 +174,7 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output char *decrypt_filepath = NULL; email_mail_data_t *p_output_mail_data = NULL; email_attachment_data_t *p_output_attachment_data = NULL; - + emstorage_account_tbl_t *p_account_tbl = NULL; EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM); @@ -189,6 +189,11 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output goto FINISH_OFF; } + if (!emstorage_get_account_by_id(p_output_mail_data->account_id, EMAIL_ACC_GET_OPT_OPTIONS, &p_account_tbl, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err); + goto FINISH_OFF; + } + if ((err = emcore_get_attachment_data_list(mail_id, &p_output_attachment_data, &p_output_attachment_count)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed"); goto FINISH_OFF; @@ -200,7 +205,7 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output goto FINISH_OFF; } - if (!emcore_smime_set_decrypt_message(p_output_attachment_data->attachment_path, p_output_mail_data->full_address_from, &decrypt_filepath, &err)) { + if (!emcore_smime_set_decrypt_message(p_output_attachment_data->attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) { EM_DEBUG_EXCEPTION("emcore_smime_set_decrypt_message failed"); goto FINISH_OFF; } @@ -213,6 +218,9 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output FINISH_OFF: + if (p_account_tbl) + emstorage_free_account(&p_account_tbl, 1, NULL); + if (p_output_mail_data) email_free_mail_data(&p_output_mail_data, 1); @@ -289,7 +297,7 @@ EXPORT_API int email_verify_certificate(char *certificate_path, int *verify) goto FINISH_OFF; } - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, strlen(certificate_path)+1)) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, EM_SAFE_STRLEN(certificate_path)+1)) { EM_DEBUG_EXCEPTION("emipc_add_paramter failed : [%s]", certificate_path); err = EMAIL_ERROR_NULL_VALUE; goto FINISH_OFF; @@ -334,12 +342,12 @@ EXPORT_API int email_check_ocsp_status(char *email_address, char *response_url, EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, strlen(email_address)+1)) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) { EM_DEBUG_EXCEPTION("email_check_ocsp_status--ADD Param email_address failed"); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, response_url, strlen(response_url)+1)) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, response_url, EM_SAFE_STRLEN(response_url)+1)) { EM_DEBUG_EXCEPTION("email_check_ocsp_status--ADD Param response_url failed"); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } diff --git a/email-api/include/email-api-mail.h b/email-api/include/email-api-mail.h index a34e1fe..afb1b9b 100755 --- a/email-api/include/email-api-mail.h +++ b/email-api/include/email-api-mail.h @@ -295,6 +295,8 @@ EXPORT_API int email_add_read_receipt(int input_read_mail_id, int *output_receip */ EXPORT_API int email_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas); +EXPORT_API int email_update_mail_attribute(int *input_mail_id_array, int input_mail_id_count, email_mail_attribute_type input_attribute, email_mail_attribute_value_t input_value); + /** * @fn email_count_mail(email_mailbox_t* mailbox, int* total, int* unseen) * @brief Get mail count from mailbox.This function is invoked when user wants to know how many toatl mails and out of that diff --git a/email-api/include/email-api-mailbox.h b/email-api/include/email-api-mailbox.h index ef39612..fa7dca8 100755 --- a/email-api/include/email-api-mailbox.h +++ b/email-api/include/email-api-mailbox.h @@ -132,7 +132,6 @@ extern "C" /** - * @fn int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle) * @brief Create a new mailbox or mailbox.This function is invoked when user wants to create a new mailbox for the specified account. * If On_server is true then it will create the mailbox on server as well as in local also. @@ -165,7 +164,6 @@ EXPORT_API int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, in EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, int *output_handle); /** - * @fn int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_handle) * @brief Delete a mailbox or mailbox.This function deletes the existing mailbox for specified account based on the option on_server. * If the on_server is true then it deletes mailbox from server as well as locally. @@ -180,6 +178,8 @@ EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_na */ EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_handle); +EXPORT_API int email_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int *output_handle); + /** * @fn int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type) * @brief Change the mailbox type. This function is invoked when user wants to change the mailbox type. @@ -193,6 +193,7 @@ EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, i */ EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type); + /** * @fn int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox) * @brief Change the attribute 'local' of email_mailbox_t. This function is invoked when user wants to change the attribute 'local'. @@ -207,8 +208,6 @@ EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e EXPORT_API int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox); /** - - * @fn email_get_mailbox_list(int account_id, int mailbox_sync_type, email_mailbox_t** mailbox_list, int* count) * @brief Get all mailboxes from account. * @@ -253,7 +252,6 @@ EXPORT_API int email_get_mailbox_list(int account_id, int mailbox_sync_type, ema EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, email_mailbox_t** mailbox_list, int* count); /** - * @fn email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t** mailbox) * @brief Get mailbox by mailbox_type.This function is invoked when user wants to know the mailbox information by mailbox_type for the given account. * @@ -268,7 +266,6 @@ EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t** mailbox); /** - * @fn email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailbox_t** output_mailbox) * @brief Get mailbox by mailbox_id. This function is invoked when user wants to know the mailbox information by mailbox id. * @@ -282,7 +279,6 @@ EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_t EXPORT_API int email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailbox_t** output_mailbox); /** - * @fn email_set_mail_slot_size(int input_account_id, int input_mailbox_id, int input_new_slot_size) * @brief Set mail slot size.This function is invoked when user wants to set the size of mail slot. * @@ -297,7 +293,6 @@ EXPORT_API int email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailb EXPORT_API int email_set_mail_slot_size(int input_account_id, int input_mailbox_id, int input_new_slot_size); /** - * @fn email_stamp_sync_time_of_mailbox(int input_mailbox_id) * @brief Stamp sync time of mailbox. This function is invoked when user wants to set the sync time of the mailbox. * @@ -311,7 +306,6 @@ EXPORT_API int email_stamp_sync_time_of_mailbox(int input_mailbox_id); /** - * @fn email_free_mailbox(email_mailbox_t** mailbox_list, int count) * @brief Free allocated memory for mailbox information. * diff --git a/email-common-use/email-convert.c b/email-common-use/email-convert.c index 580f194..e576d01 100755 --- a/email-common-use/email-convert.c +++ b/email-common-use/email-convert.c @@ -241,6 +241,7 @@ INTERNAL_FUNC int em_convert_mailbox_to_mailbox_tbl(email_mailbox_t *mailbox, em mailbox_tbl->mail_slot_size = mailbox->mail_slot_size; mailbox_tbl->no_select = mailbox->no_select; mailbox_tbl->last_sync_time = mailbox->last_sync_time; + mailbox_tbl->deleted_flag = mailbox->deleted_flag; EM_DEBUG_FUNC_END(); return ret; @@ -263,6 +264,7 @@ INTERNAL_FUNC int em_convert_mailbox_tbl_to_mailbox(emstorage_mailbox_tbl_t *mai mailbox->mail_slot_size = mailbox_tbl->mail_slot_size; mailbox->no_select = mailbox_tbl->no_select; mailbox->last_sync_time = mailbox_tbl->last_sync_time; + mailbox->deleted_flag = mailbox_tbl->deleted_flag; EM_DEBUG_FUNC_END(); return ret; diff --git a/email-common-use/email-utilities.c b/email-common-use/email-utilities.c index 5d03b81..f342c05 100755 --- a/email-common-use/email-utilities.c +++ b/email-common-use/email-utilities.c @@ -68,8 +68,10 @@ INTERNAL_FUNC void* em_memdup(void* src, int len) } void *p = calloc(1,len); - if (!p) + if (!p) { EM_DEBUG_EXCEPTION("malloc failed"); + return NULL; + } memcpy(p, src, len); @@ -92,8 +94,8 @@ INTERNAL_FUNC char *em_trim_left(char *str) temp_buffer = EM_SAFE_STRDUP(p); - strncpy(str, temp_buffer, strlen(str)); - str[strlen(temp_buffer)] = NULL_CHAR; + strncpy(str, temp_buffer, EM_SAFE_STRLEN(str)); + str[EM_SAFE_STRLEN(temp_buffer)] = NULL_CHAR; EM_SAFE_FREE(temp_buffer); @@ -108,7 +110,7 @@ INTERNAL_FUNC char *em_trim_right(char *str) /* EM_DEBUG_FUNC_BEGIN() */ if (!str) return NULL; - p = str+strlen(str)-1; + p = str+EM_SAFE_STRLEN(str)-1; while (((int)p >= (int)str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR)) *p --= '\0'; @@ -140,7 +142,7 @@ INTERNAL_FUNC char* em_lower_string(char *str) INTERNAL_FUNC int em_upper_path(char *path) { - int i = 0, is_utf7 = 0, len = path ? (int)strlen(path) : -1; + int i = 0, is_utf7 = 0, len = path ? (int)EM_SAFE_STRLEN(path) : -1; for (; i < len; i++) { if (path[i] == '&' || path[i] == 5) { is_utf7 = 1; @@ -165,7 +167,7 @@ INTERNAL_FUNC void em_skip_whitespace(char *addr_str, char **pAddr) if (!addr_str) return ; char *str = addr_str; - char ptr[strlen(str)+1] ; + char ptr[EM_SAFE_STRLEN(str)+1] ; int i, j = 0; str = addr_str ; @@ -210,8 +212,8 @@ INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, EM_IF_NULL_RETURN_VALUE(old_string, NULL); EM_IF_NULL_RETURN_VALUE(new_string, NULL); - old_str_length = strlen(old_string); - new_str_length = strlen(new_string); + old_str_length = EM_SAFE_STRLEN(old_string); + new_str_length = EM_SAFE_STRLEN(new_string); if (old_str_length != new_str_length) { for (i = 0; source_string[i] != '\0';) { @@ -223,7 +225,7 @@ INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, } } } else { - i = strlen(source_string); + i = EM_SAFE_STRLEN(source_string); } result_buffer = (char *)malloc(i + 1 + count*(new_str_length-old_str_length)); @@ -265,7 +267,7 @@ INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, cha return NULL; } - buffer_length = strlen(source_string) + 1024; + buffer_length = EM_SAFE_STRLEN(source_string) + 1024; result_buffer = (char *)em_malloc(buffer_length); if (!result_buffer) { @@ -274,9 +276,9 @@ INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, cha } strncpy(result_buffer, source_string, p - source_string); - snprintf(result_buffer + strlen(result_buffer), buffer_length - strlen(result_buffer), "%s%s", new_string, p + strlen(old_string)); + snprintf(result_buffer + strlen(result_buffer), buffer_length - strlen(result_buffer), "%s%s", new_string, p + strlen(old_string)); /*prevent 34351*/ - EM_DEBUG_FUNC_END("result_buffer[%s]", result_buffer); + EM_DEBUG_FUNC_END("result_buffer[%p]", result_buffer); return result_buffer; } @@ -352,7 +354,7 @@ INTERNAL_FUNC int em_get_file_name_from_file_path(char *input_source_file_path, goto FINISH_OFF; } - pos_on_string = strlen(input_source_file_path) - 1; + pos_on_string = EM_SAFE_STRLEN(input_source_file_path) - 1; end_pos_of_file_path = input_source_file_path + pos_on_string; end_pos_of_file_name = end_pos_of_file_path; @@ -397,7 +399,7 @@ INTERNAL_FUNC int em_get_file_name_and_extension_from_file_path(char *input_sour goto FINISH_OFF; } - pos_on_string = strlen(input_source_file_path) - 1; + pos_on_string = EM_SAFE_STRLEN(input_source_file_path) - 1; end_pos_of_file_path = input_source_file_path + pos_on_string; end_pos_of_file_name = end_pos_of_file_path; @@ -446,7 +448,7 @@ INTERNAL_FUNC char *em_get_extension_from_file_path(char *source_file_path, int goto FINISH_OFF; } - pos_on_string = strlen(source_file_path) - 1; + pos_on_string = EM_SAFE_STRLEN(source_file_path) - 1; while(pos_on_string > 0 && source_file_path[pos_on_string--] != '.') ; @@ -479,7 +481,7 @@ INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_pat goto FINISH_OFF; } - enf_of_string = pos_of_filename = strlen(input_file_path); + enf_of_string = pos_of_filename = EM_SAFE_STRLEN(input_file_path); while(pos_of_filename >= 0 && input_file_path[pos_of_filename--] != '/') { if(input_file_path[pos_of_filename] == '.') @@ -584,7 +586,7 @@ INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, in int ret = false, error = EMAIL_ERROR_NONE; char *reg_rule = NULL; - if(!address || strlen(address) == 0) { + if(!address || EM_SAFE_STRLEN(address) == 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -603,7 +605,7 @@ INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, in return false; } - int alias_len = strlen(address) + 1; + int alias_len = EM_SAFE_STRLEN(address) + 1; regmatch_t pmatch[alias_len]; bzero(pmatch, alias_len); @@ -1086,6 +1088,14 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.handle), DBUS_TYPE_INVALID); break; + case ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX : + dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.account_id), DBUS_TYPE_INVALID); + dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.mailbox_id_count), DBUS_TYPE_INVALID); + for(i = 0; i delete_mailbox_ex.mailbox_id_count; i++) + dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.mailbox_id_array[i]), DBUS_TYPE_INVALID); + dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.handle), DBUS_TYPE_INVALID); + break; + default: EM_DEBUG_EXCEPTION("Invalid Notification type of Active Sync : subType[%d]", subType); return FAILURE; diff --git a/email-common-use/include/email-debug-log.h b/email-common-use/include/email-debug-log.h index 09a1c47..5eecb68 100755 --- a/email-common-use/include/email-debug-log.h +++ b/email-common-use/include/email-debug-log.h @@ -55,9 +55,9 @@ extern "C" #define LOG_TAG "EMAIL_SERVICE" -#define EM_DEBUG_LOG(format, arg...) SLOGD(format, ##arg) -#define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[EXCEPTION!] " format "\n", ##arg) - +#define EM_DEBUG_LOG(format, arg...) SLOGD(format, ##arg) +#define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[EXCEPTION!] " format "\n", ##arg) + #ifdef _DEBUG_MIME_PARSE_ #define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG(format, ##arg) #else /* _DEBUG_MIME_PARSE */ diff --git a/email-common-use/include/email-errors.h b/email-common-use/include/email-errors.h index dad69bf..3fcb365 100755 --- a/email-common-use/include/email-errors.h +++ b/email-common-use/include/email-errors.h @@ -62,6 +62,7 @@ #define EMAIL_ERROR_ACCOUNT_MAX_COUNT -1053 /* There is too many account */ #define EMAIL_ERROR_MAIL_MEMORY_FULL -1054 /* There is no more storage */ #define EMAIL_ERROR_DATA_TOO_LONG -1025 /* Data is too long */ +#define EMAIL_ERROR_MAXIMUM_DEVICES_LIMIT_REACHED -1530 /* EAS - Maximum devices limit reached */ /* Error codes for storage */ #define EMAIL_ERROR_DB_FAILURE -1029 /* database operation failed */ @@ -149,6 +150,7 @@ /* Error codes for mails */ #define EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER -1055 /* The expected mail is not found in server */ +#define EMAIL_ERROR_MAIL_IS_NOT_DOWNLOADED -1095 /* The mail is not downloaded */ /* Error codes for attachment */ #define EMAIL_ERROR_ATTACHMENT_SIZE_EXCEED_POLICY_LIMIT -7001 diff --git a/email-common-use/include/email-internal-types.h b/email-common-use/include/email-internal-types.h index 0a6aae3..baa9c31 100755 --- a/email-common-use/include/email-internal-types.h +++ b/email-common-use/include/email-internal-types.h @@ -45,7 +45,6 @@ extern "C" /* ----------------------------------------------------------------------------- */ /* Feature definitions */ -#define __FEATURE_USING_ACCOUNT_SVC__ #define __FEATURE_BACKUP_ACCOUNT__ #define __FEATURE_MOVE_TO_OUTBOX_FIRST__ /* #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */ @@ -65,6 +64,7 @@ extern "C" #define __FEATURE_SUPPORT_IMAP_ID__ #define __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ #define __FEATURE_SUPPORT_VALIDATION_SYSTEM__ +#define __FEATURE_PROGRESS_IN_OUTBOX__ /* #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ /* #define __FEATURE_IMAP_IDLE__ */ @@ -92,6 +92,7 @@ extern "C" #define MAX_PATH 4096 /* /usr/src/linux-2.4.20-8/include/linux/limits.h */ #define DATETIME_LENGTH 16 #define MAIL_ID_STRING_LENGTH 10 +#define MAILBOX_ID_STRING_LENGTH 10 #define EMAIL_LIMITATION_FREE_SPACE (5) /* This value is 5MB */ #define EMAIL_MAIL_MAX_COUNT 5000 #define HTML_EXTENSION_STRING ".htm" @@ -108,7 +109,7 @@ extern "C" #define EMAILPATH DATA_PATH"/email" #define MAILHOME DATA_PATH"/email/.email_data" #define MAILTEMP MAILHOME"/tmp" -#define DIRECTORY_PERMISSION 0775 +#define DIRECTORY_PERMISSION 0755 #define MIME_SUBTYPE_DRM_OBJECT "vnd.oma.drm.message" #define MIME_SUBTYPE_DRM_RIGHTS "vnd.oma.drm.rights+xml" @@ -202,6 +203,9 @@ typedef pthread_t thread_t; #define TYPEPKCS7_SIGN 10 #define TYPEPKCS7_MIME 11 +#define INLINE_ATTACHMENT 1 +#define ATTACHMENT 2 + /* __FEATURE_LOCAL_ACTIVITY__ supported #define BULK_OPERATION_COUNT 50 #define ALL_ACTIVITIES 0 diff --git a/email-common-use/include/email-types.h b/email-common-use/include/email-types.h index a34d97e..4d36781 100755 --- a/email-common-use/include/email-types.h +++ b/email-common-use/include/email-types.h @@ -58,7 +58,8 @@ extern "C" /*****************************************************************************/ #define MAILBOX_NAME_LENGTH 256 -#define MAX_EMAIL_ADDRESS_LENGTH 320 /* 64(user name) + 1(@) + 255(host name */ +#define MAX_EMAIL_ADDRESS_LENGTH 254 /* RFC5322, RFC3696 */ +#define MAX_USER_NAME_LENGTH 64 #define MAX_DATETIME_STRING_LENGTH 20 #define MAX_PREVIEW_TEXT_LENGTH 512 #define STRING_LENGTH_FOR_DISPLAY 100 @@ -176,6 +177,7 @@ enum { _EMAIL_API_UPDATE_MAIL = 0x01100018, _EMAIL_API_ADD_READ_RECEIPT = 0x01100019, _EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED = 0x0110001A, + _EMAIL_API_UPDATE_MAIL_ATTRIBUTE = 0x0110001B, /* Thread */ _EMAIL_API_MOVE_THREAD_TO_MAILBOX = 0x01110000, @@ -269,6 +271,7 @@ typedef enum NOTI_MAILBOX_ADD = 40000, NOTI_MAILBOX_DELETE = 40001, NOTI_MAILBOX_UPDATE = 40002, + NOTI_MAILBOX_FIELD_UPDATE = 40003, NOTI_MAILBOX_RENAME = 40010, NOTI_MAILBOX_RENAME_FAIL = 40011, @@ -369,7 +372,7 @@ typedef enum typedef enum { EMAIL_BIND_TYPE_DISABLE = 0, /**< Specifies the bind type for Disabled account.*/ - EMAIL_BIND_TYPE_EM_CORE = 1, /**< Specifies the bind type for Callia.*/ + EMAIL_BIND_TYPE_EM_CORE = 1, /**< Specifies the bind type for email-service .*/ } email_account_bind_t DEPRECATED; /** @@ -717,7 +720,7 @@ typedef enum EMAIL_EVENT_DELETE_MAIL_ALL = 8, /* delete all mails (network unused) */ EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER = 9, /* sync mail flag to server */ EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER = 10, /* sync a field of flags to server */ - EMAIL_EVENT_SAVE_MAIL = 11, /* Deprecated */ + EMAIL_EVENT_SAVE_MAIL = 11, /* add mail on server */ EMAIL_EVENT_MOVE_MAIL = 12, /* move mails to specific mailbox on server */ EMAIL_EVENT_CREATE_MAILBOX = 13, EMAIL_EVENT_UPDATE_MAILBOX = 14, @@ -1202,14 +1205,14 @@ typedef struct int incoming_server_requires_apop; /**< APOP authentication */ /* S/MIME Options */ - email_smime_type smime_type; /**< Sepeifies the smime type 0=Normal 1=Clear signed 2=encrypted 3=Signed + encrypted */ - char *certificate_path; /**< Sepeifies the certificate path of private*/ - email_cipher_type cipher_type; /**< Sepeifies the encryption algorithm*/ - email_digest_type digest_type; /**< Sepeifies the digest algorithm*/ + email_smime_type smime_type; /**< Specifies the smime type 0=Normal 1=Clear signed 2=encrypted 3=Signed + encrypted */ + char *certificate_path; /**< Specifies the certificate path of private*/ + email_cipher_type cipher_type; /**< Specifies the encryption algorithm*/ + email_digest_type digest_type; /**< Specifies the digest algorithm*/ } email_account_t; /** - * This structure is used to save the information of certificiate + * This structure is used to save the information of certificate */ typedef struct @@ -1295,19 +1298,19 @@ typedef struct char flags_draft_field; /**< Specifies the draft flags*/ char flags_forwarded_field; /**< Specifies the forwarded flags*/ int DRM_status; /**< Has the mail DRM content? (1 : true, 0 : false) */ - email_mail_priority_t priority; /**< Specifies the priority of the mail.*/ /* email_mail_priority_t */ - email_mail_status_t save_status; /**< Specifies the save status*/ /* email_mail_status_t */ + email_mail_priority_t priority; /**< Specifies the priority of the mail.*/ + email_mail_status_t save_status; /**< Specifies the save status*/ int lock_status; /**< Specifies the mail is locked*/ - email_mail_report_t report_status; /**< Specifies the Mail Report.*/ /* email_mail_report_t */ + email_mail_report_t report_status; /**< Specifies the Mail Report.*/ int attachment_count; /**< Specifies the attachment count. */ int inline_content_count; /**< Specifies the inline content count. */ int thread_id; /**< Specifies the thread id for thread view. */ int thread_item_count; /**< Specifies the item count of specific thread. */ char *preview_text; /**< Specifies the preview body. */ - email_mail_type_t meeting_request_status; /**< Specifies the status of meeting request. */ /* email_mail_type_t */ + email_mail_type_t meeting_request_status; /**< Specifies the status of meeting request. */ int message_class; /**< Specifies the class of message for EAS. */ /* email_message_class */ - email_digest_type digest_type; /**< Specifies the digest algorithm*/ /* email_digest_type */ - email_smime_type smime_type; /**< Specifies the SMIME type. */ /* email_smime_type */ + email_digest_type digest_type; /**< Specifies the digest algorithm*/ + email_smime_type smime_type; /**< Specifies the SMIME type. */ } email_mail_data_t; /** @@ -1385,7 +1388,7 @@ typedef struct { unsigned int priority : 3; /**< Specifies the mail priority. The value is greater than or equal to EMAIL_MAIL_PRIORITY_HIGH. - The value is less than or eqult to EMAIL_MAIL_PRIORITY_LOW.*/ + The value is less than or equal to EMAIL_MAIL_PRIORITY_LOW.*/ unsigned int status : 4; /**< Specifies the mail status. The value is a value of enumeration email_mail_status_t.*/ unsigned int noti : 1; /**< Specifies the notified mail.*/ @@ -1436,7 +1439,7 @@ typedef struct } email_meeting_request_t; /** - * This structure is used to save the informatioin of sender list with unread/total mail counts + * This structure is used to save the information of sender list with unread/total mail counts */ typedef struct { @@ -1464,6 +1467,7 @@ typedef struct int mail_slot_size; /**< Specifies how many mails can be stored in local mailbox.*/ int no_select; /**< Specifies the 'no_select' attribute from xlist.*/ time_t last_sync_time; + int deleted_flag; /**< Specifies whether mailbox is deleted.*/ } email_mailbox_t; typedef struct @@ -1486,8 +1490,8 @@ typedef struct typedef struct { int address_type; /* type of mail (sender : 0, recipient : 1)*/ - int address_count; /* The number of email addresse */ - char **address_list; /* strings of email addresse */ + int address_count; /* The number of email addresses */ + char **address_list; /* strings of email addresses */ } email_email_address_list_t; @@ -1517,16 +1521,16 @@ typedef enum { EMAIL_CASE_INSENSITIVE = 1, } email_list_filter_case_sensitivity_t; +typedef union { + int integer_type_value; + char *string_type_value; + time_t datetime_type_value; +} email_mail_attribute_value_t; + typedef struct { email_list_filter_rule_type_t rule_type; email_mail_attribute_type target_attribute; - - union { - int integer_type_value; - char *string_type_value; - time_t datetime_type_value; - } key_value; - + email_mail_attribute_value_t key_value; email_list_filter_case_sensitivity_t case_sensitivity; } email_list_filter_rule_t; @@ -1590,6 +1594,8 @@ typedef enum ACTIVE_SYNC_NOTI_ADD_MAILBOX, /* a notification to add mailbox */ ACTIVE_SYNC_NOTI_RENAME_MAILBOX, /* a notification to rename mailbox */ ACTIVE_SYNC_NOTI_DELETE_MAILBOX, /* a notification to delete mailbox */ + ACTIVE_SYNC_NOTI_CANCEL_SENDING_MAIL, /* a notification to cancel a sending mail */ + ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX, /* a notification to delete multiple mailboxes */ } eactivesync_noti_t; typedef union @@ -1709,6 +1715,20 @@ typedef union int mailbox_id; } delete_mailbox; + struct _cancel_sending_mail + { + int mail_id; + } cancel_sending_mail; + + struct _delete_mailbox_ex + { + int handle; + int account_id; + int *mailbox_id_array; + int mailbox_id_count; + int on_server; + } delete_mailbox_ex; + } ASNotiData; /* types for noti string */ @@ -1759,6 +1779,7 @@ typedef enum { EMAIL_ASYNC_TASK_DELETE_MAILBOX = 62020, EMAIL_ASYNC_TASK_RENAME_MAILBOX = 62030, EMAIL_ASYNC_TASK_DOWNLOAD_IMAP_MAILBOX_LIST = 62040, + EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX = 62050, /* Async tasks for mail - from 63000 */ EMAIL_ASYNC_TASK_ADD_MAIL = 63010, diff --git a/email-common-use/tpl.c b/email-common-use/tpl.c index 60b3be8..00d3d32 100644 --- a/email-common-use/tpl.c +++ b/email-common-use/tpl.c @@ -343,7 +343,7 @@ static tpl_node *tpl_map_va(char *fmt, va_list ap) { /* set up root nodes special ser_osz to reflect overhead of preamble */ root->ser_osz = sizeof(uint32_t); /* tpl leading length */ - root->ser_osz += strlen(fmt) + 1; /* fmt + NUL-terminator */ + root->ser_osz += EM_SAFE_STRLEN(fmt) + 1; /* fmt + NUL-terminator */ root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */ parent=root; @@ -560,10 +560,10 @@ static tpl_node *tpl_map_va(char *fmt, va_list ap) { if (lparen_level != 0) goto fail; /* copy the format string, save for convenience */ - ((tpl_root_data*)(root->data))->fmt = tpl_hook.malloc(strlen(fmt)+1); + ((tpl_root_data*)(root->data))->fmt = tpl_hook.malloc(EM_SAFE_STRLEN(fmt)+1); if (((tpl_root_data*)(root->data))->fmt == NULL) fatal_oom(); - memcpy(((tpl_root_data*)(root->data))->fmt,fmt,strlen(fmt)+1); + memcpy(((tpl_root_data*)(root->data))->fmt,fmt,EM_SAFE_STRLEN(fmt)+1); return root; @@ -875,7 +875,7 @@ static void *tpl_dump_atyp(tpl_node *n, tpl_atyp* at, void *dv) { /* dump the string length followed by the string */ for(i=0; i < c->num; i++) { memcpy(&strp,datav,sizeof(char*)); /* cp to aligned */ - slen = strp ? (strlen(strp)+1) : 0; + slen = strp ? (EM_SAFE_STRLEN(strp)+1) : 0; dv = tpl_cpv(dv,&slen,sizeof(uint32_t)); if (slen > 1) dv = tpl_cpv(dv,strp,slen-1); datav = (void*)((uintptr_t)datav + sizeof(char*)); @@ -944,7 +944,7 @@ static size_t tpl_ser_osz(tpl_node *n) { for(i=0; i < c->num; i++) { sz += sizeof(uint32_t); /* string len */ memcpy(&strp,&((char**)c->data)[i],sizeof(char*)); /* cp to aligned */ - sz += strp ? strlen(strp) : 0; + sz += strp ? EM_SAFE_STRLEN(strp) : 0; } break; case TPL_TYPE_ARY: @@ -1080,7 +1080,7 @@ static int tpl_dump_to_mem(tpl_node *r,void *addr,size_t sz) { dv = tpl_cpv(dv,TPL_MAGIC,3); /* copy tpl magic prefix */ dv = tpl_cpv(dv,&flags,1); /* copy flags byte */ dv = tpl_cpv(dv,&sz32,sizeof(uint32_t));/* overall length (inclusive) */ - dv = tpl_cpv(dv,fmt,strlen(fmt)+1); /* copy format with NUL-term */ + dv = tpl_cpv(dv,fmt,EM_SAFE_STRLEN(fmt)+1); /* copy format with NUL-term */ fxlens = tpl_fxlens(r,&num_fxlens); dv = tpl_cpv(dv,fxlens,num_fxlens*sizeof(uint32_t));/* fmt # lengths */ @@ -1106,7 +1106,7 @@ static int tpl_dump_to_mem(tpl_node *r,void *addr,size_t sz) { case TPL_TYPE_STR: for(i=0; i < c->num; i++) { char *str = ((char**)c->data)[i]; - slen = str ? strlen(str)+1 : 0; + slen = str ? EM_SAFE_STRLEN(str)+1 : 0; dv = tpl_cpv(dv,&slen,sizeof(uint32_t)); /* string len */ if (slen>1) dv = tpl_cpv(dv,str,slen-1); /*string*/ } @@ -1358,7 +1358,7 @@ TPL_API char* tpl_peek(int mode, ...) { first_atom = strspn(fmt, "S()"); /* skip any leading S() */ - datapeek_flen = strlen(datapeek_f); + datapeek_flen = EM_SAFE_STRLEN(datapeek_f); if (strspn(datapeek_f, tpl_datapeek_ok_chars) < datapeek_flen) { tpl_hook.oops("invalid TPL_DATAPEEK format: %s\n", datapeek_f); tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ @@ -1848,7 +1848,7 @@ TPL_API int tpl_pack(tpl_node *r, int i) { block also works if the string pointer is NULL. */ char *caddr = ((char**)child->addr)[fidx]; char **cdata = &((char**)child->data)[fidx]; - slen = caddr ? (strlen(caddr) + 1) : 0; + slen = caddr ? (EM_SAFE_STRLEN(caddr) + 1) : 0; if (slen) { str = tpl_hook.malloc(slen); if (!str) fatal_oom(); diff --git a/email-core/CMakeLists.txt b/email-core/CMakeLists.txt index 46175e4..67c2bf3 100755 --- a/email-core/CMakeLists.txt +++ b/email-core/CMakeLists.txt @@ -170,7 +170,7 @@ INCLUDE_DIRECTORIES( INCLUDE(FindPkgConfig) -pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf vconf-internal-keys contacts-service2 secure-storage openssl accounts-svc mm-player mm-session devman_haptic alarm-service notification libcurl libxml-2.0 cert-svc cert-svc-vcore badge) +pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf vconf-internal-keys contacts-service2 secure-storage openssl accounts-svc mm-player mm-session alarm-service notification libcurl libxml-2.0 cert-svc cert-svc-vcore badge feedback) set(EXTRA_CFLAGS "") FOREACH(flag ${core_pkgs_CFLAGS}) diff --git a/email-core/email-core-account.c b/email-core/email-core-account.c index 268fdfa..8784b9c 100755 --- a/email-core/email-core-account.c +++ b/email-core/email-core-account.c @@ -51,10 +51,6 @@ #include "email-core-signal.h" #include "email-core-imap-mailbox.h" -#ifdef __FEATURE_USING_ACCOUNT_SVC__ -#include "account.h" -#endif /* __FEATURE_USING_ACCOUNT_SVC__ */ - char *g_default_mbox_alias[MAILBOX_COUNT] = { EMAIL_INBOX_DISPLAY_NAME, @@ -88,35 +84,38 @@ email_mailbox_type_e g_default_mbox_type[MAILBOX_COUNT] = INTERNAL_FUNC email_account_t* emcore_get_account_reference(int account_id) { EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id); - EM_PROFILE_BEGIN(profile_emcore_get_account_reference); email_account_list_t **p; + email_account_t *result_account = NULL; - if (account_id == NEW_ACCOUNT_ID) - return emcore_get_new_account_reference(); - - if (account_id > 0) { + if (account_id < 0){ + emcore_get_account_from_unvalidated_account_list(account_id, &result_account); + return result_account; + } + else if (account_id > 0) { p = &g_account_list; while (*p) { - if ((*p)->account->account_id == account_id) - return ((*p)->account); + if ((*p)->account->account_id == account_id) { + result_account = ((*p)->account); + break; + } p = &(*p)->next; } - /* refresh and check once agai */ + /* refresh and check once again */ if (emcore_refresh_account_reference() == true) { p = &g_account_list; while (*p) { - if ((*p)->account->account_id == account_id) - return ((*p)->account); - + if ((*p)->account->account_id == account_id) { + result_account = ((*p)->account); + break; + } p = &(*p)->next; } } } - EM_PROFILE_END(profile_emcore_get_account_reference); - EM_DEBUG_FUNC_END(); - return NULL; + EM_DEBUG_FUNC_END("[%p]", result_account); + return result_account; } @@ -328,23 +327,6 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) #endif -#ifdef __FEATURE_USING_ACCOUNT_SVC__ - { - int error_code; - email_account_t *account_to_be_deleted; - - account_to_be_deleted = emcore_get_account_reference(account_id); - if (account_to_be_deleted && account_to_be_deleted->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { - EM_DEBUG_LOG("Calling account_svc_delete with account_svc_id[%d]", account_to_be_deleted->account_svc_id); - error_code = account_connect(); - EM_DEBUG_LOG("account_connect returns [%d]", error_code); - error_code = account_delete_from_db_by_id(account_to_be_deleted->account_svc_id); - EM_DEBUG_LOG("account_delete_from_db_by_id returns [%d]", error_code); - error_code = account_disconnect(); - EM_DEBUG_LOG("account_disconnect returns [%d]", error_code); - } - } -#endif if (emcore_cancel_all_threads_of_an_account(account_id) < EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("There are some remaining jobs. I couldn't stop them."); err = EMAIL_ERROR_CANNOT_STOP_THREAD; @@ -424,7 +406,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) int ret = false; int err = EMAIL_ERROR_NONE; - int i, count = 0, is_preset_IMAP_account = false; + int i, count = 0; int private_id = 0; char vconf_private_id[MAX_PATH] = {0, }; email_mailbox_t local_mailbox = {0}; @@ -484,11 +466,8 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) goto FINISH_OFF; } account->account_id = temp_account_tbl->account_id; - is_preset_IMAP_account = ((account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4)) ? true : false;/* && (account->is_preset_account)) ? true : false */ - - EM_DEBUG_LOG("is_preset_IMAP_account : %d", is_preset_IMAP_account); - if ((account->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && (!is_preset_IMAP_account)) { + if (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { /* 1. create default local mailbox * (Inbox, Draft, Outbox, Sentbox) */ for (i = 0; i < MAILBOX_COUNT; i++) { @@ -1185,12 +1164,13 @@ INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, ema { EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_set_operator [%d], input_sync_status [%d]", input_account_id, input_set_operator, input_sync_status); int err = EMAIL_ERROR_NONE; - emstorage_account_tbl_t *account_tbl_data = NULL; + if (!emstorage_update_sync_status_of_account(input_account_id, input_set_operator, input_sync_status, true, &err)) EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); + if (account_tbl_data) emstorage_free_account(&account_tbl_data, 1, NULL); diff --git a/email-core/email-core-cert.c b/email-core/email-core-cert.c index 93fb3a7..7e691fb 100755 --- a/email-core/email-core-cert.c +++ b/email-core/email-core-cert.c @@ -256,7 +256,7 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5 } /* Make the pfxID string */ - err = certsvc_string_new(cert_instance, certificate, strlen(certificate), &csstring); + err = certsvc_string_new(cert_instance, certificate, EM_SAFE_STRLEN(certificate), &csstring); if (err != CERTSVC_SUCCESS) { EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err); err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; @@ -630,6 +630,8 @@ FINISH_OFF: *err_code = err; } + cert_svc_cert_context_final(context); + EM_DEBUG_FUNC_END(); return ret; } diff --git a/email-core/email-core-event.c b/email-core/email-core-event.c index 3d51a32..31e418e 100755 --- a/email-core/email-core-event.c +++ b/email-core/email-core-event.c @@ -250,7 +250,7 @@ INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id found = true; goto EXIT; } - break; + break; case EMAIL_EVENT_MOVE_MAIL: if (action == EMAIL_ACTION_MOVE_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { @@ -738,7 +738,8 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in case EMAIL_EVENT_ISSUE_IDLE: case EMAIL_EVENT_SYNC_IMAP_MAILBOX: case EMAIL_EVENT_VALIDATE_ACCOUNT: - case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + case EMAIL_EVENT_SAVE_MAIL: case EMAIL_EVENT_MOVE_MAIL: case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: @@ -1136,6 +1137,7 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo MAILSTREAM *stream = NULL; #endif char mailbox_id_param_string[10] = {0,}; + char *input_mailbox_id_str = NULL; if (input_mailbox_id == 0) sync_type = EMAIL_SYNC_ALL_MAILBOX; @@ -1148,16 +1150,18 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if(mailbox_tbl_target) SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl_target->mailbox_id); - if (!emcore_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, 0)) + input_mailbox_id_str = (input_mailbox_id == 0)? NULL: mailbox_id_param_string; + + if (!emcore_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, input_mailbox_id_str, handle_to_be_published, 0)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_START] Failed >>>> "); if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_id_str, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); } - else { + else { if (sync_type != EMAIL_SYNC_ALL_MAILBOX) { /* Sync only particular mailbox */ if ((err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) @@ -1209,7 +1213,7 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if (!emstorage_get_account_by_id(input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account_tbl_array, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [ %d ] ", err); - if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_id_str, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); goto FINISH_OFF; } @@ -1225,7 +1229,7 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if (!emstorage_get_mailbox_list(account_tbl_array[account_index].account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &mailbox_count, &mailbox_tbl_list, true, &err) || mailbox_count <= 0) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err); - if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, input_mailbox_id_str, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); continue; @@ -1363,7 +1367,7 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou goto FINISH_OFF; } else { - EM_DEBUG_LOG("incoming_server_address : %s", account->incoming_server_address); + EM_DEBUG_LOG("incoming_server_address : %s", account->incoming_server_address); if (!emcore_validate_account_with_account_info(account, &err)) { EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info failed err : %d", err); @@ -1377,6 +1381,8 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou goto FINISH_OFF; } else { + emcore_delete_account_from_unvalidated_account_list(account->account_id); + if (emcore_create_account(account, &err) == false) { EM_DEBUG_EXCEPTION(" emdaemon_create_account failed - %d", err); goto FINISH_OFF; @@ -1384,9 +1390,11 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou emcore_refresh_account_reference(); + EM_DEBUG_LOG("incoming_server_type [%d]", account->incoming_server_type); + if ((EMAIL_SERVER_TYPE_IMAP4 == account->incoming_server_type)) { if (!emcore_sync_mailbox_list(account->account_id, "", handle_to_be_published, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_mailbox_list_to_be_sync falied [%d]", err); + EM_DEBUG_EXCEPTION("emcore_get_mailbox_list_to_be_sync failed [%d]", err); /* delete account whose mailbox couldn't be obtained from server */ emcore_delete_account(account->account_id, NULL); goto FINISH_OFF; @@ -1403,11 +1411,11 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou ret = true; FINISH_OFF: - - if (ret == false && err != EMAIL_ERROR_CANCELLED) { + if (ret == false && err != EMAIL_ERROR_CANCELLED && account) { if (!emcore_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, account->account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } + if (error) *error = err; @@ -1475,13 +1483,13 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, email_ ret = true; -FINISH_OFF: +FINISH_OFF: if (old_account_tbl) emstorage_free_account(&old_account_tbl, 1, NULL); if (new_account_tbl) emstorage_free_account(&new_account_tbl, 1, NULL); - if (ret == false && err != EMAIL_ERROR_CANCELLED) { + if (ret == false && err != EMAIL_ERROR_CANCELLED && new_account_info) { if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, new_account_info->account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } @@ -1805,6 +1813,16 @@ int event_handler_EMAIL_EVENT_UPDATE_MAIL(email_mail_data_t *input_mail_data, em EM_DEBUG_FUNC_END("err [%d", err); return err; } +int event_handler_EMAIL_EVENT_SAVE_MAIL(int input_account_id, int input_mail_id, int input_handle_to_be_published) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mail_id [%d] input_handle_to_be_published [%d]", input_account_id, input_mail_id, input_handle_to_be_published); + int err = EMAIL_ERROR_NONE; + + err = emcore_sync_mail_from_client_to_server(input_mail_id); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} int event_handler_EMAIL_EVENT_MOVE_MAIL(int account_id, int *mail_ids, int mail_id_count, int dest_mailbox_id, int src_mailbox_id, int handle_to_be_published, int *error) { @@ -1934,12 +1952,12 @@ int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) return true; } -int event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(int input_mailbox_id, int input_from_server, int *error) +int event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(int input_account_id, int input_mailbox_id, int input_from_server, int *error) { - EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_from_server [%d], error [%p]", input_mailbox_id, input_from_server, error); + EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id [%d], input_from_server [%d], error [%p]", input_account_id, input_mailbox_id, input_from_server, error); int err = EMAIL_ERROR_NONE; - if (!emcore_delete_all_mails_of_mailbox(input_mailbox_id, input_from_server, &err)) + if (!emcore_delete_all_mails_of_mailbox(input_account_id, input_mailbox_id, input_from_server, &err)) EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); if (error) @@ -2319,7 +2337,7 @@ void* thread_func_branch_command(void *arg) break; case EMAIL_EVENT_DELETE_MAIL_ALL: /* delete all mails */ - event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(event_data.event_param_data_4, (int)event_data.event_param_data_5, &err); + event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(event_data.account_id, event_data.event_param_data_4, (int)event_data.event_param_data_5, &err); break; #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: @@ -2337,9 +2355,12 @@ void* thread_func_branch_command(void *arg) event_handler_EMAIL_EVENT_DELETE_MAILBOX(event_data.event_param_data_4, event_data.event_param_data_4, handle_to_be_published, &err); break; + case EMAIL_EVENT_SAVE_MAIL: + err = event_handler_EMAIL_EVENT_SAVE_MAIL(event_data.account_id, event_data.event_param_data_4, handle_to_be_published); + break; + case EMAIL_EVENT_MOVE_MAIL: event_handler_EMAIL_EVENT_MOVE_MAIL(event_data.account_id, (int *)event_data.event_param_data_3, event_data.event_param_data_4, event_data.event_param_data_5, event_data.event_param_data_8, handle_to_be_published, &err); - EM_SAFE_FREE(event_data.event_param_data_3); break; @@ -2348,19 +2369,21 @@ void* thread_func_branch_command(void *arg) break; case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: { -/* event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emcore_get_new_account_reference(), handle_to_be_published, &err);*/ +/* event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emcore_get_account_from_unvalidated_account_list(), handle_to_be_published, &err);*/ email_account_t *account = (email_account_t *)event_data.event_param_data_1; event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(account, handle_to_be_published, &err); - emcore_free_account(account); - memset(account, 0, sizeof(email_account_t)); /*global account */ + if(account) { + emcore_free_account(account); + EM_SAFE_FREE(account); + } } break; case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: { - email_account_t *pAccount = (email_account_t *)event_data.event_param_data_1; - event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(event_data.account_id, pAccount, handle_to_be_published, &err); - emcore_free_account(pAccount); - EM_SAFE_FREE(pAccount); + email_account_t *account = (email_account_t *)event_data.event_param_data_1; + event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(event_data.account_id, account, handle_to_be_published, &err); + emcore_free_account(account); + EM_SAFE_FREE(account); } break; @@ -2430,6 +2453,7 @@ void* thread_func_branch_command(void *arg) case EMAIL_EVENT_DELETE_MAIL_ALL: case EMAIL_EVENT_VALIDATE_ACCOUNT: case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_SAVE_MAIL: case EMAIL_EVENT_MOVE_MAIL: case EMAIL_EVENT_CREATE_MAILBOX: case EMAIL_EVENT_DELETE_MAILBOX: @@ -2701,6 +2725,7 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_SAVE_MAIL: case EMAIL_EVENT_MOVE_MAIL: case EMAIL_EVENT_CREATE_MAILBOX: case EMAIL_EVENT_DELETE_MAILBOX: diff --git a/email-core/email-core-global.c b/email-core/email-core-global.c index f9b7c77..14699b7 100755 --- a/email-core/email-core-global.c +++ b/email-core/email-core-global.c @@ -34,20 +34,120 @@ #include #include #include "email-core-global.h" +#include "email-debug-log.h" +#include "email-types.h" +#include "email-utilities.h" +#include "email-core-account.h" -email_account_t g_new_account; +email_account_list_t *g_unvalidated_account_list = NULL; email_account_list_t *g_account_list = NULL; int g_account_num = 0; int g_account_retrieved = 0; extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) __THROW __nonnull ((1)); -INTERNAL_FUNC email_account_t *emcore_get_new_account_reference() +INTERNAL_FUNC int emcore_get_account_from_unvalidated_account_list(int input_unvalidated_account_id, email_account_t **oupput_account) { - return &g_new_account; + EM_DEBUG_FUNC_BEGIN("input_unvalidated_account_id[%d], oupput_account[%p]", input_unvalidated_account_id, oupput_account); + email_account_list_t *account_node = g_unvalidated_account_list; + int err = EMAIL_ERROR_NONE; + + if(oupput_account == NULL) { + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + goto FINISH_OFF; + } + + *oupput_account = NULL; + + while(account_node) { + if(account_node->account->account_id == input_unvalidated_account_id) { + *oupput_account = account_node->account; + break; + } + + account_node = account_node->next; + } + + if(*oupput_account == NULL) + err = EMAIL_ERROR_DATA_NOT_FOUND; + +FINISH_OFF: + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +INTERNAL_FUNC int emcore_add_account_to_unvalidated_account_list(email_account_t *input_new_account) +{ + EM_DEBUG_FUNC_BEGIN("input_new_account[%p]", input_new_account); + email_account_list_t **account_node = &g_unvalidated_account_list; + email_account_list_t *new_account_node = NULL; + int new_account_id = -1; + int err = EMAIL_ERROR_NONE; + + if(input_new_account == NULL) { + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + goto FINISH_OFF; + } + + new_account_node = em_malloc(sizeof(email_account_list_t)); + + if(new_account_node == NULL) { + err = EMAIL_ERROR_OUT_OF_MEMORY; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + goto FINISH_OFF; + } + + new_account_node->account = input_new_account; + new_account_node->next = NULL; + + while(*account_node) { + if((*account_node)->account->account_id < new_account_id) { + new_account_id = (*account_node)->account->account_id - 1; + } + account_node = &((*account_node)->next); + } + + input_new_account->account_id = new_account_id; + *account_node = new_account_node; + +FINISH_OFF: + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } +INTERNAL_FUNC int emcore_delete_account_from_unvalidated_account_list(int input_account_id) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id[%d]", input_account_id); + email_account_list_t *account_node = g_unvalidated_account_list, *prev_node = NULL; + email_account_t *found_account = NULL; + int err = EMAIL_ERROR_NONE; + + while(account_node) { + if(account_node->account->account_id == input_account_id) { + found_account = account_node->account; + if(prev_node) + prev_node->next = account_node->next; + else + g_unvalidated_account_list = account_node->next; + break; + } + prev_node = account_node; + account_node = account_node->next; + } + if(found_account) { + EM_SAFE_FREE(account_node); + } + else { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_DATA_NOT_FOUND"); + err = EMAIL_ERROR_DATA_NOT_FOUND; + } + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} diff --git a/email-core/email-core-imap-idle.c b/email-core/email-core-imap-idle.c index abc76e6..690de1f 100755 --- a/email-core/email-core-imap-idle.c +++ b/email-core/email-core-imap-idle.c @@ -192,7 +192,7 @@ int emcore_imap_idle_loop_start(email_mailbox_t *mailbox_list, int num, int *er sprintf(tag, "%08lx", 0xffffffff & (((MAILSTREAM *)temp->mail_stream)->gensym++)); sprintf(cmd, "%s DONE\015\012", tag); - if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)strlen(cmd))) { + if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("network error - failed to DONE on Mailbox - %s ", temp->name); } else { @@ -412,7 +412,7 @@ static int emcore_imap_idle_connect_and_idle_on_mailbox(email_mailbox_t *mailbox sprintf(cmd, "%s IDLE\015\012", tag); /* Send IDLE command */ - if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)strlen(cmd))) { + if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("network error - failed to IDLE on Mailbox - %s ", mailbox->mailbox_name); err = EMAIL_ERROR_IMAP4_IDLE_FAILURE; goto FINISH_OFF; diff --git a/email-core/email-core-imap-mailbox.c b/email-core/email-core-imap-mailbox.c index 1e1ad6d..877cf16 100755 --- a/email-core/email-core-imap-mailbox.c +++ b/email-core/email-core-imap-mailbox.c @@ -256,11 +256,11 @@ static int emcore_get_mailbox_connection_path(int account_id, char *mailbox_name return 0; } - path_len = strlen(ref_account->incoming_server_address) + - (mailbox_name ? strlen(mailbox_name) : 0) + 50; + path_len = EM_SAFE_STRLEN(ref_account->incoming_server_address) + + (mailbox_name ? EM_SAFE_STRLEN(mailbox_name) : 0) + 50; - *path = em_malloc(path_len);/* strlen(ref_account->incoming_server_address) + */ - /* (mailbox_name ? strlen(mailbox_name) : 0) + 20); */ + *path = em_malloc(path_len);/* EM_SAFE_STRLEN(ref_account->incoming_server_address) + */ + /* (mailbox_name ? EM_SAFE_STRLEN(mailbox_name) : 0) + 20); */ if (!*path) return 0; memset(*path, 0x00, path_len); @@ -274,20 +274,20 @@ static int emcore_get_mailbox_connection_path(int account_id, char *mailbox_name } /* 2. set tls option if security connection */ -/* if (ref_account->incoming_server_secure_connection) strncat(*path + 1, "/tls", path_len-(strlen(*path)-1)); */ +/* if (ref_account->incoming_server_secure_connection) strncat(*path + 1, "/tls", path_len-(EM_SAFE_STRLEN(*path)-1)); */ if (ref_account->incoming_server_secure_connection & 0x01) { - strncat(*path + 1, "/ssl", path_len-(strlen(*path)-1)); + strncat(*path + 1, "/ssl", path_len-(EM_SAFE_STRLEN(*path)-1)); } if (ref_account->incoming_server_secure_connection & 0x02) - strncat(*path + 1, "/tls", path_len-(strlen(*path)-1)); + strncat(*path + 1, "/tls", path_len-(EM_SAFE_STRLEN(*path)-1)); else - strncat(*path + 1, "/notls", path_len-(strlen(*path)-1)); + strncat(*path + 1, "/notls", path_len-(EM_SAFE_STRLEN(*path)-1)); /* 3. re-format mailbox name (ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}"} */ - strncat(*path + 1, "}", path_len-strlen(*path)-1); + strncat(*path + 1, "}", path_len-EM_SAFE_STRLEN(*path)-1); **path = '{'; - if (mailbox_name) strncat(*path, mailbox_name, path_len-strlen(*path)-1); + if (mailbox_name) strncat(*path, mailbox_name, path_len-EM_SAFE_STRLEN(*path)-1); return 1; } @@ -425,7 +425,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i mailbox_tbl.mailbox_id = 0; mailbox_tbl.local_yn = 1; mailbox_tbl.mailbox_type = counter; - mailbox_tbl.sync_with_server_yn = 0; + mailbox_tbl.deleted_flag = 0; mailbox_tbl.modifiable_yn = 1; mailbox_tbl.total_mail_count_on_server = 0; emcore_get_default_mail_slot_count(&mailbox_tbl.mail_slot_size, NULL); @@ -568,9 +568,9 @@ int emcore_download_mailbox_list(void *mail_stream, /* reference (ex : "{mail.test.com}", "{mail.test.com}inbox") */ if (mailbox_name) { char *s = NULL; - reference = em_malloc(strlen(stream->original_mailbox) + strlen(mailbox_name) + 1); + reference = em_malloc(EM_SAFE_STRLEN(stream->original_mailbox) + strlen(mailbox_name) + 1); /*prevent 34352*/ if (reference) { - strncpy(reference, stream->original_mailbox, (size_t)strlen(stream->original_mailbox)); + strncpy(reference, stream->original_mailbox, (size_t)EM_SAFE_STRLEN(stream->original_mailbox)); if ((s = strchr(reference, '}'))) *(++s) = '\0'; strcat(reference, mailbox_name); @@ -720,7 +720,7 @@ INTERNAL_FUNC int emcore_set_sync_imap_mailbox(email_internal_mailbox_t *mailbox } /* select the mailbox and get its UID */ - if (!imap_local || !imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)strlen(cmd))) { + if (!imap_local || !imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("network error - failed to IDLE on Mailbox [%s]", mailbox->mailbox_name); /* err = EMAIL_ERROR_CONNECTION_BROKEN; @@ -752,7 +752,7 @@ INTERNAL_FUNC int emcore_set_sync_imap_mailbox(email_internal_mailbox_t *mailbox EM_DEBUG_LINE; /* check if OK or BAD response comes. */ /* if response is OK the try getting UID list. */ - if (!strncmp((char *)imap_local->reply.key, "OK", strlen("OK"))) { + if (!strncmp((char *)imap_local->reply.key, "OK", EM_SAFE_STRLEN("OK"))) { EM_DEBUG_LOG(">>>>>>>>>>Select success on %s mailbox", mailbox->mailbox_name); if (!imap4_mailbox_get_uids(stream, &uid_list, &err)) { EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed - %d", err); @@ -806,7 +806,7 @@ INTERNAL_FUNC int emcore_set_sync_imap_mailbox(email_internal_mailbox_t *mailbox mailbox->alias = emcore_get_alias_of_mailbox((const char *)mailbox->mailbox_name); mailbox_tbl.alias = mailbox->alias; - mailbox_tbl.sync_with_server_yn = 1; + mailbox_tbl.deleted_flag = 1; mailbox_tbl.modifiable_yn = 1; mailbox_tbl.total_mail_count_on_server = 0; @@ -823,6 +823,7 @@ INTERNAL_FUNC int emcore_set_sync_imap_mailbox(email_internal_mailbox_t *mailbox mailbox_tbl.mailbox_id = mailbox->mailbox_id; mailbox_tbl.account_id = mailbox->account_id; mailbox_tbl.local_yn = 0; + mailbox_tbl.deleted_flag = 0; mailbox_tbl.mailbox_type = mailbox->mailbox_type; mailbox_tbl.mailbox_name = mailbox->mailbox_name; mailbox_tbl.mail_slot_size = mailbox->mail_slot_size; @@ -836,7 +837,6 @@ INTERNAL_FUNC int emcore_set_sync_imap_mailbox(email_internal_mailbox_t *mailbox EM_DEBUG_LOG("mailbox->alias [%s] ", mailbox->alias); mailbox_tbl.alias = mailbox->alias; - mailbox_tbl.sync_with_server_yn = 1; mailbox_tbl.modifiable_yn = 1; mailbox_tbl.total_mail_count_on_server = 0; @@ -981,7 +981,7 @@ INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code } /* connect mail server */ - if (!emcore_connect_to_remote_mailbox(ref_account->account_id, 0, (void **)&tmp_stream, &err)) { + if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&tmp_stream, &err)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); goto FINISH_OFF; } @@ -1006,12 +1006,6 @@ INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code EM_SAFE_FREE(long_enc_path); - /* if deleted imap mailbox is synchronous mailbox, delete db imap mailbox from db */ - if (!emstorage_delete_mailbox(ref_account->account_id, 0, input_mailbox_id, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_delete_mailbox failed [%d]", err); - goto FINISH_OFF; - } - ret = true; FINISH_OFF: diff --git a/email-core/email-core-mail.c b/email-core/email-core-mail.c index 59a4f35..31528b1 100755 --- a/email-core/email-core-mail.c +++ b/email-core/email-core-mail.c @@ -271,7 +271,7 @@ static int pop3_mail_delete(MAILSTREAM *stream, int msgno, int *err_code) #endif /* send command : delete specified mail */ - if (!net_sout(pop3local->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(pop3local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; @@ -548,7 +548,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_ while (uid_range_node != NULL) { /* Remove comma from end of uid_range */ - uid_range_node->uid_range[strlen(uid_range_node->uid_range) - 1] = '\0'; + uid_range_node->uid_range[EM_SAFE_STRLEN(uid_range_node->uid_range) - 1] = '\0'; EM_DEBUG_LOG("uid_range_node->uid_range - %s", uid_range_node->uid_range); if (!mail_copy_full(stream, uid_range_node->uid_range, dest_mailbox->mailbox_name, CP_UID | CP_MOVE)) { EM_DEBUG_EXCEPTION("emcore_move_mail_on_server_ex : Mail cannot be moved failed"); @@ -695,7 +695,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv while (uid_range_node != NULL) { /* Remove comma from end of uid_range */ - uid_range_node->uid_range[strlen(uid_range_node->uid_range) - 1] = '\0'; + uid_range_node->uid_range[EM_SAFE_STRLEN(uid_range_node->uid_range) - 1] = '\0'; if (!(imaplocal = stream->local) || !imaplocal->netstream) { EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected..."); @@ -714,7 +714,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv /* send command : set deleted flag */ - if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN */ @@ -745,8 +745,8 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv */ - if (!strncmp(p, tag, strlen(tag))) { - if (!strncmp(p + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { /*Error scenario delete all local activity and entry from mail_read_mail_uid_tbl */ EM_DEBUG_LOG(" OK Response recieved "); delete_success = true; @@ -775,7 +775,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv EM_DEBUG_LOG("[IMAP4] >>> %s", cmd); /* send command : EXPUNGE */ - if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; @@ -793,8 +793,8 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv EM_DEBUG_LOG("[IMAP4] <<< %s", p); - if (!strncmp(p, tag, strlen(tag))) { - if (!strncmp(p + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { #ifdef __FEATURE_LOCAL_ACTIVITY__ int index = 0; emstorage_mail_tbl_t **mail = NULL; @@ -949,7 +949,7 @@ static int imap4_send_command(MAILSTREAM *stream, imap4_cmd_t cmd_type, int *err #endif /* send command : delete flaged mail */ - if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; @@ -969,8 +969,8 @@ static int imap4_send_command(MAILSTREAM *stream, imap4_cmd_t cmd_type, int *err EM_DEBUG_LOG("[IMAP4] <<< %s", p); #endif - if (!strncmp(p, tag, strlen(tag))) { - if (!strncmp(p + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { EM_SAFE_FREE(p); break; } @@ -1346,7 +1346,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ temp_emailaddr = NULL; } else { - address_length = 2 * strlen(full_address); + address_length = 2 * EM_SAFE_STRLEN(full_address); temp_emailaddr = (char *)calloc(1, address_length); } @@ -1391,7 +1391,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ while (addr != NULL) { if (addr->mailbox && addr->host) { - if (!strncmp(addr->mailbox , "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS")) || !strncmp(addr->mailbox , "INVALID_ADDRESS", strlen("INVALID_ADDRESS")) || !strncmp(addr->host , ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) + if (!strncmp(addr->mailbox , "UNEXPECTED_DATA_AFTER_ADDRESS", EM_SAFE_STRLEN("UNEXPECTED_DATA_AFTER_ADDRESS")) || !strncmp(addr->mailbox , "INVALID_ADDRESS", EM_SAFE_STRLEN("INVALID_ADDRESS")) || !strncmp(addr->host , ".SYNTAX-ERROR.", EM_SAFE_STRLEN(".SYNTAX-ERROR."))) { EM_DEBUG_LOG("Invalid address "); addr = addr->next; @@ -1421,7 +1421,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ is_searched = true; if (mail_id == 0 || (contact_name_len == 0)) { /* save only the first address information - 09-SEP-2010 */ - contact_display_name_len = strlen(contact_display_name); + contact_display_name_len = EM_SAFE_STRLEN(contact_display_name); if (contact_name_len + contact_display_name_len >= contact_name_buffer_size) { /* re-alloc memory */ char *temp = contact_name; contact_name_buffer_size += contact_name_buffer_size; @@ -1443,7 +1443,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>, ", contact_display_name, email_address); } - contact_display_name_len = strlen(temp_string); + contact_display_name_len = EM_SAFE_STRLEN(temp_string); if (contact_name_len + contact_display_name_len >= contact_name_buffer_size) { /* re-alloc memory */ char *temp = contact_name; contact_name_buffer_size += contact_name_buffer_size; @@ -1505,7 +1505,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ } EM_DEBUG_LOG("temp_string[%s]", temp_string); - contact_display_name_len = strlen(temp_string); + contact_display_name_len = EM_SAFE_STRLEN(temp_string); if (contact_name_len + contact_display_name_len >= contact_name_buffer_size) { /* re-alloc memory */ char *temp = contact_name; contact_name_buffer_size += contact_name_buffer_size; @@ -1892,7 +1892,7 @@ INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char email_sender_list_t *temp_recipients_list = NULL; email_sender_list_t *old_recipients_list_t = NULL; - if (full_address == NULL || strlen(full_address) == 0) { + if (full_address == NULL || EM_SAFE_STRLEN(full_address) == 0) { EM_DEBUG_EXCEPTION("Invalid param : full_address NULL or empty"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -2430,7 +2430,7 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt goto FINISH_OFF; } - msg_no = atoi(s_uid); + msg_no = s_uid? atoi(s_uid): 0; /* get body structure. */ /* don't free mbody because mbody is freed in closing mail_stream. */ @@ -3026,7 +3026,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in while (part_child) { BODY *body = &(part_child->body); if (only_body_download == true) { - if (((body->id) && strlen(body->id) > 1) || (body->location)) + if (((body->id) && EM_SAFE_STRLEN(body->id) > 1) || (body->location)) is_attachment = 0; else if (body->disposition.type) { /* "attachment" or "inline" or etc... */ PARAMETER *param = body->disposition.parameter; @@ -3089,7 +3089,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in /* save message into tempfile */ /* download body text and get attachment list. */ if (emcore_get_body_part_list_full(stream, uid, account_id, mail_id, mbody, cnt_info, &err, section_list, event_handle) < 0) { - EM_DEBUG_EXCEPTION("emcore_get_body falied [%d]", err); + EM_DEBUG_EXCEPTION("emcore_get_body_part_list_full failed [%d]", err); goto FINISH_OFF; } FINISH_OFF_IF_CANCELED; @@ -3131,11 +3131,11 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in } if (cnt_info->text.plain_charset != NULL) { - memcpy(html_body, cnt_info->text.plain_charset, strlen(cnt_info->text.plain_charset)); + memcpy(html_body, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset)); strcat(html_body, HTML_EXTENSION_STRING); } else { - memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm")); + memcpy(html_body, "UTF-8.htm", EM_SAFE_STRLEN("UTF-8.htm")); } if (!emstorage_get_save_name(account_id, mail_id, 0, html_body, buf, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); @@ -3596,17 +3596,15 @@ FINISH_OFF: return err; } -int emcore_delete_all_mails_of_mailbox(int input_mailbox_id, int input_from_server, int *err_code) +INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int input_mailbox_id, int input_from_server, int *err_code) { - EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_from_server [%d], err_code [%p]", input_mailbox_id, input_from_server, err_code); + EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_mailbox_id[%d] input_from_server[%d] err_code[%p]", input_account_id, input_mailbox_id, input_from_server, err_code); int ret = false; int err = EMAIL_ERROR_NONE; - int search_handle = 0; - int *mail_ids = NULL; - int i = 0; - int total = 0; - emstorage_mailbox_tbl_t *mailbox_tbl = NULL; + int *mail_id_array = NULL; + int mail_id_count = 0; + char conditional_clause[QUERY_SIZE] = { 0, }; if (!input_mailbox_id) { err = EMAIL_ERROR_INVALID_PARAM; @@ -3614,36 +3612,16 @@ int emcore_delete_all_mails_of_mailbox(int input_mailbox_id, int input_from_serv goto FINISH_OFF; } - if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl) != EMAIL_ERROR_NONE)) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); - goto FINISH_OFF; - } /* Delete all mails in specific mailbox */ - if (!emstorage_mail_search_start(NULL, mailbox_tbl->account_id, mailbox_tbl->mailbox_name, 0, &search_handle, &total, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_mail_search_start failed [%d]", err); - goto FINISH_OFF; - } + SNPRINTF(conditional_clause, QUERY_SIZE, " where mailbox_id = %d ", input_mailbox_id); - EM_DEBUG_LOG("emstorage_mail_search_start returns [%d]", total); + emstorage_query_mail_id_list(conditional_clause, false, &mail_id_array, &mail_id_count); - if (total > 0) { - mail_ids = em_malloc(sizeof(int) * total); - if (mail_ids == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed..."); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - for (i = 0; i < total; i++) { - if (!emstorage_mail_search_result(search_handle, RETRIEVE_ID, (void**)&mail_ids[i], true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_mail_search_result failed [%d]", err); + EM_DEBUG_LOG("emstorage_query_mail_id_list returns [%d]", mail_id_count); - goto FINISH_OFF; - } - } - - if (!emcore_delete_mail(mailbox_tbl->account_id, mail_ids, total, input_from_server, EMAIL_DELETED_BY_COMMAND, false, &err)) { + if (mail_id_count > 0) { + if (!emcore_delete_mail(input_account_id, mail_id_array, mail_id_count, input_from_server, EMAIL_DELETED_BY_COMMAND, false, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err); goto FINISH_OFF; } @@ -3652,17 +3630,11 @@ int emcore_delete_all_mails_of_mailbox(int input_mailbox_id, int input_from_serv ret = true; FINISH_OFF: - if (search_handle >= 0) { - if (!emstorage_mail_search_end(search_handle, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_mail_search_end failed [%d]", err); - } - - if (mailbox_tbl) - emstorage_free_mailbox(&mailbox_tbl, 1, NULL); + EM_SAFE_FREE(mail_id_array); - EM_SAFE_FREE(mail_ids); if (err_code != NULL) *err_code = err; + EM_DEBUG_FUNC_END("ret [%d], err [%d]", ret, err); return ret; } @@ -4921,121 +4893,159 @@ FINISH_OFF: } -INTERNAL_FUNC int emcore_move_mail_to_another_account_on_local_storeage(int input_task_id, int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int *result_mail_id) +static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_id, emstorage_mailbox_tbl_t *input_source_mailbox, emstorage_mailbox_tbl_t *input_target_mailbox, int input_task_id, int *output_mail_id) { - EM_DEBUG_FUNC_BEGIN("input_task_id [%d] input_mail_id[%d] input_source_mailbox_id[%d] input_target_mailbox_id[%d] result_mail_id[%p]", input_task_id, input_mail_id, input_source_mailbox_id, input_target_mailbox_id, result_mail_id); + EM_DEBUG_FUNC_BEGIN("input_mail_id[%d] input_source_mailbox[%p] input_target_mailbox[%p] input_task_id [%d] output_mail_id[%p]", input_mail_id, input_source_mailbox, input_target_mailbox, input_task_id, output_mail_id); int err = EMAIL_ERROR_NONE; int attachment_count = 0; email_mail_data_t *mail_data = NULL; - emstorage_mailbox_tbl_t *source_mailbox = NULL; - emstorage_mailbox_tbl_t *target_mailbox = NULL; - email_account_t *account_ref = NULL; email_attachment_data_t *attachment_data = NULL; - if ( input_source_mailbox_id <= 0 || input_target_mailbox_id <= 0 || input_mail_id <= 0 || result_mail_id == NULL) { + if ( input_source_mailbox == NULL || input_target_mailbox == NULL || input_mail_id <= 0 || output_mail_id == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } + if((err = emcore_get_mail_data(input_mail_id, &mail_data)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err); + err = EMAIL_ERROR_INVALID_MAIL; + goto FINISH_OFF; + } + + /* Check download status */ + if(mail_data->body_download_status != 1) { + /* If not downloaded, download fully */ + if (!emcore_download_body_multi_sections_bulk(NULL, + input_source_mailbox->account_id, + input_mail_id, + 0, + (mail_data->attachment_count > 0)?1:0, + NO_LIMITATION, + input_task_id, + &err)) { + EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed [%d]", err); + goto FINISH_OFF; + } + } + + /* Get attachments */ + if((err = emcore_get_attachment_data_list(input_mail_id, &attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err); + goto FINISH_OFF; + } + + mail_data->account_id = input_target_mailbox->account_id; + mail_data->mail_id = 0; + mail_data->mailbox_id = input_target_mailbox->mailbox_id; + mail_data->mailbox_type = input_target_mailbox->mailbox_type; + mail_data->thread_id = 0; + mail_data->thread_item_count = 0; + + if((err = emcore_add_mail(mail_data, attachment_data, attachment_count, NULL, false)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err); + goto FINISH_OFF; + } + + *output_mail_id = mail_data->mail_id; + +FINISH_OFF: + if (mail_data) { + emcore_free_mail_data(mail_data); + free(mail_data); /* prevent 34648 */ + } + + if (attachment_data) + emcore_free_attachment_data(&attachment_data, attachment_count, NULL); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id) +{ + EM_DEBUG_FUNC_BEGIN("input_mail_id[%d] input_source_mailbox_id[%d] input_target_mailbox_id[%d] result_mail_id[%p] input_task_id [%d]", input_mail_id, input_source_mailbox_id, input_target_mailbox_id, input_task_id); + int err = EMAIL_ERROR_NONE; + int err_for_delete_mail = EMAIL_ERROR_NONE; + int moved_mail_id = 0; + emstorage_mailbox_tbl_t *source_mailbox = NULL; + emstorage_mailbox_tbl_t *target_mailbox = NULL; + email_account_t *source_account_ref = NULL; + email_account_t *target_account_ref = NULL; + if((err = emstorage_get_mailbox_by_id(input_source_mailbox_id, &source_mailbox)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed for source_mailbox [%d]", err); goto FINISH_OFF; } if((err = emstorage_get_mailbox_by_id(input_target_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed for source_mailbox [%d]", err); + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed for target_mailbox [%d]", err); goto FINISH_OFF; } + /* Check account type */ /* POP -> IMAP possible */ /* IMAP -> POP possible, but the mail would not be on server */ /* EAS -> X impossible */ /* X -> EAS impossible */ - account_ref = emcore_get_account_reference(source_mailbox->account_id); + source_account_ref = emcore_get_account_reference(source_mailbox->account_id); - if(account_ref == NULL || account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { + if(source_account_ref == NULL || source_account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { EM_DEBUG_EXCEPTION("Invalid account"); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - account_ref = emcore_get_account_reference(target_mailbox->account_id); + target_account_ref = emcore_get_account_reference(target_mailbox->account_id); - if(account_ref == NULL || account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { + if(target_account_ref == NULL || target_account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { EM_DEBUG_EXCEPTION("Invalid account"); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - if((err = emcore_get_mail_data(input_mail_id, &mail_data)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err); - err = EMAIL_ERROR_INVALID_MAIL; - goto FINISH_OFF; - } - /* Check download status */ - if(mail_data->body_download_status != 1) { - /* If not downloaded, download fully */ - if (!emcore_download_body_multi_sections_bulk(NULL, - source_mailbox->account_id, - input_mail_id, - 1, - 1, - NO_LIMITATION, - input_task_id, - &err)) { - EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed [%d]", err); - goto FINISH_OFF; - } + if((err = emcore_copy_mail_to_another_account_on_local_storeage(input_mail_id, source_mailbox, target_mailbox, input_task_id, &moved_mail_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_copy_mail_to_another_account_on_local_storeage failed [%d]", err); + goto FINISH_OFF; } - /* Get attachments */ - if((err = emcore_get_attachment_data_list(input_mail_id, &attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err); + if(!emcore_set_flags_field(source_mailbox->account_id, &input_mail_id, 1, EMAIL_FLAGS_DELETED_FIELD, 1 , &err)) { + EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err); goto FINISH_OFF; } - mail_data->account_id = target_mailbox->account_id; - mail_data->mail_id = 0; - mail_data->mailbox_id = input_target_mailbox_id; - mail_data->mailbox_type = target_mailbox->mailbox_type; - mail_data->thread_id = 0; - mail_data->thread_item_count = 0; + if(target_account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + if((err = emcore_sync_mail_from_client_to_server(moved_mail_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_sync_mail_from_client_to_server failed [%d]", err); - /* begin transaction */ - /* EMSTORAGE_START_WRITE_TRANSACTION(1, err); */ + /* if append is failed, restore source mail and delete copied mail. */ + if(!emcore_set_flags_field(source_mailbox->account_id, &input_mail_id, 1, EMAIL_FLAGS_DELETED_FIELD, 0 , &err)) { + EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err); + goto FINISH_OFF; + } - if((err = emcore_add_mail(mail_data, attachment_data, attachment_count, NULL, false)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err); - goto FINISH_OFF; + if(!emcore_delete_mail(target_mailbox->account_id, &moved_mail_id, 1, false, 0, 0, &err_for_delete_mail)) + EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err_for_delete_mail); + goto FINISH_OFF; + } } - *result_mail_id = mail_data->mail_id; - if(!emcore_delete_mail(source_mailbox->account_id, &input_mail_id, 1, true, 0, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err); goto FINISH_OFF; } - /* transaction_type = 1; - EMSTORAGE_FINISH_WRITE_TRANSACTION(1, transaction_type, err); */ FINISH_OFF: - if (mail_data) - emcore_free_mail_data(mail_data); - if (source_mailbox) emstorage_free_mailbox(&source_mailbox, 1, NULL); if (target_mailbox) emstorage_free_mailbox(&target_mailbox, 1, NULL); - if (attachment_data) - emcore_free_attachment_data(&attachment_data, attachment_count, NULL); - EM_DEBUG_FUNC_END("err [%d]", err); return err; } @@ -5078,9 +5088,7 @@ FINISH_OFF: return 1; } -/* description - * update mail information - */ +/* description : update mail information */ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas) { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], input_meeting_request[%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas); @@ -5329,8 +5337,9 @@ INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err); goto FINISH_OFF; } - - emcore_display_unread_in_badge(); + + if(field_type == EMAIL_FLAGS_SEEN_FIELD) + emcore_display_unread_in_badge(); ret = true; @@ -5376,7 +5385,7 @@ int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, in /* send command : LIST [msgno] - to get the size of the mail */ - if (!net_sout(pop3local->netstream, command, (int)strlen(command))) { + if (!net_sout(pop3local->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_INVALID_RESPONSE; @@ -5401,7 +5410,7 @@ int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, in if (*response == '+') { /* "+ OK" */ char *p = NULL; - if (!(p = strchr(response + strlen("+OK "), ' '))) { + if (!(p = strchr(response + EM_SAFE_STRLEN("+OK "), ' '))) { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } @@ -5562,13 +5571,13 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) else sprintf(clear_flags, "%s $Forwarded", clear_flags); - if (strlen(set_flags) > 0) { + if (EM_SAFE_STRLEN(set_flags) > 0) { EM_DEBUG_LOG(">>>> Calling mail_setflag [%s] ", set_flags); mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT); EM_DEBUG_LOG(">>>> End mail_setflag "); } - if (strlen(clear_flags) > 0) { + if (EM_SAFE_STRLEN(clear_flags) > 0) { EM_DEBUG_LOG(">>>> Calling mail_clearflag [%s]", clear_flags); mail_clearflag(stream, tmp, clear_flags); EM_DEBUG_LOG(">>>> End mail_clearflag "); @@ -5577,7 +5586,7 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) if (mail->lock_status) { memset(set_flags, 0x00, 100); sprintf(set_flags, "Sticky"); - if (strlen(set_flags) > 0) { + if (EM_SAFE_STRLEN(set_flags) > 0) { EM_DEBUG_LOG(">>>> Calling mail_setflag [%s]", set_flags); mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT); EM_DEBUG_LOG(">>>> End mail_setflag "); @@ -5698,7 +5707,7 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int sprintf(clear_flags, "\\Seen"); EM_DEBUG_LOG("new_flag.seen : %s ", set_flags); - if (strlen(set_flags) > 0) { + if (EM_SAFE_STRLEN(set_flags) > 0) { EM_DEBUG_LOG(">>>> Calling mail_setflag "); mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT); EM_DEBUG_LOG(">>>> End mail_setflag "); @@ -6006,7 +6015,7 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e while (uid_range_node != NULL) { /* Remove comma from end of uid_range */ - uid_range_node->uid_range[strlen(uid_range_node->uid_range) - 1] = '\0'; + uid_range_node->uid_range[EM_SAFE_STRLEN(uid_range_node->uid_range) - 1] = '\0'; /* Form the IMAP command */ @@ -6028,7 +6037,7 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e goto FINISH_OFF; } - if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; @@ -6048,8 +6057,8 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e EM_DEBUG_LOG("[IMAP4 Response ] %s", p); - if (!strncmp(p, tag, strlen(tag))) { - if (!strncmp(p + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { /*Delete all local activities */ command_success = true; diff --git a/email-core/email-core-mailbox-sync.c b/email-core/email-core-mailbox-sync.c index 00f71bc..dad5ba5 100755 --- a/email-core/email-core-mailbox-sync.c +++ b/email-core/email-core-mailbox-sync.c @@ -65,7 +65,8 @@ static char g_append_uid_rsp[129]; /* added for getting server response */ extern void imap_parse_body_structure (MAILSTREAM *stream, BODY *body, unsigned char **txtptr, IMAPPARSEDREPLY *reply); #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ -static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply, int input_download_size); +static void emcore_free_email_partial_buffer(email_partial_buffer **partial_buffer, int item_count); +static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply, int input_download_size, int item_count); static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, char *uid, int mailbox_id, int *err_code); #endif @@ -104,7 +105,7 @@ int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *er /* EM_DEBUG_LOG(" [POP3] >>> %s", command); */ /* send command : get rfc822 size by msgno */ - if (!net_sout(pop3local->netstream, command, (int)strlen(command))) { + if (!net_sout(pop3local->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed..."); err = EMAIL_ERROR_INVALID_RESPONSE; @@ -122,7 +123,7 @@ int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *er if (*response == '+') { /* "+ OK" */ char *p = NULL; - if (!(p = strchr(response + strlen("+OK "), ' '))) { + if (!(p = strchr(response + EM_SAFE_STRLEN("+OK "), ' '))) { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } @@ -182,7 +183,7 @@ int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *e /* EM_DEBUG_LOG(" [IMAP4] >>> %s", command); */ /* send command : get rfc822 size by msgno */ - if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) { + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed..."); err = EMAIL_ERROR_INVALID_RESPONSE; @@ -199,8 +200,8 @@ int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *e /* EM_DEBUG_LOG(" [IMAP4] <<< %s", response); */ - if (!strncmp(response, tag, strlen(tag))) { - if (!strncmp(response + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { EM_SAFE_FREE(response); break; } @@ -216,7 +217,7 @@ int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *e continue; } - s = t + strlen("FETCH (RFC822.SIZE "); + s = t + EM_SAFE_STRLEN("FETCH (RFC822.SIZE "); if (!(t = strchr(s, ' '))) { err = EMAIL_ERROR_INVALID_RESPONSE; @@ -278,7 +279,7 @@ int pop3_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int *e #endif /* send command : get msgno/uid for all message */ - if (!net_sout(pop3local->netstream, command, (int)strlen(command))) { + if (!net_sout(pop3local->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; @@ -394,7 +395,7 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * #endif /* send command : get msgno/uid for all message */ - if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) { + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed...\n"); err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; @@ -419,8 +420,8 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * EM_DEBUG_LOG(" [IMAP4] <<< [%s]", response); #endif - if (!strncmp(response, tag, strlen(tag))) { - if (!strncmp(response + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { free(response); response = NULL; break; } @@ -432,14 +433,14 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * if ((p = strstr(response, " FETCH ("))) { if (!strstr(p, "\\Deleted")) { /* undeleted only */ - *p = '\0'; p += strlen(" FETCH "); + *p = '\0'; p += EM_SAFE_STRLEN(" FETCH "); seen = strstr(p, "\\Seen") ? 1 : 0; draft = strstr(p, "\\Draft") ? 1 : 0; forwarded = strstr(p, "$Forwarded") ? 1 : 0; if ((p = strstr(p, "UID "))) { - s = p + strlen("UID "); + s = p + EM_SAFE_STRLEN("UID "); while (isdigit(*s)) s++; @@ -452,8 +453,8 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * goto FINISH_OFF; } - uid_elem->msgno = atoi(response + strlen("* ")); - uid_elem->uid = EM_SAFE_STRDUP(p + strlen("UID ")); + uid_elem->msgno = atoi(response + EM_SAFE_STRLEN("* ")); + uid_elem->uid = EM_SAFE_STRDUP(p + EM_SAFE_STRLEN("UID ")); uid_elem->flag.seen = seen; uid_elem->flag.draft = draft; uid_elem->flag.forwarded = forwarded; @@ -608,7 +609,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui #endif /* send command : get msgno/uid for all message */ - if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) { + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN */ goto FINISH_OFF; @@ -628,8 +629,8 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui EM_DEBUG_LOG(" [IMAP4] <<< [%s]", response); #endif - if (!strncmp(response, tag, strlen(tag))) { - if (!strncmp(response + strlen(tag) + 1, "OK", 2)) { + if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { free(response); response = NULL; break; } @@ -640,7 +641,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui } if ((p = strstr(response, " SEARCH "))){ - *p = '\0'; p += strlen(" SEARCH "); + *p = '\0'; p += EM_SAFE_STRLEN(" SEARCH "); result = strtok(p, delims); @@ -669,8 +670,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - - free(response); response = NULL; + /* Delete the dead code */ } ret = true; @@ -708,7 +708,7 @@ static int emcore_parse_header(char *rfc822_header, int *req_read_receipt, int * memset(buf, 0x00, PARSE_BUFFER_LENGTH); - for (len = strlen(rfc822_header), i = 0, j = 0; i < len; i++) { + for (len = EM_SAFE_STRLEN(rfc822_header), i = 0, j = 0; i < len; i++) { if (rfc822_header[i] == CR && rfc822_header[i+1] == LF){ if (j + 3 < PARSE_BUFFER_LENGTH) /* '3' include CR LF NULL */ strncpy(buf + j, CRLF_STRING, PARSE_BUFFER_LENGTH - (j + 2)); /* '3' include CR LF */ @@ -731,7 +731,7 @@ static int emcore_parse_header(char *rfc822_header, int *req_read_receipt, int * /* x-priority */ if (buf[0] == 'X' && buf[2] == 'P' && buf[9] == 'Y'){ - size_t len_2 = strlen(buf); + size_t len_2 = EM_SAFE_STRLEN(buf); if (len_2 >= 12){ buf[len_2 - 2] = '\0'; *priority = atoi(buf + 11); @@ -1177,9 +1177,9 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub EM_DEBUG_LOG("rule : full_address_from[%s], addr->mailbox[%s], addr->host[%s]", input_full_address_from, addr->mailbox, addr->host); if (addr->mailbox) - len = strlen(addr->mailbox); + len = EM_SAFE_STRLEN(addr->mailbox); if (addr->host) - len += strlen(addr->host); + len += EM_SAFE_STRLEN(addr->host); len += 2; if (!(from_address = em_malloc(len))) { @@ -1812,7 +1812,8 @@ FINISH_OFF: if (!emcore_remove_overflowed_mails(input_mailbox_tbl, &err_2)) EM_DEBUG_EXCEPTION("emcore_remove_overflowed_mails failed - %d", err_2); - emstorage_stamp_last_sync_time_of_mailbox(input_mailbox_tbl->mailbox_id, 1); + if (input_mailbox_tbl) + emstorage_stamp_last_sync_time_of_mailbox(input_mailbox_tbl->mailbox_id, 1); #ifdef __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ if ((err_from_vconf = vconf_set_int(VCONFKEY_EMAIL_SYNC_STATE, 0)) != 0 ) { @@ -1931,7 +1932,7 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** EM_DEBUG_LOG("[POP3] >>> [%s]", cmd); #endif - if (!net_sout(pop3local->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(pop3local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; @@ -2035,7 +2036,7 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("[IMAP] >>> %s", cmd); #endif - if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; @@ -2050,7 +2051,7 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** /* EM_DEBUG_LOG(" [IMAP] <<< %s", p); */ /* tagged line - end of command */ - if (!strncmp(p, tag, strlen(tag))) + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) break; /* check that reply is reply to our command */ @@ -2098,7 +2099,7 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** /* parse uid */ s = strstr(++t, "UID "); if (s) { - s += strlen("UID "); + s += EM_SAFE_STRLEN("UID "); t = strchr(s, ')'); if (!t) { @@ -2227,7 +2228,7 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(cmd, sizeof(cmd), "%s SEARCH UID %s\015\012", tag, uid); - if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) { + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; @@ -2240,7 +2241,7 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int break; /* tagged line - end of command */ - if (!strncmp(p, tag, strlen(tag))) + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) break; /* check that reply is reply to our command */ @@ -2401,12 +2402,11 @@ void mail_appenduid(char *mailbox, unsigned long uidvalidity, SEARCHSET *set) EM_DEBUG_LOG("append uid - %s", g_append_uid_rsp); } -INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_code) +INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id) { - EM_DEBUG_FUNC_BEGIN("mail_id [%d], err_code [%p]", mail_id, *err_code); + EM_DEBUG_FUNC_BEGIN("mail_id [%d]", mail_id); int err = EMAIL_ERROR_NONE; - int ret = false; int len = 0; int read_size = 0; int attachment_tbl_count = 0; @@ -2418,23 +2418,26 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_c FILE *fp = NULL; STRING str; MAILSTREAM *stream = NULL; + email_account_t *account_ref = NULL; emstorage_mail_tbl_t *mail_table_data = NULL; emstorage_attachment_tbl_t *attachment_tbl_data = NULL; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; - if (mail_id < 1){ - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - /* get a mail from mail table */ if (!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) { 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) { + account_ref = emcore_get_account_reference(mail_table_data->account_id); + + if(account_ref == NULL || account_ref->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) { + EM_DEBUG_EXCEPTION("This account doesn't support sync"); + err = EMAIL_ERROR_INVALID_ACCOUNT; + goto FINISH_OFF; + } + + 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; } @@ -2445,7 +2448,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_c goto FINISH_OFF; } - if (mailbox_tbl->sync_with_server_yn == 0) { + if (mailbox_tbl->local_yn == 0) { EM_DEBUG_EXCEPTION("The mailbox [%s] is not on server.", mail_table_data->mailbox_name); err = EMAIL_ERROR_INVALID_MAILBOX; goto FINISH_OFF; @@ -2482,14 +2485,18 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_c rewind(fp); - ret = fseek(fp, 0, SEEK_END) == 0 && (len = ftell(fp)) != -1; + /* get file length */ + if(fseek(fp, 0, SEEK_END) != 0 || (len = ftell(fp)) == -1) { + EM_DEBUG_EXCEPTION("fseek or ftell failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } if (fname) EM_DEBUG_LOG("Composed file name [%s] and file size [%d]", fname, len); rewind(fp); - ret = 0; stream = NULL; if (!emcore_connect_to_remote_mailbox(mail_table_data->account_id, 0, (void **)&stream, &err)){ EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err); @@ -2514,12 +2521,14 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_c if (mail_table_data->flags_seen_field){ if (!mail_append_full(stream, long_enc_path, set_flags, NULL, &str)) { EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; goto FINISH_OFF; } } else{ if (!mail_append_full(stream, long_enc_path, NULL, NULL, &str)) { EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; goto FINISH_OFF; } } @@ -2531,7 +2540,6 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_c goto FINISH_OFF; } - ret = true; FINISH_OFF: @@ -2580,10 +2588,8 @@ FINISH_OFF: stream = NULL; } - if (err_code != NULL) - *err_code = err; - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } #endif @@ -2673,6 +2679,178 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, return ret; } +static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_server, char *bodystructure, BODY **body, struct _m_content_info **cnt_info, int *total_mail_size, unsigned long *uid_no) +{ + EM_DEBUG_FUNC_BEGIN("stream:[%p], reply_from_server:[%p], bodystructure:[%p]", stream, reply_from_server, bodystructure); + + int err = EMAIL_ERROR_NONE; + + if (!stream || !reply_from_server || !bodystructure) { + EM_DEBUG_EXCEPTION("Invalid paramter"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + int p_total_mail_size = 0; + unsigned long p_uid_no = 0; + char *uid_string = NULL; + char *bodystructure_start = NULL; + char *bodystructure_string = NULL; + char *modified_bodystructure_string = NULL; + char *bodystructure_uid_start = NULL; + BODY *p_body = NULL; + struct _m_content_info *p_cnt_info = NULL; + + /* Get the body strcuture string */ + bodystructure_start = strstr(bodystructure, "BODYSTRUCTURE (") + strlen("BODYSTRUCTURE"); + + bodystructure_string = EM_SAFE_STRDUP(bodystructure_start); + + modified_bodystructure_string = em_replace_string(bodystructure_string, "\r\n", " "); + if (modified_bodystructure_string != NULL) { + EM_DEBUG_LOG("modified_bodystrcutre_string:[%s]", modified_bodystructure_string); + EM_SAFE_STRNCPY(bodystructure_string, modified_bodystructure_string, EM_SAFE_STRLEN(modified_bodystructure_string)); + EM_SAFE_FREE(modified_bodystructure_string); + } + + /* Get the UID */ + bodystructure_uid_start = strcasestr(bodystructure, "UID ") + strlen("UID "); + + uid_string = em_malloc((bodystructure_start - bodystructure_uid_start) + 1); + if (uid_string == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + memcpy(uid_string, bodystructure_uid_start, bodystructure_start - bodystructure_uid_start); + + p_uid_no = strtoul(uid_string, NULL, 0); + EM_DEBUG_LOG("UID number : [%d]", p_uid_no); + + /* Parse the bodystructure string */ + p_body = mail_newbody(); + if (p_body == NULL) { + EM_DEBUG_EXCEPTION("New body creationg failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + imap_parse_body_structure(stream, p_body, (unsigned char **)&bodystructure_string, reply_from_server); + + /* Get the total mail size */ + if (emcore_set_fetch_body_section(p_body, true, &p_total_mail_size, &err) < 0) { + EM_DEBUG_EXCEPTION("emcore_set_fetch_body_section failed:[%d]", err); + goto FINISH_OFF; + } + + /* Fill the content_info structure */ + if (!(p_cnt_info = em_malloc(sizeof(struct _m_content_info)))) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + if (emcore_get_body(stream, 0, 0, 0, p_body, p_cnt_info, &err) < 0 || !p_cnt_info) { + EM_DEBUG_EXCEPTION("emcore_get_body failed[%d]", err); + err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; + goto FINISH_OFF; + } + +FINISH_OFF: + + EM_SAFE_FREE(uid_string); +// EM_SAFE_FREE(bodystructure_string); + + if (err != EMAIL_ERROR_NONE) { + if (p_cnt_info) + emcore_free_content_info(p_cnt_info); + + if (body) + mail_free_body(&p_body); + } else { + if (cnt_info) + *cnt_info = p_cnt_info; + + if (body) + *body = p_body; + + if (total_mail_size) + *total_mail_size = p_total_mail_size; + + if (uid_no) + *uid_no = p_uid_no; + } + + EM_DEBUG_FUNC_END("Err:[%d]", err); + return err; +} + +static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_info, int account_id, int mail_id, int mailbox_id, int *output_total_attachment_size, int *output_attachment_count) +{ + EM_DEBUG_FUNC_BEGIN("cnt_info : [%p], account_id : [%d], mail_id : [%d], mailbox_id : [%d]", cnt_info, account_id, mail_id, mailbox_id); + int err = EMAIL_ERROR_NONE; + + if (!cnt_info || !account_id || !mail_id || !mailbox_id) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + + } + + if (!cnt_info->file || !cnt_info->file->name) { + EM_DEBUG_LOG("Not include attachment"); + return err; + } + + int attachment_count = 0; + int total_attach_size = 0; + int inline_attachment_count = 0; + emstorage_attachment_tbl_t attachment_tbl = {0}; + struct attachment_info *attach_info = NULL; + + attachment_tbl.account_id = account_id; + attachment_tbl.mail_id = mail_id; + attachment_tbl.mailbox_id = mailbox_id; + attachment_tbl.attachment_save_status = 0; + + for (attachment_count = 1, attach_info = cnt_info->file; attach_info; attach_info = attach_info->next, attachment_count++) { + if (attach_info->type == INLINE_ATTACHMENT) { + EM_DEBUG_LOG("INLINE ATTACHMENT"); + inline_attachment_count++; + continue; + } + + total_attach_size += attach_info->size; + attachment_tbl.attachment_size = attach_info->size; + attachment_tbl.attachment_path = attach_info->save; + attachment_tbl.attachment_name = attach_info->name; + attachment_tbl.attachment_drm_type = attach_info->drm; + attachment_tbl.attachment_mime_type = attach_info->attachment_mime_type; +#ifdef __ATTACHMENT_OPTI__ + attachment_tbl.encoding = attach_info->encoding; + attachment_tbl.section = attach_info->section; +#endif + + EM_DEBUG_LOG("attachment_count [%d]", attachment_count); + + if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_add_attachment failed : [%d]", err); + goto FINISH_OFF; + } + } + +FINISH_OFF: + + if (output_attachment_count) + *output_attachment_count = attachment_count - inline_attachment_count; + + if (output_total_attachment_size) + *output_total_attachment_size = total_attach_size; + + EM_DEBUG_FUNC_END("err : [%d]", err); + return err; +} #define UID_RANGE_STRING_LENGTH 3000 #define TEMP_STRING_LENGTH 50 @@ -2712,6 +2890,10 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou /* HTML Content found */ + if(!start_header) { /*prevent 27448*/ + EM_DEBUG_EXCEPTION("start_header NULL"); + return false; + } txt_html = start_header; txt_html = strstr(txt_html, CRLF_STRING CRLF_STRING); @@ -2742,7 +2924,7 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou else end = strstr(txt_html, multipart_boundary); - memset(multipart_boundary, 0, strlen(multipart_boundary)); + memset(multipart_boundary, 0, EM_SAFE_STRLEN(multipart_boundary)); EM_DEBUG_LOG("end [%p], txt_html [%p]", end, txt_html); @@ -2772,9 +2954,9 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou if (iEncodingHeader == 1){ enc_type = ENCOTHER; - if (strncasecmp(Encoding, "base64", strlen("base64")) == 0) + if (strncasecmp(Encoding, "base64", EM_SAFE_STRLEN("base64")) == 0) enc_type = ENCBASE64; - else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0) + else if (strncasecmp(Encoding, "quoted-printable", EM_SAFE_STRLEN("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); @@ -2784,20 +2966,20 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0) EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); } - else if (start_header && ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) != NULL) && !(temp_enc1 && temp_enc1 >= end)){ + else if ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) && (temp_enc1 < end)){ /*prevent 27448*/ if (temp_enc1) start_header = temp_enc1; - start_header += strlen("Content-Transfer-Encoding:"); + start_header += EM_SAFE_STRLEN("Content-Transfer-Encoding:"); start_header = em_skip_whitespace_without_strdup(start_header); if (!start_header) EM_DEBUG_EXCEPTION(" Invalid parsing "); else{ enc_type = ENCOTHER; - if (strncasecmp(start_header, "base64", strlen("base64")) == 0) + if (strncasecmp(start_header, "base64", EM_SAFE_STRLEN("base64")) == 0) enc_type = ENCBASE64; - else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0) + else if (strncasecmp(start_header, "quoted-printable", EM_SAFE_STRLEN("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); @@ -2863,16 +3045,19 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c } /* Plain text content found */ - + if(!start_header) { /*prevent 27450*/ + EM_DEBUG_EXCEPTION("start_header NULL"); + return false; + } txt_plain = start_header; txt_plain = strstr(txt_plain, CRLF_STRING CRLF_STRING); if (txt_plain != NULL){ - txt_plain += strlen(CRLF_STRING CRLF_STRING); /* txt_plain points at plain text content */ + txt_plain += EM_SAFE_STRLEN(CRLF_STRING CRLF_STRING); /* txt_plain points at plain text content */ /* Fix is done for mail having "Content-Type: text/plain" but there is no content but having only attachment. */ - strcmpret = strncmp(txt_plain, boundary_string, strlen(boundary_string)); + strcmpret = strncmp(txt_plain, boundary_string, EM_SAFE_STRLEN(boundary_string)); if (strcmpret == 0){ } else{ @@ -2897,9 +3082,9 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c if (iEncodingHeader == 1){ enc_type = ENCOTHER; - if (strncasecmp(Encoding, "base64", strlen("base64")) == 0) + if (strncasecmp(Encoding, "base64", EM_SAFE_STRLEN("base64")) == 0) enc_type = ENCBASE64; - else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0) + else if (strncasecmp(Encoding, "quoted-printable", EM_SAFE_STRLEN("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); @@ -2913,16 +3098,16 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c if (temp_enc1) start_header = temp_enc1; - start_header += strlen("Content-Transfer-Encoding:"); + start_header += EM_SAFE_STRLEN("Content-Transfer-Encoding:"); start_header = em_skip_whitespace_without_strdup(start_header); if (!start_header) EM_DEBUG_EXCEPTION(" Invalid parsing "); else{ enc_type = ENCOTHER; - if (strncasecmp(start_header, "base64", strlen("base64")) == 0) + if (strncasecmp(start_header, "base64", EM_SAFE_STRLEN("base64")) == 0) enc_type = ENCBASE64; - else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0) + else if (strncasecmp(start_header, "quoted-printable", EM_SAFE_STRLEN("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); @@ -2951,9 +3136,33 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c /* Content-Type: IMAGE/octet-stream; name = Default.png */ /* Content-Transfer-Encoding: BASE64 */ -/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@org.tizen.email> */ +/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@org.tizen.slp.email> */ /* Content-Disposition: inline; filename = Default.png */ +static void emcore_free_email_image_data(email_image_data **image_data, int count) +{ + EM_DEBUG_FUNC_BEGIN("image_data : [%p], count : [%d]", image_data, count); + + if ((image_data == NULL) || (*image_data == NULL) || (count <= 0)) { + EM_DEBUG_EXCEPTION("Invalid paramter"); + return; + } + + email_image_data *p = *image_data; + int i = 0; + + for (i = 0; i < count; i++) { + EM_SAFE_FREE(p[i].text_image); + EM_SAFE_FREE(p[i].content_id); + EM_SAFE_FREE(p[i].mime_type); + } + + EM_SAFE_FREE(p); + *image_data = NULL; + + EM_DEBUG_FUNC_END(); +} + 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(); @@ -3017,6 +3226,12 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c char *decoded_filename = NULL; memset(image_data[i].image_file_name, 0, 100); + + if(!start_header) { /*prevent 27449*/ + EM_DEBUG_EXCEPTION("start_header NULL"); + return false; + } + txt_image = start_header; temp_image = start_header; @@ -3081,24 +3296,24 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c end = txt_image + body_size - (txt_image-bufsendforparse); } else{ - boundarylen = strlen(boundary_string); + boundarylen = EM_SAFE_STRLEN(boundary_string); end -= 2; } - if (start_header && ((temp_enc1 = (char *)strcasestr((const char *)start_header, "Content-transfer-encoding:")) != NULL)){ + if ((temp_enc1 = (char *)strcasestr((const char *)start_header, "Content-transfer-encoding:")) != NULL){ /*prevent 27449*/ if (temp_enc1) start_header = temp_enc1; - start_header += strlen("Content-Transfer-Encoding:"); + start_header += EM_SAFE_STRLEN("Content-Transfer-Encoding:"); start_header = em_skip_whitespace_without_strdup(start_header); if (!start_header) EM_DEBUG_EXCEPTION(" Invalid parsing "); else{ enc_type = ENCOTHER; - if (strncasecmp(start_header, "base64", strlen("base64")) == 0) + if (strncasecmp(start_header, "base64", EM_SAFE_STRLEN("base64")) == 0) enc_type = ENCBASE64; - else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0) + else if (strncasecmp(start_header, "quoted-printable", EM_SAFE_STRLEN("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); @@ -3196,6 +3411,169 @@ FINISH_OFF: return ret; } +static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_content_info *cnt_info, int encoding_type, char **output_text_plain, char **output_text_html, email_image_data **output_image_data) +{ + EM_DEBUG_FUNC_BEGIN("body_str:[%p], cnt_info:[%p], encoding_type:[%d]", body_str, cnt_info, encoding_type); + int err = EMAIL_ERROR_NONE; + + if (!body_str || strlen(body_str) == 0 || !cnt_info) { + EM_DEBUG_EXCEPTION("Invalid paramter"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + int dec_len = 0; + int no_alternative_part_flag = 0; + int no_html = 0; + char *boundary_start = NULL; + char *boundary_end = NULL; + char *boundary_string = NULL; + char *p_body_str = NULL; + char *start_header = NULL; + char *text_plain = NULL; + char *text_html = NULL; + email_image_data *image_data = NULL; + + char *temp_alternative_plain_header = NULL; + char *temp_content_type = NULL; + + p_body_str = EM_SAFE_STRDUP(body_str); + + text_plain = em_malloc(body_size + 1); + text_html = em_malloc(body_size + 1); + + if (!text_plain || !text_html) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + if (!strcasestr(p_body_str, "Content-Type: ") && (cnt_info->text.plain || cnt_info->text.html)) { + /* Encoded Content-Type: text/html or Content-Type: text/plain */ + /* No Partial body has No headers with Content-Type: text/html or Content-Type: text/plain */ + + EM_DEBUG_LOG("mbody->encoding [%d] ", encoding_type); + + if (emcore_decode_body_text(p_body_str, EM_SAFE_STRLEN(p_body_str), encoding_type, &dec_len, &err) < 0) { + EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); + goto FINISH_OFF; + } + + EM_DEBUG_LOG("Decoded length [%d]", dec_len); + + if (dec_len > 0) { + if (cnt_info->text.plain) { + memcpy(text_plain, p_body_str, dec_len); + } + + if (cnt_info->text.html) { + memcpy(text_html, p_body_str, dec_len); + } + } + } else { /* Partial body has headers with Content-Type: text/html or Content-Type: text/plain */ + no_alternative_part_flag = 0; + if (((temp_alternative_plain_header = (char *)strcasestr(p_body_str, "Content-type: multipart/alternative")) != NULL)) { /* Found 'alternative' */ + if (((temp_content_type = (char *)strcasestr(p_body_str, "Content-type: text/plain")) != NULL)) { + if (temp_content_type < temp_alternative_plain_header) { + /* This part is text/plain not alternative. */ + no_html = 1; + no_alternative_part_flag = 1; + } else { + EM_DEBUG_LOG(" Content-type: multipart/alternative "); + boundary_start = strstr(temp_alternative_plain_header, "--") + strlen("--"); + boundary_end = strcasestr(boundary_start, "Content-type:"); + + boundary_string = em_malloc(boundary_end - boundary_start); + 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); + } + } + } else + no_alternative_part_flag = 1; + + if (no_alternative_part_flag) { + boundary_start = strstr(p_body_str, "--") + strlen("--"); + boundary_end = strcasestr(boundary_start, "Content-type:"); + + boundary_string = em_malloc(boundary_end - boundary_start); + 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); + } + + if (boundary_string != NULL) { + EM_DEBUG_LOG("boundary_string : [%s]", boundary_string); + + if (((start_header = (char *)strcasestr(boundary_end, "Content-Type: text/html")) != NULL) && (no_html != 1) &&(((char *)strcasestr(boundary_end, "Content-Type: message/rfc822")) == NULL) && + (((char *)strcasestr(boundary_end, "Content-Type: text/rfc822-headers")) == NULL)) + emcore_parse_html_part_for_partial_body(start_header, boundary_string, p_body_str, text_html, body_size); + + if (((start_header = (char *)strcasestr(boundary_end, "Content-Type: text/plain")) != NULL)) { + char *internal_boundary_string = NULL; + + if(!emcore_find_boundary_string_of_the_part(p_body_str, start_header, &internal_boundary_string, &err)) { + EM_DEBUG_EXCEPTION("internal_boundary_string failed [%d]", err); + } + + if(!internal_boundary_string) + internal_boundary_string = EM_SAFE_STRDUP(boundary_string); + + emcore_parse_plain_part_for_partial_body(boundary_end, start_header, internal_boundary_string, p_body_str, text_plain, body_size); + EM_SAFE_FREE(internal_boundary_string); + } + + if (((start_header = (char *)strcasestr((const char *)boundary_end, "Content-type: image/jpeg")) != (char *)NULL) || + ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/jpg")) != (char *)NULL) || + ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/gif")) != (char *)NULL) || + ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/bmp")) != (char *)NULL) || + ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/png")) != (char *)NULL)) { + image_data = em_malloc(sizeof(email_image_data) * IMAGE_DISPLAY_PARTIAL_BODY_COUNT); + if (image_data == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + emcore_parse_image_part_for_partial_body(boundary_end, start_header, boundary_string, p_body_str, image_data, body_size); + } + } + } + +FINISH_OFF: + + EM_SAFE_FREE(p_body_str); + EM_SAFE_FREE(boundary_string); + + if (err != EMAIL_ERROR_NONE) { + EM_SAFE_FREE(text_plain); + EM_SAFE_FREE(text_html); + + if (image_data) + emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT); + } else { + if (output_text_plain) + *output_text_plain = text_plain; + + if (output_text_html) + *output_text_html = text_html; + + if (output_image_data) + *output_image_data = image_data; + } + + EM_DEBUG_FUNC_END("err : [%d]", err); + return err; +} + #define TAG_LENGTH 16 #define COMMAND_LENGTH 2000 static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error) @@ -3203,41 +3581,28 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i EM_DEBUG_FUNC_BEGIN("stream [%p], input_download_size[%d], pbd_event [%p], item_count [%d], error [%p]", stream, input_download_size, pbd_event, item_count, error); int ret = false, err = EMAIL_ERROR_NONE; - int encoding = 0; - int j = 0; - int i32_index = 0, temp_string_index = 0; - int no_alternative_part_flag = 0; - int dec_len = 0, response_buffer_length = 0, image_length = 0, tempmailparselen = 0; - int temp_count = 0, total_mail_size = 0, attachment_num, body_size = 0, total_mail_size_except_attach = 0; - int total_parsed_len_per_uid = 0, total_parsed_len = 0; + int j = 0, i = 0; + int i32_index = 0; + int total_mail_size = 0, total_attachment_size = 0; + int temp_count = 0, attachment_num = 0; unsigned long uidno = 0; char buf[512] = {0, }; char *text_plain = NULL; char *text_html = NULL; - char *temp_text_buf = NULL; char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0, }; char imap_tag[TAG_LENGTH] = {0, }; char command[COMMAND_LENGTH] = {0, }; - char *p = NULL, *s = NULL, *decoded_text_buffer = NULL; - char *response_buffer = NULL; - char *bufsendforparse = NULL; - char *start_header = NULL; - char *boundary_string = NULL; - char *temp_content_type1 = NULL; char *temp_data_html = NULL; - char *bodystructure_start = NULL, *bodystructure_end = NULL, *body_structure_string = NULL, *modified_body_structure_string = NULL; - char *plain_text_file_name_from_content_info = NULL, *html_text_file_name_from_content_info = NULL, *plain_charset_from_content_info = NULL; - char temp_string[TEMP_STRING_LENGTH] = {0, }; + char uid_string[TEMP_STRING_LENGTH] = {0, }; IMAPLOCAL *imaplocal = NULL; IMAPPARSEDREPLY *reply_from_server = NULL; emstorage_mail_tbl_t *mail = NULL; email_partial_buffer *imap_response = NULL; BODY *body = NULL; struct _m_content_info *cnt_info = NULL; - struct attachment_info *attach_info = NULL; emstorage_attachment_tbl_t attachment_tbl; email_event_partial_body_thd *stSectionNo = NULL; - email_image_data image_data[IMAGE_DISPLAY_PARTIAL_BODY_COUNT]; + email_image_data *image_data = NULL; if (!(stream) || !(imaplocal = stream->local) || !imaplocal->netstream || !pbd_event) { EM_DEBUG_EXCEPTION("invalid parameter"); @@ -3246,21 +3611,6 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i return ret; } - text_plain = em_malloc(sizeof(char) * (input_download_size + 1)); - text_html = em_malloc(sizeof(char) * (input_download_size + 1)); - temp_text_buf = em_malloc(sizeof(char) * (input_download_size + 1)); - - if(!text_plain || !text_plain || !temp_text_buf) { - EM_SAFE_FREE(text_plain); - EM_SAFE_FREE(text_html); - EM_SAFE_FREE(temp_text_buf); - - EM_DEBUG_EXCEPTION("em_malloc failed"); - return EMAIL_ERROR_OUT_OF_MEMORY; - } - - memset(image_data, 0x00 , sizeof(email_image_data) * IMAGE_DISPLAY_PARTIAL_BODY_COUNT); - EM_DEBUG_LOG("Start of emcore_get_section_for_partial_download, item_count = %d ", item_count); /* For constructing UID list which is having 10 UID or less at a time */ @@ -3286,550 +3636,205 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i EM_DEBUG_LOG("command : %s", command); /* Sending out the IMAP request */ - if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) { + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } /* responce from the server */ - imap_response = emcore_get_response_from_server(imaplocal->netstream, imap_tag, &reply_from_server, input_download_size); + imap_response = emcore_get_response_from_server(imaplocal->netstream, imap_tag, &reply_from_server, input_download_size, item_count); if (!imap_response || !reply_from_server ){ EM_DEBUG_EXCEPTION(" Invalid response from emcore_get_response_from_server"); goto FINISH_OFF; } - if (!imap_response->buffer || imap_response->buflen == 0){ - EM_DEBUG_EXCEPTION(" NULL partial BODY Content "); - goto FINISH_OFF; - } - EM_DEBUG_LOG("imap_response->buffer [%s]",imap_response->buffer); - response_buffer = imap_response->buffer; - response_buffer_length = imap_response->buflen; + for (i = 0; i < item_count ; i++) { + total_mail_size = 0; + total_attachment_size = 0; + attachment_num = 0; + uidno = 0; - while (response_buffer && (bodystructure_start = strstr(response_buffer, "BODYSTRUCTURE (")) != NULL){ - /* if it has BODYSTRUCTURE */ - EM_DEBUG_LOG("response_buffer [%s]",response_buffer); - bodystructure_start = bodystructure_start + strlen("BODYSTRUCTURE"); - bodystructure_end = strstr(bodystructure_start, "BODY["); - - if (bodystructure_end != NULL) { - int bodystructure_length = bodystructure_end - bodystructure_start; - - EM_DEBUG_LOG("bodystructure_length [%d]", bodystructure_length); - - if (bodystructure_length > response_buffer_length){ - EM_DEBUG_EXCEPTION("bodystructure_length[%d] is longer than response_buffer_length[%d]", bodystructure_length, response_buffer_length); - err = EMAIL_ERROR_INVALID_RESPONSE; - goto FINISH_OFF; - } - - body_structure_string = (char *)em_malloc(sizeof(char) * bodystructure_length + 1); + if ((err = emcore_parse_bodystructure(stream, reply_from_server, imap_response[i].header, &body, &cnt_info, &total_mail_size, &uidno)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_parse_bodystructure failed : [%d]", err); + goto FINISH_OFF; + } - if (NULL == body_structure_string){ - EM_DEBUG_EXCEPTION("em_malloc failed...!"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + /* Search the account id of pbd_event */ + for (temp_count = 0; temp_count <= item_count && pbd_event[temp_count].server_mail_id != uidno; temp_count++) + continue; + + if (temp_count > item_count) { + EM_DEBUG_EXCEPTION("Can't find proper server_mail_id"); + goto FINISH_OFF; + } - memcpy(body_structure_string, bodystructure_start, bodystructure_length); + /* Start to parse the body */ + EM_DEBUG_LOG("Start partial body"); - body = mail_newbody(); - - if (NULL == body){ - EM_DEBUG_EXCEPTION("New body creation failed...!"); - EM_SAFE_FREE(body_structure_string); + /* Check the body download status and body size */ + SNPRINTF(uid_string, sizeof(uid_string), "%ld", uidno); + if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].account_id, uid_string, &mail, true, &err) || !mail) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err); + if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail) goto FINISH_OFF; - } + } - /* Parse body_structure_string to BODY */ - EM_DEBUG_LOG("body_structure_string [%s]", body_structure_string); - /* body_structure_string modified */ - modified_body_structure_string = em_replace_string(body_structure_string, "}\r\n", "} "); - if (modified_body_structure_string != NULL) { - EM_SAFE_STRNCPY(body_structure_string, modified_body_structure_string, strlen(modified_body_structure_string)); - EM_DEBUG_LOG("modified_body_structure_string [%s]", modified_body_structure_string); - EM_SAFE_FREE(modified_body_structure_string); - } - imap_parse_body_structure (stream, body, (unsigned char **)&body_structure_string, reply_from_server); - - total_mail_size = 0; + if (mail->body_download_status == EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + EM_DEBUG_LOG("Downloaded mail"); + continue; + } - if (emcore_set_fetch_body_section(body, true, &total_mail_size, &err) < 0) { - EM_DEBUG_EXCEPTION("emcore_set_fetch_body_section failed - %d", err); - goto FINISH_OFF; - } - - if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) { - EM_DEBUG_EXCEPTION("em_malloc failed..."); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + /* Update the attachment info except inline attachment */ + if ((err = emcore_update_attachment_except_inline(cnt_info, pbd_event[temp_count].account_id, mail->mail_id, pbd_event[temp_count].mailbox_id, &total_attachment_size, &attachment_num)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err); + goto FINISH_OFF; + } - /* getting content info from body */ - - if (emcore_get_body(stream, 0, 0, 0, body, cnt_info, &err) < 0 || !cnt_info) { - EM_DEBUG_EXCEPTION("emcore_get_body falied [%d]", err); - err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; - goto FINISH_OFF; - } + EM_DEBUG_LOG("total_mail_size:[%d], total_attachment_size:[%d], attachment_num:[%d]", total_mail_size, total_attachment_size, attachment_num); + mail->mail_size = total_mail_size; + mail->attachment_count = attachment_num; - EM_DEBUG_LOG("Start parsing partial body..."); - - int no_html = 0; - char *temp_alternative_plain_header = NULL; - - p = (char *)strstr(response_buffer, "> {"); - if (p != NULL){ - EM_DEBUG_LOG("Getting the body size"); - p += strlen("> {"); - s = p; + if (imap_response[i].body_len == 0) { + EM_DEBUG_LOG("BODY size is zero"); + continue; + } - temp_string_index = 0; - memset(temp_string, 0, TEMP_STRING_LENGTH); - - while (isdigit(*s) && temp_string_index < TEMP_STRING_LENGTH){ - memcpy(temp_string + temp_string_index, s, 1); /* ! */ - s++; - temp_string_index++; - } - - body_size = atoi(temp_string); - if (body_size >= input_download_size) - body_size = input_download_size + 2; - EM_DEBUG_LOG("body_size [%d]", body_size); - } - else{ - body_size = 0; - EM_DEBUG_EXCEPTION("Can't find body size from MIME header"); - /* err = EMAIL_ERROR_INVALID_RESPONSE; */ - /* goto FINISH_OFF; */ - } - - /* Find data line : 2 is CRLF, 1 is } */ - EM_DEBUG_LOG("temp_string_index : [%d]", temp_string_index); - tempmailparselen = (p - response_buffer) + temp_string_index + 2 + 1; + if ((err = emcore_parse_body_for_imap(imap_response[i].body, imap_response[i].body_len, cnt_info, body->encoding, &text_plain, &text_html, &image_data)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_parse_body_for_imap failed"); + goto FINISH_OFF; + } - if (imap_response->buflen < (total_parsed_len + body_size)){ - err = EMAIL_ERROR_CONNECTION_BROKEN; - EM_DEBUG_EXCEPTION("EMAIL_ERROR_CONNECTION_BROKEN : imap_response->buflen [%d], total_parsed_len [%d], body_size [%d]", imap_response->buflen, total_parsed_len, body_size); - goto FINISH_OFF; - } - else { - if ((p = strstr(response_buffer, "UID "))) { - EM_DEBUG_LOG("getting the UID number"); - p += strlen("UID "); - s = p; - - temp_string_index = 0; - memset(temp_string, 0, TEMP_STRING_LENGTH); + memset(buf, 0x00, sizeof(buf)); - while (isdigit(*s) && temp_string_index < TEMP_STRING_LENGTH){ - memcpy(temp_string + temp_string_index, s, 1); - s++; - temp_string_index++; - } - - uidno = strtoul(temp_string, NULL, 0); - EM_DEBUG_LOG("UID [%d]", uidno); - - for (temp_count = 0; temp_count < BULK_PARTIAL_BODY_DOWNLOAD_COUNT && - pbd_event[temp_count].server_mail_id != uidno && temp_count != item_count; temp_count++) - continue; + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - if (temp_count >= BULK_PARTIAL_BODY_DOWNLOAD_COUNT){ - EM_DEBUG_EXCEPTION("Can't find proper server_mail_id"); - goto FINISH_OFF; - } + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : "UTF-8", buf, &err)) + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - EM_SAFE_FREE(plain_text_file_name_from_content_info); - EM_SAFE_FREE(html_text_file_name_from_content_info); - EM_SAFE_FREE(plain_charset_from_content_info); + if (!emstorage_create_file(text_plain, EM_SAFE_STRLEN(text_plain), buf, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - /* partial_body_complete = -1; */ /* Meaningless */ - /* encoding = -1; */ /* Meaningless */ - - plain_text_file_name_from_content_info = EM_SAFE_STRDUP(cnt_info->text.plain); - html_text_file_name_from_content_info = EM_SAFE_STRDUP(cnt_info->text.html); - plain_charset_from_content_info = EM_SAFE_STRDUP(cnt_info->text.plain_charset); + mail->file_path_plain = EM_SAFE_STRDUP(buf); + EM_DEBUG_LOG("mail->file_path_plain [%s]", mail->file_path_plain); - EM_DEBUG_LOG("plain_text_file_name_from_content_info [%s]", plain_text_file_name_from_content_info); - EM_DEBUG_LOG("html_text_file_name_from_content_info [%s]", html_text_file_name_from_content_info); - EM_DEBUG_LOG("plain_charset_from_content_info [%s]", plain_charset_from_content_info); + if (image_data != NULL && image_data[0].text_image != NULL && image_data[0].text_image[0] != NULL_CHAR) { + char *result_string_of_replcaing = NULL; + int store_file = 0; + int content_index = 0; - encoding = body->encoding; - - if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].account_id, temp_string, &mail , true, &err) || !mail){ - EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid failed [%d]", err); - if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail) - goto FINISH_OFF; - } - - /* Assign calculated mail size */ - mail->mail_size = total_mail_size; - total_mail_size_except_attach = total_mail_size; - - /* Update attachment details except inline content */ - if (cnt_info->file && cnt_info->file->name){ - memset(&attachment_tbl, 0x00, sizeof(email_attachment_data_t)); - - attachment_tbl.account_id = pbd_event[temp_count].account_id; - attachment_tbl.mail_id = mail->mail_id; - attachment_tbl.mailbox_id = pbd_event[temp_count].mailbox_id; - attachment_tbl.attachment_save_status = 0; - - for (attachment_num = 1, attach_info = cnt_info->file; attach_info; attach_info = attach_info->next, attachment_num++) { - total_mail_size_except_attach -= attach_info->size; - attachment_tbl.attachment_size = attach_info->size; - attachment_tbl.attachment_path = attach_info->save; - attachment_tbl.attachment_name = attach_info->name; - attachment_tbl.attachment_drm_type = attach_info->drm; - attachment_tbl.attachment_inline_content_status = (attach_info->type == 1) ? 1 : 0; - attachment_tbl.attachment_mime_type = attach_info->attachment_mime_type; -#ifdef __ATTACHMENT_OPTI__ - attachment_tbl.encoding = attach_info->encoding; - attachment_tbl.section = attach_info->section; -#endif - - if (attach_info->type == 1) { - EM_DEBUG_LOG("Breaking attachment_num [%d] attach_info->type [%d]", attachment_num, attach_info->type); - break; /* Inline images at end of list not to be added */ - } - - EM_DEBUG_LOG("attach_info->type != 1 [%d]", attachment_num); - - mail->attachment_count++; - if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err); - - goto FINISH_OFF; - } - - } - } - - emcore_free_content_info(cnt_info); - cnt_info = NULL; - - mail_free_body(&body); - body = NULL; - - } - - /* Removed the response header and send the buffer for parsing */ - response_buffer = response_buffer + tempmailparselen; - response_buffer_length = response_buffer_length - tempmailparselen; + temp_data_html = em_malloc(imap_response[i].body_len + 1); + if(!temp_data_html) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - bufsendforparse = em_malloc(body_size + 1); /* old */ - /* bufsendforparse = em_malloc(response_buffer_length + 1); */ /* new */ + memset(buf, 0x00, sizeof(buf)); + if (text_html != NULL) + memcpy(temp_data_html, text_html, EM_SAFE_STRLEN(text_html)); + /* EM_SAFE_STRNCPY(temp_data_html, text_html, text_html); */ - EM_DEBUG_LOG("body_size [%d], response_buffer_length [%d]", body_size, response_buffer_length); + do { + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - if (bufsendforparse == NULL){ - EM_DEBUG_EXCEPTION("Allocation for bufsendforparse failed."); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - memcpy(bufsendforparse, response_buffer, body_size); /* old */ - bufsendforparse[body_size] = NULL_CHAR; /* old */ - /* EM_SAFE_STRNCPY(bufsendforparse, response_buffer, response_buffer_length);*/ /* new */ - /* bufsendforparse[response_buffer_length] = '\0'; */ /* new */ - - if (strlen(bufsendforparse) == 0) - EM_DEBUG_EXCEPTION(" NULL partial BODY Content "); + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, image_data[store_file].image_file_name, buf, &err)) + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - EM_DEBUG_LOG("string bufendforparse :[%s]", bufsendforparse); - p = bufsendforparse; - - if (mail && mail->body_download_status == EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) /* No need to save */ - goto NEXTUIDPARSING; + if (!emstorage_create_file(image_data[store_file].text_image, image_data[store_file].dec_len, buf, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - if (!strcasestr(p, "Content-Type: text/plain") && !strcasestr(p, "Content-Type: text/html") && !strcasestr(p, "Content-type: image/jpeg") - && !strcasestr(p, "Content-Type: image/gif") && !strcasestr(p, "Content-Type: image/bmp")&&(plain_text_file_name_from_content_info || html_text_file_name_from_content_info)){ - /* Encoded Content-Type: text/html or Content-Type: text/plain */ - /* No Partial body has No headers with Content-Type: text/html or Content-Type: text/plain */ - - EM_DEBUG_LOG("plain_text_file_name_from_content_info [%p] html_text_file_name_from_content_info[%p] ", plain_text_file_name_from_content_info, html_text_file_name_from_content_info); - EM_DEBUG_LOG("mbody->encoding [%d] ", encoding); - - if (emcore_decode_body_text(p, strlen(p), encoding , &dec_len, &err) < 0) { - EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); - goto FINISH_OFF; - } - - decoded_text_buffer = p; - - EM_DEBUG_LOG("Decoded length [%d]", dec_len); - /* EM_DEBUG_LOG("p - %s", p); */ - - if (dec_len > 0){ - if (plain_text_file_name_from_content_info){ - EM_DEBUG_LOG(" plain_text_file_name_from_content_info [%s]", plain_text_file_name_from_content_info); - memcpy(text_plain, decoded_text_buffer, dec_len); - /* EM_DEBUG_LOG(" Content-Type : text/plain [%s]", text_plain); */ - } - - if (html_text_file_name_from_content_info){ - EM_DEBUG_LOG("html_text_file_name_from_content_info [%s]", html_text_file_name_from_content_info); - memcpy(text_html, decoded_text_buffer, dec_len); - /* EM_DEBUG_LOG(" Content-Type: text/html [%s]", text_html); */ - } - } + if (mail->body_download_status != EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED){ + memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); + attachment_tbl.mail_id = mail->mail_id; + attachment_tbl.account_id = pbd_event[temp_count].account_id; + attachment_tbl.mailbox_id = pbd_event[temp_count].mailbox_id; + attachment_tbl.attachment_name = image_data[store_file].image_file_name; + attachment_tbl.attachment_size = image_data[store_file].dec_len; + attachment_tbl.attachment_path = buf; + attachment_tbl.attachment_save_status = 1; + attachment_tbl.attachment_inline_content_status = 1; /* set to 1 for inline image */ + attachment_tbl.attachment_mime_type = image_data[store_file].mime_type; + mail->attachment_count++; + mail->inline_content_count++; + if (!emstorage_add_attachment (&attachment_tbl, false, false, &err)) + EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); } - else{ /* Partial body has headers with Content-Type: text/html or Content-Type: text/plain */ - no_alternative_part_flag = 0; - if (((temp_alternative_plain_header = (char *)strcasestr(p, "Content-type: multipart/alternative")) != NULL)) { /* Found 'alternative' */ - if (((temp_content_type1 = (char *)strcasestr(p, "Content-type: text/plain")) != NULL)) { - if (temp_content_type1 < temp_alternative_plain_header) /* This part is text/plain not alternative. */ - no_html = 1; - no_alternative_part_flag = 1; - } - else{ - EM_DEBUG_LOG(" Content-type: multipart/alternative "); - p = strstr(bufsendforparse, CRLF_STRING CRLF_STRING); - - if (p == NULL) - EM_DEBUG_EXCEPTION(" Incorrect parsing "); - else{ - p += strlen(CRLF_STRING CRLF_STRING); - boundary_string = p; - if (boundary_string[0] == CR){ - EM_DEBUG_EXCEPTION(" Incorrect Body structure "); - goto NEXTUIDPARSING; - } - - p = strstr(p, CRLF_STRING); - - if (p == NULL) - EM_DEBUG_EXCEPTION(" Invalid parsing "); - } - } - } - else - no_alternative_part_flag = 1; - - if (no_alternative_part_flag){ - p = strstr(bufsendforparse, "--"); - - boundary_string = p; - if (boundary_string == NULL){ - EM_DEBUG_EXCEPTION("Should not have come here "); - goto NEXTUIDPARSING; - } - - if (boundary_string[0] == CR){ - EM_DEBUG_EXCEPTION(" Incorrect Body structure "); - goto NEXTUIDPARSING; - } - - p = strstr(p, CRLF_STRING); - if (p == NULL) - EM_DEBUG_EXCEPTION(" Invalid parsing "); - } - - /* EM_DEBUG_LOG("p[%s]", p); */ - - if (p != NULL){ - *p = NULL_CHAR; /* Boundary value set */ - EM_DEBUG_LOG("Boundary value [%s]", boundary_string); - p += 2; /* p points to content after boundary_string */ + + store_file++; + } while (image_data[store_file].text_image != NULL && image_data[store_file].text_image[0] != NULL_CHAR && (store_file < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)); - if (((start_header = (char *)strcasestr(p, "Content-Type: text/html")) != NULL) && (no_html != 1) &&(((char *)strcasestr(p, "Content-Type: message/rfc822")) == NULL) && - (((char *)strcasestr(p, "Content-Type: text/rfc822-headers")) == NULL)) - emcore_parse_html_part_for_partial_body(start_header, boundary_string, bufsendforparse, text_html, body_size); - - if (((start_header = (char *)strcasestr(p, "Content-Type: text/plain")) != NULL)) { - char *internal_boundary_string = NULL; - if(!emcore_find_boundary_string_of_the_part(bufsendforparse, start_header, &internal_boundary_string, &err)) { - EM_DEBUG_EXCEPTION("internal_boundary_string failed [%d]", err); - } - - if(!internal_boundary_string) - internal_boundary_string = EM_SAFE_STRDUP(boundary_string); - - emcore_parse_plain_part_for_partial_body(p, start_header, internal_boundary_string, bufsendforparse, text_plain, body_size); - EM_SAFE_FREE(internal_boundary_string); - } + while (image_data[content_index].text_image != NULL && image_data[content_index].text_image[0] != NULL_CHAR && + image_data[content_index].content_id && image_data[content_index].content_id[0] != NULL_CHAR && (content_index < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)){ /* Finding CID in HTML and replacing with image name. */ + result_string_of_replcaing = em_replace_string((char *)temp_data_html, (char *)image_data[content_index].content_id, (char *)image_data[content_index].image_file_name); + + EM_SAFE_STRNCPY(temp_data_html, result_string_of_replcaing, EM_SAFE_STRLEN(result_string_of_replcaing)); + EM_SAFE_FREE(result_string_of_replcaing); - if (((start_header = (char *)strcasestr((const char *)p, "Content-type: image/jpeg")) != (char *)NULL) || - ((start_header = (char *)strcasestr((const char *)p, "Content-Type: image/jpg")) != (char *)NULL) || - ((start_header = (char *)strcasestr((const char *)p, "Content-Type: image/gif")) != (char *)NULL) || - ((start_header = (char *)strcasestr((const char *)p, "Content-Type: image/bmp")) != (char *)NULL) || - ((start_header = (char *)strcasestr((const char *)p, "Content-Type: image/png")) != (char *)NULL)) - emcore_parse_image_part_for_partial_body(p, start_header, boundary_string, bufsendforparse, image_data, body_size); - } - } + if (strstr(temp_data_html, image_data[content_index].content_id) != NULL) + continue; /* Replace content id on HTML with same file name one more time. */ - /* Updating mail information */ - memset(buf, 0x00, sizeof(buf)); + content_index++; + } - if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) - EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - - if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, - plain_charset_from_content_info ? plain_charset_from_content_info : "UTF-8", buf, &err)) - EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - - if (!emstorage_create_file(text_plain, strlen(text_plain), buf, &err)) - EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - - mail->file_path_plain = EM_SAFE_STRDUP(buf); - EM_DEBUG_LOG("mail->file_path_plain [%s]", mail->file_path_plain); - - if (image_data[0].text_image != NULL && image_data[0].text_image[0] != NULL_CHAR){ - char *result_string_of_replcaing = NULL; - int store_file = 0; - int content_index = 0; - - temp_data_html = em_malloc(sizeof(char) * (input_download_size + 1)); - - if(!temp_data_html) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - memset(buf, 0x00, sizeof(buf)); - if (text_html[0] != NULL_CHAR) - memcpy(temp_data_html, text_html, strlen(text_html)); - /* EM_SAFE_STRNCPY(temp_data_html, text_html, text_html); */ + memset(text_html, 0, imap_response[i].body_len + 1); - do { - if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) - EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - - if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, image_data[store_file].image_file_name, buf, &err)) - EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - - if (!emstorage_create_file(image_data[store_file].text_image, image_data[store_file].dec_len, buf, &err)) - EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - - if (mail->body_download_status != EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED){ - memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); - attachment_tbl.mail_id = mail->mail_id; - attachment_tbl.account_id = pbd_event[temp_count].account_id; - attachment_tbl.mailbox_id = pbd_event[temp_count].mailbox_id; - attachment_tbl.attachment_name = image_data[store_file].image_file_name; - attachment_tbl.attachment_size = image_data[store_file].dec_len; - attachment_tbl.attachment_path = buf; - attachment_tbl.attachment_save_status = 1; - attachment_tbl.attachment_inline_content_status = 1; /* set to 1 for inline image */ - attachment_tbl.attachment_mime_type = image_data[store_file].mime_type; - mail->attachment_count++; - mail->inline_content_count++; - if (!emstorage_add_attachment (&attachment_tbl, false, false, &err)) - EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); - } - - store_file++; - } while (image_data[store_file].text_image != NULL && image_data[store_file].text_image[0] != NULL_CHAR && (store_file < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)); - - while (image_data[content_index].text_image != NULL && image_data[content_index].text_image[0] != NULL_CHAR && - image_data[content_index].content_id && image_data[content_index].content_id[0] != NULL_CHAR && (content_index < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)){ /* Finding CID in HTML and replacing with image name. */ - result_string_of_replcaing = em_replace_string((char *)temp_data_html, (char *)image_data[content_index].content_id, (char *)image_data[content_index].image_file_name); - - EM_SAFE_STRNCPY(temp_data_html, result_string_of_replcaing, input_download_size); - EM_SAFE_FREE(result_string_of_replcaing); + if (temp_data_html != NULL) + memcpy(text_html, temp_data_html, EM_SAFE_STRLEN(temp_data_html)); - if (strstr(temp_data_html, image_data[content_index].content_id) != NULL) - continue; /* Replace content id on HTML with same file name one more time. */ - - EM_SAFE_FREE(image_data[content_index].content_id); - EM_SAFE_FREE(image_data[content_index].text_image); - EM_SAFE_FREE(image_data[content_index].mime_type); - memset(image_data[content_index].image_file_name, 0x00, 100); - image_data[content_index].dec_len = 0; - content_index++; - } - - image_length = 0; - memset(text_html, 0, (input_download_size + 1)); + EM_SAFE_FREE(temp_data_html); + } - if (temp_data_html[0] != NULL_CHAR) - memcpy(text_html, temp_data_html, strlen(temp_data_html)); - memset(temp_data_html, 0x00, (input_download_size + 1)); + if (EM_SAFE_STRLEN(text_html) > 0) { + memset(buf, 0x00, sizeof(buf)); + char html_body[MAX_CHARSET_VALUE] = {0x00, }; + if (cnt_info->text.plain_charset != NULL){ + if (EM_SAFE_STRLEN(cnt_info->text.plain_charset) < MAX_CHARSET_VALUE) + memcpy(html_body, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset)); + else + memcpy(html_body, "UTF-8", EM_SAFE_STRLEN("UTF-8")); + } + if (html_body[0] != NULL_CHAR) + strcat(html_body, HTML_EXTENSION_STRING); + else + memcpy(html_body, "UTF-8.htm", EM_SAFE_STRLEN("UTF-8.htm")); - EM_SAFE_FREE(temp_data_html); - } - - if (strlen(text_html) > 0){ - memset(buf, 0x00, sizeof(buf)); - char html_body[MAX_CHARSET_VALUE] = {0x00, }; - if (plain_charset_from_content_info != NULL){ - if (strlen(plain_charset_from_content_info) < MAX_CHARSET_VALUE) - memcpy(html_body, plain_charset_from_content_info, strlen(plain_charset_from_content_info)); - else - memcpy(html_body, "UTF-8", strlen("UTF-8")); - } - if (html_body[0] != NULL_CHAR) - strcat(html_body, HTML_EXTENSION_STRING); - else - memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm")); + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) - EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, html_body, buf, &err)) + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, html_body, buf, &err)) - EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + if (!emstorage_create_file(text_html, EM_SAFE_STRLEN(text_html), buf, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - if (!emstorage_create_file(text_html, strlen(text_html), buf, &err)) - EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); + mail->file_path_html = EM_SAFE_STRDUP(buf); + + } - mail->file_path_html = EM_SAFE_STRDUP(buf); - - } - - mail->body_download_status = (total_mail_size_except_attach < input_download_size) ? 1 : 2; - EM_DEBUG_LOG("total_mail_size_except_attach [%d], mail->body_download_status [%d]", total_mail_size_except_attach, mail->body_download_status); + mail->body_download_status = (total_mail_size - total_attachment_size < input_download_size) ? 1 : 2; + EM_DEBUG_LOG("mail->body_download_status [%d]", mail->body_download_status); - /* Get preview text */ - if ( (err = emcore_get_preview_text_from_file(mail->file_path_plain, mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail->preview_text))) != EMAIL_ERROR_NONE) - EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file() failed[%d]", err); - - /* Update body contents */ - if (!emstorage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err); - -NEXTUIDPARSING: - response_buffer = response_buffer + body_size; /* Set pointer for next mail body. */ - - /* Find end of body */ - if ((response_buffer[0] == CR) && (response_buffer[1] == LF)&& (response_buffer[2] == ')') - && (response_buffer[3] == CR) && (response_buffer[4] == LF)){ - response_buffer = response_buffer + 5; - total_parsed_len_per_uid = body_size+tempmailparselen + 5; - } - else if ((response_buffer[0] == ')') && (response_buffer[1] == CR) && (response_buffer[2] == LF)){ - response_buffer = response_buffer + 3; - total_parsed_len_per_uid = body_size+tempmailparselen + 3; - } - else { - EM_DEBUG_EXCEPTION("Mail response end could not found, - %c : %c : %c", response_buffer[0], response_buffer[1], response_buffer[2]); - } + /* Get preview text */ + if ( (err = emcore_get_preview_text_from_file(mail->file_path_plain, mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail->preview_text))) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file() failed[%d]", err); + + /* Update body contents */ + if (!emstorage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err)) + EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err); - EM_SAFE_FREE(bufsendforparse); - - memset(text_html, 0, input_download_size+1); - memset(text_plain, 0, input_download_size+1); - memset(temp_text_buf, 0, input_download_size+1); + if (mail) + emstorage_free_mail(&mail, 1, NULL); - if (mail) - emstorage_free_mail(&mail, 1, NULL); - - /* Free the activity for mail id in partial body activity table */ - if (false == emcore_delete_pbd_activity(pbd_event[temp_count].account_id, pbd_event[temp_count].mail_id, pbd_event[temp_count].activity_id, &err)){ - EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err); - goto FINISH_OFF; - } - } - - total_parsed_len += total_parsed_len_per_uid; + if (false == emcore_delete_pbd_activity(pbd_event[temp_count].account_id, pbd_event[temp_count].mail_id, pbd_event[temp_count].activity_id, &err)){ + EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err); + goto FINISH_OFF; } - } + } - EM_DEBUG_LOG("imap_response buflen is [%d]", imap_response->buflen); ret = true; FINISH_OFF: @@ -3850,12 +3855,9 @@ FINISH_OFF: EM_SAFE_FREE(text_plain); EM_SAFE_FREE(text_html); - EM_SAFE_FREE(temp_text_buf); - EM_SAFE_FREE(bufsendforparse); - EM_SAFE_FREE(plain_text_file_name_from_content_info); - EM_SAFE_FREE(html_text_file_name_from_content_info); - EM_SAFE_FREE(plain_charset_from_content_info); + if (image_data) + emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT); if (cnt_info) emcore_free_content_info(cnt_info); @@ -3863,13 +3865,12 @@ FINISH_OFF: if (body) mail_free_body(&body); - if (imap_response) - EM_SAFE_FREE(imap_response->buffer); - EM_SAFE_FREE(imap_response); - if (mail) emstorage_free_mail(&mail, 1, NULL); - + + if (imap_response) + emcore_free_email_partial_buffer(&imap_response, item_count); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -3957,8 +3958,28 @@ FINISH_OFF: return ret; } +static void emcore_free_email_partial_buffer(email_partial_buffer **partial_buffer, int item_count) +{ + EM_DEBUG_FUNC_BEGIN("count : [%d]", item_count); + + if (item_count <= 0 || !partial_buffer || !*partial_buffer) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + return; + } + + email_partial_buffer *p = *partial_buffer; + int i; -static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply, int input_download_size) + for (i = 0; i < item_count ; i++, p++) { + EM_SAFE_FREE(p->header); + EM_SAFE_FREE(p->body); + } + + EM_SAFE_FREE(*partial_buffer); + EM_DEBUG_FUNC_END(); +} + +static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply, int input_download_size, int item_count) { EM_DEBUG_FUNC_BEGIN(); @@ -3969,89 +3990,82 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream email_partial_buffer *retPartialBuffer = NULL; IMAPPARSEDREPLY *ret_reply = NULL; + char *pre_content = NULL; char *pline = NULL; - int linelen = 0; - int bytes_copied = 0; - int temp_body_buffer_size = 0; - int flags = 0; + char *p = NULL; + int body_size = 0; + int header_len = 0; int count = 0; - int allocated_buffer_size = (BULK_PARTIAL_BODY_DOWNLOAD_COUNT + 2) * input_download_size ; - - retPartialBuffer = (email_partial_buffer *)em_malloc(sizeof(email_partial_buffer)); + int ret = false; + int header_start = false; + retPartialBuffer = (email_partial_buffer *)em_malloc(sizeof(email_partial_buffer) * item_count); if (NULL == retPartialBuffer){ EM_DEBUG_EXCEPTION("em_malloc failed"); return NIL; } - retPartialBuffer->buffer = (char *)em_malloc(allocated_buffer_size); - - if (NULL == retPartialBuffer->buffer){ - EM_DEBUG_EXCEPTION("em_malloc failed"); - EM_SAFE_FREE(retPartialBuffer); - return NIL; - } - while (nstream){ if (!(pline = net_getline(nstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); - EM_SAFE_FREE(retPartialBuffer->buffer); - EM_SAFE_FREE(retPartialBuffer); - - return NIL; + goto FINISH_OFF; } - linelen = strlen(pline); + /* Search the start of header */ if (strcasestr(pline, "BODYSTRUCTURE") != NULL) { - temp_body_buffer_size = 0; - flags = 0; - count++; - } else if (strstr(pline, "> {") != NULL) { - temp_body_buffer_size = 0; - flags = 0; - } else { - temp_body_buffer_size = temp_body_buffer_size + linelen + 2; - } + header_len = EM_SAFE_STRLEN(pline); + header_start = true; + } - if (temp_body_buffer_size > input_download_size && !flags) { - linelen = linelen - (temp_body_buffer_size - input_download_size) + 2; - temp_body_buffer_size = input_download_size; - flags = 1; - } + /* Search the end of header */ + if ((p = strcasestr(pline, "BODY[TEXT]")) != NULL && header_len > 0) { + /* Get the header content */ + retPartialBuffer[count].header_len = (p - pline) + EM_SAFE_STRLEN(pre_content); + retPartialBuffer[count].header = em_malloc(retPartialBuffer[count].header_len + 1); + if (retPartialBuffer[count].header == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + goto FINISH_OFF; + } + + if (pre_content != NULL) + SNPRINTF(retPartialBuffer[count].header, retPartialBuffer[count].header_len, "%s%s", pre_content, pline); + else + SNPRINTF(retPartialBuffer[count].header, retPartialBuffer[count].header_len, "%s", pline); + + /* Get the body content */ + p += strlen("BODY[TEXT]<0> {"); + body_size = atoi(p); + retPartialBuffer[count].body_len = (body_size > input_download_size) ? input_download_size : body_size ; + retPartialBuffer[count].body = em_malloc(retPartialBuffer[count].body_len + 1); + if (retPartialBuffer[count].body == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + goto FINISH_OFF; + } - if (temp_body_buffer_size <= input_download_size) { - if (allocated_buffer_size < (bytes_copied + linelen)) { - allocated_buffer_size = allocated_buffer_size + (BULK_PARTIAL_BODY_DOWNLOAD_COUNT - count + 1) * input_download_size; - retPartialBuffer->buffer = (char *)realloc(retPartialBuffer->buffer, allocated_buffer_size); - if (NULL == retPartialBuffer->buffer) { - EM_DEBUG_EXCEPTION("realloc failed"); - EM_SAFE_FREE(pline); - EM_SAFE_FREE(retPartialBuffer); - return NIL; - } - } - memcpy(retPartialBuffer->buffer + bytes_copied, pline, linelen); - bytes_copied += linelen; - memcpy(retPartialBuffer->buffer + bytes_copied, CRLF_STRING, 2); - bytes_copied += 2; + if (net_getbuffer(nstream, retPartialBuffer[count].body_len, retPartialBuffer[count].body) <= 0) { + EM_DEBUG_EXCEPTION("net_getbuffer failed"); + goto FINISH_OFF; + } + + count++; + header_start = false; } - - if (0 == strncmp(pline, tag, strlen(tag))) { - ret_reply = em_malloc(sizeof(IMAPPARSEDREPLY)); + if (header_start) + pre_content = EM_SAFE_STRDUP(pline); + + if (0 == strncmp(pline, tag, EM_SAFE_STRLEN(tag))) { + ret_reply = em_malloc(sizeof(IMAPPARSEDREPLY)); if (!ret_reply){ EM_DEBUG_EXCEPTION("em_malloc failed"); - EM_SAFE_FREE(pline); - EM_SAFE_FREE(retPartialBuffer->buffer); - EM_SAFE_FREE(retPartialBuffer); - return NIL; + goto FINISH_OFF; } if(reply) *reply = ret_reply; - if (0 == strncmp(pline + strlen(tag) + 1, "OK", 2)) { + if (0 == strncmp(pline + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { ret_reply->line = (unsigned char*)EM_SAFE_STRDUP(tag); ret_reply->tag = (unsigned char*)EM_SAFE_STRDUP(tag); ret_reply->key = (unsigned char*)EM_SAFE_STRDUP("OK"); @@ -4066,23 +4080,23 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream ret_reply->key = (unsigned char*)EM_SAFE_STRDUP("NO"); ret_reply->text = (unsigned char*)EM_SAFE_STRDUP("Fail"); - EM_SAFE_FREE(pline); - EM_SAFE_FREE(retPartialBuffer->buffer); - EM_SAFE_FREE(retPartialBuffer); + goto FINISH_OFF; - return NIL; } - - EM_DEBUG_LOG("ret_reply->line [%s]", ret_reply->line); - EM_DEBUG_LOG("ret_reply->tag [%s]", ret_reply->tag); - EM_DEBUG_LOG("ret_reply->key [%s]", ret_reply->key); - EM_DEBUG_LOG("ret_reply->text [%s]", ret_reply->text); - } EM_SAFE_FREE(pline); } - - retPartialBuffer->buflen = strlen(retPartialBuffer->buffer); + + ret = true; + +FINISH_OFF: + + EM_SAFE_FREE(pline); + EM_SAFE_FREE(pre_content); + + if (!ret) { + emcore_free_email_partial_buffer(&retPartialBuffer, item_count); + } EM_DEBUG_FUNC_END("retPartialBuffer [%p]", retPartialBuffer); return retPartialBuffer; diff --git a/email-core/email-core-mailbox.c b/email-core/email-core-mailbox.c index c4c041a..b8204af 100755 --- a/email-core/email-core-mailbox.c +++ b/email-core/email-core-mailbox.c @@ -374,7 +374,6 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser local_mailbox.mailbox_id = new_mailbox->mailbox_id; local_mailbox.account_id = new_mailbox->account_id; local_mailbox.local_yn = new_mailbox->local; - local_mailbox.sync_with_server_yn = local_mailbox.local_yn ? 0 : 1; local_mailbox.mailbox_name = new_mailbox->mailbox_name; local_mailbox.alias = new_mailbox->alias; local_mailbox.mailbox_type = new_mailbox->mailbox_type; @@ -383,10 +382,10 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser local_mailbox.total_mail_count_on_server = 0; emcore_get_default_mail_slot_count(&local_mailbox.mail_slot_size, NULL); - if (strncmp(new_mailbox->mailbox_name, EMAIL_INBOX_NAME, strlen(EMAIL_INBOX_NAME)) == 0 || - strncmp(new_mailbox->mailbox_name, EMAIL_DRAFTBOX_NAME, strlen(EMAIL_DRAFTBOX_NAME)) == 0 || - strncmp(new_mailbox->mailbox_name, EMAIL_OUTBOX_NAME, strlen(EMAIL_OUTBOX_NAME)) == 0 || - strncmp(new_mailbox->mailbox_name, EMAIL_SENTBOX_NAME, strlen(EMAIL_SENTBOX_NAME)) == 0) + if (strncmp(new_mailbox->mailbox_name, EMAIL_INBOX_NAME, EM_SAFE_STRLEN(EMAIL_INBOX_NAME)) == 0 || + strncmp(new_mailbox->mailbox_name, EMAIL_DRAFTBOX_NAME, EM_SAFE_STRLEN(EMAIL_DRAFTBOX_NAME)) == 0 || + strncmp(new_mailbox->mailbox_name, EMAIL_OUTBOX_NAME, EM_SAFE_STRLEN(EMAIL_OUTBOX_NAME)) == 0 || + strncmp(new_mailbox->mailbox_name, EMAIL_SENTBOX_NAME, EM_SAFE_STRLEN(EMAIL_SENTBOX_NAME)) == 0) local_mailbox.modifiable_yn = 0; /* can be deleted/modified */ else local_mailbox.modifiable_yn = 1; @@ -426,19 +425,19 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int on_server, int goto FINISH_OFF; } - if (!emcore_delete_all_mails_of_mailbox(input_mailbox_id, on_server, &err)) { - EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); - goto FINISH_OFF; - } - if (on_server) { - EM_DEBUG_LOG(">> Delete the mailbox in Sever >>> "); + EM_DEBUG_LOG("Delete the mailbox in Sever >>> "); if (!emcore_delete_imap_mailbox(input_mailbox_id, &err)) - EM_DEBUG_EXCEPTION("Delete the mailbox in server : failed"); + EM_DEBUG_EXCEPTION("Delete the mailbox in server : failed [%d]", err); else EM_DEBUG_LOG("Delete the mailbox in server : success"); } + if (!emcore_delete_all_mails_of_mailbox(mailbox_tbl->account_id, input_mailbox_id, false, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); + goto FINISH_OFF; + } + if (!emstorage_delete_mailbox(mailbox_tbl->account_id, -1, input_mailbox_id, true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_delete_mailbox failed - %d", err); @@ -453,27 +452,54 @@ FINISH_OFF: if (err_code != NULL) *err_code = err; - + EM_DEBUG_FUNC_END("err[%d]", err); return ret; } + +INTERNAL_FUNC int emcore_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_on_server[%d]", input_mailbox_id_array, input_mailbox_id_array, input_mailbox_id_count, input_on_server); + int err = EMAIL_ERROR_NONE; + int i = 0; + + if(input_account_id == 0 || input_mailbox_id_count <= 0 || input_mailbox_id_array == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if((err = emstorage_set_field_of_mailbox_with_integer_value(input_account_id, input_mailbox_id_array, input_mailbox_id_count, "deleted_flag", 1, true)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_set_field_of_mailbox_with_integer_value failed[%d]", err); + goto FINISH_OFF; + } + + for(i = 0; i < input_mailbox_id_count; i++) { + if(!emcore_delete_mailbox(input_mailbox_id_array[i] , input_on_server, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_mailbox failed [%d]", err); + goto FINISH_OFF; + } + } + +FINISH_OFF: + EM_DEBUG_FUNC_END("err[%d]", err); + return err; +} + INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_code) { - EM_DEBUG_FUNC_BEGIN(); - - EM_DEBUG_LOG(" mailbox[%p], err_code[%p]", mailbox, err_code); + EM_DEBUG_FUNC_BEGIN(" mailbox[%p], err_code[%p]", mailbox, err_code); int ret = false; int err = EMAIL_ERROR_NONE; if (mailbox == NULL) { EM_DEBUG_EXCEPTION(" mailbox[%p]", mailbox); - err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (!emcore_delete_all_mails_of_mailbox(mailbox->mailbox_id, 0, /*NULL, */ &err)) { + if (!emcore_delete_all_mails_of_mailbox(mailbox->account_id, mailbox->mailbox_id, 0, /*NULL, */ &err)) { EM_DEBUG_EXCEPTION(" emcore_delete_all_mails_of_mailbox failed - %d", err); goto FINISH_OFF; @@ -491,7 +517,7 @@ INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_c FINISH_OFF: if (err_code != NULL) *err_code = err; - + EM_DEBUG_FUNC_END("err[%d]", err); return ret; } @@ -739,7 +765,7 @@ FINISH_OFF: EM_SAFE_FREE(mailbox_name); if (mailbox) { - emstorage_free_mailbox(&mailbox, 1, &error); + emstorage_free_mailbox(&mailbox, 1, NULL); } if (err_code != NULL) @@ -983,14 +1009,11 @@ INTERNAL_FUNC void emcore_bind_mailbox_type(email_internal_mailbox_t *mailbox_li for (i = 0 ; i < MAX_MAILBOX_TYPE ; i++) { pMailboxType1 = g_mailbox_type + i; - - if (pMailboxType1->mailbox_name) { - if (0 == strcmp(pMailboxType1->mailbox_name, mailbox_list->mailbox_name)) { - mailbox_list->mailbox_type = pMailboxType1->mailbox_type; - EM_DEBUG_LOG("mailbox_list->mailbox_type[%d]", mailbox_list->mailbox_type); - bIsNotUserMailbox = true; - break; - } + if (0 == EM_SAFE_STRCMP(pMailboxType1->mailbox_name, mailbox_list->mailbox_name)) { /*prevent 24662*/ + mailbox_list->mailbox_type = pMailboxType1->mailbox_type; + EM_DEBUG_LOG("mailbox_list->mailbox_type[%d]", mailbox_list->mailbox_type); + bIsNotUserMailbox = true; + break; } } diff --git a/email-core/email-core-mime.c b/email-core/email-core-mime.c index eea5152..a0c84af 100755 --- a/email-core/email-core-mime.c +++ b/email-core/email-core-mime.c @@ -93,9 +93,6 @@ #define SAVE_TYPE_BUFFER 2 /* save content to buffe */ #define SAVE_TYPE_FILE 3 /* save content to temporary fil */ -#define INLINE_ATTACHMENT 1 -#define ATTACHMENT 2 - #define EML_FOLDER 20 /* save eml content to temporary folder */ /* @@ -334,7 +331,7 @@ char *em_split_file_path(char *str) char *temp_cid_data = NULL; char *temp_cid = NULL; temp_str = EM_SAFE_STRDUP(str); - buf_length = strlen(str) + 1024; + buf_length = EM_SAFE_STRLEN(str) + 1024; buf = em_malloc(buf_length); content_id = temp_str; temp_cid = strstr(temp_str, "\""); @@ -365,9 +362,9 @@ char *em_split_file_path(char *str) if (strcasestr(content_id, ".bmp") || strcasestr(content_id, ".jpeg") || strcasestr(content_id, ".png") || strcasestr(content_id, ".jpg") || strcasestr(content_id, ".gif")) - snprintf(buf+strlen(buf), buf_length - strlen(buf), "%s\"", content_id); + snprintf(buf+EM_SAFE_STRLEN(buf), buf_length - EM_SAFE_STRLEN(buf), "%s\"", content_id); else - snprintf(buf+strlen(buf), buf_length - strlen(buf), "%s%s", content_id, ".jpeg\""); + snprintf(buf+EM_SAFE_STRLEN(buf), buf_length - EM_SAFE_STRLEN(buf), "%s%s", content_id, ".jpeg\""); } else { EM_DEBUG_EXCEPTION(">>>> File Path Doesnot contain end line for CID "); @@ -379,7 +376,7 @@ char *em_split_file_path(char *str) result = strstr(result, "\""); if (result != NULL) { result++; - snprintf(buf+strlen(buf), buf_length - strlen(buf), "%s", result); + snprintf(buf+EM_SAFE_STRLEN(buf), buf_length - EM_SAFE_STRLEN(buf), "%s", result); } } EM_SAFE_FREE(temp_str); @@ -412,10 +409,10 @@ static char *em_replace_string_with_split_file_path(char *source_string, char *o return NULL; } - buf_len = strlen(source_string) + 1024; + buf_len = EM_SAFE_STRLEN(source_string) + 1024; buffer = (char *)em_malloc(buf_len); - if(p - source_string < strlen(source_string) + 1024 + 1) { + if(p - source_string < EM_SAFE_STRLEN(source_string) + 1024 + 1) { strncpy(buffer, source_string, p - source_string); EM_DEBUG_LOG("BUFFER [%s]", buffer); @@ -430,7 +427,7 @@ static char *em_replace_string_with_split_file_path(char *source_string, char *o q = strstr(split_str, old_string); if (q) { EM_DEBUG_LOG("Split string [%s]", split_str); - snprintf(buffer + strlen(buffer), buf_len - strlen(buffer), "%s%s", new_string, q+strlen(old_string)); + snprintf(buffer + EM_SAFE_STRLEN(buffer), buf_len - EM_SAFE_STRLEN(buffer), "%s%s", new_string, q+strlen(old_string)); /*prevent 34353*/ EM_DEBUG_LOG("BUFFER 1 [%s]", buffer); EM_SAFE_FREE(split_str); EM_DEBUG_FUNC_END("Suceeded"); @@ -655,6 +652,7 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r *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))) { @@ -711,7 +709,7 @@ int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_head memset(tmp_header, 0, sizeof(struct _m_part_header)); while (true) { - if (!strncmp(buf, CRLF_STRING, strlen(CRLF_STRING))) break; + if (!strncmp(buf, CRLF_STRING, EM_SAFE_STRLEN(CRLF_STRING))) break; is_longheader = (buf[0] == ' ' || buf[0] == TAB); @@ -844,12 +842,12 @@ 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 = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_CHARSET, err_code); + 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"))) + if (!charset || !strncmp(charset, "X-UNKNOWN", EM_SAFE_STRLEN("X-UNKNOWN"))) cnt_info->text.plain_charset = EM_SAFE_STRDUP("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); @@ -863,7 +861,7 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru } else if (mmsg->header) { - if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) + if (!charset || !strncmp(charset, "X-UNKNOWN", EM_SAFE_STRLEN("X-UNKNOWN"))) cnt_info->text.plain_charset = EM_SAFE_STRDUP("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); @@ -1131,7 +1129,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par char *charset = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_CHARSET, err_code); EM_DEBUG_LOG(" charset [%s]", charset); - if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) + if (!charset || !strncmp(charset, "X-UNKNOWN", EM_SAFE_STRLEN("X-UNKNOWN"))) cnt_info->text.plain_charset = EM_SAFE_STRDUP("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); @@ -1207,7 +1205,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par file->size = size; if (strstr(content_type, APPLICATION_STR)) { - pTemp = content_type + strlen(APPLICATION_STR); + pTemp = content_type + EM_SAFE_STRLEN(APPLICATION_STR); if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_OBJECT) == 0) file->drm = EMAIL_ATTACHMENT_DRM_OBJECT; @@ -1283,8 +1281,7 @@ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *nam char **p = NULL; char *t = NULL; - /* ? ? ? why return value is 1 */ - if (!value || !*value) return true; + if (!value || !*value || !name ) return false; /*prevent 34354*/ if (!*header) { *header = em_malloc(sizeof(struct _rfc822header)); @@ -1294,50 +1291,47 @@ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *nam } } - if (name) { + em_upper_string(name); - if (strncmp(name, "RETURN-PATH", strlen("RETURN-PATH")) == 0) - p = &(*header)->return_path;/* Return-Rat */ - else if (strncmp(name, "RECEIVED", strlen("RECEIVED")) == 0) - p = &(*header)->received; /* Receive */ - else if (strncmp(name, "REPLY-TO", strlen("REPLY-TO")) == 0) - p = &(*header)->reply_to; /* Reply-T */ - else if (strncmp(name, "DATE", strlen("DATE")) == 0) - p = &(*header)->date; /* Dat */ - else if (strncmp(name, "FROM", strlen("FROM")) == 0) - p = &(*header)->from; /* Fro */ - else if (strncmp(name, "SUBJECT", strlen("SUBJECT")) == 0) - p = &(*header)->subject; /* Subjec */ - else if (strncmp(name, "SENDER", strlen("SENDER")) == 0) - p = &(*header)->sender; /* Sende */ - else if (strncmp(name, "TO", strlen("TO")) == 0) - p = &(*header)->to; /* T */ - else if (strncmp(name, "CC", strlen("CC")) == 0) - p = &(*header)->cc; /* C */ - else if (strncmp(name, "BCC", strlen("BCC")) == 0) - p = &(*header)->bcc; /* Bc */ - else if (strncmp(name, "X-PRIORITY", strlen("X-PRIORITY")) == 0) - p = &(*header)->priority; /* Prorit */ - else if (strncmp(name, "X-MSMAIL-PRIORITY", strlen("X-MSMAIL-PRIORITY")) == 0) - p = &(*header)->ms_priority;/* Prorit */ - else if (strncmp(name, "DISPOSITION-NOTIFICATION-TO", strlen("DISPOSITION-NOTIFICATION-TO")) == 0) - p = &(*header)->dsp_noti_to;/* Disposition-Notification-T */ - else { - return false; - } + if (strncmp(name, "RETURN-PATH", EM_SAFE_STRLEN("RETURN-PATH")) == 0) + p = &(*header)->return_path;/* Return-Rat */ + else if (strncmp(name, "RECEIVED", EM_SAFE_STRLEN("RECEIVED")) == 0) + p = &(*header)->received; /* Receive */ + else if (strncmp(name, "REPLY-TO", EM_SAFE_STRLEN("REPLY-TO")) == 0) + p = &(*header)->reply_to; /* Reply-T */ + else if (strncmp(name, "DATE", EM_SAFE_STRLEN("DATE")) == 0) + p = &(*header)->date; /* Dat */ + else if (strncmp(name, "FROM", EM_SAFE_STRLEN("FROM")) == 0) + p = &(*header)->from; /* Fro */ + else if (strncmp(name, "SUBJECT", EM_SAFE_STRLEN("SUBJECT")) == 0) + p = &(*header)->subject; /* Subjec */ + else if (strncmp(name, "SENDER", EM_SAFE_STRLEN("SENDER")) == 0) + p = &(*header)->sender; /* Sende */ + else if (strncmp(name, "TO", EM_SAFE_STRLEN("TO")) == 0) + p = &(*header)->to; /* T */ + else if (strncmp(name, "CC", EM_SAFE_STRLEN("CC")) == 0) + p = &(*header)->cc; /* C */ + else if (strncmp(name, "BCC", EM_SAFE_STRLEN("BCC")) == 0) + p = &(*header)->bcc; /* Bc */ + else if (strncmp(name, "X-PRIORITY", EM_SAFE_STRLEN("X-PRIORITY")) == 0) + p = &(*header)->priority; /* Prorit */ + else if (strncmp(name, "X-MSMAIL-PRIORITY", EM_SAFE_STRLEN("X-MSMAIL-PRIORITY")) == 0) + p = &(*header)->ms_priority;/* Prorit */ + else if (strncmp(name, "DISPOSITION-NOTIFICATION-TO", EM_SAFE_STRLEN("DISPOSITION-NOTIFICATION-TO")) == 0) + p = &(*header)->dsp_noti_to;/* Disposition-Notification-T */ + else { + return false; } - if (p) { - if (!*p) - *p = EM_SAFE_STRDUP(value); - else { /* Long Heade */ - if (!(t = realloc(*p, strlen(*p) + strlen(value)+1))) - return false; + if (!*p) + *p = EM_SAFE_STRDUP(value); + else { /* Long Header */ + if (!(t = realloc(*p, strlen(*p) + strlen(value)+1))) /*prevent 34354*/ + return false; - strncat(t, value, strlen(value)); - *p = t; - } + strncat(t, value, strlen(value)); /*prevent 34354*/ + *p = t; } return true; @@ -1377,7 +1371,7 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name } if (name) { - if (strncmp(name, "CONTENT-TYPE", strlen("CONTENT-TYPE")) == 0) { + if (strncmp(name, "CONTENT-TYPE", EM_SAFE_STRLEN("CONTENT-TYPE")) == 0) { p_val = strtok(value, ";"); if (p_val) { @@ -1400,7 +1394,7 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name if (t->value == NULL) { char *pointer = NULL; - if (strlen(p_val) > 0) { + if (EM_SAFE_STRLEN(p_val) > 0) { if ((pointer = strchr(p_val, '\"'))) { p_val = pointer + 1; if (!*p_val) return false; @@ -1429,15 +1423,15 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name } } } - else if (strncmp(name, "CONTENT-TRANSFER-ENCODING", strlen("CONTENT-TRANSFER-ENCODING")) == 0) { + else if (strncmp(name, "CONTENT-TRANSFER-ENCODING", EM_SAFE_STRLEN("CONTENT-TRANSFER-ENCODING")) == 0) { em_upper_string(value); (*header)->encoding = EM_SAFE_STRDUP(value); } - else if (strncmp(name, "CONTENT-DESCRPTION", strlen("CONTENT-DESCRPTION")) == 0) { + else if (strncmp(name, "CONTENT-DESCRPTION", EM_SAFE_STRLEN("CONTENT-DESCRPTION")) == 0) { em_upper_string(value); (*header)->desc = EM_SAFE_STRDUP(value); } - else if (strncmp(name, "CONTENT-DISPOSITION", strlen("CONTENT-DISPOSITION")) == 0) { + else if (strncmp(name, "CONTENT-DISPOSITION", EM_SAFE_STRLEN("CONTENT-DISPOSITION")) == 0) { p_val = strtok(value, ";"); if (p_val) { @@ -1457,9 +1451,9 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name } } } - else if (strncmp(name, "CONTENT-ID", strlen("CONTENT-ID")) == 0) { + else if (strncmp(name, "CONTENT-ID", EM_SAFE_STRLEN("CONTENT-ID")) == 0) { size_t len = 0; - len = strlen(value); + len = EM_SAFE_STRLEN(value); /* em_upper_string(value) */ if ((len) && (value[0] == '<')) { @@ -1472,7 +1466,7 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name (*header)->content_id = EM_SAFE_STRDUP(value); } - else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0) + else if (strncmp(name, "CONTENT-LOCATION", EM_SAFE_STRLEN("CONTENT-LOCATION")) == 0) (*header)->content_location = EM_SAFE_STRDUP(value); } EM_DEBUG_FUNC_END(); @@ -1507,7 +1501,7 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er /* Name set */ /* Check string length */ - if (strlen(p_name) > 0) { + if (EM_SAFE_STRLEN(p_name) > 0) { em_upper_string(p_name); (*param)->name = EM_SAFE_STRDUP(p_name); } @@ -1520,7 +1514,7 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er return true; } - if (strlen(p_val) > 0) { + if (EM_SAFE_STRLEN(p_val) > 0) { if ((p = strchr(p_val, '\"'))) { p_val = p + 1; if (!*p_val) return false; @@ -1528,7 +1522,7 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er if ((p = strchr(p_val, '\"'))) *p = '\0'; - if (strncmp(p_name, "BOUNDARY", strlen("BOUNDARY")) != 0 && !strstr(p_name, "NAME")) + if (strncmp(p_name, "BOUNDARY", EM_SAFE_STRLEN("BOUNDARY")) != 0 && !strstr(p_name, "NAME")) em_upper_string(p_val); /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */ @@ -1748,13 +1742,17 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b if (is_file) { EM_DEBUG_LOG("from file"); - if ((error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, size)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_file failed : [%d]", error); - goto FINISH_OFF; + error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, size); + if (error != EMAIL_ERROR_NONE) { + if (error != EMAIL_ERROR_NO_MORE_DATA) { + EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_file failed : [%d]", error); + goto FINISH_OFF; + } } } else { EM_DEBUG_LOG("from sock"); - if ((error = emcore_decode_body_text_from_sock(stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, &sz)) != EMAIL_ERROR_NONE) { + error = emcore_decode_body_text_from_sock(stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, &sz); + if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_sock failed : [%d]", error); goto FINISH_OFF; } @@ -1765,7 +1763,7 @@ FINISH_OFF: if (err_code != NULL) *err_code = error; - close(fd); + if(fd>0) close(fd); /*prevent 32736*/ if (ret) { if (size) @@ -1809,7 +1807,7 @@ int emcore_mime_skip_content_data(void *stream, *size = sz; return false; } - sz += strlen(buf); + sz += EM_SAFE_STRLEN(buf); } } else { /* if there boundary, this content is from current line to ending boundary */ @@ -1848,7 +1846,7 @@ int emcore_mime_skip_content_data(void *stream, return true; } - sz += strlen(buf); + sz += EM_SAFE_STRLEN(buf); } } @@ -1915,7 +1913,7 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err if (!pop3_reply((MAILSTREAM *)stream)) { /* if TRUE, check respons */ EM_DEBUG_LOG("p_pop3local->response 1[%s]", p_pop3local->response); if (p_pop3local->response) { - if (*p_pop3local->response == '.' && strlen(p_pop3local->response) == 1) { + if (*p_pop3local->response == '.' && EM_SAFE_STRLEN(p_pop3local->response) == 1) { free(p_pop3local->response); p_pop3local->response = NULL; if (err_code != NULL) @@ -1925,7 +1923,7 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err } EM_DEBUG_LOG("Not end of response"); strncpy(buf, p_pop3local->response, size-1); - strncat(buf, CRLF_STRING, size-(strlen(buf) + 1)); + strncat(buf, CRLF_STRING, size-(EM_SAFE_STRLEN(buf) + 1)); free(p_pop3local->response); p_pop3local->response = NULL; @@ -1940,7 +1938,7 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err /* if response isn't NULL, check whether this response start with '+' */ /* if the first character is '+', return error because this response is normal data */ strncpy(buf, p_pop3local->response, size-1); - strncat(buf, CRLF_STRING, size-(strlen(buf)+1)); + strncat(buf, CRLF_STRING, size-(EM_SAFE_STRLEN(buf)+1)); free(p_pop3local->response); p_pop3local->response = NULL; goto FINISH_OFF; } @@ -1955,7 +1953,7 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err FINISH_OFF: if (buf) { int received_percentage, last_notified_percentage; - _pop3_received_body_size += strlen(buf); + _pop3_received_body_size += EM_SAFE_STRLEN(buf); last_notified_percentage = (double)_pop3_last_notified_body_size / (double)_pop3_total_body_size *100.0; received_percentage = (double)_pop3_received_body_size / (double)_pop3_total_body_size *100.0; @@ -2122,6 +2120,7 @@ static PARTLIST *emcore_get_allnested_part_full(MAILSTREAM *stream, int msg_uid, part_child = part_child->next; } + EM_DEBUG_FUNC_END(); return section_list; } @@ -2435,13 +2434,13 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha if (!encoded || !filename || !write_mode) { EM_DEBUG_EXCEPTION("Invalid Param "); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + if( err ) *err = EMAIL_ERROR_INVALID_PARAM; /* prevent 28347 */ + return false; } - EM_DEBUG_LOG("Encoded buffer length [%d]", strlen(encoded)); - encoded_len = strlen(encoded); + EM_DEBUG_LOG("Encoded buffer length [%d]", EM_SAFE_STRLEN(encoded)); + encoded_len = EM_SAFE_STRLEN(encoded); EM_DEBUG_LOG("encoding_type [%d]", encoding_type); switch (encoding_type) { @@ -2494,19 +2493,19 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha memset(body_inline_id, 0x00, 512); - if (body_inline && body_inline->id && strlen(body_inline->id) > 0) { + if (body_inline && body_inline->id && EM_SAFE_STRLEN(body_inline->id) > 0) { EM_DEBUG_LOG("body_inline->id - %s", body_inline->id); EM_DEBUG_LOG("param - %p param1 - %p", param, param1); decoded_content_id = strstr(decoded, "cid:"); if (body_inline->id[0] == '<') - memcpy(body_inline_id, body_inline->id + 1, strlen(body_inline->id) - 2); + memcpy(body_inline_id, body_inline->id + 1, EM_SAFE_STRLEN(body_inline->id) - 2); else - memcpy(body_inline_id, body_inline->id , strlen(body_inline->id)); + memcpy(body_inline_id, body_inline->id , EM_SAFE_STRLEN(body_inline->id)); EM_DEBUG_LOG("Inline body_inline_id [%s] ", body_inline_id); - if ((param || param1) && 0 == strncmp(body_inline_id , decoded_content_id + strlen("cid:"), strlen(body_inline_id))) { + if ((param || param1) && 0 == strncmp(body_inline_id , decoded_content_id + EM_SAFE_STRLEN("cid:"), EM_SAFE_STRLEN(body_inline_id))) { EM_DEBUG_LOG(" Inline CID Found "); memset(save_file_name, 0x00, MAX_PATH); @@ -2515,15 +2514,15 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha /* Finding 'filename' attribute from content inf */ emcore_get_file_pointer(body_inline, true, save_file_name, NULL, &error); - if (strlen(save_file_name) > 0) { + if (EM_SAFE_STRLEN(save_file_name) > 0) { /* Content ID will be replaced with its file name in html */ - memcpy(html_cid_path, decoded_content_id , strlen("cid:") + strlen(body_inline_id)); + memcpy(html_cid_path, decoded_content_id , EM_SAFE_STRLEN("cid:") + EM_SAFE_STRLEN(body_inline_id)); EM_DEBUG_LOG("Replacing %s with %s ", html_cid_path, save_file_name); if ((decoded_temp = em_replace_string(decoded, html_cid_path, save_file_name))) { EM_SAFE_FREE(decoded); decoded = decoded_temp; - decoded_len = strlen(decoded); + decoded_len = EM_SAFE_STRLEN(decoded); EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len); inline_support = 1; not_found = false; @@ -2548,8 +2547,8 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha /* EM_DEBUG_LOG(">>>> decoded_temp 2 [ %s ] ", decoded_temp) */ EM_SAFE_FREE(decoded); decoded = decoded_temp; - temp_decoded_len = strlen(body_inline_id); - decoded_len = strlen(decoded); + temp_decoded_len = EM_SAFE_STRLEN(body_inline_id); + decoded_len = EM_SAFE_STRLEN(decoded); EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len); inline_support = 1; } @@ -2604,7 +2603,7 @@ static BODY *emcore_select_body_structure_from_section_list(PARTLIST *section_li } - +#define MAX_WRITE_BUFFER_SIZE 0 /* should be tuned */ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int mail_id, int is_attachment, char *filepath, int uid, char *section, int encoding, int *decoded_total, char *section_subtype, int *err_code) { @@ -2613,7 +2612,6 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int int ret = false; int err = EMAIL_ERROR_NONE; - FILE *fp = NULL; IMAPLOCAL *imaplocal = NULL; char tag[16], command[64]; @@ -2621,14 +2619,15 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int char *decoded = NULL; int body_size = 0, total = 0; char *file_id = NULL; - char server_uid[129]; + char server_uid[129] = { 0, }; 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; + 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); @@ -2636,14 +2635,8 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } - int max_write_buffer_size = 0; - if (vconf_get_int("db/email/write_buffer_mode", &max_write_buffer_size) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_int failed. So set direct file writing"); - /* set as default profile typ */ - max_write_buffer_size = 0; - } - 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))) { @@ -2665,7 +2658,6 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int if (!imaplocal->netstream) { EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected... %p", imaplocal->netstream); - err = EMAIL_ERROR_INVALID_STREAM; goto FINISH_OFF; } @@ -2682,7 +2674,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int EM_DEBUG_LOG("[IMAP4] >>> [%s]", command); /* send command : get msgno/uid for all messag */ - if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) { + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; @@ -2718,7 +2710,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) { server_response_yn = 1; - p += strlen("BODY["); + p += EM_SAFE_STRLEN("BODY["); s = p; while (*s != ']') @@ -2732,7 +2724,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int } if ((p = strstr(s+1, " {"))) { - p += strlen(" {"); + p += EM_SAFE_STRLEN(" {"); s = p; while (isdigit(*s)) @@ -2745,7 +2737,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int else { /* no body length is replied */ if ((p = strstr(s+1, " \""))) { /* seek the termination of double quot */ char *t = NULL; - p += strlen(" \""); + p += EM_SAFE_STRLEN(" \""); if ((t = strstr(p, "\""))) { body_size = t - p; *t = '\0'; @@ -2820,7 +2812,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } - total = strlen((char *)encoded); + total = EM_SAFE_STRLEN((char *)encoded); EM_DEBUG_LOG("total = %d", total); EM_DEBUG_LOG("write_response_into_file successful %s.....", filename); @@ -2868,7 +2860,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int while (temp_body_size && (total netstream, (long)x, (char *)encoded) <= 0) { @@ -2878,9 +2870,9 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int } temp_body_size = temp_body_size - x; - strncat((char *)test_buffer, (char *)encoded, strlen((char *)encoded)); + strncat((char *)test_buffer, (char *)encoded, EM_SAFE_STRLEN((char *)encoded)); total = total + x; - _imap4_received_body_size += strlen((char *)encoded); + _imap4_received_body_size += EM_SAFE_STRLEN((char *)encoded); if ( !(temp_body_size/x) && temp_body_size%x) x = temp_body_size%x; @@ -2930,7 +2922,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } } - EM_DEBUG_LOG("%d has been written", strlen((char *)test_buffer)); + EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer)); /* notif */ } } @@ -2942,8 +2934,8 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int } } - else if (!strncmp(response, tag, strlen(tag))) { /* end of respons */ - if (!strncmp(response + strlen(tag) + 1, "OK", 2)) { + else if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { /* end of respons */ + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { EM_SAFE_FREE(response); } else { /* 'NO' or 'BAD */ @@ -3050,14 +3042,14 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a } } - if ((strlen(sections) == (sizeof(sections)-1)) || (strlen(sections) == 0)) { + if ((EM_SAFE_STRLEN(sections) == (sizeof(sections)-1)) || (EM_SAFE_STRLEN(sections) == 0)) { EM_DEBUG_EXCEPTION(" Too many body parts or nil. IMAP command may cross 1000bytes."); return_value = -1; goto FINISH_OFF; } - if (sections[strlen(sections)-1] == ' ') { - sections[strlen(sections)-1] = '\0'; + if (sections[EM_SAFE_STRLEN(sections)-1] == ' ') { + sections[EM_SAFE_STRLEN(sections)-1] = '\0'; } EM_DEBUG_LOG("sections <%s>", sections); @@ -3066,14 +3058,14 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a SNPRINTF(command, sizeof(command), "%s UID FETCH %d (%s)\015\012", tag, msg_uid, sections); EM_DEBUG_LOG("command %s", command); - if (strlen(command) == (sizeof(command)-1)) { + if (EM_SAFE_STRLEN(command) == (sizeof(command)-1)) { EM_DEBUG_EXCEPTION("Too many body parts. IMAP command will fail."); return_value = -1; goto FINISH_OFF; } /* send command : get msgno/uid for all message */ - if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) { + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; return_value = -1; @@ -3228,7 +3220,7 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a EM_DEBUG_LOG("total = %d", total); EM_DEBUG_LOG("write_response_into_file successful %s.....", buf); - total = _imap4_received_body_size = strlen((char *)encoded); + total = _imap4_received_body_size = EM_SAFE_STRLEN((char *)encoded); EM_DEBUG_LOG("_imap4_last_notified_body_size [%d]", _imap4_last_notified_body_size); EM_DEBUG_LOG("_imap4_download_noti_interval_value [%d]", _imap4_download_noti_interval_value); @@ -3292,7 +3284,7 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a while (temp_body_size && (total netstream, (long)x, (char *)encoded) <= 0) { @@ -3303,9 +3295,9 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a } temp_body_size = temp_body_size - x; - strncat((char *)test_buffer, (char *)encoded, strlen((char *)encoded)); + strncat((char *)test_buffer, (char *)encoded, EM_SAFE_STRLEN((char *)encoded)); total = total + x; - _imap4_received_body_size += strlen((char *)encoded); + _imap4_received_body_size += EM_SAFE_STRLEN((char *)encoded); EM_DEBUG_LOG("total = %d", total); @@ -3373,12 +3365,12 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a goto FINISH_OFF; } } - EM_DEBUG_LOG("%d has been written", strlen((char *)test_buffer)); + EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer)); } } } - else if (!strncmp(response, tag, strlen(tag))) /* end of respons */ { - if (!strncmp(response + strlen(tag) + 1, "OK", 2)) + else if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) /* end of respons */ { + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) EM_SAFE_FREE(response); else /* 'NO' or 'BAD */ { err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; @@ -3489,11 +3481,11 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ } if (body->subtype[0] == 'H') { if (cnt_info->text.plain_charset != NULL) { - memcpy(output_file_name_string, cnt_info->text.plain_charset, strlen(cnt_info->text.plain_charset)); + memcpy(output_file_name_string, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset)); strcat(output_file_name_string, HTML_EXTENSION_STRING); } else { - memcpy(output_file_name_string, "UTF-8.htm", strlen("UTF-8.htm")); + memcpy(output_file_name_string, "UTF-8.htm", EM_SAFE_STRLEN("UTF-8.htm")); } cnt_info->text.html = EM_SAFE_STRDUP(output_file_name_string); } @@ -3503,10 +3495,10 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ if (emcore_get_attribute_value_of_body_part(param, "CHARSET", charset_string, 512, false, &error)) { cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_string); - memcpy(output_file_name_string, cnt_info->text.plain_charset, strlen(cnt_info->text.plain_charset)); + memcpy(output_file_name_string, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset)); } else - memcpy(output_file_name_string, "UTF-8", strlen("UTF-8")); + memcpy(output_file_name_string, "UTF-8", EM_SAFE_STRLEN("UTF-8")); cnt_info->text.plain = EM_SAFE_STRDUP(output_file_name_string); } @@ -3539,7 +3531,7 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ else SNPRINTF(attachment_file_name, MAX_PATH, "%s", body->id); /* fname = em_parse_filename(body->id */ - len = strlen(attachment_file_name); + len = EM_SAFE_STRLEN(attachment_file_name); if ((len > 1) && (attachment_file_name[len-1] == '>')) attachment_file_name[len - 1] = '\0'; @@ -3547,16 +3539,16 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ } EM_DEBUG_LOG("attachment_file_name [%s]", attachment_file_name); if (decoded_filename != NULL) - memcpy(output_file_name_string, decoded_filename, strlen(decoded_filename)); + memcpy(output_file_name_string, decoded_filename, EM_SAFE_STRLEN(decoded_filename)); else - memcpy(output_file_name_string, attachment_file_name, strlen(attachment_file_name)); + memcpy(output_file_name_string, attachment_file_name, EM_SAFE_STRLEN(attachment_file_name)); } else if (body->disposition.type != NULL) { /* disposition type is existing and not inline and body_id is nul */ PARAMETER *param = body->parameter; if (!emcore_get_attribute_value_of_body_part(param, "NAME", attachment_file_name, MAX_PATH, true, &error)) emcore_get_attribute_value_of_body_part(param, "FILENAME", attachment_file_name, MAX_PATH, true, &error); - memcpy(output_file_name_string, attachment_file_name, strlen(attachment_file_name)); + memcpy(output_file_name_string, attachment_file_name, EM_SAFE_STRLEN(attachment_file_name)); } if(input_check_duplicated_file_name) { @@ -3596,7 +3588,7 @@ static PARTLIST *emcore_add_node(PARTLIST *section_list, BODY *body) temp->body = body; temp->next = NULL; - if (section_list == NULL)/* first node in lis */ { + if (section_list == NULL)/* first node in list */ { section_list = temp; } else/* has min 1 nod */ { @@ -3635,7 +3627,7 @@ static int emcore_get_section_body_size(char *response, char *section, int *body int size = 0; if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) { - p += strlen("BODY["); + p += EM_SAFE_STRLEN("BODY["); s = p; while (*s != ']') @@ -3651,7 +3643,7 @@ static int emcore_get_section_body_size(char *response, char *section, int *body }*/ p = strstr(s+1, " {"); if (p) { - p += strlen(" {"); + p += EM_SAFE_STRLEN(" {"); s = p; while (isdigit(*s)) @@ -3695,16 +3687,16 @@ static char *em_parse_filename(char *filename) memset(parsed_filename, 0x00, 512); if (!strstr(filename, delims)) { - EM_DEBUG_EXCEPTION("FileName doesnot contain @ "); + EM_DEBUG_EXCEPTION("FileName does not contain @ "); return NULL; } result = strtok(filename, delims); if (strcasestr(result, ".bmp") || strcasestr(result, ".jpeg") || strcasestr(result, ".png") || strcasestr(result, ".jpg")) - sprintf(parsed_filename + strlen(parsed_filename), "%s", result); + sprintf(parsed_filename + EM_SAFE_STRLEN(parsed_filename), "%s", result); else - sprintf(parsed_filename + strlen(parsed_filename), "%s%s", result, ".jpeg"); + sprintf(parsed_filename + EM_SAFE_STRLEN(parsed_filename), "%s%s", result, ".jpeg"); EM_DEBUG_LOG(">>> FileName [ %s ] ", result); @@ -3786,7 +3778,7 @@ INTERNAL_FUNC int emcore_get_content_type_from_mail_bodystruct(BODY *input_body, goto FINISH_OFF; } - EM_SAFE_STRNCPY(subtype_string, input_body->subtype, SUBTYPE_STRING_LENGTH); + EM_SAFE_STRNCPY(subtype_string, input_body->subtype, SUBTYPE_STRING_LENGTH-1); /* prevent 21983 */ em_lower_string(subtype_string); switch(input_body->type) { @@ -3869,9 +3861,9 @@ INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param } EM_DEBUG_LOG("result_value [%s]", result_value); if(result_value) { - if(output_buffer_length > strlen(result_value)) { + if(output_buffer_length > EM_SAFE_STRLEN(result_value)) { strncpy(output_value, result_value, output_buffer_length); - output_value[strlen(result_value)] = NULL_CHAR; + output_value[EM_SAFE_STRLEN(result_value)] = NULL_CHAR; ret = true; } else { @@ -3974,7 +3966,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } } /* is_pbd */ - if ((body->id) && strlen(body->id) > 1) { /* if Content-ID or Content-Location exists, it is inline contents */ + if ((body->id) && EM_SAFE_STRLEN(body->id) > 1) { /* if Content-ID or Content-Location exists, it is inline contents */ EM_DEBUG_LOG("body->id exist"); size_t len = 0; /* Get actual name of file - fix for inline images to be stored with actual names and not .jpeg */ @@ -4037,7 +4029,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai else SNPRINTF(filename, MAX_PATH, "%s", body->id); - len = strlen(filename); + len = EM_SAFE_STRLEN(filename); if ((len > 1) && (filename[len-1] == '>')) filename[len-1] = '\0'; @@ -4053,7 +4045,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai EM_SAFE_FREE(decoded_filename); EM_DEBUG_LOG("body->location [%s]", body->location); } - else if (is_pbd && (strncmp(body->subtype, "RFC822", strlen("RFC822")) == 0) && (cnt_info->grab_type == 0 || (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT))) { + else if (is_pbd && (strncmp(body->subtype, "RFC822", EM_SAFE_STRLEN("RFC822")) == 0) && (cnt_info->grab_type == 0 || (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT))) { EM_DEBUG_LOG("Beause subtype is RFC822. This is ttachment"); is_attachment = 1; @@ -4142,7 +4134,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai EM_DEBUG_LOG(">>>> Extension Exist in the Attachment [ %s ] ", extcheck); else { /* No extension attached , So add the Extension based on the subtype */ if (body->subtype) { - if (strlen(filename) + strlen(body->subtype) + 1 < MAX_PATH) { + if (EM_SAFE_STRLEN(filename) + EM_SAFE_STRLEN(body->subtype) + 1 < MAX_PATH) { strcat(filename, "."); strcat(filename, body->subtype); } @@ -4189,7 +4181,12 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } if (!imap_mail_write_body_to_file(stream, account_id, mail_id, 0, o_data, msg_uid, body->sparep, body->encoding, &o_data_len, body->subtype, &err)) { - EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err); + EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err); + if(err == EMAIL_ERROR_INVALID_STREAM) { + email_session_t *session = NULL; + emcore_get_current_session(&session); + err = session->error; + } goto FINISH_OFF; } } @@ -4589,10 +4586,10 @@ INTERNAL_FUNC int emcore_set_fetch_body_section(BODY *body, int enable_inline_li EM_SAFE_FREE(g_inline_list); emcore_set_fetch_part_section(body, (char *)NULL, 0, enable_inline_list, total_mail_size, err_code); - if (body->id && body) - EM_DEBUG_LOG(">>>>> FILE NAME [ %s ] ", body->id); + if (body && body->id) + EM_DEBUG_LOG(">>>>> FILE NAME [%s] ", body->id); else - EM_DEBUG_LOG(">>>>> BODY NULL ", body->id); + EM_DEBUG_LOG(">>>>> BODY NULL "); EM_DEBUG_FUNC_END(); return SUCCESS; @@ -4702,7 +4699,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) gchar *charset = NULL, *encoded_text = NULL; char *decoded_text = NULL, *decoded_word = NULL; char *current = NULL, *start = NULL, *end = NULL; - char *buffer = (char*) em_malloc(strlen(encoded_word) * 2 + 1); + char *buffer = (char*) em_malloc(EM_SAFE_STRLEN(encoded_word) * 2 + 1); if (buffer == NULL) { EM_DEBUG_EXCEPTION("Memory allocation fail"); @@ -4783,7 +4780,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) unsigned long len = 0; if (encoded_text != NULL) { if (base64_encoded == true) { - if (!(decoded_text = (char *)rfc822_base64((unsigned char *)encoded_text, strlen(encoded_text), &len))) { + if (!(decoded_text = (char *)rfc822_base64((unsigned char *)encoded_text, EM_SAFE_STRLEN(encoded_text), &len))) { EM_DEBUG_EXCEPTION("rfc822_base64 falied..."); goto FINISH_OFF; } @@ -4791,21 +4788,23 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) else { g_strdelimit(encoded_text, "_", ' '); - if (!(decoded_text = (char *)rfc822_qprint((unsigned char *)encoded_text, strlen(encoded_text), &len))) { + if (!(decoded_text = (char *)rfc822_qprint((unsigned char *)encoded_text, EM_SAFE_STRLEN(encoded_text), &len))) { EM_DEBUG_EXCEPTION("rfc822_base64 falied..."); goto FINISH_OFF; } } src.data = (unsigned char *)decoded_text; - src.size = strlen(decoded_text); + src.size = EM_SAFE_STRLEN(decoded_text); if (!utf8_text(&src, charset, &dst, 0)) { EM_DEBUG_EXCEPTION("utf8_text falied..."); - strncat(buffer, (char *)src.data, src.size); /* Eventhough failed to decode, downloading should go on. Kyuho Jo */ + if (src.data) + strncat(buffer, (char *)src.data, src.size); /* Eventhough failed to decode, downloading should go on. Kyuho Jo */ + } else { + if (dst.data) + strncat(buffer, (char *)dst.data, dst.size); } - else - strncat(buffer, (char *)dst.data, dst.size); #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("2 - Buffer[%s]", buffer); #endif @@ -4828,7 +4827,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) } else { /* unencoded text */ - length = strlen(start); + length = EM_SAFE_STRLEN(start); strncat(buffer, start, length); current = start + length; #ifdef FEATURE_CORE_DEBUG @@ -4838,7 +4837,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) } else { /* unencoded text */ - length = strlen(current); + length = EM_SAFE_STRLEN(current); strncat(buffer, current, length); current = current + length; #ifdef FEATURE_CORE_DEBUG @@ -5378,8 +5377,16 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in search++; if (search == 1) { start_mime_entity = ftell(fp_read); + if( start_mime_entity < 0 ) { /*prevent 24473*/ + EM_DEBUG_EXCEPTION("ftell failed [%s]", EM_STRERROR(errno)); + goto FINISH_OFF; + } } else if (search == 2) { end_mime_entity = ftell(fp_read); + if( end_mime_entity < 0 ) { /*prevent 24473*/ + EM_DEBUG_EXCEPTION("ftell failed [%s]", EM_STRERROR(errno)); + goto FINISH_OFF; + } break; } } @@ -5399,7 +5406,7 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in } /* +2 : CRLF line */ - if ((ret = fread(p_mime_entity, 1, end_mime_entity - (start_mime_entity + strlen(boundary) + 2), fp_read)) < 0) { + if ((ret = fread(p_mime_entity, 1, end_mime_entity - (start_mime_entity + EM_SAFE_STRLEN(boundary) + 2), fp_read)) < 0) { EM_DEBUG_EXCEPTION("fread failed"); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; diff --git a/email-core/email-core-mm-callbacks.c b/email-core/email-core-mm-callbacks.c index ff7b426..042159a 100755 --- a/email-core/email-core-mm-callbacks.c +++ b/email-core/email-core-mm-callbacks.c @@ -153,7 +153,7 @@ INTERNAL_FUNC void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox, lon else p[count].mailbox_name = cpystr(enc_path); - EM_DEBUG_LOG("mm_list mailbox name is %s ", p[count].mailbox_name); + EM_DEBUG_LOG("mailbox name [%s] mailbox_type [%d] no_select [%d]", p[count].mailbox_name, p[count].mailbox_type, p[count].no_select); p[count].alias = emcore_get_alias_of_mailbox((const char *)enc_path); p[count].local = 0; @@ -236,12 +236,12 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial) password = EM_SAFE_STRDUP(ref_account->incoming_server_password); - if (username && password && strlen(username) > 0 && strlen(password) > 0) { + if(EM_SAFE_STRLEN(username) > 0 && EM_SAFE_STRLEN(password) > 0) { /*prevent 34355*/ strcpy(user, username); strcpy(pwd, password); } else - EM_DEBUG_EXCEPTION("User Information is NULL || strlen is 0 "); + EM_DEBUG_EXCEPTION("User Information is NULL || EM_SAFE_STRLEN is 0 "); EM_SAFE_FREE(username); EM_SAFE_FREE(password); @@ -259,7 +259,6 @@ INTERNAL_FUNC void mm_dlog(char *string) INTERNAL_FUNC void mm_log(char *string, long errflg) { - /* EM_DEBUG_FUNC_BEGIN(); */ switch ((short)errflg) { case NIL: @@ -294,20 +293,6 @@ INTERNAL_FUNC void mm_log(char *string, long errflg) EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%d]", session->error); } - /* Handling exceptional case of connection failures. */ - /* - if (string) { - if (strstr(string, "15 minute") != 0) { - if (session) - session->error = EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS; - } - else if (strstr(string, "Too many login failures") == 0) { - if (session) - session->error = EMAIL_ERROR_TOO_MANY_LOGIN_FAILURE; - } - } - */ - break; } } @@ -426,6 +411,8 @@ INTERNAL_FUNC void mm_get_error(char *string, int *err_code) *err_code = EMAIL_ERROR_INVALID_SERVER; else if (strstr(string, "SELECT failed")) *err_code = EMAIL_ERROR_MAILBOX_NOT_FOUND; + else if (strstr(string, "15 minute")) + *err_code = EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS; else *err_code = EMAIL_ERROR_UNKNOWN; } @@ -435,10 +422,12 @@ INTERNAL_FUNC void mm_imap_id (char **id_string) { EM_DEBUG_FUNC_BEGIN("id_string [%p]", id_string); + int err = EMAIL_ERROR_NONE; + /* char *result_string = NULL; char *tag_string = "ID (\"os\" \"" IMAP_ID_OS "\" \"os-version\" \"" IMAP_ID_OS_VERSION "\" \"vendor\" \"" IMAP_ID_VENDOR "\" \"device\" \"" IMAP_ID_DEVICE_NAME "\" \"AGUID\" \"" IMAP_ID_AGUID "\" \"ACLID\" \"" IMAP_ID_ACLID "\""; int tag_length = 0; - int err = EMAIL_ERROR_NONE; + */ if (id_string == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -449,7 +438,7 @@ INTERNAL_FUNC void mm_imap_id (char **id_string) *id_string = NULL; /* - tag_length = strlen(tag_string); + tag_length = EM_SAFE_STRLEN(tag_string); result_string = EM_SAFE_STRDUP(tag_string); if(result_string == NULL) { diff --git a/email-core/email-core-smime.c b/email-core/email-core-smime.c index 760e671..4d2c9ce 100755 --- a/email-core/email-core-smime.c +++ b/email-core/email-core-smime.c @@ -154,6 +154,7 @@ static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) ** temp_recipient_certs = sk_X509_new_null(); temp_recipients = EM_SAFE_STRDUP(recipients); + temp_recipients = em_replace_all_string(temp_recipients, ",", ";"); token = strtok_r(temp_recipients, ";", &str); do { @@ -346,8 +347,8 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_ ret = true; FINISH_OFF: - if (file_path) - *file_path = temp_smime_filepath; + if (file_path && ret) + *file_path = EM_SAFE_STRDUP(temp_smime_filepath); X509_free(cert); sk_X509_pop_free(other_certs, X509_free); @@ -429,8 +430,8 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m ret = true; FINISH_OFF: - if (file_path) - *file_path = temp_smime_filepath; + if (file_path && ret) + *file_path = EM_SAFE_STRDUP(temp_smime_filepath); PKCS7_free(encrypt_message); @@ -555,8 +556,8 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li ret = true; FINISH_OFF: - if (file_path) - *file_path = temp_smime_filepath; + if (file_path && ret) + *file_path = EM_SAFE_STRDUP(temp_smime_filepath); PKCS7_free(signed_message); PKCS7_free(encrypt_message); @@ -581,10 +582,9 @@ FINISH_OFF: -INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char *from_address, char **decrypt_message, int *err_code) +INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char *certificate, char **decrypt_message, int *err_code) { - EM_DEBUG_FUNC_BEGIN("encrypt_file : [%s], from_addres : [%s]", encrypt_message, from_address); - int i = 0; + EM_DEBUG_FUNC_BEGIN("encrypt_file : [%s], certificate : [%s]", encrypt_message, certificate); int ret = false; int err = EMAIL_ERROR_NONE; char temp_decrypt_filepath[512] = {0, }; @@ -623,15 +623,12 @@ INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char * goto FINISH_OFF; } - /* Search Public cert */ - if (!get_x509_stack_of_recipient_certs(from_address, &recipient_certs, &err)) { - EM_DEBUG_EXCEPTION("get_x509_stack_of_recipient_certs failed [%d]", err); + /* Search private cert */ + if (!emcore_load_PFX_file(certificate, &private_key, &cert, NULL, &err)) { + EM_DEBUG_EXCEPTION("Load the private certificate failed : [%d]", err); goto FINISH_OFF; } - for (i = 0; i < sk_X509_num(recipient_certs); i++) - cert = sk_X509_value(recipient_certs, i); - if (!PKCS7_decrypt(p7_encrypt_message, private_key, cert, out_buf, 0)) { EM_DEBUG_EXCEPTION("Decrpyt failed"); err = EMAIL_ERROR_DECRYPT_FAILED; @@ -642,7 +639,8 @@ INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char * FINISH_OFF: - *decrypt_message = temp_decrypt_filepath; + if (decrypt_message && ret) + *decrypt_message = EM_SAFE_STRDUP(temp_decrypt_filepath); EVP_cleanup(); X509_free(cert); @@ -810,13 +808,14 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t int smime_type = EMAIL_SMIME_NONE; int address_length = 0; int attachment_count = input_attachment_count; + int file_size = 0; char *name = NULL; char *rfc822_file = NULL; char *mime_entity = NULL; char *smime_file_path = NULL; char *other_certificate_list = NULL; email_attachment_data_t new_attachment_data = {0}; - email_attachment_data_t *temp_attachment_data = NULL; + email_attachment_data_t *new_attachment_list = NULL; /* Validating parameters */ @@ -903,21 +902,25 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t break; } -/* - if (!emcore_get_file_size(smime_file_path, &size, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_file_size failed : [%d]", err); + + if (!emcore_get_file_size(smime_file_path, &file_size, NULL)) { + EM_DEBUG_EXCEPTION("emcore_get_file_size failed"); goto FINISH_OFF; } -*/ - new_attachment_data.attachment_size = 1; + + new_attachment_data.attachment_size = file_size; new_attachment_data.save_status = 1; + new_attachment_list = (email_attachment_data_t *)em_malloc(sizeof(email_attachment_data_t) * attachment_count); + if (new_attachment_list == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + goto FINISH_OFF; + } - temp_attachment_data = (email_attachment_data_t *)em_malloc(sizeof(email_attachment_data_t) * attachment_count); if (input_attachment_data_list != NULL) - temp_attachment_data = input_attachment_data_list; + new_attachment_list = input_attachment_data_list; - temp_attachment_data[attachment_count-1] = new_attachment_data; + new_attachment_list[attachment_count-1] = new_attachment_data; input_mail_data->smime_type = smime_type; input_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(mime_entity); @@ -930,14 +933,10 @@ FINISH_OFF: *output_attachment_count = attachment_count; if (output_attachment_data_list) - *output_attachment_data_list = temp_attachment_data; - + *output_attachment_data_list = new_attachment_list; *output_mail_data = input_mail_data; - if (!ret && temp_attachment_data) - emcore_free_attachment_data(&temp_attachment_data, attachment_count, NULL); - return ret; } diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c index 65cc3a7..64f4871 100755 --- a/email-core/email-core-smtp.c +++ b/email-core/email-core-smtp.c @@ -110,7 +110,7 @@ static char *emcore_find_img_tag(char *source_string) if (!source_string) return false; - string_length = strlen(source_string); + string_length = EM_SAFE_STRLEN(source_string); for (cur = 0; cur < string_length; cur++) { if (source_string[cur] == 'I' || source_string[cur] == 'i') { @@ -157,20 +157,23 @@ static char *emcore_replace_inline_image_path_with_content_id(char *source_strin memset(content_id_buffer, 0, CONTENT_ID_BUFFER_SIZE); if (cur_body->id) { EM_SAFE_STRNCPY(content_id_buffer, cur_body->id + 1, CONTENT_ID_BUFFER_SIZE - 1); /* Removing <, > */ - content_id_buffer[strlen(content_id_buffer) - 1] = NULL_CHAR; + /* prevent 34413 */ + char *last_bracket = rindex(content_id_buffer, '>'); + last_bracket = NULL_CHAR; + /* if (emcore_get_attribute_value_of_body_part(cur_body->parameter, "name", file_name_buffer, CONTENT_ID_BUFFER_SIZE, false, &err)) { */ if (emcore_get_attribute_value_of_body_part(cur_body->parameter, "name", file_name_buffer, CONTENT_ID_BUFFER_SIZE, true, &err)) { EM_DEBUG_LOG("Content-ID[%s], filename[%s]", content_id_buffer, file_name_buffer); SNPRINTF(new_string, CONTENT_ID_BUFFER_SIZE, "cid:%s", content_id_buffer); result_string = em_replace_string(input_string, file_name_buffer, new_string); - if (input_string) - EM_SAFE_FREE(input_string); } } } } - if (result_string) + if (result_string) { + EM_SAFE_FREE(input_string); input_string = result_string; + } cur_part = cur_part->next; } @@ -188,9 +191,9 @@ FINISH_OFF: static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_code) { - EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_FUNC_BEGIN("fp[%d]", fp); char *file_path = NULL; - char buf[RFC822_STRING_BUFFER_SIZE + 1] = {0, }; + char buf[RFC822_STRING_BUFFER_SIZE + 1]; char *img_tag_pos = NULL; char *p = NULL; char *replaced_string = NULL; @@ -199,7 +202,7 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod file_path = body->sparep; - if (!file_path || strlen(file_path) == 0) { + if (!file_path || EM_SAFE_STRLEN(file_path) == 0) { EM_DEBUG_LOG("There is no file path"); switch (body->encoding) { case 0: @@ -230,10 +233,11 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod } while (1) { + memset(&buf, 0x00, RFC822_STRING_BUFFER_SIZE + 1); nread = read(fd, buf, (body->encoding == ENCBASE64 ? 57 : RFC822_READ_BLOCK_SIZE - 2)); if (nread <= 0) { - EM_DEBUG_LOG("Can't read anymore"); + EM_DEBUG_LOG("Can't read anymore : nread[%d]", nread); break; } @@ -251,7 +255,7 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod if (replaced_string) { EM_DEBUG_LOG("emcore_replace_inline_image_path_with_content_id succeeded"); strcpy(buf, replaced_string); - nread = len = strlen(buf); + nread = len = EM_SAFE_STRLEN(buf); EM_DEBUG_LOG("buf[%s], nread[%d], len[%d]", buf, nread, len); } else @@ -274,7 +278,6 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod // } nwrite = fprintf(fp, "%s", (p ? p : buf)); - if (nwrite != len) { fclose(fp); close(fd); @@ -382,9 +385,9 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email rfc822_encode_body_7bit(env, body); /* if contents.text.data isn't NULL, the data will be encoded. */ /* FIXME : create memory map for this file */ - p_len = (env->subject ? strlen(env->subject) : 0) + 8192; + p_len = (env->subject ? EM_SAFE_STRLEN(env->subject) : 0) + 8192; - if (!(p = em_malloc(p_len))) { /* (env->subject ? strlen(env->subject) : 0) + 8192))) */ + if (!(p = em_malloc(p_len))) { /* (env->subject ? EM_SAFE_STRLEN(env->subject) : 0) + 8192))) */ EM_DEBUG_EXCEPTION(" malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; @@ -437,8 +440,8 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email LF_STRING"%s"LF_STRING " =============================================================================== ", p); - if (strlen(p) > 2) - *(p + strlen(p) - 2) = '\0'; + if (EM_SAFE_STRLEN(p) > 2) + *(p + EM_SAFE_STRLEN(p) - 2) = '\0'; if (input_report_flag) { @@ -462,28 +465,28 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email if(input_report_flag & EMAIL_MAIL_REQUEST_MDN) { /* require read status */ rfc822_address(buf, env->from); - if (strlen(buf)) - SNPRINTF(p + strlen(p), p_len-(strlen(p)), "Disposition-Notification-To: %s"CRLF_STRING, buf); + if (EM_SAFE_STRLEN(buf)) + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "Disposition-Notification-To: %s"CRLF_STRING, buf); } } if (input_priority) { /* priority (1:high 3:normal 5:low) */ - SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-Priority: %d"CRLF_STRING, input_priority); + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-Priority: %d"CRLF_STRING, input_priority); switch (input_priority) { case EMAIL_MAIL_PRIORITY_HIGH: - SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: HIgh"CRLF_STRING); + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-MSMail-Priority: HIgh"CRLF_STRING); break; case EMAIL_MAIL_PRIORITY_NORMAL: - SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: Normal"CRLF_STRING); + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-MSMail-Priority: Normal"CRLF_STRING); break; case EMAIL_MAIL_PRIORITY_LOW: - SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: Low"CRLF_STRING); + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-MSMail-Priority: Low"CRLF_STRING); break; } } - SNPRINTF(p + strlen(p), p_len-(strlen(p)), CRLF_STRING); + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), CRLF_STRING); if (!emcore_get_temp_file_name(&fname, &error)) { EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed[%d]", error); @@ -585,7 +588,9 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta mailbox_id_target = mail_data->mailbox_id; - if (input_from_eas == 0) { + if (input_from_eas == 0 && + !(input_mail_data->message_class & EMAIL_MESSAGE_CLASS_SMART_REPLY) && + !(input_mail_data->message_class & EMAIL_MESSAGE_CLASS_SMART_FORWARD) ) { if (mail_data->file_path_plain) { if (stat(mail_data->file_path_plain, &st_buf) < 0) { EM_DEBUG_EXCEPTION("mail_data->file_path_plain, stat(\"%s\") failed...", mail_data->file_path_plain); @@ -904,11 +909,11 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta } if ((ext = strrchr(attachment_data_list[i].attachment_name, '.'))) { - if (!strncmp(ext, ".vcs", strlen(".vcs"))) + if (!strncmp(ext, ".vcs", EM_SAFE_STRLEN(".vcs"))) remove(attachment_data_list[i].attachment_path); - else if (!strncmp(ext, ".vcf", strlen(".vcf"))) + else if (!strncmp(ext, ".vcf", EM_SAFE_STRLEN(".vcf"))) remove(attachment_data_list[i].attachment_path); - else if (!strncmp(ext, ".vnt", strlen(".vnt"))) + else if (!strncmp(ext, ".vnt", EM_SAFE_STRLEN(".vnt"))) remove(attachment_data_list[i].attachment_path); } } @@ -1019,14 +1024,14 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re receipt_mail_data->message_id = EM_SAFE_STRDUP(read_mail_data->message_id); if (read_mail_data->subject) { - receipt_mail_data->subject = em_malloc(strlen(read_mail_data->subject) + 7); + receipt_mail_data->subject = em_malloc(EM_SAFE_STRLEN(read_mail_data->subject) + 7); if (!(receipt_mail_data->subject)) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - SNPRINTF(receipt_mail_data->subject, strlen(read_mail_data->subject) + 7, "Read: %s", read_mail_data->subject); + SNPRINTF(receipt_mail_data->subject, EM_SAFE_STRLEN(read_mail_data->subject) + 7, "Read: %s", read_mail_data->subject); } if (!emstorage_get_mailbox_by_mailbox_type(receipt_mail_data->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_tbl, true, &err)) { @@ -1494,7 +1499,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam int ret = false; int err = EMAIL_ERROR_NONE; int status = EMAIL_SEND_FAIL; - int mail_id = 0; + int *mail_ids = NULL; int handle = 0; int i = 0; int total = 0; @@ -1508,7 +1513,6 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam email_option_t *opt = NULL; sslstart_t stls = NULL; void *tmp_stream = NULL; - void *p = NULL; emstorage_mailbox_tbl_t* local_mailbox = NULL; int dst_mailbox_id = 0; @@ -1518,7 +1522,6 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam goto FINISH_OFF; } - mail_send_notify(EMAIL_SEND_PREPARE, 0, 0, account_id, mail_id, err); if (!(ref_account = emcore_get_account_reference(account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); @@ -1535,24 +1538,47 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam EM_DEBUG_EXCEPTION("emstorage_mail_search_start failed [%d]", err); goto FINISH_OFF; } - - while (i++ < total) { - FINISH_OFF_IF_CANCELED; - - p = NULL; - if (!emstorage_mail_search_result(handle, RETRIEVE_ID, (void **)&p, true, &err)) { + + mail_ids = em_malloc(sizeof(int) * total); + if (mail_ids == NULL) { + EM_DEBUG_EXCEPTION("malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + for (i = 0; i < total ; i++) { + if (!emstorage_mail_search_result(handle, RETRIEVE_ID, (void **)&mail_ids[i], true, &err)) { EM_DEBUG_EXCEPTION("emstorage_mail_search_result failed [%d]", err); goto FINISH_OFF; } + } + + if (!emstorage_mail_search_end(handle, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_mail_search_end failed [%d]", err); + goto FINISH_OFF; + } + + handle = 0; + + mail_send_notify(EMAIL_SEND_PREPARE, 0, 0, account_id, mail_ids[total], err); + + for (i = 0; i < total; i++) { + FINISH_OFF_IF_CANCELED; - mail_id = (int)p; - - if (!emstorage_get_mail_by_id(mail_id, &searched_mail_tbl_data, false, &err)) { + if (!emstorage_get_mail_by_id(mail_ids[i], &searched_mail_tbl_data, false, &err)) { 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) { + /* Skip the mail canceled */ + if (searched_mail_tbl_data->save_status == EMAIL_MAIL_STATUS_SEND_CANCELED) { + EM_DEBUG_EXCEPTION("The mail was canceled. [%d]", mail_ids[i]); + emstorage_free_mail(&searched_mail_tbl_data, 1, &err); + searched_mail_tbl_data = NULL; + continue; + } + + if ( (err = emstorage_get_attachment_list(mail_ids[i], false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); goto FINISH_OFF; } @@ -1564,15 +1590,6 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam goto FINISH_OFF; } - /* check that this mail was saved in offline-mode. */ -/* - if (searched_mail_tbl_data->save_status != EMAIL_MAIL_STATUS_SAVED_OFFLINE) { - EM_DEBUG_EXCEPTION(" mail was not saved in offline mode..."); - emstorage_free_mail(&searched_mail_tbl_data, 1, &err); - searched_mail_tbl_data = NULL; - continue; - } -*/ searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING; if (!emcore_make_rfc822_file_from_mail(searched_mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) { @@ -1605,7 +1622,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam FINISH_OFF_IF_CANCELED; - mail_send_notify(EMAIL_SEND_CONNECTION_SUCCEED, 0, 0, account_id, mail_id, err); + mail_send_notify(EMAIL_SEND_CONNECTION_SUCCEED, 0, 0, account_id, mail_ids[i], err); /* reqest of delivery status. */ if (opt && opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON) { @@ -1615,25 +1632,25 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam stream->protocol.esmtp.dsn.notify.success = 1; } - mail_send_notify(EMAIL_SEND_START, 0, 0, account_id, mail_id, err); + mail_send_notify(EMAIL_SEND_START, 0, 0, account_id, mail_ids[i], err); } searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING; /* update mail status to sending. */ - if (!emstorage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) { + if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); goto FINISH_OFF; } - if (!emcore_send_mail_smtp(stream, envelope, fpath, account_id, mail_id, &err)) { + if (!emcore_send_mail_smtp(stream, envelope, fpath, account_id, mail_ids[i], &err)) { EM_DEBUG_EXCEPTION("emcore_send_mail_smtp failed [%d]", err); searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_FAILURE; /* update mail status to failure. */ - if (!emstorage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) + if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, true, &err)) { @@ -1642,7 +1659,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam } dst_mailbox_id = local_mailbox->mailbox_id; - emcore_move_mail(&mail_id, 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, NULL); + emcore_move_mail(&mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, NULL); if(local_mailbox) emstorage_free_mailbox(&local_mailbox, 1, NULL); @@ -1653,7 +1670,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENT; /* update mail status to sent mail. */ - if (!emstorage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) { + if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); goto FINISH_OFF; } @@ -1666,14 +1683,14 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam } dst_mailbox_id = local_mailbox->mailbox_id; - if (!emcore_move_mail(&mail_id, 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err)) + if (!emcore_move_mail(&mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err)) EM_DEBUG_EXCEPTION("emcore_mail_move falied [%d]", err); if(local_mailbox) emstorage_free_mailbox(&local_mailbox, 1, NULL); } else { - if (!emcore_delete_mail(account_id, &mail_id, 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err)) + if (!emcore_delete_mail(account_id, &mail_ids[i], 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err)) EM_DEBUG_EXCEPTION("emcore_delete_mail falied [%d]", err); } @@ -1731,11 +1748,14 @@ FINISH_OFF: emstorage_free_mailbox(&local_mailbox, 1, NULL); if (ret == true) - mail_send_notify(EMAIL_SEND_FINISH, 0, 0, account_id, mail_id, err); + mail_send_notify(EMAIL_SEND_FINISH, 0, 0, account_id, mail_ids[total], err); else { - mail_send_notify(status, 0, 0, account_id, mail_id, err); + if(mail_ids) /* prevent 34385 */ + mail_send_notify(status, 0, 0, account_id, mail_ids[total], err); emcore_show_user_message(account_id, EMAIL_ACTION_SEND_MAIL, err); } + + EM_SAFE_FREE(mail_ids); if (err_code != NULL) *err_code = err; @@ -1786,15 +1806,15 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f /* set DSN for ESMTP */ if (stream->protocol.esmtp.ok) { if (stream->protocol.esmtp.eightbit.ok && stream->protocol.esmtp.eightbit.want) - strncat (buf, " BODY=8BITMIME", sizeof(buf)-(strlen(buf)+1)); + strncat (buf, " BODY=8BITMIME", sizeof(buf)-(EM_SAFE_STRLEN(buf)+1)); EM_DEBUG_LOG("stream->protocol.esmtp.dsn.ok [%d]", stream->protocol.esmtp.dsn.ok); if (stream->protocol.esmtp.dsn.ok && stream->protocol.esmtp.dsn.want) { EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is required"); - strncat (buf, stream->protocol.esmtp.dsn.full ? " RET=FULL" : " RET=HDRS", sizeof(buf)-strlen(buf)-1); + strncat (buf, stream->protocol.esmtp.dsn.full ? " RET=FULL" : " RET=HDRS", sizeof(buf)-EM_SAFE_STRLEN(buf)-1); if (stream->protocol.esmtp.dsn.envid) - SNPRINTF (buf + strlen (buf), sizeof(buf)-(strlen(buf)), " ENVID=%.100s", stream->protocol.esmtp.dsn.envid); + SNPRINTF (buf + EM_SAFE_STRLEN (buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)), " ENVID=%.100s", stream->protocol.esmtp.dsn.envid); } else EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required or DSN is not supported"); @@ -1984,7 +2004,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f #ifdef FEATURE_SEND_DATA_DEBUG EM_DEBUG_LOG("%s", buf); #endif - sent += strlen(buf); + sent += EM_SAFE_STRLEN(buf); if (!(send_ret = smtp_soutr(stream->netstream, buf))) break; @@ -2045,7 +2065,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err) return NULL; } - int cid_length = RANDOM_NUMBER_LENGTH + strlen(hostname) + 2, random_number_1, random_number_2, random_number_3, random_number_4; + int cid_length = RANDOM_NUMBER_LENGTH + EM_SAFE_STRLEN(hostname) + 2, random_number_1, random_number_2, random_number_3, random_number_4; char *cid_string = NULL; cid_string = malloc(cid_length); @@ -2145,7 +2165,7 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char if (filename) { /* attachment */ source_text.data = (unsigned char*)filename; - source_text.size = strlen(filename); + source_text.size = EM_SAFE_STRLEN(filename); result_charset = (CHARSET*)utf8_infercharset(&source_text); @@ -2171,7 +2191,7 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char if(encoded_file_name == NULL) encoded_file_name = strdup(filename); - if(!em_encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) { + if(!em_encode_base64(encoded_file_name, EM_SAFE_STRLEN(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) { EM_DEBUG_EXCEPTION("em_encode_base64 failed. error [%d]", error); goto FINISH_OFF; } @@ -2182,12 +2202,12 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char if(result_file_name) { EM_SAFE_FREE(encoded_file_name); - encoded_file_name = em_malloc(strlen(result_file_name) + 15); + encoded_file_name = em_malloc(EM_SAFE_STRLEN(result_file_name) + 15); if(!encoded_file_name) { EM_DEBUG_EXCEPTION("em_malloc failed."); goto FINISH_OFF; } - snprintf(encoded_file_name, strlen(result_file_name) + 15, "=?UTF-8?B?%s?=", result_file_name); + snprintf(encoded_file_name, EM_SAFE_STRLEN(result_file_name) + 15, "=?UTF-8?B?%s?=", result_file_name); EM_DEBUG_LOG("encoded_file_name [%s]", encoded_file_name); EM_SAFE_FREE(result_file_name); } @@ -2235,7 +2255,7 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char if (is_inline) { /* CONTENT-ID */ - part->body.id = emcore_generate_content_id_string("org.tizen.email", &error); + part->body.id = emcore_generate_content_id_string("org.tizen.slp.email", &error); part->body.type = TYPEIMAGE; /* EM_SAFE_FREE(part->body.subtype); */ /* part->body.subtype = EM_SAFE_STRDUP(content_sub_type); */ @@ -2512,7 +2532,7 @@ static char *emcore_encode_rfc2047_text(char *utf8_text, int *err_code) return NULL; } - gsize len = strlen(utf8_text); + gsize len = EM_SAFE_STRLEN(utf8_text); EM_DEBUG_FUNC_END(); @@ -2554,7 +2574,7 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d if (!input_mail_tbl_data || !output_envelope) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + return error; /* prevent 32729 */ } if ( (input_mail_tbl_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0 && !input_mail_tbl_data->body_download_status) { @@ -2649,14 +2669,14 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d int i, j; if (input_mail_tbl_data->full_address_from) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_from); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_from); i < j; i++) { if (input_mail_tbl_data->full_address_from[i] == ';') input_mail_tbl_data->full_address_from[i] = ','; } } if (input_mail_tbl_data->full_address_return) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_return); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_return); i < j; i++) { if (input_mail_tbl_data->full_address_return[i] == ';') input_mail_tbl_data->full_address_return[i] = ','; } @@ -2680,21 +2700,21 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d int i, j; if (input_mail_tbl_data->full_address_to) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_to); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_to); i < j; i++) { if (input_mail_tbl_data->full_address_to[i] == ';') input_mail_tbl_data->full_address_to[i] = ','; } } if (input_mail_tbl_data->full_address_cc) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_cc); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_cc); i < j; i++) { if (input_mail_tbl_data->full_address_cc[i] == ';') input_mail_tbl_data->full_address_cc[i] = ','; } } if (input_mail_tbl_data->full_address_bcc) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_bcc); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_bcc); i < j; i++) { if (input_mail_tbl_data->full_address_bcc[i] == ';') input_mail_tbl_data->full_address_bcc[i] = ','; } @@ -2739,7 +2759,7 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d char localtime_string[DATE_STR_LENGTH] = { 0, }; strftime(localtime_string, 128, "%a, %e %b %Y %H : %M : %S ", localtime(&input_mail_tbl_data->date_time)); /* append last 5byes("+0900") */ - g_strlcat(localtime_string, rfc822_date_string + (strlen(rfc822_date_string) - 5), DATE_STR_LENGTH); + g_strlcat(localtime_string, rfc822_date_string + (EM_SAFE_STRLEN(rfc822_date_string) - 5), DATE_STR_LENGTH); envelope->date = (unsigned char *)cpystr((const char *)localtime_string); } else { @@ -2896,7 +2916,7 @@ 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 && strlen(input_mail_tbl_data->file_path_plain) > 0) { + 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); @@ -2904,7 +2924,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } } - if (input_mail_tbl_data->file_path_html && strlen(input_mail_tbl_data->file_path_html) > 0) { + 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); @@ -2919,7 +2939,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } } - if (input_mail_tbl_data->file_path_mime_entity && strlen(input_mail_tbl_data->file_path_mime_entity) > 0) { + if (input_mail_tbl_data->file_path_mime_entity && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_mime_entity) > 0) { EM_DEBUG_LOG("file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity); root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_mime_entity); } @@ -2979,7 +2999,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ if (input_mail_tbl_data->file_path_html != NULL && input_mail_tbl_data->file_path_html[0] != '\0') text_body->subtype = EM_SAFE_STRDUP("html"); if (text_body->sparep) - text_body->size.bytes = strlen(text_body->sparep); + text_body->size.bytes = EM_SAFE_STRLEN(text_body->sparep); else text_body->size.bytes = 0; } @@ -2992,7 +3012,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } if (file_path) { - EM_DEBUG_LOG("write rfc822 : file_path[%s]", file_path); + EM_DEBUG_LOG("write rfc822 : file_path[%p]", file_path); if (part_for_html) html_body = &(part_for_html->body); @@ -3139,14 +3159,14 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data int i, j; if (input_mail_tbl_data->full_address_from) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_from); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_from); i < j; i++) { if (input_mail_tbl_data->full_address_from[i] == ';') input_mail_tbl_data->full_address_from[i] = ','; } } if (input_mail_tbl_data->full_address_return) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_return); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_return); i < j; i++) { if (input_mail_tbl_data->full_address_return[i] == ';') input_mail_tbl_data->full_address_return[i] = ','; } @@ -3170,21 +3190,21 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data int i, j; if (input_mail_tbl_data->full_address_to) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_to); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_to); i < j; i++) { if (input_mail_tbl_data->full_address_to[i] == ';') input_mail_tbl_data->full_address_to[i] = ','; } } if (input_mail_tbl_data->full_address_cc) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_cc); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_cc); i < j; i++) { if (input_mail_tbl_data->full_address_cc[i] == ';') input_mail_tbl_data->full_address_cc[i] = ','; } } if (input_mail_tbl_data->full_address_bcc) { - for (i = 0, j = strlen(input_mail_tbl_data->full_address_bcc); i < j; i++) { + for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_bcc); i < j; i++) { if (input_mail_tbl_data->full_address_bcc[i] == ';') input_mail_tbl_data->full_address_bcc[i] = ','; } @@ -3230,7 +3250,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data if (!is_incomplete) { strftime(localtime_string, 128, "%a, %e %b %Y %H : %M : %S ", localtime(&input_mail_tbl_data->date_time)); /* append last 5byes("+0900") */ - g_strlcat(localtime_string, rfc822_date_string + (strlen(rfc822_date_string) - 5), DATE_STR_LENGTH); + g_strlcat(localtime_string, rfc822_date_string + (EM_SAFE_STRLEN(rfc822_date_string) - 5), DATE_STR_LENGTH); envelope->date = (unsigned char *)cpystr((const char *)localtime_string); } else { @@ -3288,7 +3308,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data text_body = &part_for_text->body; - if (input_mail_tbl_data->file_path_plain && strlen(input_mail_tbl_data->file_path_plain) > 0) { + 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 *)temp_file_path_plain, 0, NULL, NULL, false, &error)) { EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); @@ -3296,7 +3316,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data } } - if (input_mail_tbl_data->file_path_html && strlen(input_mail_tbl_data->file_path_html) > 0) { + 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); @@ -3364,7 +3384,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data if (input_mail_tbl_data->file_path_html != NULL && input_mail_tbl_data->file_path_html[0] != '\0') text_body->subtype = EM_SAFE_STRDUP("html"); if (text_body->sparep) - text_body->size.bytes = strlen(text_body->sparep); + text_body->size.bytes = EM_SAFE_STRLEN(text_body->sparep); else text_body->size.bytes = 0; } @@ -3383,14 +3403,14 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data *file_path = fname; } - if (strlen(temp_file_path_plain) > 0) { + if (EM_SAFE_STRLEN(temp_file_path_plain) > 0) { if (!emstorage_delete_file(temp_file_path_plain, &error)) { EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", error); goto FINISH_OFF; } } - if (strlen(temp_file_path_html) > 0) { + if (EM_SAFE_STRLEN(temp_file_path_html) > 0) { if (!emstorage_delete_file(temp_file_path_html, &error)) { EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", error); goto FINISH_OFF; diff --git a/email-core/email-core-sound.c b/email-core/email-core-sound.c index 9d46c4a..8814b22 100755 --- a/email-core/email-core-sound.c +++ b/email-core/email-core-sound.c @@ -33,14 +33,9 @@ #define TIMER 30000 // 30 seconds #define HAPTIC_TEST_ITERATION 1 -#define SETTING_SOUND_STATUS_OFF 0 -#define SETTING_SOUND_STATUS_GLOBAL 1 -#define SETTING_SOUND_STATUS_EMAIL 2 - static MMHandleType email_mmhandle = 0; static alarm_id_t email_alarm_id = 0; -static int email_vibe_handle = 0; -static int setting_sound_status = 0; +static int setting_noti_status = 0; static char *filename; alarm_entry_t *alarm_info = NULL; @@ -51,8 +46,6 @@ static pthread_mutex_t mmhandle_mutex = PTHREAD_MUTEX_INITIALIZER; static thread_t g_alert_thread; void emcore_set_repetition_alarm(int repetition); -int emcore_vibration_destory(); -int emcore_vibration_stop(); int emcore_sound_mp_player_stop(); bool emcore_sound_mp_player_destory(); void *start_alert_thread(void *arg); @@ -83,12 +76,15 @@ int emcore_alert_sound_init() int emcore_alert_alarm_init() { + EM_DEBUG_FUNC_BEGIN(); + int ret = ALARMMGR_RESULT_SUCCESS; ret = alarmmgr_init("email-service-0"); - if (ret != 0) + if (ret != ALARMMGR_RESULT_SUCCESS) EM_DEBUG_EXCEPTION("alarmmgr_init failed : [%d]", ret); + EM_DEBUG_FUNC_END(); return ret; } @@ -109,24 +105,11 @@ int emcore_alert_sound_filepath_init() return true; } -int emcore_alert_vibe_init() -{ - email_vibe_handle = device_haptic_open(DEV_IDX_0, 0); - if (!email_vibe_handle) { - EM_DEBUG_EXCEPTION("device_haptic_open failed"); - return false; - } - - return true; -} - void emcore_global_noti_key_changed_cb(keynode_t *key_node, void *data) { + EM_DEBUG_FUNC_BEGIN(); int ret = 0; - if (setting_sound_status != SETTING_SOUND_STATUS_GLOBAL) - return; - switch (vconf_keynode_get_type(key_node)) { case VCONF_TYPE_INT: ret = alarmmgr_remove_alarm(email_alarm_id); @@ -142,6 +125,8 @@ void emcore_global_noti_key_changed_cb(keynode_t *key_node, void *data) EM_DEBUG_EXCEPTION("Invalid key type"); break; } + + EM_DEBUG_FUNC_END(); } void emcore_email_noti_key_changed_cb(keynode_t *key_node, void *data) @@ -149,9 +134,6 @@ void emcore_email_noti_key_changed_cb(keynode_t *key_node, void *data) EM_DEBUG_FUNC_BEGIN(); int ret = 0; - if (setting_sound_status != SETTING_SOUND_STATUS_EMAIL) - return; - switch (vconf_keynode_get_type(key_node)) { case VCONF_TYPE_INT: ret = alarmmgr_remove_alarm(email_alarm_id); @@ -170,7 +152,7 @@ void emcore_email_noti_key_changed_cb(keynode_t *key_node, void *data) EM_DEBUG_FUNC_END(); } -bool emcore_update_sound_status() +bool emcore_update_noti_status() { EM_DEBUG_FUNC_BEGIN(); int ticker_noti = 0; @@ -181,33 +163,37 @@ bool emcore_update_sound_status() return false; } - setting_sound_status = SETTING_SOUND_STATUS_EMAIL; + EM_DEBUG_LOG("ticker_noti of vip : [%d]", ticker_noti); - if (!ticker_noti) { + if (ticker_noti <= 0) { /* Get the Global noti ticker */ if (vconf_get_bool(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, &ticker_noti) != 0) { EM_DEBUG_EXCEPTION("Not display the noti of email"); return false; } + EM_DEBUG_LOG("ticker_noti of global : [%d]", ticker_noti); + if (!ticker_noti) { EM_DEBUG_LOG("Not use the notification"); - setting_sound_status = SETTING_SOUND_STATUS_OFF; + setting_noti_status = SETTING_NOTI_STATUS_OFF; return true; } - setting_sound_status = SETTING_SOUND_STATUS_GLOBAL; + setting_noti_status = SETTING_NOTI_STATUS_GLOBAL; + } else { + setting_noti_status = SETTING_NOTI_STATUS_EMAIL; } EM_DEBUG_FUNC_END(); return true; } -void emcore_sound_status_changed_cb(keynode_t *key_node, void *data) +void emcore_noti_status_changed_cb(keynode_t *key_node, void *data) { EM_DEBUG_FUNC_BEGIN(); - if (!emcore_update_sound_status()) { - EM_DEBUG_EXCEPTION("emcore_update_sound_status failed"); + if (!emcore_update_noti_status()) { + EM_DEBUG_EXCEPTION("emcore_update_noti_status failed"); return; } EM_DEBUG_FUNC_END(); @@ -215,44 +201,40 @@ void emcore_sound_status_changed_cb(keynode_t *key_node, void *data) bool emcore_noti_init(void *data) { + EM_DEBUG_FUNC_BEGIN(); struct appdata *ap = data; - if (!emcore_update_sound_status()) { - EM_DEBUG_EXCEPTION("emcore_update_sound_status failed"); + if (!emcore_update_noti_status()) { + EM_DEBUG_EXCEPTION("emcore_update_noti_status failed"); return false; } /* Noti callback registration */ if (vconf_notify_key_changed(VCONFKEY_SETAPPL_NOTI_EMAIL_ALERT_REP_TYPE_INT, emcore_global_noti_key_changed_cb, ap) < 0) { EM_DEBUG_EXCEPTION("Register failed : alert type"); - return false; } if (vconf_notify_key_changed(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, emcore_global_noti_key_changed_cb, ap) < 0) { EM_DEBUG_EXCEPTION("Register failed : Ringtone path"); - return false; } if (vconf_notify_key_changed(VCONF_VIP_NOTI_REP_TYPE, emcore_email_noti_key_changed_cb, ap) < 0) { EM_DEBUG_EXCEPTION("Register failed : alert type"); - return false; } if (vconf_notify_key_changed(VCONF_VIP_NOTI_RINGTONE_PATH, emcore_email_noti_key_changed_cb, ap) < 0) { EM_DEBUG_EXCEPTION("Register failed : Ringtone path"); - return false; } - if (vconf_notify_key_changed(VCONF_VIP_NOTI_NOTIFICATION_TICKER, emcore_sound_status_changed_cb, ap) < 0) { + if (vconf_notify_key_changed(VCONF_VIP_NOTI_NOTIFICATION_TICKER, emcore_noti_status_changed_cb, ap) < 0) { EM_DEBUG_EXCEPTION("Register failed : Ringtone path"); - return false; } - if (vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, emcore_sound_status_changed_cb, ap) < 0) { + if (vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, emcore_noti_status_changed_cb, ap) < 0) { EM_DEBUG_EXCEPTION("Register failed : Ringtone path"); - return false; } + EM_DEBUG_FUNC_END(); return true; } @@ -277,11 +259,6 @@ int emcore_alert_init() return false; } - if (!emcore_alert_vibe_init()) { - EM_DEBUG_EXCEPTION("emcore_alert_vibe_init failed"); - return false; - } - if (!emcore_noti_init(NULL)) { EM_DEBUG_EXCEPTION("emcore_noti_init failed"); return false; @@ -339,20 +316,6 @@ bool emcore_sound_mp_player_create() return true; } -bool emcore_vibration_create() -{ - EM_DEBUG_FUNC_BEGIN(); - - email_vibe_handle = device_haptic_open(DEV_IDX_0, 0); - - if (email_vibe_handle < 0) { - EM_DEBUG_EXCEPTION("vibration create failed"); - return false; - } - EM_DEBUG_FUNC_END(); - return true; -} - bool emcore_alarm_create() { EM_DEBUG_FUNC_BEGIN(); @@ -416,12 +379,6 @@ bool emcore_alert_destory() return false; } - /* Destroy the vibration handle */ - if (!emcore_vibration_destory()) { - EM_DEBUG_EXCEPTION("emcore_vibration_destory fail"); - return false; - } - /* Destroy the alarm handle */ ret = alarmmgr_free_alarm(alarm_info); if (ret != ALARMMGR_RESULT_SUCCESS) { @@ -452,62 +409,49 @@ gboolean mp_player_timeout_cb(void *data) return false; } -gboolean vibration_timeout_cb(void *data) +bool emcore_vibration_start() { EM_DEBUG_FUNC_BEGIN(); + int ret = false; + int error = FEEDBACK_ERROR_NONE; + int call_state = 0; - emcore_vibration_stop(); - emcore_vibration_destory(); - - EM_DEBUG_FUNC_END(); - return false; -} - -bool emcore_vibration_start(int haptic_level) -{ - EM_DEBUG_FUNC_BEGIN(); - int ret = 0; - int vibPattern = EFFCTVIBE_NOTIFICATION; + error = vconf_get_int(VCONFKEY_CALL_STATE, &call_state); + if (error == -1) { + EM_DEBUG_EXCEPTION("vconf_get_int failed"); + goto FINISH_OFF; + } - if (haptic_level == 0) { - EM_DEBUG_LOG("The level of haptic is zero"); - return true; + error = feedback_initialize(); + if (error != FEEDBACK_ERROR_NONE) { + EM_DEBUG_EXCEPTION("feedback_initialize failed : [%d]", error); + goto FINISH_OFF; } - ret = device_haptic_play_pattern(email_vibe_handle, vibPattern, HAPTIC_TEST_ITERATION, haptic_level); + if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) { + error = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_EMAIL_ON_CALL); + } else { + error = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_EMAIL); + } - if (ret != 0) { - EM_DEBUG_EXCEPTION("Fail to play haptic : [%d]", ret); - return false; + if (error != FEEDBACK_ERROR_NONE) { + EM_DEBUG_EXCEPTION("feedback_play failed : [%d]", error); + goto FINISH_OFF; } - if ((ret = g_timeout_add(TIMER, (GSourceFunc) vibration_timeout_cb, NULL) <= 0)) - { - EM_DEBUG_EXCEPTION("play_alert - Failed to start timer [%d]", ret); - return false; - } - - EM_DEBUG_FUNC_END(); - return true; -} + ret = true; -int emcore_vibration_stop() -{ - int err = MM_ERROR_NONE; - if ((err = device_haptic_stop_play(email_vibe_handle)) != 0) - EM_DEBUG_EXCEPTION("Fail to stop haptic : [%d]", err); +FINISH_OFF: - return err; + error = feedback_deinitialize(); + if (error != FEEDBACK_ERROR_NONE) { + EM_DEBUG_EXCEPTION("feedback_deinitialize failed : [%d]", error); + } + + EM_DEBUG_FUNC_END(); + return ret; } -int emcore_vibration_destory() -{ - int err = MM_ERROR_NONE; - if ((err = device_haptic_close(email_vibe_handle)) != 0) - EM_DEBUG_EXCEPTION("Fail to close haptic : [%d]", err); - - return err; -} int emcore_sound_mp_player_start(char *filepath) { EM_DEBUG_FUNC_BEGIN(); @@ -527,7 +471,7 @@ int emcore_sound_mp_player_start(char *filepath) mm_player_set_message_callback(email_mmhandle, emcore_mp_player_state_cb, (void *)email_mmhandle); EM_DEBUG_LOG("Before mm_player_set_attribute filepath = %s", filepath); - if ((err = mm_player_set_attribute(email_mmhandle, NULL, "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION, "profile_uri", filepath, strlen(filepath), NULL)) != MM_ERROR_NONE) + if ((err = mm_player_set_attribute(email_mmhandle, NULL, "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION, "profile_uri", filepath, EM_SAFE_STRLEN(filepath), NULL)) != MM_ERROR_NONE) { EM_DEBUG_EXCEPTION("mm_player_set_attribute faile [ %d ] ", err); return err; @@ -648,8 +592,7 @@ int emcore_get_alert_type() int err; int alert_type = -1; - if (!(err = get_vconf_data(EMAIL_SOUND_STATUS, &sound_status))) - { + if (!(err = get_vconf_data(EMAIL_SOUND_STATUS, &sound_status))) { EM_DEBUG_EXCEPTION("Don't get sound status"); return err; } @@ -776,7 +719,7 @@ bool set_alarm(int repetition_time) ret = alarmmgr_set_cb(emcore_alarm_timeout_cb, NULL); - if (ret != 0) { + if (ret != ALARMMGR_RESULT_SUCCESS) { EM_DEBUG_EXCEPTION("Failed : alarmmgr_set_cb() -> error[%d]", ret); return false; } @@ -821,10 +764,10 @@ void emcore_set_repetition_alarm(int repetition) void *start_alert_thread(void *arg) { - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_BEGIN(); int err = 0; - int level = 0; + int repetition = 0; if (!emcore_alert_init()) { @@ -838,14 +781,12 @@ void *start_alert_thread(void *arg) return 0; } - err = get_vconf_data(EMAIL_ALERT_REP_TYPE, &level); - emcore_set_repetition_alarm(level); + err = get_vconf_data(EMAIL_ALERT_REP_TYPE, &repetition); + emcore_set_repetition_alarm(repetition); ENTER_CRITICAL_SECTION(sound_mutex); SLEEP_CONDITION_VARIABLE(sound_condition , sound_mutex); - err = get_vconf_data(EMAIL_ALERT_VIBE_STENGTH, &level); - switch (emcore_get_alert_type()) { case EMAIL_ALERT_TYPE_MELODY: @@ -856,12 +797,10 @@ void *start_alert_thread(void *arg) emcore_sound_mp_player_start(filename); break; case EMAIL_ALERT_TYPE_VIB: - emcore_vibration_create(); - emcore_vibration_start(level); + emcore_vibration_start(); break; case EMAIL_ALERT_TYPE_MELODY_AND_VIB: - emcore_vibration_create(); - emcore_vibration_start(level); + emcore_vibration_start(); if (!emcore_sound_mp_player_create()) { EM_DEBUG_LOG("emcore_sound_mp_player_create failed : [%d]", email_mmhandle); break; @@ -880,15 +819,19 @@ void *start_alert_thread(void *arg) EM_DEBUG_LOG("Start FINISH"); emcore_alarm_destory(); } + + EM_DEBUG_FUNC_END(); return 0; } INTERNAL_FUNC void emcore_start_alert() { - if (setting_sound_status == SETTING_SOUND_STATUS_OFF) + EM_DEBUG_FUNC_BEGIN("setting_noti_status : [%d]", setting_noti_status); + + if (setting_noti_status == SETTING_NOTI_STATUS_OFF) return; ENTER_CRITICAL_SECTION(sound_mutex); WAKE_CONDITION_VARIABLE(sound_condition); LEAVE_CRITICAL_SECTION(sound_mutex); -} +} diff --git a/email-core/email-core-task-manager.c b/email-core/email-core-task-manager.c index 1bfceea..730d187 100755 --- a/email-core/email-core-task-manager.c +++ b/email-core/email-core-task-manager.c @@ -228,6 +228,7 @@ INTERNAL_FUNC int emcore_init_task_handler_array() _task_handler_array_size = 0; REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT); + REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX); } EM_DEBUG_FUNC_END(); diff --git a/email-core/email-core-tasks.c b/email-core/email-core-tasks.c index dd43d18..a7fa5e4 100755 --- a/email-core/email-core-tasks.c +++ b/email-core/email-core-tasks.c @@ -36,6 +36,7 @@ #include "email-core-task-manager.h" #include "email-core-mail.h" #include "email-core-mailbox-sync.h" +#include "email-core-signal.h" #include "tpl.h" /*-------------------------------------------------------------------------------------------*/ @@ -112,15 +113,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAI EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb.addr); } else { - task_parameter->mail_id_array = em_malloc(sizeof(int) * task_parameter->mail_id_count); - - if(task_parameter->mail_id_array == NULL) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - memcpy(task_parameter->mail_id_array, tb.addr, sizeof(int) * task_parameter->mail_id_count); - EM_SAFE_FREE(tb.addr); + task_parameter->mail_id_array = tb.addr; } *output_task_parameter_struct = task_parameter; @@ -134,34 +127,124 @@ FINISH_OFF: return EMAIL_ERROR_NONE; } -void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param) +INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param) { EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param); int err = EMAIL_ERROR_NONE; + int err_for_signal = EMAIL_ERROR_NONE; int i = 0; - int moved_mail_id = 0; + int task_id = THREAD_SELF(); task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param; - email_active_task_t *active_task = NULL; - if((err = emcore_get_active_task_by_thread_id(THREAD_SELF(), &active_task)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_get_active_task_by_thread_id failed [%d]", err); - goto FINISH_OFF; - } for(i = 0; i < task_param->mail_id_count; i++) { - if((err = emcore_move_mail_to_another_account_on_local_storeage(active_task->task_id, task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, &moved_mail_id)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account_on_local_storeage failed [%d]", err); - /* goto FINISH_OFF; */ + if((err = emcore_move_mail_to_another_account(task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, task_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err); + goto FINISH_OFF; } - if((err = emcore_sync_mail_from_client_to_server(moved_mail_id, &err)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_sync_mail_from_client_to_server failed [%d]", err); - /* goto FINISH_OFF; */ - } + /* Send progress signal */ + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mail_id_count)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + +FINISH_OFF: + /* Free task parameter */ + EM_SAFE_FREE(task_param->mail_id_array); + EM_SAFE_FREE(task_param); + + EM_DEBUG_FUNC_END("err [%d]", err); + return NULL; +} +/*-------------------------------------------------------------------------------------------*/ +/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */ +#define task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX "iiBi" + +INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size) +{ + EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size); + + int err = EMAIL_ERROR_NONE; + task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = input_task_parameter_struct; + tpl_bin tb; + tpl_node *tn = NULL; + void *result_data = NULL; + size_t result_data_length = 0; + + if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX + , &task_parameter->account_id + , &task_parameter->mailbox_id_count + , &tb + , &task_parameter->on_server); + tb.sz = sizeof(int) * task_parameter->mailbox_id_count; + tb.addr = task_parameter->mailbox_id_array; + tpl_pack(tn, 0); + tpl_dump(tn, TPL_MEM, &result_data, &result_data_length); + tpl_free(tn); + + *output_byte_stream = result_data; + *output_stream_size = result_data_length; + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return EMAIL_ERROR_NONE; +} + +INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct) +{ + EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct); + int err = EMAIL_ERROR_NONE; + tpl_bin tb; + tpl_node *tn = NULL; + task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = NULL; + + if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX)); + + if(task_parameter == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX + , &task_parameter->account_id + , &task_parameter->mailbox_id_count + , &tb + , &task_parameter->on_server); + tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size); + tpl_unpack(tn, 0); + if(task_parameter->mailbox_id_count <= 0 || tb.addr == NULL) { + EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mailbox_id_count, tb.addr); + } + else { + task_parameter->mailbox_id_array = tb.addr; } + *output_task_parameter_struct = task_parameter; + FINISH_OFF: + if(tn) + tpl_free(tn); + EM_DEBUG_FUNC_END("err [%d]", err); + return EMAIL_ERROR_NONE; +} + +INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param) +{ return NULL; } /*-------------------------------------------------------------------------------------------*/ diff --git a/email-core/email-core-utils.c b/email-core/email-core-utils.c index fba12e5..4c7d3fb 100755 --- a/email-core/email-core-utils.c +++ b/email-core/email-core-utils.c @@ -123,7 +123,7 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha size_t long_enc_path_len = 0; - if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, strlen(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */ + if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */ EM_DEBUG_LOG("account->incoming_server_address[%p]", account->incoming_server_address); EM_DEBUG_LOG("account->incoming_server_address[%s]", account->incoming_server_address); @@ -133,7 +133,7 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha goto FINISH_OFF; } - long_enc_path_len = strlen(account->incoming_server_address) + (path ? strlen(path) : 0) + 64; + long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 64; /*prevent 34357*/ *long_enc_path = em_malloc(long_enc_path_len); if (!*long_enc_path) { @@ -152,27 +152,27 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id); if (account->incoming_server_secure_connection & 0x01) { - strncat(p, "/ssl", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); /* strcat(p, "/tryssl"); */ } /* Currently, receiving servers doesn't require tls. if (account->incoming_server_secure_connection & 0x02) - strncat(p, "/tls", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); else - strncat(p, "/notls", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); */ if (account->incoming_server_requires_apop) { EM_DEBUG_LOG("emcore_get_long_encoded_path - incoming_server_requires_apop - %d", account->incoming_server_requires_apop); - strncat(p, "/apop", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/apop", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); EM_DEBUG_LOG("long_enc_path - %s", p); } } else { /* smtp */ - long_enc_path_len = strlen(account->outgoing_server_address) + 64; + long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64; - *long_enc_path = em_malloc(strlen(account->outgoing_server_address) + 64); + *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64); if (!*long_enc_path) { EM_DEBUG_EXCEPTION("\t malloc failed...\n"); @@ -190,21 +190,21 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha "smtp"); if (account->outgoing_server_need_authentication) { - SNPRINTF(p + strlen(p), long_enc_path_len-(strlen(p)), "/user=%d", account->account_id); + SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d", account->account_id); } if (account->outgoing_server_secure_connection & 0x01) { - strncat(p, "/ssl", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); /* strcat(p, "/tryssl"); */ } if (account->outgoing_server_secure_connection & 0x02) - strncat(p, "/tls", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); else - strncat(p, "/notls", long_enc_path_len-(strlen(p)+1)); + strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); } - if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, strlen(ENCODED_PATH_SMTP)) != 0)) { - strncat(p, "}", long_enc_path_len-(strlen(p)+1)); + if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { + strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); if (path != NULL) { char *enc_name = NULL; @@ -216,7 +216,7 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha } if (enc_name) { - strncat(p, enc_name, long_enc_path_len-(strlen(p)+1)); + strncat(p, enc_name, long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); EM_SAFE_FREE(enc_name); } } @@ -276,7 +276,7 @@ int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code) /* encoding mailbox name (Charset->UTF8->UTF7) */ - *enc_name = em_malloc(strlen(name)+1); + *enc_name = em_malloc(EM_SAFE_STRLEN(name)+1); if (*enc_name == NULL) { EM_DEBUG_EXCEPTION("malloc failed..."); if (err_code != NULL) @@ -351,7 +351,7 @@ int emcore_get_file_name(char *path, char **filename, int *err_code) goto FINISH_OFF; } - int i = (int)strlen(path); + int i = (int)EM_SAFE_STRLEN(path); /* get filename */ for (; i >= 0; i--) @@ -409,7 +409,7 @@ static int _emcore_check_host(char *host) { if (!host) return 0; - return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR.")); + return strncmp(host, ".SYNTAX-ERROR.", EM_SAFE_STRLEN(".SYNTAX-ERROR.")); } @@ -438,7 +438,7 @@ int emcore_get_address_count(char *addr_str, int *count, int *err_code) EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p); - for (i = 0, j = strlen(p); i < j; i++) + for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++) if (p[i] == ';') p[i] = ','; rfc822_parse_adrlist(&addr, p, NULL); EM_SAFE_FREE(p); @@ -446,7 +446,9 @@ int emcore_get_address_count(char *addr_str, int *count, int *err_code) for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) { if (p_addr->mailbox && p_addr->host) { - if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS")) || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS")) || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { + if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS")) + || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS")) + || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/ EM_DEBUG_LOG("Invalid address "); continue; } @@ -546,7 +548,7 @@ int emcore_get_current_session(email_session_t **session) return (i != SESSION_MAX) ? true : false; } -int emcore_get_mail_count_by_query(int priority_sender, int *total_mail, int *unread_mail, int *err_code) +int emcore_get_mail_count_by_query(int account_id, int priority_sender, int *total_mail, int *unread_mail, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -573,7 +575,12 @@ int emcore_get_mail_count_by_query(int priority_sender, int *total_mail, int *un } /* Make query for searching unread mail */ - filter_count = (rule_count * 2) + 1; // 1 is unseen field. + if (account_id != ALL_ACCOUNT) { + filter_count = (rule_count * 2) + 3; + } else { + filter_count = (rule_count * 2) + 1; // 1 is unseen field. + } + filter_list = em_malloc(sizeof(email_list_filter_t) * filter_count); if (filter_list == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -600,6 +607,16 @@ int emcore_get_mail_count_by_query(int priority_sender, int *total_mail, int *un filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD; filter_list[i].list_filter_item.rule.key_value.integer_type_value = 0; + if (account_id != ALL_ACCOUNT) { + filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND; + + filter_list[i+2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[i+2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[i+2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID; + filter_list[i+2].list_filter_item.rule.key_value.integer_type_value = account_id; + } + if ((err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err); goto FINISH_OFF; @@ -613,7 +630,7 @@ int emcore_get_mail_count_by_query(int priority_sender, int *total_mail, int *un goto FINISH_OFF; } } else { - if (!emstorage_get_mail_count(ALL_ACCOUNT, NULL, &total_count, &unread_count, true, &err)) { + if (!emstorage_get_mail_count(account_id, NULL, &total_count, &unread_count, true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_get_mail_count failed - %d", err); goto FINISH_OFF; @@ -681,7 +698,7 @@ int emcore_display_unread_in_badge() } /* Get unread mail count */ - if (!emcore_get_mail_count_by_query(priority_sender, &total_mail_count, &total_unread_count, &err)) { + if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, priority_sender, &total_mail_count, &total_unread_count, &err)) { EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed"); goto FINISH_OFF; } @@ -697,7 +714,7 @@ int emcore_display_unread_in_badge() badge_error_e badge_err = BADGE_ERROR_NONE; bool exist; - if((badge_err = badge_is_existing(" org.tizen.email ", &exist)) != BADGE_ERROR_NONE) { + if((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) { EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err); err = EMAIL_ERROR_BADGE_API_FAILED; goto FINISH_OFF; @@ -841,10 +858,10 @@ FINISH_OFF: static int emcore_add_notification(int account_id, int mail_id, email_action_t action) { EM_DEBUG_FUNC_BEGIN(); - int ret = EMAIL_ERROR_NONE; + int err = EMAIL_ERROR_NONE; - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + EM_DEBUG_FUNC_END("ret [%d]", err); + return err; } INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error) @@ -1017,6 +1034,9 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path) index++; name = g_strdup(token_list[index - 1]); + if(!name) /* prevent 27459 */ + return NULL; + g_strfreev(token_list); converted_name = emcore_convert_mutf7_to_utf8(name); @@ -1144,7 +1164,8 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * char *local_preview_text = NULL; char *encoding_type = NULL; char *utf8_encoded_string = NULL; - FILE *fp = NULL; + FILE *fp_html = NULL; + FILE *fp_plain = NULL; GError *glib_error = NULL; struct stat st_buf; @@ -1169,7 +1190,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } - if (!(fp = fopen(input_html_path, "r"))) { + if (!(fp_html = fopen(input_html_path, "r"))) { EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -1181,9 +1202,9 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } - byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp); + byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp_html); - if (ferror(fp)) { + if (ferror(fp_html)) { EM_DEBUG_EXCEPTION("fread failed [%s]", input_html_path); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -1195,14 +1216,14 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * } } - if ( (local_preview_text == NULL || (local_preview_text && strlen(local_preview_text) == 0) ) && input_plain_path != NULL) { + if ( (local_preview_text == NULL || (local_preview_text && EM_SAFE_STRLEN(local_preview_text) == 0) ) && input_plain_path != NULL) { /* get preview text from plain text file */ if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err); goto FINISH_OFF; } - if (!(fp = fopen(input_plain_path, "r"))) { + 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; @@ -1213,9 +1234,9 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } - byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp); + byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain); - if (ferror(fp)) { + if (ferror(fp_plain)) { EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -1234,7 +1255,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error); if(utf8_encoded_string == NULL) { - EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], strlen : [%d]", byte_read, EM_SAFE_STRLEN(local_preview_text)); + EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], EM_SAFE_STRLEN : [%d]", byte_read, EM_SAFE_STRLEN(local_preview_text)); EM_DEBUG_LOG("Error is G_CONVERT_ERROR_ILLEGAL_SEQUENCE"); if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) { @@ -1264,8 +1285,11 @@ FINISH_OFF: EM_SAFE_FREE(local_preview_text); EM_SAFE_FREE(encoding_type); - if (fp != NULL) - fclose(fp); + if (fp_html != NULL) + fclose(fp_html); + + if (fp_plain != NULL) + fclose(fp_plain); EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -1397,7 +1421,7 @@ int reg_replace (char *input_source_text, char *input_old_pattern_string, char * goto FINISH_OFF; } - source_text_length = strlen(input_source_text); + source_text_length = EM_SAFE_STRLEN(input_source_text); regcomp(®_pattern, input_old_pattern_string, REG_ICASE); @@ -1427,10 +1451,10 @@ int reg_replace (char *input_source_text, char *input_old_pattern_string, char * EM_DEBUG_LOG("so [%d], n [%d]", so, n); - if (so < 0 || strlen (input_new_string) + n - 1 > source_text_length) + if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length) break; - memmove (pos + n, pos + 2, strlen (pos) - 1); + memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1); memmove (pos, input_source_text + so, n); pos = pos + n - 2; } @@ -1440,9 +1464,9 @@ int reg_replace (char *input_source_text, char *input_old_pattern_string, char * n = pmatch[0].rm_eo - pmatch[0].rm_so; pos += pmatch[0].rm_so; - memmove (pos + strlen (input_new_string), pos + n, strlen (pos) - n + 1); - memmove (pos, input_new_string, strlen (input_new_string)); - pos += strlen (input_new_string); + memmove (pos + EM_SAFE_STRLEN (input_new_string), pos + n, EM_SAFE_STRLEN (pos) - n + 1); + memmove (pos, input_new_string, EM_SAFE_STRLEN (input_new_string)); + pos += EM_SAFE_STRLEN (input_new_string); n_count++; } @@ -1524,6 +1548,7 @@ INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_na { EM_DEBUG_FUNC_BEGIN("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime); int error_code = EMAIL_ERROR_NONE; + int param_length = 0; char *param_string = NULL; if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) { @@ -1532,17 +1557,18 @@ INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_na goto FINISH_OFF; } - param_string = malloc(strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5); + param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/ + param_string = em_malloc(param_length); if (param_string == NULL) { error_code = EMAIL_ERROR_OUT_OF_MEMORY; EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed"); goto FINISH_OFF; } - memset(param_string, 0x00, sizeof(param_string)); + memset(param_string, 0x00, param_length); - SNPRINTF(param_string, sizeof(param_string), "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime); + SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime); if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */ error_code = EMAIL_ERROR_UNKNOWN; @@ -1551,8 +1577,8 @@ INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_na } FINISH_OFF: - if (param_string) - free(param_string); + + EM_SAFE_FREE(param_string); EM_DEBUG_FUNC_END(); return error_code; } @@ -1826,11 +1852,11 @@ int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_rang else { /* Apart from first call to this function flow will always come here */ current_node = (*current_node_adr); - int len_sub_string = strlen(subset_string); - int space_left_in_buffer = range_len - strlen(current_node->uid_range); + int len_sub_string = EM_SAFE_STRLEN(subset_string); + int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range); if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ { - SNPRINTF(current_node->uid_range + strlen(current_node->uid_range), space_left_in_buffer, "%s,", subset_string); + SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string); current_node->highest_uid = huid; } else { @@ -1968,9 +1994,9 @@ INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_cou memset(num, 0x00, MAX_INTEGER_LENGTH + 1); SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]); - num_len = strlen(num); + num_len = EM_SAFE_STRLEN(num); - len_of_string_formed = strlen(string_list[num_of_strings - 1]); + len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]); space_in_buffer = max_string_len - len_of_string_formed ; @@ -2003,7 +2029,7 @@ INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_cou } /* Removing comma at end of string */ - len_of_string_formed = strlen(string_list[num_of_strings - 1]); + len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]); string_list[num_of_strings - 1][len_of_string_formed-1] = '\0'; ret = true; diff --git a/email-core/email-network/email-network.c b/email-core/email-network/email-network.c index 0983388..c772cde 100755 --- a/email-core/email-network/email-network.c +++ b/email-core/email-network/email-network.c @@ -452,7 +452,7 @@ INTERNAL_FUNC long tcp_sout_lnx(TCPSTREAM *stream, char *string, unsigned long s continue; } - if (!(nwrite = write(sockid, string, size)) < 0) { + if ((nwrite = write(sockid, string, size)) < 0) { /*prevent 22857*/ EM_DEBUG_EXCEPTION("socket write error"); /* if (errno == EINTR) continue; */ tcp_abort(stream); @@ -485,6 +485,6 @@ JOB_CANCEL: INTERNAL_FUNC long tcp_soutr_lnx(TCPSTREAM *stream, char *string) { - return tcp_sout_lnx(stream, string, strlen(string)); + return tcp_sout_lnx(stream, string, EM_SAFE_STRLEN(string)); } diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index 30f7405..153ccbf 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -751,7 +751,7 @@ static char *g_test_query[] = { " mailbox_name, " " mailbox_type, " " alias, " - " sync_with_server_yn, " + " deleted_flag, " " modifiable_yn, " " total_mail_count_on_server, " " has_archived_mails, " @@ -971,7 +971,7 @@ static int _get_table_field_data_string(char **table, char **buf, int ucs2, int if (pTemp == NULL) *buf = NULL; else { - sLen = strlen(pTemp); + sLen = EM_SAFE_STRLEN(pTemp); if(sLen) { *buf = (char *) em_malloc(sLen + 1); if (*buf == NULL) { @@ -1323,11 +1323,11 @@ char *cpy_str(char *src) char *p = NULL; if (src) { - if (!(p = em_malloc((int)strlen(src) + 1))) { + if (!(p = em_malloc((int)EM_SAFE_STRLEN(src) + 1))) { EM_DEBUG_EXCEPTION("mailoc failed..."); return NULL; } - strncpy(p, src, strlen(src)); + strncpy(p, src, EM_SAFE_STRLEN(src)); } return p; @@ -1704,7 +1704,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e ", mailbox_name VARCHAR(256) \n" ", mailbox_type INTEGER \n" ", alias VARCHAR(256) \n" - ", sync_with_server_yn INTEGER \n" + ", deleted_flag INTEGER \n" ", modifiable_yn INTEGER \n" ", total_mail_count_on_server INTEGER \n" ", has_archived_mails INTEGER \n" @@ -2252,7 +2252,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_certificate_tbl"); - EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TASK_TBL], sizeof(sql_query_string)); + EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TASK_TBL], sizeof(sql_query_string)-1); /*prevent 21984 */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -2315,7 +2315,7 @@ INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_claus EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause); if (output_total_mail_count) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -2668,13 +2668,13 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t if (p_data_tbl[i].body_download_status) { struct stat buf; - if (p_data_tbl[i].file_path_html && strlen(p_data_tbl[i].file_path_html) > 0) { + if (p_data_tbl[i].file_path_html && EM_SAFE_STRLEN(p_data_tbl[i].file_path_html) > 0) { if (stat(p_data_tbl[i].file_path_html, &buf) == -1) { EM_DEBUG_LINE; p_data_tbl[i].body_download_status = 0; } } - else if (p_data_tbl[i].file_path_plain && strlen(p_data_tbl[i].file_path_plain) > 0) { + else if (p_data_tbl[i].file_path_plain && EM_SAFE_STRLEN(p_data_tbl[i].file_path_plain) > 0) { if (stat(p_data_tbl[i].file_path_plain, &buf) == -1){ EM_DEBUG_LINE; p_data_tbl[i].body_download_status = 0; @@ -2725,18 +2725,17 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau int total_count = 0; char **result; char sql_query_string[QUERY_SIZE] = {0, }; - char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, no_select, last_sync_time "; + char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, deleted_flag, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, no_select, last_sync_time "; emstorage_mailbox_tbl_t* p_data_tbl = NULL; - DB_STMT hStmt = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(input_transaction); - if (input_get_mail_count == 0) { /* without mail count */ + if (input_get_mail_count == 0) { /* without mail count */ col_index = 13; SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl AS MBT %s", fields, input_conditional_clause); } - else { /* with read count and total count */ + else { /* with read count and total count */ col_index = 15; SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl %s GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name %s %s", fields, input_conditional_clause, input_conditional_clause, input_ordering_clause); } @@ -2756,7 +2755,7 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau } if ((p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t) * count)) == NULL) { - EM_DEBUG_EXCEPTION("malloc failed..."); + EM_DEBUG_EXCEPTION("em_malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } @@ -2768,7 +2767,7 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++); _get_table_field_data_int(result, (int*)&(p_data_tbl[i].mailbox_type), col_index++); _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].deleted_flag), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++); @@ -2794,19 +2793,11 @@ FINISH_OFF: *output_mailbox_count = count; EM_DEBUG_LOG("Mailbox Count [ %d]", count); } - else if (p_data_tbl != NULL) - emstorage_free_mailbox(&p_data_tbl, count, NULL); - if (hStmt != NULL) { - rc = sqlite3_finalize(hStmt); - if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); + EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); - error = EMAIL_ERROR_DB_FAILURE; - } - } + sqlite3_release_memory(-1); - EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); _DISCONNECT_DB; EM_DEBUG_FUNC_END("error [%d]", error); @@ -2902,7 +2893,7 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int * EMSTORAGE_START_READ_TRANSACTION(transaction); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_account_tbl"); EM_DEBUG_LOG("SQL STMT [ %s ]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -2981,7 +2972,7 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ } SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_account_tbl ORDER BY account_id"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -3081,14 +3072,12 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } - EM_DEBUG_LOG("recv_password_file_name[%s], incoming_server_password[%s]", recv_password_file_name, p_data_tbl[i].incoming_server_password); if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl[i].outgoing_server_password))) < 0) { EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed. [%d]", error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } - EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl[i].outgoing_server_password); } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); @@ -3552,7 +3541,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em /* Make query string */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); - sql_len = strlen(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) { SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, @@ -3583,12 +3572,12 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em "user_data_length," "check_interval," "sync_status,"); - sql_len = strlen(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); } if (pulloption & EMAIL_ACC_GET_OPT_ACCOUNT_NAME) { SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " account_name, "); - sql_len = strlen(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); } /* get from secure storage, not from db */ @@ -3616,7 +3605,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em "cipher_type," "digest_type,"); - sql_len = strlen(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); } /* dummy value, FROM WHERE clause */ @@ -3626,7 +3615,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em EM_DEBUG_LOG("query = [%s]", sql_query_string); /* execute a sql and count rows */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -3786,7 +3775,7 @@ INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int * goto FINISH_OFF; } - *password_length = strlen(temp_password); + *password_length = EM_SAFE_STRLEN(temp_password); EM_DEBUG_LOG("recv_password_file_name[%s], *password_length[%d]", recv_password_file_name, *password_length); @@ -3876,7 +3865,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl ", digest_type = ?" " WHERE account_id = ?"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_LOG("SQL[%s]", sql_query_string); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -3957,16 +3946,16 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl /* save passwords to the secure storage */ EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account_tbl->incoming_server_password, send_password_file_name, account_tbl->outgoing_server_password); - if (account_tbl->incoming_server_password && (strlen(account_tbl->incoming_server_password) > 0)) { - if (ssm_write_buffer(account_tbl->incoming_server_password, strlen(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { + if (account_tbl->incoming_server_password && (EM_SAFE_STRLEN(account_tbl->incoming_server_password) > 0)) { + if (ssm_write_buffer(account_tbl->incoming_server_password, EM_SAFE_STRLEN(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -recv incoming_server_password : file[%s]", recv_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } } - if (account_tbl->outgoing_server_password && (strlen(account_tbl->outgoing_server_password) > 0)) { - if (ssm_write_buffer(account_tbl->outgoing_server_password, strlen(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { + if (account_tbl->outgoing_server_password && (EM_SAFE_STRLEN(account_tbl->outgoing_server_password) > 0)) { + if (ssm_write_buffer(account_tbl->outgoing_server_password, EM_SAFE_STRLEN(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -send password : file[%s]", send_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -4263,7 +4252,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in " , ? " /* digest_type */ ") "); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -4332,12 +4321,12 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in /* save passwords to the secure storage */ EM_DEBUG_LOG("save to the secure storage : recv_file[%s], send_file[%s]", recv_password_file_name, send_password_file_name); - if ( (error_from_ssm = ssm_write_buffer(account_tbl->incoming_server_password, strlen(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { + if ( (error_from_ssm = ssm_write_buffer(account_tbl->incoming_server_password, EM_SAFE_STRLEN(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d] - recv password : file[%s]", error_from_ssm, recv_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - if ( (error_from_ssm = ssm_write_buffer(account_tbl->outgoing_server_password, strlen(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { + if ( (error_from_ssm = ssm_write_buffer(account_tbl->outgoing_server_password, EM_SAFE_STRLEN(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d] - send password : file[%s]", error_from_ssm, send_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -4568,12 +4557,12 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email if (account_id == ALL_ACCOUNT) { if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL) - SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " WHERE local_yn = %d ", local_yn); + SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " WHERE local_yn = %d ", local_yn); } else { SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d ", account_id); if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL) - SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND local_yn = %d ", local_yn); + SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " AND local_yn = %d ", local_yn); } EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string); @@ -4631,17 +4620,17 @@ INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, in } if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL) { - SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), "WHERE local_yn = %d ", local_yn); + SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), "WHERE local_yn = %d ", local_yn); where_clause_count++; } if (account_id > 0) { if (where_clause_count == 0) { - SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " WHERE "); - SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " account_id = %d ", account_id); + SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " WHERE "); + SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " account_id = %d ", account_id); } else - SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND account_id = %d ", account_id); + SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " AND account_id = %d ", account_id); } SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY MBT.mailbox_name "); @@ -4815,7 +4804,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch (*result_mailbox)->mailbox_name = EM_SAFE_STRDUP(mailbox_name); (*result_mailbox)->mailbox_type = EMAIL_MAILBOX_TYPE_SEARCH_RESULT; (*result_mailbox)->alias = EM_SAFE_STRDUP(mailbox_name); - (*result_mailbox)->sync_with_server_yn = 0; + (*result_mailbox)->deleted_flag = 0; (*result_mailbox)->modifiable_yn = 1; (*result_mailbox)->total_mail_count_on_server = 1; (*result_mailbox)->has_archived_mails = 0; @@ -4868,7 +4857,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma emstorage_account_tbl_t *account = NULL; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0,}; - char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, no_select, last_sync_time "; + char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, deleted_flag, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, no_select, last_sync_time "; sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); @@ -4888,7 +4877,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma EM_DEBUG_LOG("query = [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -4918,7 +4907,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, col_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->mailbox_type), col_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl->alias), 0, col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->sync_with_server_yn), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->deleted_flag), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->modifiable_yn), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->total_mail_count_on_server), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->has_archived_mails), col_index++); @@ -4931,8 +4920,6 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma FINISH_OFF: if (ret == true) *mailbox_name = p_data_tbl; - else if (p_data_tbl != NULL) - emstorage_free_mailbox(&p_data_tbl, 1, NULL); if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); @@ -5013,7 +5000,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email EM_DEBUG_LOG("query = [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5085,7 +5072,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, ema EM_DEBUG_LOG("query = [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5238,7 +5225,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp ", mailbox_name = ?" ", mailbox_type = ?" ", alias = ?" - ", sync_with_server_yn = ?" + ", deleted_flag = ?" ", modifiable_yn= ?" ", mail_slot_size= ?" ", total_mail_count_on_server = ?" @@ -5256,7 +5243,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp ", mailbox_name = ?" ", mailbox_type = ?" ", alias = ?" - ", sync_with_server_yn = ?" + ", deleted_flag = ?" ", modifiable_yn= ?" ", mail_slot_size= ?" ", total_mail_count_on_server = ?" @@ -5268,7 +5255,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5276,7 +5263,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp _bind_stmt_field_data_string(hStmt, i++, (char *)result_mailbox->mailbox_name ? result_mailbox->mailbox_name : "", 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->mailbox_type); _bind_stmt_field_data_string(hStmt, i++, (char *)result_mailbox->alias ? result_mailbox->alias : "", 0, ALIAS_LEN_IN_MAIL_BOX_TBL); - _bind_stmt_field_data_int(hStmt, i++, result_mailbox->sync_with_server_yn); + _bind_stmt_field_data_int(hStmt, i++, result_mailbox->deleted_flag); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->modifiable_yn); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->mail_slot_size); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->total_mail_count_on_server); @@ -5358,7 +5345,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch EM_DEBUG_LOG("SQL(%s)", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5392,7 +5379,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch EM_DEBUG_LOG("SQL[%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5457,7 +5444,7 @@ INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is EM_DEBUG_LOG("SQL(%s)", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5496,6 +5483,83 @@ FINISH_OFF: return error; } +INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_field_name[%p] input_value[%d] err_code[%p]", input_account_id, input_mailbox_id_array, input_mailbox_id_count, input_field_name, input_value, transaction); + int i = 0; + int err = EMAIL_ERROR_NONE; + int rc = 0; + int result = false; + int cur_mailbox_id_string = 0; + int mailbox_id_string_buffer_length = 0; + char sql_query_string[QUERY_SIZE] = {0, }; + char *mailbox_id_string_buffer = NULL; + char *parameter_string = NULL; + sqlite3 *local_db_handle = NULL; + + if (input_mailbox_id_array == NULL || input_mailbox_id_count == 0 || input_field_name == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + return EMAIL_ERROR_INVALID_PARAM; + } + + local_db_handle = emstorage_get_db_connection(); + + /* Generating mail id list string */ + mailbox_id_string_buffer_length = MAILBOX_ID_STRING_LENGTH * input_mailbox_id_count; + + mailbox_id_string_buffer = em_malloc(mailbox_id_string_buffer_length); + + if(!mailbox_id_string_buffer) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + for(i = 0; i < input_mailbox_id_count; i++) + cur_mailbox_id_string += SNPRINTF_OFFSET(mailbox_id_string_buffer, cur_mailbox_id_string, mailbox_id_string_buffer_length, "%d,", input_mailbox_id_array[i]); + + if(EM_SAFE_STRLEN(mailbox_id_string_buffer) > 1) + mailbox_id_string_buffer[EM_SAFE_STRLEN(mailbox_id_string_buffer) - 1] = NULL_CHAR; + + /* Generating notification parameter string */ + parameter_string = em_malloc(mailbox_id_string_buffer_length + EM_SAFE_STRLEN(input_field_name) + 2); + + if(!parameter_string) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + SNPRINTF(parameter_string, QUERY_SIZE, "%s%c%s", input_field_name, 0x01, mailbox_id_string_buffer); + + /* Write query string */ + SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_box_tbl SET %s = %d WHERE mailbox_id in (%s) ", input_field_name, input_value, mailbox_id_string_buffer); + + EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); + + /* Execute query */ + EMSTORAGE_START_WRITE_TRANSACTION(transaction, err); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + if (sqlite3_changes(local_db_handle) == 0) + EM_DEBUG_LOG("no mail matched..."); + + result = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, err); + _DISCONNECT_DB; + + if (result && parameter_string && !emcore_notify_storage_event(NOTI_MAILBOX_FIELD_UPDATE, input_account_id, 0, parameter_string, input_value)) + EM_DEBUG_EXCEPTION("emcore_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", input_field_name, input_value); + + EM_SAFE_FREE(mailbox_id_string_buffer); + EM_SAFE_FREE(parameter_string); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, int transaction, int *err_code) { @@ -5542,7 +5606,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in ", ?" /* mailbox_name */ ", ?" /* mailbox_type */ ", ?" /* alias */ - ", ?" /* sync_with_server_yn */ + ", ?" /* deleted_flag */ ", ?" /* modifiable_yn */ ", ?" /* total_mail_count_on_server */ ", ?" /* has_archived_mails */ @@ -5551,7 +5615,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in ", ? )");/* last_sync_time */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -5564,7 +5628,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in _bind_stmt_field_data_string(hStmt, col_index++, (char *)mailbox_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL); _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->mailbox_type); _bind_stmt_field_data_string(hStmt, col_index++, (char *)mailbox_tbl->alias, 0, ALIAS_LEN_IN_MAIL_BOX_TBL); - _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->sync_with_server_yn); + _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->deleted_flag); _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->modifiable_yn); _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->total_mail_count_on_server); _bind_stmt_field_data_int(hStmt, col_index++, 0); @@ -5673,7 +5737,7 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d ", account_id, local_yn); if (input_mailbox_id > 0) { /* 0 means all mailbox_name */ - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(1+ strlen(sql_query_string)), "AND mailbox_id = %d", input_mailbox_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(1+ EM_SAFE_STRLEN(sql_query_string)), "AND mailbox_id = %d", input_mailbox_id); } EM_DEBUG_LOG("mailbox sql_query_string [%s]", sql_query_string); @@ -5860,7 +5924,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE local_uid = %d", mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -5946,7 +6010,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6064,7 +6128,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailb } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6147,7 +6211,7 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r ", ? )"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc2); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc2); if (rc2 != SQLITE_OK) { EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)); @@ -6245,7 +6309,7 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, " AND s_uid = ?"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6319,11 +6383,11 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d ", account_id); if (mailbox_name) { /* NULL means all mailbox_name */ - SNPRINTF(sql_query_string+strlen(sql_query_string), sizeof(sql_query_string) - (1 + strlen(sql_query_string)), "AND mailbox_name = '%s' ", mailbox_name); + SNPRINTF(sql_query_string+EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), "AND mailbox_name = '%s' ", mailbox_name); } if (uid) { /* NULL means all mail */ - SNPRINTF(sql_query_string+strlen(sql_query_string), sizeof(sql_query_string) - (1 + strlen(sql_query_string)), "AND s_uid='%s' ", uid); + SNPRINTF(sql_query_string+EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), "AND s_uid='%s' ", uid); } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); @@ -6456,7 +6520,7 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d ORDER BY type", account_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6563,7 +6627,7 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d AND rule_id = %d", account_id, rule_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6599,8 +6663,6 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag FINISH_OFF: if (ret == true) *rule = p_data_tbl; - else if (p_data_tbl != NULL) - emstorage_free_rule(&p_data_tbl, 1, NULL); if (hStmt != NULL) { EM_DEBUG_LOG(" before sqlite3_finalize hStmt = %p", hStmt); @@ -6657,7 +6719,7 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r " AND rule_id = ?"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6729,7 +6791,7 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio rule->type, rule->value); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6817,7 +6879,7 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction ", ?" /* flag1 */ ", ?)"); /* flag2 */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc_2); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc_2); if (rc_2 != SQLITE_OK) { EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc_2, sqlite3_errmsg(local_db_handle)); error = EMAIL_ERROR_DB_FAILURE; @@ -6964,12 +7026,12 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl"); if (account_id != ALL_ACCOUNT) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); if (mailbox_name) - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name); } else if (mailbox_name) - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name); #ifdef USE_GET_RECORD_COUNT_API char **result; @@ -6982,7 +7044,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n sqlite3_free_table(result); #else - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF2; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -6997,12 +7059,12 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_seen_field = 0"); /* fSEEN = 0x01 */ if (account_id != ALL_ACCOUNT) - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND account_id = %d", account_id); if (mailbox_name) - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name); else - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_type NOT IN (3, 5)"); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_type NOT IN (3, 5)"); char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); @@ -7097,7 +7159,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -7253,9 +7315,9 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i for(i = 0; i < number_of_mails; i++) cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]); - sql_query_string[strlen(sql_query_string) - 1] = ')'; + sql_query_string[EM_SAFE_STRLEN(sql_query_string) - 1] = ')'; - EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, strlen(sql_query_string)); + EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, EM_SAFE_STRLEN(sql_query_string)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, @@ -7271,8 +7333,8 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i if(number_of_mails != item_count) { EM_DEBUG_EXCEPTION("Can't find all emails"); - /* error = EMAIL_ERROR_MAIL_NOT_FOUND; - goto FINISH_OFF; */ /* removed temporarily */ + error = EMAIL_ERROR_MAIL_NOT_FOUND; + goto FINISH_OFF; } col_index = field_count; @@ -7411,32 +7473,32 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_tbl"); if (account_id != ALL_ACCOUNT) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); and = true; } if (mailbox_name) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", and ? "AND" : "WHERE", mailbox_name); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_name = '%s'", and ? "AND" : "WHERE", mailbox_name); and = true; } while (p) { if (p->key_type) { - if (!strncmp(p->key_type, "subject", strlen("subject"))) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s subject LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value); + if (!strncmp(p->key_type, "subject", EM_SAFE_STRLEN("subject"))) { + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s subject LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value); and = true; } - else if (!strncmp(p->key_type, "full_address_from", strlen("full_address_from"))) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s full_address_from LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value); + else if (!strncmp(p->key_type, "full_address_from", EM_SAFE_STRLEN("full_address_from"))) { + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s full_address_from LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value); and = true; } - else if (!strncmp(p->key_type, "full_address_to", strlen("full_address_to"))) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s full_address_to LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value); + else if (!strncmp(p->key_type, "full_address_to", EM_SAFE_STRLEN("full_address_to"))) { + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s full_address_to LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value); and = true; } - else if (!strncmp(p->key_type, "email_address", strlen("email_address"))) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s email_address_sender = '%s' OR email_address_recipient = '%s'", and ? "AND" : "WHERE", p->key_value, p->key_value); + else if (!strncmp(p->key_type, "email_address", EM_SAFE_STRLEN("email_address"))) { + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s email_address_sender = '%s' OR email_address_recipient = '%s'", and ? "AND" : "WHERE", p->key_value, p->key_value); and = true; } p = p->next; @@ -7444,12 +7506,12 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, } if (sorting) - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY date_time"); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " ORDER BY date_time"); EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -7498,7 +7560,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail { EM_DEBUG_FUNC_BEGIN("search_handle[%d], type[%d], data[%p], transaction[%d], err_code[%p]", search_handle, type, data, transaction, err_code); - if (search_handle < 0 || !data) { + if (search_handle == 0 || !data) { EM_DEBUG_EXCEPTION(" search_handle[%d], type[%d], data[%p]", search_handle, type, data); if (err_code != NULL) @@ -7644,7 +7706,7 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, int error = EMAIL_ERROR_NONE; int rc, ret = false; - if (search_handle < 0) { + if (search_handle == 0) { EM_DEBUG_EXCEPTION(" search_handle[%d]", search_handle); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -7737,7 +7799,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -7967,11 +8029,11 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id for(i = 0; i < mail_ids_count; i++) cur_mail_id_string += SNPRINTF_OFFSET(mail_id_string_buffer, cur_mail_id_string, mail_id_string_buffer_length, "%d,", mail_ids[i]); - if(strlen(mail_id_string_buffer) > 1) - mail_id_string_buffer[strlen(mail_id_string_buffer) - 1] = NULL_CHAR; + if(EM_SAFE_STRLEN(mail_id_string_buffer) > 1) + mail_id_string_buffer[EM_SAFE_STRLEN(mail_id_string_buffer) - 1] = NULL_CHAR; /* Generating notification parameter string */ - parameter_string = em_malloc(mail_id_string_buffer_length + strlen(field_name) + 2); + parameter_string = em_malloc(mail_id_string_buffer_length + EM_SAFE_STRLEN(field_name) + 2); if(!parameter_string) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -8064,7 +8126,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; @@ -8113,7 +8175,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -8143,7 +8205,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -8167,7 +8229,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); break; @@ -8182,7 +8244,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); break; @@ -8226,7 +8288,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -8275,7 +8337,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , (int)now , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); break; @@ -8291,7 +8353,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ hStmt = NULL; - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; @@ -8308,7 +8370,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ hStmt = NULL; - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; @@ -8326,7 +8388,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ hStmt = NULL; - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; @@ -8350,7 +8412,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; @@ -8375,7 +8437,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -8616,7 +8678,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge ", ?" /* smime_type */ ")"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -8732,7 +8794,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i for(i = 0; i < number_of_mails; i++) cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]); - conditional_clause[strlen(conditional_clause) - 1] = ')'; + conditional_clause[EM_SAFE_STRLEN(conditional_clause) - 1] = ')'; EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -8772,7 +8834,9 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i for(i = 0; i < number_of_mails; i++) cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]); - conditional_clause[strlen(conditional_clause) - 1] = ')'; + /* prevent 34415 */ + char *last_comma = rindex(conditional_clause, ','); + last_comma = ")"; /* replace , with ) */ memset(sql_query_string, 0x00, QUERY_SIZE); SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', mailbox_id = %d, account_id = %d %s", target_mailbox_name, input_mailbox_id, target_account_id, conditional_clause); @@ -8861,7 +8925,9 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_ for(i = 0; i < number_of_mails; i++) cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]); - sql_query_string[strlen(sql_query_string) - 1] = ')'; + /* prevent 34414 */ + char *last_comma = rindex(sql_query_string, ','); + last_comma = ")"; /* replace , with ) */ EM_DEBUG_LOG("Query [%s]", sql_query_string); @@ -9129,7 +9195,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d ORDER BY attachment_id", input_mail_id); EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); @@ -9204,7 +9270,7 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme sqlite3_stmt* hStmt = NULL; - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -9297,7 +9363,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a DB_STMT hStmt = NULL; - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -9319,9 +9385,9 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a } p_data_tbl->attachment_id = sqlite3_column_int(hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); - if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p)) + if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->attachment_name = cpy_str(p); - if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p)) + if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->attachment_path = cpy_str(p); p_data_tbl->attachment_size = sqlite3_column_int(hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL); p_data_tbl->mail_id = sqlite3_column_int(hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL); @@ -9331,11 +9397,11 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a p_data_tbl->attachment_drm_type = sqlite3_column_int(hStmt, ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL); p_data_tbl->attachment_drm_method = sqlite3_column_int(hStmt, ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL); p_data_tbl->attachment_inline_content_status = sqlite3_column_int(hStmt, ATTACHMENT_INLINE_CONTENT_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL); - if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p)) + if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->attachment_mime_type = cpy_str(p); #ifdef __ATTACHMENT_OPTI__ p_data_tbl->encoding = sqlite3_column_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); - if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p)) + if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->section= cpy_str(p); #endif ret = true; @@ -9343,8 +9409,6 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a FINISH_OFF: if (ret == true) *attachment_tbl = p_data_tbl; - else if (p_data_tbl != NULL) - emstorage_free_attachment(&p_data_tbl, 1, NULL); if (hStmt != NULL) { EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt); @@ -9399,7 +9463,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_attachment_tbl SET mailbox_id = ? WHERE mail_id = %d", mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -9426,7 +9490,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan , attachment->attachment_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -9649,7 +9713,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen ")"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -9750,7 +9814,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach " WHERE attachment_id = ?;"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -9854,19 +9918,19 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code); + int rc, ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + sqlite3 *local_db_handle = NULL; - if (mail_id < 0) { + if (mail_id <= 0) { EM_DEBUG_EXCEPTION("mail_id[%d]", mail_id); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - int rc, ret = false; - int error = EMAIL_ERROR_NONE; - char sql_query_string[QUERY_SIZE] = {0, }; - - sqlite3 *local_db_handle = emstorage_get_db_connection(); + local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -9904,10 +9968,10 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl"); if (account_id != ALL_ACCOUNT) /* '0' means all account */ - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); if (mailbox) /* NULL means all mailbox_name */ - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mailbox); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mailbox); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -10178,13 +10242,13 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ } sprintf(name_buf, "%s", MAILHOME); - sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, account_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, account_id); if (mail_id > 0) - sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, mail_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id); if (atch_id > 0) - sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, atch_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id); if (fname) { temp_file = EM_SAFE_STRDUP(fname); @@ -10203,7 +10267,7 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ if (fname) { EM_DEBUG_LOG(">>>>> fname [ %s ]", fname); - sprintf(name_buf+strlen(name_buf), "%s%s", DIR_SEPERATOR, fname); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, fname); } @@ -10233,20 +10297,20 @@ INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_ return false; } - sprintf(name_buf+strlen(name_buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id); if (mail_id > 0) - sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, mail_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id); else goto FINISH_OFF; if (atch_id > 0) - sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, atch_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id); else goto FINISH_OFF; FINISH_OFF: - sprintf(name_buf+strlen(name_buf), ".DELE"); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), ".DELE"); EM_DEBUG_FUNC_END(); return true; @@ -10288,7 +10352,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, goto FINISH_OFF; } - SNPRINTF(buf+strlen(buf), sizeof(buf), "%s%d", DIR_SEPERATOR, mail_id); + SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf), "%s%d", DIR_SEPERATOR, mail_id); if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { @@ -10316,7 +10380,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, goto FINISH_OFF; } - SNPRINTF(buf+strlen(buf), sizeof(buf)-(strlen(buf)+1), "%s%d", DIR_SEPERATOR, atch_id); + SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)+1), "%s%d", DIR_SEPERATOR, atch_id); if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { @@ -10386,13 +10450,13 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s } if (buf) { - if (!(fp_src = open(src_file, O_RDONLY))) { + if ((fp_src = open(src_file, O_RDONLY))<0) { /*prevent 24474*/ EM_DEBUG_EXCEPTION(">>>> Source Fail open %s Failed [ %d ] - Error [ %s ]", src_file, errno, strerror(errno)); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - if (!(fp_dst = open(dst_file, O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) { + if ((fp_dst = open(dst_file, O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))<0) { /*prevent 24474*/ EM_DEBUG_EXCEPTION(">>>> Destination Fail open %s Failed [ %d ] - Error [ %s ]", dst_file, errno, strerror(errno)); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -10414,10 +10478,10 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s ret = true; FINISH_OFF: - if (fp_src) + if (fp_src>0) /*prevent 24474*/ close(fp_src); - if (fp_dst) { + if (fp_dst>0) { /*prevent 24474*/ if (sync_status) { EM_DEBUG_LOG("Before fsync"); fsync(fp_dst); @@ -10545,13 +10609,13 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in * 2. If not based on the character set, Append it in File **/ - low_char_set = calloc(1, strlen(char_set) + strlen(" \" />") +1); + low_char_set = calloc(1, EM_SAFE_STRLEN(char_set) + strlen(" \" />") +1); /*prevent 34359*/ - strncat(low_char_set, char_set, strlen(char_set)); + strncat(low_char_set, char_set, EM_SAFE_STRLEN(char_set)); EM_DEBUG_LOG(">>>> CHAR SET [ %s ] ", low_char_set); - strncat(low_char_set, " \" />", strlen(" \" />")); + strncat(low_char_set, " \" />", strlen(" \" />")); /*prevent 34359*/ EM_DEBUG_LOG(">>> CHARSET [ %s ] ", low_char_set); @@ -10565,18 +10629,18 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in if (fp_src !=NULL) { fclose(fp_src);fp_src = NULL; } - data_count_to_written = strlen(low_char_set)+strlen(CONTENT_DATA)+1; + data_count_to_written = EM_SAFE_STRLEN(low_char_set)+strlen(CONTENT_DATA)+1; /*prevent 34359*/ EM_DEBUG_LOG(">>>>emstorage_add_content_type 4 "); buf1 = (char *)calloc(1, data_count_to_written); EM_DEBUG_LOG(">>>>emstorage_add_content_type 5 "); if (buf1) { EM_DEBUG_LOG(">>>>emstorage_add_content_type 6 "); - strncat(buf1, CONTENT_DATA, strlen(CONTENT_DATA)); + strncat(buf1, CONTENT_DATA, strlen(CONTENT_DATA)); /*prevent 34359*/ EM_DEBUG_LOG(">>>>> BUF 1 [ %s ] ", buf1); - strncat(buf1, low_char_set, strlen(low_char_set)); + strncat(buf1, low_char_set, EM_SAFE_STRLEN(low_char_set)); EM_DEBUG_LOG(">>>> HTML TAG DATA [ %s ] ", buf1); @@ -10796,7 +10860,7 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code) } while ((dp=readdir(dirp))) { - if (strncmp(dp->d_name, ".", strlen(".")) == 0 || strncmp(dp->d_name, "..", strlen("..")) == 0) + if (strncmp(dp->d_name, ".", 1) == 0 || strncmp(dp->d_name, "..", 2) == 0) /* prevent 34360 */ continue; SNPRINTF(buf, sizeof(buf), "%s/%s", src_dir, dp->d_name); @@ -10957,7 +11021,7 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co else SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND flags_seen_field = 0 ORDER BY mail_id DESC", account_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -11123,7 +11187,7 @@ FINISH_OFF: else *total_usage = 0; - fclose(fp); + if(fp) fclose(fp); /* prevent 32730 */ EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -11194,7 +11258,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -11318,15 +11382,15 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * goto FINISH_OFF; } - if (strlen(stripped_subject) < 2) { + if (EM_SAFE_STRLEN(stripped_subject) < 2) { result_thread_id = -1; goto FINISH_OFF; } - EM_DEBUG_LOG("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", strlen(stripped_subject), stripped_subject); + EM_DEBUG_LOG("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", EM_SAFE_STRLEN(stripped_subject), stripped_subject); if (account_id > 0) { - query_size_account = 3 + strlen(sql_format_account); + query_size_account = 3 + EM_SAFE_STRLEN(sql_format_account); sql_account = malloc(query_size_account); if (sql_account == NULL) { EM_DEBUG_EXCEPTION("malloc for sql_account is failed %d", query_size_account); @@ -11336,6 +11400,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * snprintf(sql_account, query_size_account, sql_format_account, account_id); } + /* prevent 34362 */ query_size = strlen(sql_format) + strlen(stripped_subject) + 50 + query_size_account + strlen(sql_format_order_by); /* + query_size_mailbox; */ sql_query_string = malloc(query_size); @@ -11462,35 +11527,35 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ /* mailbox_name */ if (mailbox_name) - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s') ", mailbox_name); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s') ", mailbox_name); else /* NULL means all mailbox_name. but except for trash(3), spambox(5), all emails(for GMail, 7) */ - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), " WHERE mailbox_type not in (3, 5, 7, 8) "); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE mailbox_type not in (3, 5, 7, 8) "); /* account id */ /* '0' (ALL_ACCOUNT) means all account */ if (account_id > ALL_ACCOUNT) - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), " AND account_id = %d ", account_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND account_id = %d ", account_id); if (search_value) { switch (search_type) { case EMAIL_SEARCH_FILTER_SUBJECT: - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", search_value); break; case EMAIL_SEARCH_FILTER_SENDER: - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) " ") ", search_value); break; case EMAIL_SEARCH_FILTER_RECIPIENT: - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) " ") ", search_value, search_value, search_value); break; case EMAIL_SEARCH_FILTER_ALL: - SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') " " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) " @@ -11505,7 +11570,7 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ /* sorting option is not available now. The order of sender list is ascending order by display name */ - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), "GROUP BY email_address_sender " "ORDER BY UPPER(alias_sender) "); @@ -11546,8 +11611,6 @@ FINISH_OFF: *sender_count = count; EM_DEBUG_LOG(">>>> COUNT : %d >>", count); } - else if (p_sender_list != NULL) - emstorage_free_sender_list(&p_sender_list, count); _DISCONNECT_DB; @@ -11696,7 +11759,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local EM_DEBUG_LOG(" MAILBOX ID [ %d ]", local_activity->mailbox_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -11793,7 +11856,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l EM_DEBUG_LOG(" Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -11900,7 +11963,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -12010,7 +12073,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -12163,7 +12226,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int i EM_DEBUG_LOG(" Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -12229,7 +12292,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int tran EM_DEBUG_LOG(" Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -12657,7 +12720,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo EM_DEBUG_LOG("rule->value [%s]", rule->value); - where_pararaph_length = strlen(rule->value) + 100; + where_pararaph_length = EM_SAFE_STRLEN(rule->value) + 100; where_pararaph = malloc(sizeof(char) * where_pararaph_length); if (where_pararaph == NULL) { @@ -12688,6 +12751,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo goto FINISH_OFF; } + /* prevent 34361 */ if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); @@ -12715,7 +12779,8 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_id = %d, mailbox_type = 5 ", dest_mailbox_id); - if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) + /* prevent 34361 */ + if(strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); @@ -12796,9 +12861,9 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i } if (new_slot_size == 0) - SNPRINTF(where_pararaph + strlen(where_pararaph), where_pararaph_length - strlen(where_pararaph), " %s total_mail_count_on_server > mail_slot_size ", (and ? "AND" : "WHERE")); + SNPRINTF(where_pararaph + EM_SAFE_STRLEN(where_pararaph), where_pararaph_length - EM_SAFE_STRLEN(where_pararaph), " %s total_mail_count_on_server > mail_slot_size ", (and ? "AND" : "WHERE")); - if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) + if (strlen(sql_query_string) + EM_SAFE_STRLEN(where_pararaph) < QUERY_SIZE) /* prevent 34363 */ strcat(sql_query_string, where_pararaph); else { EM_DEBUG_EXCEPTION("Query buffer overflowed !!!"); @@ -12873,7 +12938,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo ", ?" /* daylight_bias */ " )"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); if (rc != SQLITE_OK) { EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)); @@ -12981,7 +13046,7 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque EM_DEBUG_LOG("sql : %s ", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -13118,7 +13183,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet EM_DEBUG_LOG("SQL(%s)", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); /* @@ -13209,15 +13274,15 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_meeting_tbl "); if (account_id != ALL_ACCOUNT) { /* NOT '0' means a specific account. '0' means all account */ - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); and = true; } if (mail_id > 0) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mail_id = %d", (and ? "AND" : "WHERE"), mail_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mail_id = %d", (and ? "AND" : "WHERE"), mail_id); and = true; } if (input_mailbox_id > 0) { /* 0 means all mailbox_id */ - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_id = '%d'", (and ? "AND" : "WHERE"), input_mailbox_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_id = '%d'", (and ? "AND" : "WHERE"), input_mailbox_id); } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); @@ -13514,7 +13579,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -13642,19 +13707,19 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]); - if (result[col_index] && strlen(result[col_index])>0) + if (result[col_index] && EM_SAFE_STRLEN(result[col_index])>0) p_activity_tbl[i].server_mailid = EM_SAFE_STRDUP(result[col_index++]); else col_index++; EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]); - if (result[col_index] && strlen(result[col_index])>0) + if (result[col_index] && EM_SAFE_STRLEN(result[col_index])>0) p_activity_tbl[i].src_mbox = EM_SAFE_STRDUP(result[col_index++]); else col_index++; EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]); - if (result[col_index] && strlen(result[col_index])>0) + if (result[col_index] && EM_SAFE_STRLEN(result[col_index])>0) p_activity_tbl[i].dest_mbox = EM_SAFE_STRDUP(result[col_index++]); else col_index++; @@ -13874,14 +13939,14 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca EM_DEBUG_LOG(">>> Query [ %s ] ", sql_query_string); if (local_activity->account_id) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d ", local_activity->account_id); query_and = 1; query_where = 1; } if (local_activity->server_mailid) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s %s server_mailid = '%s' ", query_where? "": "WHERE", query_and? "AND":"", local_activity->server_mailid); query_and = 1; query_where = 1; @@ -13891,7 +13956,7 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca if (local_activity->mail_id) { EM_DEBUG_LOG(">>>> MAIL ID [ %d ] , ACTIVITY TYPE [%d ]", local_activity->mail_id, local_activity->activity_type); - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s %s mail_id = %d ", query_where? "": "WHERE", query_and? "AND":"", local_activity->mail_id); query_and = 1; @@ -13900,12 +13965,12 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca } if (local_activity->activity_type > 0) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s %s activity_type = %d ", query_where? "": "WHERE", query_and? "AND" : "" , local_activity->activity_type); } if (local_activity->activity_id > 0) { - SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s %s activity_id = %d ", query_where? "": "WHERE", query_and? "AND" : "" , local_activity->activity_id); } @@ -14142,7 +14207,7 @@ static int _get_key_value_string_for_list_filter_rule(email_list_filter_rule_t * break; } - if(ret == EMAIL_ERROR_NONE && strlen(key_value_string) > 0) { + if(ret == EMAIL_ERROR_NONE && EM_SAFE_STRLEN(key_value_string) > 0) { *output_key_value_string = strdup(key_value_string); } @@ -14203,8 +14268,8 @@ static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_ return EMAIL_ERROR_INVALID_PARAM; } - length_field_name = strlen(temp_field_name_string); - length_value = strlen(temp_key_value_string); + length_field_name = EM_SAFE_STRLEN(temp_field_name_string); + length_value = EM_SAFE_STRLEN(temp_key_value_string); switch(input_list_filter_rule->target_attribute) { case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME : @@ -14225,8 +14290,8 @@ static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_ } if(is_alpha == 1 && input_list_filter_rule->case_sensitivity == false) { - length_field_name += strlen("UPPER() "); - length_value += strlen("UPPER() "); + length_field_name += EM_SAFE_STRLEN("UPPER() "); + length_value += EM_SAFE_STRLEN("UPPER() "); mod_field_name_string = em_malloc(sizeof(char) * length_field_name); mod_value_string = em_malloc(sizeof(char) * length_value); SNPRINTF(mod_field_name_string, length_field_name, "UPPER(%s)", temp_field_name_string); @@ -14369,7 +14434,7 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email goto FINISH_OFF; } - if(strlen(conditional_clause_string) + strlen(result_string_for_a_item) >= QUERY_SIZE) { + if(strlen(conditional_clause_string) + EM_SAFE_STRLEN(result_string_for_a_item) >= QUERY_SIZE) { /* prevent 34364 */ EM_DEBUG_EXCEPTION("Query is too long"); ret = EMAIL_ERROR_DATA_TOO_LONG; goto FINISH_OFF; @@ -14503,8 +14568,8 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi ") "); - /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL); */ + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -14528,7 +14593,7 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); #ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ - if (ssm_write_buffer(certificate->password, strlen(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { + if (ssm_write_buffer(certificate->password, EM_SAFE_STRLEN(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { EM_DEBUG_EXCEPTION("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -14643,8 +14708,8 @@ INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_cert EM_DEBUG_LOG("count = %d", rc); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_certificate_tbl ORDER BY account_id"); - /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL); */ + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -14768,7 +14833,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address /* Make query string */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); - sql_len = strlen(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); /* dummy value, FROM WHERE clause */ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE email_address = '%s'", email_address); @@ -14777,7 +14842,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address EM_DEBUG_LOG("query = [%s]", sql_query_string); /* execute a sql and count rows */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -14832,10 +14897,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address FINISH_OFF: if (ret == true) *certificate = p_data_tbl; - else { - if (p_data_tbl) - emstorage_free_certificate((emstorage_certificate_tbl_t **)&p_data_tbl, 1, NULL); - } + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { @@ -14880,7 +14942,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif /* Make query string */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); - sql_len = strlen(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); /* dummy value, FROM WHERE clause */ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE certificate_id = %d", index); @@ -14889,7 +14951,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif EM_DEBUG_LOG("query = [%s]", sql_query_string); /* execute a sql and count rows */ - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -14945,10 +15007,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif FINISH_OFF: if (ret == true) *certificate = p_data_tbl; - else { - if (p_data_tbl) - emstorage_free_certificate((emstorage_certificate_tbl_t **)&p_data_tbl, 1, NULL); - } + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { @@ -15080,7 +15139,7 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer ", password = ?" " WHERE certificate_id = ?"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -15120,7 +15179,7 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer } /* save passwords to the secure storage */ - if (ssm_write_buffer(certificate->password, strlen(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { + if (ssm_write_buffer(certificate->password, EM_SAFE_STRLEN(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { EM_DEBUG_EXCEPTION("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; @@ -15205,7 +15264,7 @@ INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_ta " , ? " /* date_time */ ") "); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -15354,7 +15413,7 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT %s FROM mail_task_tbl %s %s", field_list, input_conditional_clause, input_ordering_clause); EM_DEBUG_LOG("emstorage_query_mail_list : query[%s].", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, diff --git a/email-core/email-storage/include/email-storage.h b/email-core/email-storage/include/email-storage.h index bf7917f..946f4b7 100755 --- a/email-core/email-storage/include/email-storage.h +++ b/email-core/email-storage/include/email-storage.h @@ -154,7 +154,6 @@ typedef struct char *mailbox_name; email_mailbox_type_e mailbox_type; char *alias; - int sync_with_server_yn; /* whether mailbox is a sync IMAP mailbox */ int modifiable_yn; /* whether mailbox is able to be deleted/modified */ int unread_count; /* Removed. 16-Dec-2010, count unread mails at the moment it is required. not store in the DB */ int total_mail_count_on_local; /* Specifies the total number of mails in the mailbox in the local DB. count unread mails at the moment it is required. not store in the DB */ @@ -163,6 +162,7 @@ typedef struct int mail_slot_size; int no_select; time_t last_sync_time; /* The last synchronization time */ + int deleted_flag; /* whether mailbox is deleted */ } emstorage_mailbox_tbl_t; /* mail_read_uid_tbl table entity */ @@ -600,6 +600,8 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch */ INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox, int transaction); +INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction); + /* * emstorage_add_mailbox * diff --git a/email-core/include/email-core-global.h b/email-core/include/email-core-global.h index 8626d0b..d51a14d 100755 --- a/email-core/include/email-core-global.h +++ b/email-core/include/email-core-global.h @@ -42,7 +42,9 @@ extern email_account_list_t *g_account_list; extern int g_account_num; extern int g_account_retrieved; -INTERNAL_FUNC email_account_t *emcore_get_new_account_reference(); +INTERNAL_FUNC int emcore_get_account_from_unvalidated_account_list(int input_unvalidated_account_id, email_account_t **oupput_account); +INTERNAL_FUNC int emcore_add_account_to_unvalidated_account_list(email_account_t *input_new_account); +INTERNAL_FUNC int emcore_delete_account_from_unvalidated_account_list(int input_account_id); #ifdef __cplusplus } diff --git a/email-core/include/email-core-mail.h b/email-core/include/email-core-mail.h index 5f0c78e..fe2e5c2 100755 --- a/email-core/include/email-core-mail.h +++ b/email-core/include/email-core-mail.h @@ -185,7 +185,7 @@ INTERNAL_FUNC int emcore_delete_mail(int account_id, int mail_id[], int num, int * @return This function returns true on success or false on failure. */ INTERNAL_FUNC int emcore_delete_all_mails_of_acount(int input_account_id); -INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_mailbox_id, int input_from_server, int *err_code); +INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int input_mailbox_id, int input_from_server, int *err_code); INTERNAL_FUNC void emcore_free_mail_data_list(email_mail_data_t **mail_list, int count); INTERNAL_FUNC void emcore_free_mail_data(email_mail_data_t *mail); @@ -193,7 +193,7 @@ INTERNAL_FUNC void emcore_free_content_info(struct _m_content_info *cnt_info); INTERNAL_FUNC void emcore_free_attachment_info(struct attachment_info *attchment); INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, int mail_ids[], int num, char *dest_mailbox, int *error_code); -INTERNAL_FUNC int emcore_move_mail_to_another_account_on_local_storeage(int input_task_id, int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int *result_mail_id); +INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id); INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code); INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int *err_code); diff --git a/email-core/include/email-core-mailbox-sync.h b/email-core/include/email-core-mailbox-sync.h index 68348f0..3435be1 100755 --- a/email-core/include/email-core-mailbox-sync.h +++ b/email-core/include/email-core-mailbox-sync.h @@ -55,8 +55,10 @@ typedef struct typedef struct { - char *buffer; - int buflen; + char *header; + int header_len; + char *body; + int body_len; } email_partial_buffer; #endif @@ -168,7 +170,7 @@ int emcore_get_uid(emcore_uid_list *uid_list, int msgno, char **uid, int *err_co */ int emcore_free_uids(emcore_uid_list *uid_list, int *err_code); -INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id, int *err_code); +INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id); #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, email_event_partial_body_thd *pbd_event, int count, int *error); diff --git a/email-core/include/email-core-mailbox.h b/email-core/include/email-core-mailbox.h index 1d4bdf1..1920c52 100755 --- a/email-core/include/email-core-mailbox.h +++ b/email-core/include/email-core-mailbox.h @@ -67,6 +67,7 @@ INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mai INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, int *unseen, int *err_code); INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int *err_code); INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int on_server, int *err_code); +INTERNAL_FUNC int emcore_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server); INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_code); INTERNAL_FUNC int emcore_update_mailbox(email_mailbox_t *old_mailbox, email_mailbox_t *new_mailbox, int *err_code); INTERNAL_FUNC int emcore_save_local_activity_sync(int account_id, int *err_code); diff --git a/email-core/include/email-core-sound.h b/email-core/include/email-core-sound.h index 7b1c620..e7f0949 100755 --- a/email-core/include/email-core-sound.h +++ b/email-core/include/email-core-sound.h @@ -25,8 +25,8 @@ #include #include #include -#include #include +#include typedef enum { @@ -53,6 +53,13 @@ typedef enum EMAIL_GCONF_VALUE_REPEAT_10MINS, } EMAIL_ALERT_REPEAT_ALARM; +typedef enum +{ + SETTING_NOTI_STATUS_OFF = 0, + SETTING_NOTI_STATUS_GLOBAL = 1, + SETTING_NOTI_STATUS_EMAIL = 2, +} EMAIL_NOTI_STATUS; + #ifdef Min #undef Min #endif diff --git a/email-core/include/email-core-tasks.h b/email-core/include/email-core-tasks.h index f627d64..3fe3409 100755 --- a/email-core/include/email-core-tasks.h +++ b/email-core/include/email-core-tasks.h @@ -66,7 +66,20 @@ typedef struct } task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT; DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT); -void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *param); +INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *param); + +/*-------------------------------------------------------------------------------------------*/ +/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */ +typedef struct +{ + int account_id; + int mailbox_id_count; + int *mailbox_id_array; + int on_server; +} task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX; + +DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX); +INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param); /*-------------------------------------------------------------------------------------------*/ #endif /* EMAIL_CORE_TASKS_H_ */ diff --git a/email-daemon/CMakeLists.txt b/email-daemon/CMakeLists.txt index 146c6eb..316f1f5 100755 --- a/email-daemon/CMakeLists.txt +++ b/email-daemon/CMakeLists.txt @@ -38,9 +38,7 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 db-util openssl uw-imap-toolkit vconf contacts-service2 alarm-service mm-player drm-client devman_haptic) -# _TIZEN_PUBLIC_ -# mdm +pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 db-util openssl uw-imap-toolkit vconf contacts-service2 alarm-service mm-player drm-client feedback) FOREACH(flag ${main_pkgs_CFLAGS}) diff --git a/email-daemon/email-daemon-auto-poll.c b/email-daemon/email-daemon-auto-poll.c index 044fe15..6dbea64 100755 --- a/email-daemon/email-daemon-auto-poll.c +++ b/email-daemon/email-daemon-auto-poll.c @@ -318,7 +318,6 @@ static int _emdaemon_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id) /* alarm_info_t alarm_info = {0}; */ int a_nErrorCode = 0; - int retval =0; if((alarm_interval <= 0) || !p_alarm_id) { EM_DEBUG_EXCEPTION("Invalid param "); @@ -336,23 +335,22 @@ static int _emdaemon_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id) /* error_code = vconf_get_int(DBG_MID_MSGPORTING_NORMAL, &timeFormat); */ a_nErrorCode = alarmmgr_init(AUTO_POLL_DESTINATION); - EM_DEBUG_LOG("ErrorCode :%d, Return Value:%d ",a_nErrorCode,retval); - - if(!retval) + if (a_nErrorCode != ALARMMGR_RESULT_SUCCESS) { + EM_DEBUG_EXCEPTION("alarmmgr_init failed : ErrorCode[%d]",a_nErrorCode); return false; + } a_nErrorCode = alarmmgr_set_cb(emdaemon_alarm_polling_cb, NULL); - EM_DEBUG_LOG("ErrorCode :%d, Return Value:%d ",a_nErrorCode,retval); - - if(!retval) - return false; + if (a_nErrorCode != ALARMMGR_RESULT_SUCCESS) { + EM_DEBUG_EXCEPTION("alarmmgr_set_cb : ErrorCode[%d]",a_nErrorCode); + return false; + } error_code = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, alarm_interval * 60 /*(sec)*/, ALARM_REPEAT_MODE_ONCE, AUTO_POLL_DESTINATION, p_alarm_id); - - EM_DEBUG_LOG("ErrorCode :%d,Return Value :%d ",error_code,retval); - - if(!retval) - return false; + if (a_nErrorCode != ALARMMGR_RESULT_SUCCESS) { + EM_DEBUG_EXCEPTION("alarmmgr_add_alarm : ErrorCode[%d]",a_nErrorCode); + return false; + } return true; } diff --git a/email-daemon/email-daemon-emn.c b/email-daemon/email-daemon-emn.c index 6d69593..01219da 100755 --- a/email-daemon/email-daemon-emn.c +++ b/email-daemon/email-daemon-emn.c @@ -107,10 +107,10 @@ static void _cb_parser_start_element(void* ctx, WBXMLTag* element, WBXMLAttribut return ; } - len = strlen((char *)wbxml_tag_get_xml_name(element)) + 1; + len = EM_SAFE_STRLEN((char *)wbxml_tag_get_xml_name(element)) + 1; while (atts[j] != NULL) { - len += (strlen((char *)wbxml_attribute_get_xml_name(atts[j])) + strlen((char *)wbxml_attribute_get_xml_value(atts[j])) + 7); + len += (EM_SAFE_STRLEN((char *)wbxml_attribute_get_xml_name(atts[j])) + EM_SAFE_STRLEN((char *)wbxml_attribute_get_xml_value(atts[j])) + 7); j++; } len += 3; @@ -208,7 +208,7 @@ static int _get_addr_from_element(unsigned char* elm, if ((s = (unsigned char*)strchr((char *)p, ';'))) { *s = '\0'; - if (strlen((char *)p)) user = (unsigned char*)EM_SAFE_STRDUP((char *)p); + if (EM_SAFE_STRLEN((char *)p)) user = (unsigned char*)EM_SAFE_STRDUP((char *)p); p = s + 1; } if ((s = (unsigned char*)strchr((char *)p, '@'))) @@ -238,7 +238,7 @@ static int _get_addr_from_element(unsigned char* elm, if ((s = (unsigned char*)strchr((char *)p, ';'))) { *s = '\0'; - if (strlen((char *)p)) user = (unsigned char*)EM_SAFE_STRDUP((char *)p); + if (EM_SAFE_STRLEN((char *)p)) user = (unsigned char*)EM_SAFE_STRDUP((char *)p); p = s + 1; } if ((s = (unsigned char*)strchr((char *)p, '@'))) @@ -259,10 +259,10 @@ static int _get_addr_from_element(unsigned char* elm, if ((s = (unsigned char*)strchr((char *)p, '?'))) * s = '\0'; else if ((s = (unsigned char*)strchr((char *)p, ';'))) * s = '\0'; - else s = p + strlen((char *)p); + else s = p + EM_SAFE_STRLEN((char *)p); if (*(s - 1) == '/') *(s - 1) = '\0'; - if (strlen((char *)p)) mailbox =(unsigned char*) EM_SAFE_STRDUP((char *)p); + if (EM_SAFE_STRLEN((char *)p)) mailbox =(unsigned char*) EM_SAFE_STRDUP((char *)p); break; case 'h': /* not supported */ @@ -562,7 +562,7 @@ INTERNAL_FUNC int emdaemon_handle_emn_notification(unsigned char* wbxml_b64, ema if ((account.incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) && (account.flag2 == 3)) { - if (!mailbox_name || strncmp(pmailbox, mailbox_name, strlen(pmailbox)) != 0) { + if (!mailbox_name || strncmp(pmailbox, mailbox_name, EM_SAFE_STRLEN(pmailbox)) != 0) { EM_DEBUG_EXCEPTION("invalid inbox name [%p]", mailbox_name); err = EMAIL_ERROR_INVALID_MAILBOX; goto FINISH_OFF; diff --git a/email-daemon/email-daemon-etc.c b/email-daemon/email-daemon-etc.c index a30d700..35da020 100755 --- a/email-daemon/email-daemon-etc.c +++ b/email-daemon/email-daemon-etc.c @@ -251,26 +251,26 @@ static char *_make_criteria_to_search_filter(email_search_filter_t *search_filte case EMAIL_SEARCH_FILTER_TYPE_FROM : EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "from %s ", search_filter[i].search_filter_key_value.string_type_key_value); - strncat(criteria, temp_criteria, strlen(temp_criteria)); + strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); break; case EMAIL_SEARCH_FILTER_TYPE_SUBJECT : EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "subject %s ", search_filter[i].search_filter_key_value.string_type_key_value); - strncat(criteria, temp_criteria, strlen(temp_criteria)); + strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); break; case EMAIL_SEARCH_FILTER_TYPE_KEYWORD : EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "keyword %s ", search_filter[i].search_filter_key_value.string_type_key_value); - strncat(criteria, temp_criteria, strlen(temp_criteria)); + strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); break; case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE : EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value); time_string = _make_time_string_to_time_t(search_filter[i].search_filter_key_value.time_type_key_value); SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "before %s ", time_string); - strncat(criteria, temp_criteria, strlen(temp_criteria)); + strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); break; case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON : @@ -281,7 +281,7 @@ static char *_make_criteria_to_search_filter(email_search_filter_t *search_filte EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value); time_string = _make_time_string_to_time_t(search_filter[i].search_filter_key_value.time_type_key_value); SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "since %s ", time_string); - strncat(criteria, temp_criteria, strlen(temp_criteria)); + strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); break; default : @@ -314,7 +314,7 @@ INTERNAL_FUNC int emdaemon_search_mail_on_server(int input_account_id, int input if (input_mailbox_id == 0 || input_account_id < 0) { EM_DEBUG_EXCEPTION("Invalid parameter"); error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + return false; } email_event_t event_data; diff --git a/email-daemon/email-daemon-init.c b/email-daemon/email-daemon-init.c index 6f43372..55a7184 100755 --- a/email-daemon/email-daemon-init.c +++ b/email-daemon/email-daemon-init.c @@ -76,10 +76,12 @@ static int _emdaemon_load_email_core() if (emcore_start_event_loop_for_sending_mails(&err) < 0) goto FINISH_OFF; + /* Disabled task manager if ((err = emcore_start_task_manager_loop()) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_start_task_manager_loop failed [%d]",err); goto FINISH_OFF; } + */ #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ if (emcore_start_thread_for_downloading_partial_body(&err) < 0) { @@ -137,8 +139,8 @@ static void callback_for_SYNC_ALL_STATUS_from_account_svc(keynode_t *input_node, if(!emdaemon_sync_header(account_list[i].account_id, mailbox_tbl_data->mailbox_id, &handle, &err)) { EM_DEBUG_EXCEPTION("emdaemon_sync_header for [%d] failed [%d]", account_list[i].account_id, err); } - if(mailbox_tbl_data) - emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL); + + emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL); /* prevent 27459: remove unnecesary if clause */ mailbox_tbl_data = NULL; } else { diff --git a/email-daemon/email-daemon-mail.c b/email-daemon/email-daemon-mail.c index fa00d20..69300e6 100755 --- a/email-daemon/email-daemon-mail.c +++ b/email-daemon/email-daemon-mail.c @@ -256,13 +256,13 @@ INTERNAL_FUNC int emdaemon_add_mail(email_mail_data_t *input_mail_data, email_at } #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ - if ( input_from_eas == 0) { + if ( input_from_eas == 0 && ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { event_data.type = EMAIL_EVENT_SAVE_MAIL; event_data.account_id = input_mail_data->account_id; event_data.event_param_data_4 = input_mail_data->mail_id; - if (!emcore_insert_event_for_sending_mails(&event_data, &handle, &err)) { - EM_DEBUG_EXCEPTION("emcore_insert_event_for_sending_mails failed [%d]", err); + if (!emcore_insert_event(&event_data, &handle, &err)) { + EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } } @@ -617,7 +617,7 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o goto FINISH_OFF; } - if(!emcore_delete_all_mails_of_mailbox(input_mailbox_id, EMAIL_DELETE_LOCALLY, &err)) { + if(!emcore_delete_all_mails_of_mailbox(mailbox_tbl->account_id, input_mailbox_id, EMAIL_DELETE_LOCALLY, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); goto FINISH_OFF; } @@ -692,7 +692,7 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o ret = true; FINISH_OFF: - + if (mailbox_tbl) emstorage_free_mailbox(&mailbox_tbl, 1, NULL); diff --git a/email-daemon/email-daemon-mailbox.c b/email-daemon/email-daemon-mailbox.c index 9d555b5..18b7563 100755 --- a/email-daemon/email-daemon-mailbox.c +++ b/email-daemon/email-daemon-mailbox.c @@ -89,9 +89,6 @@ FINISH_OFF: return ret; } - - - INTERNAL_FUNC int emdaemon_get_mailbox_list(int account_id, email_mailbox_t** mailbox_list, int* count, int* err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p], err_code[%p]", account_id, mailbox_list, count, err_code); diff --git a/email-daemon/main.c b/email-daemon/main.c index e2b6bfc..d8a86d2 100755 --- a/email-daemon/main.c +++ b/email-daemon/main.c @@ -51,6 +51,7 @@ #include "email-core-smime.h" #include "email-core-cert.h" #include "email-core-task-manager.h" +#include "email-core-signal.h" #include "email-storage.h" void stb_create_account(HIPC_API a_hAPI) @@ -62,6 +63,9 @@ void stb_create_account(HIPC_API a_hAPI) email_account_t account; int err = EMAIL_ERROR_NONE; + /* Initialize the email_account_t */ + memset(&account, 0x00, sizeof(email_account_t)); + buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0); EM_DEBUG_LOG("size [%d]", buffer_size); if(buffer_size <= 0) { @@ -990,42 +994,6 @@ FINISH_OFF: emcore_free_rule(&rule); -#if 0 - /* filter_id */ - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &filter_id); - - buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1); - EM_DEBUG_LOG("size [%d]", buffer_size); - - if(buffer_size > 0) { - rule_stream = (char*)em_malloc(buffer_size); - EM_NULL_CHECK_FOR_VOID(rule_stream); - if(rule_stream) { - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, rule_stream); - rule = (email_rule_t*)em_malloc(sizeof(email_rule_t)); - - if(NULL == rule) { - EM_SAFE_FREE(rule_stream); - return; - } - - em_convert_byte_stream_to_rule(rule_stream, buffer_size, rule); - EM_SAFE_FREE(rule_stream); - } - } - - if(emdaemon_update_filter(filter_id, rule, &err)) - err = EMAIL_ERROR_NONE; - - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - - EM_SAFE_FREE(rule); -#endif - EM_DEBUG_FUNC_END(); } @@ -1221,112 +1189,6 @@ FINISH_OFF: em_flush_memory(); -#if 0 - EM_DEBUG_LOG("email_mail_data_t"); - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - - /* mail_data */ - if(buffer_size > 0) { - mail_data_stream = (char*)em_malloc(buffer_size); - if(!mail_data_stream) { - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, buffer_size, mail_data_stream); - em_convert_byte_stream_to_mail_data(mail_data_stream, buffer_size, &result_mail_data); - if(!result_mail_data) { - EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_mail_data failed"); - err = EMAIL_ERROR_ON_PARSING; - goto FINISH_OFF; - } - } - - /* attachment */ - buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); - - if(buffer_size > 0) { - attachment_data_list_stream = (char*) em_malloc(buffer_size); - if(!attachment_data_list_stream) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, buffer_size, attachment_data_list_stream); - em_convert_byte_stream_to_attachment_data(attachment_data_list_stream, buffer_size, &result_attachment_data, &result_attachment_data_count); - - EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); - - if(result_attachment_data_count && !result_attachment_data) { - EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); - err = EMAIL_ERROR_ON_PARSING; - goto FINISH_OFF; - } - } - - /* meeting request */ - EM_DEBUG_LOG("email_meeting_request_t"); - if ( result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST - || result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE - || result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { - buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - - if(buffer_size > 0) { - meeting_request_stream = (char*)em_malloc(buffer_size); - if(!meeting_request_stream) { - EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_mail_data failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, buffer_size, meeting_request_stream); - result_meeting_request = (email_meeting_request_t*)em_malloc(sizeof(email_meeting_request_t)); - if(result_meeting_request) - em_convert_byte_stream_to_meeting_req(meeting_request_stream, buffer_size, result_meeting_request); - } - } - - EM_DEBUG_LOG("sync_server"); - emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, sizeof(int), &sync_server); - - if( (err = emdaemon_add_mail(result_mail_data, result_attachment_data, result_attachment_data_count, result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emdaemon_add_mail failed [%d]", err); - goto FINISH_OFF; - } - - local_result = 1; - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->mail_id), sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->thread_id), sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - -FINISH_OFF: - if ( local_result == 0 ) { - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - } - - EM_SAFE_FREE(mail_data_stream); - EM_SAFE_FREE(attachment_data_list_stream); - EM_SAFE_FREE(meeting_request_stream); - - if(result_mail_data) - emcore_free_mail_data(&result_mail_data, 1, NULL); - - if(result_attachment_data) - emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL); - - if(result_meeting_request) - emstorage_free_meeting_request(&result_meeting_request, 1, NULL); - - em_flush_memory(); -#endif EM_DEBUG_FUNC_END(); } @@ -1562,6 +1424,48 @@ void stb_expunge_mails_deleted_flagged(HIPC_API a_hAPI) EM_DEBUG_FUNC_END(); } +void stb_update_mail_attribute(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int mail_id_count = 0, counter = 0; + email_mail_attribute_type attribute; + /* email_mail_attribute_value_t value; */ + + /* mail_id_count */ + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id_count); + EM_DEBUG_LOG("mail_id_count [%d]", mail_id_count); + + /* mail_id_array */ + int mail_id_array[mail_id_count]; + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, mail_id_count * sizeof(int), mail_id_array); + + for(counter = 0; counter < mail_id_count; counter++) + EM_DEBUG_LOG("mail_id[%d] [%d]", counter, mail_id_array[counter]); + + /* attribute */ + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &attribute); + EM_DEBUG_LOG("attribute [%d]", attribute); + + /* value */ + /* + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &value); + EM_DEBUG_LOG("target_mailbox_id [%d]", mailbox_id); + */ + + /* + if(emdaemon_move_mail(mail_ids, num, mailbox_id, EMAIL_MOVED_BY_COMMAND, 0, &err)) + EM_DEBUG_LOG("emdaemon_move_mail success"); + */ + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter fail"); + + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail"); + EM_DEBUG_FUNC_END(); +} + void stb_move_mail(HIPC_API a_hAPI) { int err = EMAIL_ERROR_NONE; @@ -2086,7 +1990,7 @@ void stb_clear_result_of_search_mail_on_server(HIPC_API a_hAPI) -void stb_create_account_with_validation(HIPC_API a_hAPI) +void stb_add_account_with_validation(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int buffer_size = 0; @@ -2110,14 +2014,23 @@ void stb_create_account_with_validation(HIPC_API a_hAPI) goto FINISH_OFF; } - account = emcore_get_new_account_reference(); + account = em_malloc(sizeof(email_account_t)); + + if(account == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + em_convert_byte_stream_to_account(stream, buffer_size, account); - account->account_id = NEW_ACCOUNT_ID; - EM_DEBUG_LOG("Account name - %s", account->account_name); - EM_DEBUG_LOG("Email Address - %s", account->user_email_address); + + if((err = emcore_add_account_to_unvalidated_account_list(account)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_account_to_unvalidated_account_list failed [%d]", err); + goto FINISH_OFF; + } if(!emdaemon_validate_account_and_create(account, &handle, &err)) { - EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_create fail "); + EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_create fail [%d]", err); goto FINISH_OFF; } #ifdef __FEATURE_AUTO_POLLING__ @@ -2320,6 +2233,8 @@ void stb_delete_certificate(HIPC_API a_hAPI) if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); + + EM_SAFE_FREE(email_address); EM_DEBUG_FUNC_END(); } @@ -2588,7 +2503,7 @@ void stb_write_mime_file(HIPC_API a_hAPI) } - if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, (char *)output_file_path, strlen(output_file_path) + 1)) { + if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, (char *)output_file_path, EM_SAFE_STRLEN(output_file_path) + 1)) { EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); err = EMAIL_ERROR_NULL_VALUE; goto FINISH_OFF; @@ -2668,6 +2583,191 @@ FINISH_OFF: EM_DEBUG_FUNC_END("err [%d]", err); } +void* thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param) +{ + EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param); + int err = EMAIL_ERROR_NONE; + int err_for_signal = EMAIL_ERROR_NONE; + int i = 0; + int task_id = THREAD_SELF(); + task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param; + + /* Send start signal */ + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + + for(i = 0; i < task_param->mail_id_count; i++) { + if((err = emcore_move_mail_to_another_account(task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, task_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err); + goto FINISH_OFF; + } + + /* Send progress signal */ + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mail_id_count)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + +FINISH_OFF: + /* Send finish signal */ + if(err == EMAIL_ERROR_NONE) { + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_FINISHED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + else { + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_FAILED, err, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + + /* Free task parameter */ + EM_SAFE_FREE(task_param->mail_id_array); + EM_SAFE_FREE(task_param); + + EM_DEBUG_FUNC_END("err [%d]", err); + return SUCCESS; +} + +void stb_move_mails_to_mailbox_of_another_account(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + int param_index = 0; + int err = EMAIL_ERROR_NONE; + int task_parameter_length = 0; + int thread_error; + thread_t task_id; + char *task_parameter = NULL; + task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *decoded_parameter = NULL; + + /* task_parameter_length */; + task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + + if(task_parameter_length <= 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* task_parameter */ + task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++); + + if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err); + goto FINISH_OFF; + } + + THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, (void*)decoded_parameter, thread_error); + + if(thread_error != 0) { + EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + THREAD_DETACH(task_id); + +FINISH_OFF: + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); + + EM_DEBUG_FUNC_END("err [%d]", err); +} + +void* thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param) +{ + EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param); + int err = EMAIL_ERROR_NONE; + int err_for_signal = EMAIL_ERROR_NONE; + int i = 0; + int task_id = THREAD_SELF(); + task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_param = input_param; + + /* Send start signal */ + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + + if((err = emcore_delete_mailbox_ex(task_param->account_id, task_param->mailbox_id_array, task_param->mailbox_id_count, task_param->on_server)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_delete_mailbox_ex failed[%d]", err); + goto FINISH_OFF; + } + /* Send progress signal */ + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mailbox_id_count)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + +FINISH_OFF: + /* Send finish signal */ + if(err == EMAIL_ERROR_NONE) { + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_FINISHED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + else { + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_FAILED, err, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + + /* Free task parameter */ + EM_SAFE_FREE(task_param->mailbox_id_array); + EM_SAFE_FREE(task_param); + + EM_DEBUG_FUNC_END("err [%d]", err); + return SUCCESS; +} + +void stb_delete_mailbox_ex(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + int param_index = 0; + int err = EMAIL_ERROR_NONE; + int task_parameter_length = 0; + int thread_error = 0; + thread_t task_id; + char *task_parameter = NULL; + task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *decoded_parameter = NULL; + + /* task_parameter_length */; + task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + + if(task_parameter_length <= 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* task_parameter */ + task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++); + + if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err); + goto FINISH_OFF; + } + + THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, (void*)decoded_parameter, thread_error); + + if(thread_error != 0) { + EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + THREAD_DETACH(task_id); + +FINISH_OFF: + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); + + EM_DEBUG_FUNC_END("err [%d]", err); +} + void stb_API_mapper(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); @@ -2790,6 +2890,10 @@ void stb_API_mapper(HIPC_API a_hAPI) stb_expunge_mails_deleted_flagged(a_hAPI); break; + case _EMAIL_API_UPDATE_MAIL_ATTRIBUTE: + stb_update_mail_attribute(a_hAPI); + break; + case _EMAIL_API_DELETE_ACCOUNT: stb_delete_account(a_hAPI); break; @@ -2863,7 +2967,7 @@ void stb_API_mapper(HIPC_API a_hAPI) break; case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION : - stb_create_account_with_validation(a_hAPI); + stb_add_account_with_validation(a_hAPI); break; case _EMAIL_API_BACKUP_ACCOUNTS: @@ -2915,7 +3019,11 @@ void stb_API_mapper(HIPC_API a_hAPI) break; case EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT : - stb_handle_task(nAPIID, a_hAPI); + stb_move_mails_to_mailbox_of_another_account(a_hAPI); + break; + + case EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX : + stb_delete_mailbox_ex(a_hAPI); break; } EM_DEBUG_FUNC_END(); diff --git a/email-ipc/CMakeLists.txt b/email-ipc/CMakeLists.txt index 3604510..2747b14 100755 --- a/email-ipc/CMakeLists.txt +++ b/email-ipc/CMakeLists.txt @@ -46,7 +46,7 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(ipc_pkgs REQUIRED dlog dbus-1 glib-2.0) +pkg_check_modules(ipc_pkgs REQUIRED dlog dbus-1 glib-2.0 libsystemd-daemon) FOREACH(flag ${ipc_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/email-ipc/email-ipc-api.c b/email-ipc/email-ipc-api.c index 91676c6..ce84689 100755 --- a/email-ipc/email-ipc-api.c +++ b/email-ipc/email-ipc-api.c @@ -27,6 +27,7 @@ #include "email-ipc-param-list.h" #include "email-ipc-socket.h" #include "email-proxy-main.h" +#include "email-core-task-manager.h" #include "email-debug-log.h" #include "email-errors.h" @@ -196,5 +197,53 @@ EXPORT_API int emipc_get_nth_parameter_length(HIPC_API api, EPARAMETER_DIRECTION return -1; } +EXPORT_API int emipc_execute_proxy_task(email_task_type_t input_task_type, void *input_task_parameter) +{ + EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_parameter [%p]", input_task_type, input_task_parameter); + + int err = EMAIL_ERROR_NONE; + int task_parameter_length = 0; + char *task_parameter_stream = NULL; + HIPC_API hAPI = NULL; + + if(input_task_parameter == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + if((err = emcore_encode_task_parameter(input_task_type, input_task_parameter, &task_parameter_stream, &task_parameter_length)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_encode_task_parameter failed [%d]", err); + goto FINISH_OFF; + } + + hAPI = emipc_create_email_api(input_task_type); + + if(!hAPI) { + EM_DEBUG_EXCEPTION("emipc_create_email_api failed"); + err = EMAIL_ERROR_NULL_VALUE; + goto FINISH_OFF; + } + + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)task_parameter_stream, task_parameter_length)) { + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed"); + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + goto FINISH_OFF; + } + + emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); + + FINISH_OFF: + if(hAPI) + emipc_destroy_email_api(hAPI); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} diff --git a/email-ipc/email-socket/email-ipc-socket.c b/email-ipc/email-socket/email-ipc-socket.c index 678693a..0ff4453 100755 --- a/email-ipc/email-socket/email-ipc-socket.c +++ b/email-ipc/email-socket/email-ipc-socket.c @@ -38,6 +38,8 @@ #include #include +#include + EXPORT_API bool emipc_init_email_socket(int *fd) { bool ret = true; @@ -201,8 +203,17 @@ EXPORT_API int emipc_accept_email_socket(int fd) EXPORT_API int emipc_open_email_socket(int fd, const char *path) { EM_DEBUG_FUNC_BEGIN("path [%s]", path); + int sock_fd = 0; + + if (strcmp(path, EM_SOCKET_PATH) == 0 && + sd_listen_fds(1) == 1 && + sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, -1, EM_SOCKET_PATH, 0) > 0) { + close(fd); + sock_fd = SD_LISTEN_FDS_START + 0; + return sock_fd; + } - if (!path || strlen(path) > 108) { + if (!path || EM_SAFE_STRLEN(path) > 108) { EM_DEBUG_LOG("Path is null"); return EMAIL_ERROR_IPC_SOCKET_FAILURE; } @@ -217,7 +228,7 @@ EXPORT_API int emipc_open_email_socket(int fd, const char *path) strcpy(local.sun_path, path); unlink(local.sun_path); - int len = strlen(local.sun_path) + sizeof(local.sun_family); + int len = EM_SAFE_STRLEN(local.sun_path) + sizeof(local.sun_family); if (bind(fd, (struct sockaddr *)&local, len) == -1) { EM_DEBUG_LOG("bind: %s", EM_STRERROR(errno)); @@ -258,7 +269,7 @@ EXPORT_API bool emipc_connect_email_socket(int fd) server.sun_family = AF_UNIX; strcpy(server.sun_path, EM_SOCKET_PATH); - int len = strlen(server.sun_path) + sizeof(server.sun_family); + int len = EM_SAFE_STRLEN(server.sun_path) + sizeof(server.sun_family); if (connect(fd, (struct sockaddr *)&server, len) == -1) { EM_DEBUG_LOG("Cannot connect server %s", EM_STRERROR(errno)); diff --git a/email-ipc/include/email-ipc.h b/email-ipc/include/email-ipc.h index 99924cc..493de64 100755 --- a/email-ipc/include/email-ipc.h +++ b/email-ipc/include/email-ipc.h @@ -51,39 +51,36 @@ typedef void (*PFN_PROXY_CALLBACK) (HIPC_API input_api_handle, void* pParam1, vo typedef void (*PFN_EXECUTE_API) (HIPC_API input_api_handle); /* ------------------------------------------------------------------------------------------------------------ */ -/* Proxy AP */ +/* Proxy API */ /* ------------------------------------------------------------------------------------------------------------ */ EXPORT_API int emipc_initialize_proxy(); - EXPORT_API int emipc_finalize_proxy(); - EXPORT_API int emipc_execute_proxy_api(HIPC_API input_api_handle); /* ------------------------------------------------------------------------------------------------------------ */ -/* Stub AP */ +/* Stub API */ /* ------------------------------------------------------------------------------------------------------------ */ EXPORT_API bool emipc_initialize_stub(PFN_EXECUTE_API input_api_mapper); - EXPORT_API bool emipc_finalize_stub(); - EXPORT_API bool emipc_execute_stub_api(HIPC_API input_api_handle); /* ------------------------------------------------------------------------------------------------------------ */ -/* AP */ +/* API */ /* ------------------------------------------------------------------------------------------------------------ */ EXPORT_API HIPC_API emipc_create_email_api(long api_id); -EXPORT_API void emipc_destroy_email_api(HIPC_API input_api_handle); +EXPORT_API void emipc_destroy_email_api(HIPC_API input_api_handle); -EXPORT_API long emipc_get_api_id(HIPC_API input_api_handle); -EXPORT_API long emipc_get_app_id(HIPC_API input_api_handle); +EXPORT_API long emipc_get_api_id(HIPC_API input_api_handle); +EXPORT_API long emipc_get_app_id(HIPC_API input_api_handle); EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length); EXPORT_API bool emipc_add_dynamic_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length); -EXPORT_API int emipc_get_parameter(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction, int input_parameter_index, int input_parameter_buffer_size, void *output_parameter); +EXPORT_API int emipc_get_parameter(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction, int input_parameter_index, int input_parameter_buffer_size, void *output_parameter); EXPORT_API void* emipc_get_nth_parameter_data(HIPC_API api_handle, EPARAMETER_DIRECTION direction, int param_index); -EXPORT_API int emipc_get_parameter_length(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction, int input_parameter_index); -EXPORT_API int emipc_get_nth_parameter_length(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction, int input_parameter_index); +EXPORT_API int emipc_get_parameter_length(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction, int input_parameter_index); +EXPORT_API int emipc_get_nth_parameter_length(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction, int input_parameter_index); +EXPORT_API int emipc_execute_proxy_task(email_task_type_t input_task_type, void *input_task_parameter); #ifdef __cplusplus } #endif diff --git a/packaging/email-service.spec b/packaging/email-service.spec index e1067b1..c3b5b16 100755 --- a/packaging/email-service.spec +++ b/packaging/email-service.spec @@ -21,7 +21,6 @@ BuildRequires: pkgconfig(gthread-2.0) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(vconf-internal-keys) BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(heynoti) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(dbus-1) @@ -33,16 +32,17 @@ BuildRequires: pkgconfig(openssl) BuildRequires: pkgconfig(alarm-service) BuildRequires: pkgconfig(mm-player) BuildRequires: pkgconfig(mm-session) -BuildRequires: pkgconfig(devman_haptic) BuildRequires: pkgconfig(secure-storage) BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(accounts-svc) +BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(libcurl) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(gconf-2.0) BuildRequires: pkgconfig(cert-svc) BuildRequires: pkgconfig(badge) +BuildRequires: pkgconfig(feedback) BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -118,9 +118,7 @@ vconftool set -t int db/private/email-service/latest_mail_id "0" -g 6514 vconftool set -t int db/private/email-service/default_account_id "0" -g 6514 # for badge -vconftool set -t int db/badge/org.tizen.email "0" -g 6514 - -vconftool set -t int db/email_handle/active_sync_handle "-1" -g 6514 +vconftool set -t int db/badge/com.samsung.email "0" -g 6514 # for default account id vconftool set -t int memory/sync/email "0" -i -g 6514 @@ -128,9 +126,9 @@ vconftool set -t int memory/sync/email "0" -i -g 6514 # for priority send vconftool set -t string db/private/email-service/noti_ringthone_path "Whistle.mp3" -g 6514 vconftool set -t int db/private/email-service/noti_rep_type "0" -g 6514 -vconftool set -t int db/private/email-service/noti_notification_ticker "0" -g 6514 -vconftool set -t int db/private/email-service/noti_display_content_ticker "0" -g 6514 -vconftool set -t int db/private/email-service/noti_badge_ticker "0" -i -g 6514 +vconftool set -t bool db/private/email-service/noti_notification_ticker "0" -g 6514 +vconftool set -t bool db/private/email-service/noti_display_content_ticker "0" -g 6514 +vconftool set -t bool db/private/email-service/noti_badge_ticker "0" -i -g 6514 vconftool set -t int db/private/email-service/noti_private_id/1 "0" -i -g 6514 vconftool set -t int db/private/email-service/noti_private_id/2 "0" -i -g 6514 vconftool set -t int db/private/email-service/noti_private_id/3 "0" -i -g 6514 @@ -253,7 +251,7 @@ CREATE TABLE mail_box_tbl mailbox_name VARCHAR(256), mailbox_type INTEGER, alias VARCHAR(256), - sync_with_server_yn INTEGER, + deleted_flag INTEGER, modifiable_yn INTEGER, total_mail_count_on_server INTEGER, has_archived_mails INTEGER, @@ -411,17 +409,33 @@ CREATE INDEX mail_idx_thread_item_count ON mail_tbl (thread_item_count); echo "[EMAIL-SERVICE] Finish Creating Email Tables." -chgrp db_email_service /opt/usr/dbspace/.email-service.db* +chgrp 6006 /opt/usr/dbspace/.email-service.db* chmod 664 /opt/usr/dbspace/.email-service.db chmod 664 /opt/usr/dbspace/.email-service.db-journal mkdir -m775 -p /opt/usr/data/email/.email_data -chgrp db_email_service /opt/usr/data/email/.email_data +chgrp 6006 /opt/usr/data/email/.email_data mkdir -m775 -p /opt/usr/data/email/.email_data/tmp -chgrp db_email_service /opt/usr/data/email/.email_data/tmp +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 + +systemctl daemon-reload +if [ $1 == 1 ]; then + systemctl restart email.service +fi + +%preun +if [ $1 == 0]; then + systemctl stop email.service +fi + +%postun +/sbin/ldconfig +systemctl daemon-reload -%postun -p /sbin/ldconfig %files %manifest email-service.manifest diff --git a/utilities/test-application/testapp-account.c b/utilities/test-application/testapp-account.c index b94116a..2621578 100755 --- a/utilities/test-application/testapp-account.c +++ b/utilities/test-application/testapp-account.c @@ -281,6 +281,7 @@ gboolean testapp_test_create_account_by_account_type(int account_type,int *accou err_code = email_add_account_with_validation(account, &handle); if( err_code < 0) { testapp_print (" email_add_account_with_validation error : %d\n",err_code); + err_code = email_free_account(&account, 1); return FALSE; } diff --git a/utilities/test-application/testapp-mail.c b/utilities/test-application/testapp-mail.c index 3b88911..d68ec59 100755 --- a/utilities/test-application/testapp-mail.c +++ b/utilities/test-application/testapp-mail.c @@ -249,7 +249,7 @@ static gboolean testapp_test_add_mail (int *result_mail_id) fflush(body_file); fclose(body_file); - testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt] : "); + testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrypt, 3: sing + encrypt] : "); result_from_scanf = scanf("%d", &smime_type); test_mail_data->smime_type = smime_type; @@ -333,6 +333,7 @@ static gboolean testapp_test_update_mail() int mail_id = 0; int err = EMAIL_ERROR_NONE; int test_attachment_data_count = 0; + int ret = 0; char arg[50]; email_mail_data_t *test_mail_data = NULL; email_attachment_data_t *test_attachment_data_list = NULL; @@ -343,6 +344,11 @@ static gboolean testapp_test_update_mail() email_get_mail_data(mail_id, &test_mail_data); + if (!test_mail_data) { + testapp_print("email_get_mail_data() failed\n"); + return FALSE; + } + testapp_print("\n > Enter Subject: "); result_from_scanf = scanf("%s", arg); @@ -351,7 +357,7 @@ static gboolean testapp_test_update_mail() if (test_mail_data->attachment_count > 0) { if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) { testapp_print("email_get_meeting_request() failed [%d]\n", err); - return FALSE; + goto FINISH_OFF; } } @@ -361,7 +367,7 @@ static gboolean testapp_test_update_mail() if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMAIL_ERROR_NONE ) { testapp_print("email_get_meeting_request() failed [%d]\n", err); - return FALSE; + goto FINISH_OFF; } testapp_print("\n > Enter meeting response: "); @@ -372,7 +378,11 @@ static gboolean testapp_test_update_mail() testapp_print("email_update_mail failed.[%d]\n", err); else testapp_print("email_update_mail success\n"); - + + ret = 1; + +FINISH_OFF: + if(test_mail_data) email_free_mail_data(&test_mail_data, 1); @@ -382,6 +392,9 @@ static gboolean testapp_test_update_mail() if(meeting_req) email_free_meeting_request(&meeting_req, 1); + if (!ret) + return FALSE; + return TRUE; } @@ -1052,6 +1065,8 @@ static gboolean testapp_test_move_mails_to_mailbox_of_another_account() testapp_print("\n > Enter mail count: "); result_from_scanf = scanf("%d", &mail_id_count); + mail_id_count = (mail_id_count < 5000)?mail_id_count:5000; + if(mail_id_count > 0) { mail_id_array = malloc(sizeof(int) * mail_id_count); } @@ -1770,7 +1785,7 @@ static gboolean testapp_test_email_write_mime_file() err = email_get_mail_data(mail_id, &mail_data); - if (err != EMAIL_ERROR_NONE) { + if (err != EMAIL_ERROR_NONE || mail_data == NULL) { testapp_print("email_get_mail_data failed : [%d]\n", err); return false; } diff --git a/utilities/test-application/testapp-mailbox.c b/utilities/test-application/testapp-mailbox.c index ecbbf9c..768a940 100755 --- a/utilities/test-application/testapp-mailbox.c +++ b/utilities/test-application/testapp-mailbox.c @@ -206,7 +206,44 @@ static gboolean testapp_test_set_local_mailbox() return FALSE; } -static gboolean testapp_test_get_mailbox_by_type () +static gboolean testapp_test_delete_mailbox_ex() +{ + int err = EMAIL_ERROR_NONE; + int mailbox_id_count = 0 ; + int *mailbox_id_array = NULL; + int account_id = 0; + int on_server = 0; + int handle = 0; + int i = 0; + int result_from_scanf = 0; + + testapp_print("\n > Enter account_id: "); + result_from_scanf = scanf("%d", &account_id); + + testapp_print("\n > Enter mailbox_id_count: "); + result_from_scanf = scanf("%d", &mailbox_id_count); + + testapp_print("\n > Enter on_server: "); + result_from_scanf = scanf("%d", &on_server); + + mailbox_id_count = (mailbox_id_count < 5000)?mailbox_id_count:5000; + + if(mailbox_id_count > 0) { + mailbox_id_array = malloc(sizeof(int) * mailbox_id_count); + } + + for(i = 0; i < mailbox_id_count; i++) { + testapp_print("\n > Enter mailbox id: "); + result_from_scanf = scanf("%d", (mailbox_id_array + i)); + } + + err = email_delete_mailbox_ex(account_id, mailbox_id_array, mailbox_id_count, on_server, &handle); + + testapp_print("\nemail_delete_mailbox_ex returns [%d], handle [%d] \n", err, handle); + return 0; +} + +static gboolean testapp_test_get_mailbox_by_type() { int account_id =0; @@ -377,6 +414,10 @@ static gboolean testapp_test_interpret_command (int menu_number) testapp_test_set_local_mailbox(); break; + case 6: + testapp_test_delete_mailbox_ex(); + break; + case 7: testapp_test_get_mailbox_by_type(); break; diff --git a/utilities/test-application/testapp-others.c b/utilities/test-application/testapp-others.c index 2d2a828..f37229a 100755 --- a/utilities/test-application/testapp-others.c +++ b/utilities/test-application/testapp-others.c @@ -238,6 +238,12 @@ static gboolean testapp_test_encoding_test() } FINISH_OFF: + if (encoded_file_name) + free(encoded_file_name); + + if (base64_file_name) + free(base64_file_name); + return error; } diff --git a/utilities/test-application/testapp-utility.c b/utilities/test-application/testapp-utility.c index dc3a39e..4a0f9f3 100755 --- a/utilities/test-application/testapp-utility.c +++ b/utilities/test-application/testapp-utility.c @@ -136,6 +136,7 @@ void testapp_show_menu (eEMAIL_MENU menu) testapp_print (" 3. Raname mailbox\n"); testapp_print (" 4. Get IMAP mailbox List\n"); testapp_print (" 5. Set local mailbox\n"); + testapp_print (" 6. Delete mailbox ex\n"); testapp_print (" 7. Get mailbox by mailbox type\n"); testapp_print (" 8. Set mailbox type\n"); testapp_print (" 9. Set mail slot size\n");