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;
}
if(emstorage_check_duplicated_account(account, true, &err) == false) {
EM_DEBUG_EXCEPTION("emstorage_check_duplicated_account failed (%d) ", err);
-
return err;
}
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);
}
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);
}
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 {
EM_DEBUG_FUNC_END();
return err;
}
+
+
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);
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;
}
/* 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);
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;
}
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);
}
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);
{
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");
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;
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;
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;
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);
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;
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;
}
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);
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;
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);
}
*/
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
/**
-
* @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.
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.
*/
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.
*/
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'.
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.
*
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.
*
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.
*
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.
*
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.
*
/**
-
* @fn email_free_mailbox(email_mailbox_t** mailbox_list, int count)
* @brief Free allocated memory for mailbox information.
*
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;
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;
}
void *p = calloc(1,len);
- if (!p)
+ if (!p) {
EM_DEBUG_EXCEPTION("malloc failed");
+ return NULL;
+ }
memcpy(p, src, len);
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);
/* 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';
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;
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 ;
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';) {
}
}
} else {
- i = strlen(source_string);
+ i = EM_SAFE_STRLEN(source_string);
}
result_buffer = (char *)malloc(i + 1 + count*(new_str_length-old_str_length));
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) {
}
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;
}
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;
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;
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--] != '.') ;
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] == '.')
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;
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);
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 <data->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;
#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 */
#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 */
/* 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
/* ----------------------------------------------------------------------------- */
/* Feature definitions */
-#define __FEATURE_USING_ACCOUNT_SVC__
#define __FEATURE_BACKUP_ACCOUNT__
#define __FEATURE_MOVE_TO_OUTBOX_FIRST__
/* #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */
#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__ */
#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"
#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"
#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
/*****************************************************************************/
#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
_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,
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,
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;
/**
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,
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
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;
/**
{
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.*/
} 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
{
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
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;
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;
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
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 */
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,
/* 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;
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;
/* 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*));
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:
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 */
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*/
}
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 */
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();
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})
#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,
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;
}
#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;
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};
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++) {
{
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);
}
/* 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;
*err_code = err;
}
+ cert_svc_cert_context_final(context);
+
EM_DEBUG_FUNC_END();
return ret;
}
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) {
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:
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;
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)
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;
}
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;
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);
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;
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;
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;
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");
}
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)
{
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)
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:
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;
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;
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:
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:
#include <stdlib.h>
#include <string.h>
#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;
+}
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 {
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;
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);
}
/* 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;
}
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);
/* 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);
}
/* 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;
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);
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;
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;
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;
}
/* 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;
}
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:
#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;
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");
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...");
/* 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 */
*/
- 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;
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;
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;
#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;
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;
}
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);
}
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;
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;
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;
}
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;
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;
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. */
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;
/* 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;
}
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);
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;
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;
}
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;
}
}
-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;
}
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);
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;
/* 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;
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;
}
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 ");
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 ");
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 ");
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 */
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;
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;
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
/* 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;
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;
}
/* 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;
/* 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;
}
continue;
}
- s = t + strlen("FETCH (RFC822.SIZE ");
+ s = t + EM_SAFE_STRLEN("FETCH (RFC822.SIZE ");
if (!(t = strchr(s, ' '))) {
err = EMAIL_ERROR_INVALID_RESPONSE;
#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;
#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;
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;
}
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++;
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;
#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;
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;
}
}
if ((p = strstr(response, " SEARCH "))){
- *p = '\0'; p += strlen(" SEARCH ");
+ *p = '\0'; p += EM_SAFE_STRLEN(" SEARCH ");
result = strtok(p, delims);
err = EMAIL_ERROR_INVALID_RESPONSE;
goto FINISH_OFF;
}
-
- free(response); response = NULL;
+ /* Delete the dead code */
}
ret = true;
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 */
/* 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);
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))) {
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 ) {
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;
#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;
/* 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 */
/* parse uid */
s = strstr(++t, "UID ");
if (s) {
- s += strlen("UID ");
+ s += EM_SAFE_STRLEN("UID ");
t = strchr(s, ')');
if (!t) {
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;
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 */
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;
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;
}
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;
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);
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;
}
}
goto FINISH_OFF;
}
- ret = true;
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
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
/* 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);
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);
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);
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);
}
/* 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{
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);
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);
/* 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();
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;
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);
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)
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");
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 */
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:
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);
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;
}
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();
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");
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;
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;
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;
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);
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;
FINISH_OFF:
if (err_code != NULL)
*err_code = err;
-
+ EM_DEBUG_FUNC_END("err[%d]", err);
return ret;
}
EM_SAFE_FREE(mailbox_name);
if (mailbox) {
- emstorage_free_mailbox(&mailbox, 1, &error);
+ emstorage_free_mailbox(&mailbox, 1, NULL);
}
if (err_code != NULL)
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;
}
}
#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 */
/*
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, "\"");
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 ");
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);
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);
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");
*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))) {
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);
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);
}
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);
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);
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;
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));
}
}
- 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;
}
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) {
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;
}
}
}
- 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) {
}
}
}
- 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] == '<')) {
(*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();
/* 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);
}
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;
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 ? */
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;
}
if (err_code != NULL)
*err_code = error;
- close(fd);
+ if(fd>0) close(fd); /*prevent 32736*/
if (ret) {
if (size)
*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 */
return true;
}
- sz += strlen(buf);
+ sz += EM_SAFE_STRLEN(buf);
}
}
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)
}
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;
/* 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;
}
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;
part_child = part_child->next;
}
+ EM_DEBUG_FUNC_END();
return section_list;
}
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) {
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);
/* 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;
/* 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;
}
}
-
+#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)
{
int ret = false;
int err = EMAIL_ERROR_NONE;
-
FILE *fp = NULL;
IMAPLOCAL *imaplocal = NULL;
char tag[16], command[64];
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);
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))) {
if (!imaplocal->netstream) {
EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected... %p", imaplocal->netstream);
-
err = EMAIL_ERROR_INVALID_STREAM;
goto FINISH_OFF;
}
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;
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 != ']')
}
if ((p = strstr(s+1, " {"))) {
- p += strlen(" {");
+ p += EM_SAFE_STRLEN(" {");
s = p;
while (isdigit(*s))
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';
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);
while (temp_body_size && (total <body_size)) {
memset(test_buffer, 0x00, sizeof(test_buffer));
- while ((total != body_size) && temp_body_size && ((strlen((char *)test_buffer) + x) < sizeof(test_buffer))) {
+ while ((total != body_size) && temp_body_size && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) {
memset(encoded, 0x00, sizeof(encoded));
if (net_getbuffer (imaplocal->netstream, (long)x, (char *)encoded) <= 0) {
}
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;
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 */
}
}
}
}
- 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 */
}
}
- 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);
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;
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);
while (temp_body_size && (total <body_size)) {
memset(test_buffer, 0x00, sizeof(test_buffer));
- while ((total != body_size) && temp_body_size && ((strlen((char *)test_buffer) + x) < sizeof(test_buffer))) {
+ while ((total != body_size) && temp_body_size && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) {
memset(encoded, 0x00, sizeof(encoded));
if (net_getbuffer (imaplocal->netstream, (long)x, (char *)encoded) <= 0) {
}
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);
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;
}
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);
}
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);
}
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';
}
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) {
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 */ {
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 != ']')
}*/
p = strstr(s+1, " {");
if (p) {
- p += strlen(" {");
+ p += EM_SAFE_STRLEN(" {");
s = p;
while (isdigit(*s))
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);
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) {
}
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 {
}
} /* 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 */
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';
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;
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);
}
}
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;
}
}
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;
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");
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;
}
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
}
else {
/* unencoded text */
- length = strlen(start);
+ length = EM_SAFE_STRLEN(start);
strncat(buffer, start, length);
current = start + length;
#ifdef FEATURE_CORE_DEBUG
}
else {
/* unencoded text */
- length = strlen(current);
+ length = EM_SAFE_STRLEN(current);
strncat(buffer, current, length);
current = current + length;
#ifdef FEATURE_CORE_DEBUG
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;
}
}
}
/* +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;
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;
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);
INTERNAL_FUNC void mm_log(char *string, long errflg)
{
- /* EM_DEBUG_FUNC_BEGIN(); */
switch ((short)errflg) {
case NIL:
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;
}
}
*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;
}
{
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");
*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) {
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 {
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);
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);
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);
-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, };
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;
FINISH_OFF:
- *decrypt_message = temp_decrypt_filepath;
+ if (decrypt_message && ret)
+ *decrypt_message = EM_SAFE_STRDUP(temp_decrypt_filepath);
EVP_cleanup();
X509_free(cert);
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 */
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);
*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;
}
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') {
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;
}
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;
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:
}
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;
}
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
// }
nwrite = fprintf(fp, "%s", (p ? p : buf));
-
if (nwrite != len) {
fclose(fp);
close(fd);
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;
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) {
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);
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);
}
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);
}
}
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)) {
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;
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;
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);
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;
}
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)) {
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) {
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)) {
}
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);
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;
}
}
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);
}
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;
/* 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");
#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;
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);
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);
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;
}
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);
}
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); */
return NULL;
}
- gsize len = strlen(utf8_text);
+ gsize len = EM_SAFE_STRLEN(utf8_text);
EM_DEBUG_FUNC_END();
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) {
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] = ',';
}
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] = ',';
}
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 {
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);
}
}
- 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);
}
}
- 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);
}
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;
}
}
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);
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] = ',';
}
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] = ',';
}
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 {
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);
}
}
- 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);
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;
}
*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;
#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;
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);
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;
}
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);
EM_DEBUG_EXCEPTION("Invalid key type");
break;
}
+
+ EM_DEBUG_FUNC_END();
}
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);
EM_DEBUG_FUNC_END();
}
-bool emcore_update_sound_status()
+bool emcore_update_noti_status()
{
EM_DEBUG_FUNC_BEGIN();
int ticker_noti = 0;
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();
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;
}
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;
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();
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) {
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();
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;
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;
}
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;
}
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())
{
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:
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;
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);
-}
+}
_task_handler_array_size = 0;\r
\r
REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);\r
+ REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);\r
}\r
\r
EM_DEBUG_FUNC_END();\r
#include "email-core-task-manager.h"\r
#include "email-core-mail.h"\r
#include "email-core-mailbox-sync.h"\r
+#include "email-core-signal.h"\r
#include "tpl.h"\r
\r
/*-------------------------------------------------------------------------------------------*/\r
EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb.addr);\r
}\r
else {\r
- task_parameter->mail_id_array = em_malloc(sizeof(int) * task_parameter->mail_id_count);\r
-\r
- if(task_parameter->mail_id_array == NULL) {\r
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
- err = EMAIL_ERROR_OUT_OF_MEMORY;\r
- goto FINISH_OFF;\r
- }\r
- memcpy(task_parameter->mail_id_array, tb.addr, sizeof(int) * task_parameter->mail_id_count);\r
- EM_SAFE_FREE(tb.addr);\r
+ task_parameter->mail_id_array = tb.addr;\r
}\r
\r
*output_task_parameter_struct = task_parameter;\r
return EMAIL_ERROR_NONE;\r
}\r
\r
-void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)\r
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)\r
{\r
EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);\r
int err = EMAIL_ERROR_NONE;\r
+ int err_for_signal = EMAIL_ERROR_NONE;\r
int i = 0;\r
- int moved_mail_id = 0;\r
+ int task_id = THREAD_SELF();\r
task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param;\r
- email_active_task_t *active_task = NULL;\r
\r
- if((err = emcore_get_active_task_by_thread_id(THREAD_SELF(), &active_task)) != EMAIL_ERROR_NONE) {\r
- EM_DEBUG_EXCEPTION("emcore_get_active_task_by_thread_id failed [%d]", err);\r
- goto FINISH_OFF;\r
- }\r
for(i = 0; i < task_param->mail_id_count; i++) {\r
- 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) {\r
- EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account_on_local_storeage failed [%d]", err);\r
- /* goto FINISH_OFF; */\r
+ 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) {\r
+ EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err);\r
+ goto FINISH_OFF;\r
}\r
\r
- if((err = emcore_sync_mail_from_client_to_server(moved_mail_id, &err)) != EMAIL_ERROR_NONE) {\r
- EM_DEBUG_EXCEPTION("emcore_sync_mail_from_client_to_server failed [%d]", err);\r
- /* goto FINISH_OFF; */\r
- }\r
+ /* Send progress signal */\r
+ 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)\r
+ EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);\r
+ }\r
+\r
+FINISH_OFF:\r
+ /* Free task parameter */\r
+ EM_SAFE_FREE(task_param->mail_id_array);\r
+ EM_SAFE_FREE(task_param);\r
+\r
+ EM_DEBUG_FUNC_END("err [%d]", err);\r
+ return NULL;\r
+}\r
+/*-------------------------------------------------------------------------------------------*/\r
+/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */\r
+#define task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX "iiBi"\r
+\r
+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)\r
+{\r
+ 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);\r
+\r
+ int err = EMAIL_ERROR_NONE;\r
+ task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = input_task_parameter_struct;\r
+ tpl_bin tb;\r
+ tpl_node *tn = NULL;\r
+ void *result_data = NULL;\r
+ size_t result_data_length = 0;\r
+\r
+ if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
+ err = EMAIL_ERROR_INVALID_PARAM;\r
+ goto FINISH_OFF;\r
+ }\r
+\r
+ tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX\r
+ , &task_parameter->account_id\r
+ , &task_parameter->mailbox_id_count\r
+ , &tb\r
+ , &task_parameter->on_server);\r
+ tb.sz = sizeof(int) * task_parameter->mailbox_id_count;\r
+ tb.addr = task_parameter->mailbox_id_array;\r
+ tpl_pack(tn, 0);\r
+ tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);\r
+ tpl_free(tn);\r
+\r
+ *output_byte_stream = result_data;\r
+ *output_stream_size = result_data_length;\r
+\r
+FINISH_OFF:\r
+\r
+ EM_DEBUG_FUNC_END("err [%d]", err);\r
+ return EMAIL_ERROR_NONE;\r
+}\r
+\r
+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)\r
+{\r
+ 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);\r
+ int err = EMAIL_ERROR_NONE;\r
+ tpl_bin tb;\r
+ tpl_node *tn = NULL;\r
+ task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = NULL;\r
+\r
+ if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {\r
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
+ err = EMAIL_ERROR_INVALID_PARAM;\r
+ goto FINISH_OFF;\r
+ }\r
+\r
+ task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX));\r
+\r
+ if(task_parameter == NULL) {\r
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
+ err = EMAIL_ERROR_OUT_OF_MEMORY;\r
+ goto FINISH_OFF;\r
+ }\r
+\r
+ tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX\r
+ , &task_parameter->account_id\r
+ , &task_parameter->mailbox_id_count\r
+ , &tb\r
+ , &task_parameter->on_server);\r
+ tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);\r
+ tpl_unpack(tn, 0);\r
+ if(task_parameter->mailbox_id_count <= 0 || tb.addr == NULL) {\r
+ EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mailbox_id_count, tb.addr);\r
+ }\r
+ else {\r
+ task_parameter->mailbox_id_array = tb.addr;\r
}\r
\r
+ *output_task_parameter_struct = task_parameter;\r
+\r
FINISH_OFF:\r
\r
+ if(tn)\r
+ tpl_free(tn);\r
+\r
EM_DEBUG_FUNC_END("err [%d]", err);\r
+ return EMAIL_ERROR_NONE;\r
+}\r
+\r
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)\r
+{\r
return NULL;\r
}\r
/*-------------------------------------------------------------------------------------------*/\r
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);
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) {
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");
"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;
}
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);
}
}
/* 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)
goto FINISH_OFF;
}
- int i = (int)strlen(path);
+ int i = (int)EM_SAFE_STRLEN(path);
/* get filename */
for (; i >= 0; i--)
{
if (!host)
return 0;
- return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
+ return strncmp(host, ".SYNTAX-ERROR.", EM_SAFE_STRLEN(".SYNTAX-ERROR."));
}
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);
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;
}
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();
}
/* 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");
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;
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;
}
/* 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;
}
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;
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)
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);
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;
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;
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;
}
}
- 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;
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;
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)) {
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;
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);
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;
}
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++;
}
{
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) {
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;
}
FINISH_OFF:
- if (param_string)
- free(param_string);
+
+ EM_SAFE_FREE(param_string);
EM_DEBUG_FUNC_END();
return error_code;
}
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 {
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 ;
}
/* 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;
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);
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));
}
" mailbox_name, "
" mailbox_type, "
" alias, "
- " sync_with_server_yn, "
+ " deleted_flag, "
" modifiable_yn, "
" total_mail_count_on_server, "
" has_archived_mails, "
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) {
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;
", 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"
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)));
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)));
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;
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);
}
}
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;
}
_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++);
*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);
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)));
}
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; },
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);
/* 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,
"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 */
"cipher_type,"
"digest_type,");
- sql_len = strlen(sql_query_string);
+ sql_len = EM_SAFE_STRLEN(sql_query_string);
}
/* dummy value, FROM WHERE clause */
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)));
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);
", 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; },
/* 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;
" , ? " /* 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)));
/* 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;
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);
}
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 ");
(*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;
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);
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)));
_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++);
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);
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)));
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)));
", mailbox_name = ?"
", mailbox_type = ?"
", alias = ?"
- ", sync_with_server_yn = ?"
+ ", deleted_flag = ?"
", modifiable_yn= ?"
", mail_slot_size= ?"
", total_mail_count_on_server = ?"
", mailbox_name = ?"
", mailbox_type = ?"
", alias = ?"
- ", sync_with_server_yn = ?"
+ ", deleted_flag = ?"
", modifiable_yn= ?"
", mail_slot_size= ?"
", total_mail_count_on_server = ?"
- 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)));
_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);
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)));
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)));
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)));
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)
{
", ?" /* mailbox_name */
", ?" /* mailbox_type */
", ?" /* alias */
- ", ?" /* sync_with_server_yn */
+ ", ?" /* deleted_flag */
", ?" /* modifiable_yn */
", ?" /* total_mail_count_on_server */
", ?" /* has_archived_mails */
", ? )");/* 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)));
_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);
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);
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; },
- 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)));
}
- 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_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));
" 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)));
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);
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)));
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)));
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);
" 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)));
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)));
", ?" /* 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;
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;
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)));
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);
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)));
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; },
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;
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;
}
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)));
{
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)
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;
, 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)));
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");
, 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;
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)));
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)));
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;
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;
, 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)));
, (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;
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;
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;
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;
, 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;
, 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)));
", ?" /* 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)));
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);
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);
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);
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);
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; },
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)));
}
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);
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;
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);
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)));
, 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)));
")");
- 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)));
" 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)));
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);
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; },
}
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);
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);
}
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;
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) {
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) {
}
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;
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);
* 2. If not based on the character set, Append it in File
**/
- low_char_set = calloc(1, strlen(char_set) + strlen(" \" /></head>") +1);
+ low_char_set = calloc(1, EM_SAFE_STRLEN(char_set) + strlen(" \" /></head>") +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, " \" /></head>", strlen(" \" /></head>"));
+ strncat(low_char_set, " \" /></head>", strlen(" \" /></head>")); /*prevent 34359*/
EM_DEBUG_LOG(">>> CHARSET [ %s ] ", low_char_set);
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);
}
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);
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)));
else
*total_usage = 0;
- fclose(fp);
+ if(fp) fclose(fp); /* prevent 32730 */
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
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)));
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);
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);
/* 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%%%%\')) "
/* 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) ");
*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;
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)));
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; },
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; },
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; },
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)));
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)));
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) {
goto FINISH_OFF;
}
+ /* prevent 34361 */
if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE)
strcat(sql_query_string, where_pararaph);
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);
}
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 !!!");
", ?" /* 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));
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)));
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)));
/*
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);
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)));
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++;
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;
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;
}
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);
}
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);
}
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 :
}
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);
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;
") ");
- /* 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)));
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;
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; },
/* 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);
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)));
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) {
/* 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);
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)));
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) {
", 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)));
}
/* 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;
" , ? " /* 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)));
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; },
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 */
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 */
*/
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
*
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
}
* @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);
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);
typedef struct
{
- char *buffer;
- int buflen;
+ char *header;
+ int header_len;
+ char *body;
+ int body_len;
} email_partial_buffer;
#endif
*/
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);
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);
#include <mm_player.h>
#include <mm_error.h>
#include <mm_session_private.h>
-#include <devman_haptic.h>
#include <alarm.h>
+#include <feedback.h>
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
} task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT;\r
\r
DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);\r
-void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *param);\r
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *param);\r
+\r
+/*-------------------------------------------------------------------------------------------*/\r
+/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */\r
+typedef struct\r
+{\r
+ int account_id;\r
+ int mailbox_id_count;\r
+ int *mailbox_id_array;\r
+ int on_server;\r
+} task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX;\r
+\r
+DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);\r
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param);\r
/*-------------------------------------------------------------------------------------------*/\r
\r
#endif /* EMAIL_CORE_TASKS_H_ */\r
)
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})
/* 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 ");
/* 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;
}
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;
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, '@')))
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, '@')))
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 */
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;
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 :
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 :
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;
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) {
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 {
}
#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;
}
}
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;
}
ret = true;
FINISH_OFF:
-
+
if (mailbox_tbl)
emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
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);
#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)
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) {
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();
}
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();
}
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;
-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;
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__
if (!emipc_execute_stub_api(a_hAPI))
EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
+
+ EM_SAFE_FREE(email_address);
EM_DEBUG_FUNC_END();
}
}
- 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;
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();
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;
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:
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();
)
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}")
#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"
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;
+}
#include <errno.h>
#include <unistd.h>
+#include <systemd/sd-daemon.h>
+
EXPORT_API bool emipc_init_email_socket(int *fd)
{
bool ret = true;
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;
}
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));
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));
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
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)
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
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
# 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
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,
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
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;
}
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;
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;
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);
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;
}
}
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: ");
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);
if(meeting_req)
email_free_meeting_request(&meeting_req, 1);
+ if (!ret)
+ return FALSE;
+
return TRUE;
}
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);
}
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;
}
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;
testapp_test_set_local_mailbox();
break;
+ case 6:
+ testapp_test_delete_mailbox_ex();
+ break;
+
case 7:
testapp_test_get_mailbox_by_type();
break;
}
FINISH_OFF:
+ if (encoded_file_name)
+ free(encoded_file_name);
+
+ if (base64_file_name)
+ free(base64_file_name);
+
return error;
}
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");