2.0_alpha release commit
[framework/messaging/email-service.git] / email-api / email-api-mail.c
index fd82130..5781c22 100755 (executable)
 
 #define _DIRECT_TO_DB
 
-EXPORT_API int email_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_from_eas)
+#define MAX_SEARCH_LEN 1000
+
+EXPORT_API int email_add_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_IF_NULL_RETURN_VALUE(input_mail_data,               EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id,   EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_name, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_mail_data,               EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id,   EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_id,   EMAIL_ERROR_INVALID_PARAM);
 
        if(input_attachment_count > 0 && !input_attachment_data_list) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
-       int       err = EMF_ERROR_NONE;
+       int       err = EMAIL_ERROR_NONE;
        int       size = 0;
        char     *mail_data_stream = NULL;
        char     *attachment_data_list_stream  = NULL;
        char     *meeting_request_stream = NULL;
        HIPC_API  hAPI = NULL;
        
-       if(input_from_eas == 0) {
+       if(input_from_eas == 0) { /* native emails */
                hAPI = emipc_create_email_api(_EMAIL_API_ADD_MAIL);
 
                if(!hAPI) {
                        EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-                       err = EMF_ERROR_NULL_VALUE;             
+                       err = EMAIL_ERROR_NULL_VALUE;           
                        goto FINISH_OFF;
                }
 
-               /* emf_mail_data_t */
-               mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
+               /* email_mail_data_t */
+               mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, &size);
 
                if(!mail_data_stream) {
                        EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
-                       err = EMF_ERROR_NULL_VALUE;
-                       goto FINISH_OFF;
-               }
-
-               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter for head failed");
-                       err = EMF_ERROR_OUT_OF_MEMORY;
+                       err = EMAIL_ERROR_NULL_VALUE;
                        goto FINISH_OFF;
                }
+               emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size);
                
-               /* emf_attachment_data_t */
+               /* email_attachment_data_t */
                attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
 
-               if(!attachment_data_list_stream) {
-                       EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
-                       err = EMF_ERROR_NULL_VALUE;
+               if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
+                       EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
-               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-                       err = EMF_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
 
-               /*  emf_meeting_request_t */
-               if ( input_mail_data->meeting_request_status != EMF_MAIL_TYPE_NORMAL ) {
+               /*  email_meeting_request_t */
+               if ( input_mail_data->meeting_request_status != EMAIL_MAIL_TYPE_NORMAL ) {
                        meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
 
                        if(!meeting_request_stream) {
                                EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
-                               err = EMF_ERROR_NULL_VALUE;
+                               err = EMAIL_ERROR_NULL_VALUE;
                                goto FINISH_OFF;
                        }
 
-                       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
-                               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-                               err = EMF_ERROR_OUT_OF_MEMORY;
-                               goto FINISH_OFF;
-                       }
+                       emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size);
                }
 
                /* input_from_eas */
-               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int))) {
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-                       err = EMF_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
+               emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int));
 
                /* Execute API */
-               if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+               if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-                       err = EMF_ERROR_IPC_SOCKET_FAILURE;
+                       err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
                        goto FINISH_OFF;
                }
 
-               emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
-
-               if(err == EMF_ERROR_NONE) {
-                       emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &input_mail_data->mail_id); /* result mail_id */
-                       emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), &input_mail_data->thread_id); /* result thread_id */
+               /* get result from service */
+               err = *((int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 0));
+               if(err == EMAIL_ERROR_NONE) {
+                       /* result mail_id */
+                       input_mail_data->mail_id = *((int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 1));
+                       /* result thread_id */
+                       input_mail_data->thread_id = *((int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 2));
                }
        } 
-       else {
-               if((err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMF_ERROR_NONE) {
+       else { /* take care of mails from eas */
+               err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas);
+               if(err != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err);
                        goto FINISH_OFF;
                }
@@ -155,9 +142,6 @@ FINISH_OFF:
        if(hAPI) 
                emipc_destroy_email_api(hAPI);
 
-       EM_SAFE_FREE(mail_data_stream);
-       EM_SAFE_FREE(attachment_data_list_stream);
-
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 
@@ -167,29 +151,29 @@ EXPORT_API int email_add_read_receipt(int input_read_mail_id, int *output_receip
 {
        EM_DEBUG_FUNC_BEGIN("input_read_mail_id [%d], output_receipt_mail_id [%p]", input_read_mail_id, output_receipt_mail_id);
 
-       EM_IF_NULL_RETURN_VALUE(output_receipt_mail_id, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_receipt_mail_id, EMAIL_ERROR_INVALID_PARAM);
 
-       int      err = EMF_ERROR_NONE;
+       int      err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_READ_RECEIPT);
 
-       EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+       EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
 
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_read_mail_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("Add Param mail body Fail");
-               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
        }
 
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
        }
 
        emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
 
        EM_DEBUG_LOG("err [%d]", err);
 
-       if(err == EMF_ERROR_NONE) {
+       if(err == EMAIL_ERROR_NONE) {
                /* Get receipt mail id */
                emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_receipt_mail_id);
                EM_DEBUG_LOG("output_receipt_mail_id [%d]", *output_receipt_mail_id);
@@ -204,14 +188,15 @@ EXPORT_API int email_add_read_receipt(int input_read_mail_id, int *output_receip
 }
 
 
+
 int email_create_db_full()
 {
        int mailbox_index, mail_index, mailbox_count, mail_slot_size;
        emstorage_mail_tbl_t mail_table_data = {0};
-       emf_mailbox_t *mailbox_list = NULL;
-       int err = EMF_ERROR_NONE;
+       email_mailbox_t *mailbox_list = NULL;
+       int err = EMAIL_ERROR_NONE;
 
-       if ( (err = email_open_db()) != EMF_ERROR_NONE) {
+       if ( (err = email_open_db()) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("email_open_db failed [%d]", err);
                return err;
        }
@@ -220,9 +205,8 @@ int email_create_db_full()
        mail_table_data.full_address_from = strdup("<dummy_from@nowhere.com>");
        mail_table_data.full_address_to = strdup("<dummy_to@nowhere.com>");
        mail_table_data.account_id =1;
-       mail_table_data.mailbox_name = (char*) em_malloc(250);
 
-       if( (err = email_get_mailbox_list_ex(1, -1, 0, &mailbox_list, &mailbox_count)) < EMF_ERROR_NONE) {
+       if( (err = email_get_mailbox_list_ex(1, -1, 0, &mailbox_list, &mailbox_count)) < EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("email_get_mailbox_list_ex failed [%d]", err);
                goto FINISH_OFF;
        }
@@ -231,7 +215,7 @@ int email_create_db_full()
                mail_slot_size= mailbox_list[mailbox_index].mail_slot_size;
                for(mail_index = 0; mail_index < mail_slot_size; mail_index++) {
                        sprintf(mail_table_data.subject, "Subject #%d",mail_index);
-                       strncpy(mail_table_data.mailbox_name, mailbox_list[mailbox_index].name, 250 - 1);
+                       mail_table_data.mailbox_id   = mailbox_list[mailbox_index].mailbox_id;
                        mail_table_data.mailbox_type = mailbox_list[mailbox_index].mailbox_type;
                        if( !emstorage_add_mail(&mail_table_data, 1, true, &err))  {
                                EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]",err);
@@ -242,7 +226,7 @@ int email_create_db_full()
        }
 
 FINISH_OFF:
-       if ( (err = email_close_db()) != EMF_ERROR_NONE) {
+       if ( (err = email_close_db()) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("email_close_db failed [%d]", err);
        }       
        
@@ -250,27 +234,25 @@ FINISH_OFF:
                email_free_mailbox(&mailbox_list, mailbox_count);
 
        EM_SAFE_FREE(mail_table_data.subject);
-       EM_SAFE_FREE(mail_table_data.mailbox_name);
        EM_SAFE_FREE(mail_table_data.full_address_from);
        EM_SAFE_FREE(mail_table_data.full_address_to);
 
        return err;
 }
 
-EXPORT_API int email_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_from_eas)
+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)
 {
        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_IF_NULL_RETURN_VALUE(input_mail_data,               EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id,   EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_name, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_mail_data,               EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id,   EMAIL_ERROR_INVALID_PARAM);
 
        if(input_attachment_count > 0 && !input_attachment_data_list) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
-       int       err = EMF_ERROR_NONE;
+       int       err = EMAIL_ERROR_NONE;
        int       size = 0;
        char     *mail_data_stream = NULL;
        char     *attachment_data_list_stream  = NULL;
@@ -283,53 +265,47 @@ EXPORT_API int email_update_mail(emf_mail_data_t *input_mail_data, emf_attachmen
 
                if(!hAPI) {
                        EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-                       err = EMF_ERROR_NULL_VALUE;             
+                       err = EMAIL_ERROR_NULL_VALUE;           
                        goto FINISH_OFF;
                }
 
-               /* emf_mail_data_t */
-               mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
+               /* email_mail_data_t */
+               mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, &size);
 
                if(!mail_data_stream) {
                        EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
-                       err = EMF_ERROR_NULL_VALUE;
+                       err = EMAIL_ERROR_NULL_VALUE;
                        goto FINISH_OFF;
                }
                
                if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
                        EM_DEBUG_EXCEPTION("emipc_add_parameter for head failed");
-                       err = EMF_ERROR_OUT_OF_MEMORY;
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
                
-               /* emf_attachment_data_t */
+               /* email_attachment_data_t */
                attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
 
-               if(!attachment_data_list_stream) {
-                       EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
-                       err = EMF_ERROR_NULL_VALUE;
+               if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
+                       EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
-               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-                       err = EMF_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
-
-               /*  emf_meeting_request_t */
-               if ( input_mail_data->meeting_request_status != EMF_MAIL_TYPE_NORMAL ) {
+               /*  email_meeting_request_t */
+               if ( input_mail_data->meeting_request_status != EMAIL_MAIL_TYPE_NORMAL ) {
                        meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
 
                        if(!meeting_request_stream) {
                                EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
-                               err = EMF_ERROR_NULL_VALUE;
+                               err = EMAIL_ERROR_NULL_VALUE;
                                goto FINISH_OFF;
                        }
 
                        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
                                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-                               err = EMF_ERROR_OUT_OF_MEMORY;
+                               err = EMAIL_ERROR_OUT_OF_MEMORY;
                                goto FINISH_OFF;
                        }
                }
@@ -337,26 +313,26 @@ EXPORT_API int email_update_mail(emf_mail_data_t *input_mail_data, emf_attachmen
                /* input_from_eas */
                if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int))) {
                        EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-                       err = EMF_ERROR_OUT_OF_MEMORY;
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
                /* Execute API */
-               if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+               if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-                       err = EMF_ERROR_IPC_SOCKET_FAILURE;
+                       err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
                        goto FINISH_OFF;
                }
 
                emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
                
-               if(err == EMF_ERROR_NONE) {
+               if(err == EMAIL_ERROR_NONE) {
                        emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &input_mail_data->mail_id);
                        emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), &input_mail_data->thread_id);
                }
        } 
        else {
-               if( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMF_ERROR_NONE) {
+               if( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_update_mail failed [%d]", err);
                        goto FINISH_OFF;
                }
@@ -367,7 +343,6 @@ FINISH_OFF:
                emipc_destroy_email_api(hAPI);
 
        EM_SAFE_FREE(mail_data_stream);
-       EM_SAFE_FREE(attachment_data_list_stream);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
@@ -377,15 +352,15 @@ FINISH_OFF:
 EXPORT_API int email_clear_mail_data()
 {
        EM_DEBUG_FUNC_BEGIN();
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_DATA);  
 
-       EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+       EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
        
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api Fail");
-               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
        }
        emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
        
@@ -397,74 +372,58 @@ EXPORT_API int email_clear_mail_data()
 }
 
 
-EXPORT_API int email_count_message(emf_mailbox_t* mailbox, int* total, int* unseen)
+EXPORT_API int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count)
 {
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
+       EM_DEBUG_FUNC_BEGIN("input_filter_list[%p], input_filter_count [%d], output_total_mail_count[%p], output_unseen_mail_count[%p]", input_filter_list, input_filter_count, output_total_mail_count, output_unseen_mail_count);
        
        int total_count = 0;
        int unread = 0;
-       int err = EMF_ERROR_NONE;
-
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(unseen, EMF_ERROR_INVALID_PARAM);
+       int err = EMAIL_ERROR_NONE;
+       char *conditional_clause_string = NULL;
 
-       if (!emstorage_get_mail_count(mailbox->account_id,  mailbox->name, &total_count, &unread, true, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
+       EM_IF_NULL_RETURN_VALUE(input_filter_list, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_filter_count, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_total_mail_count, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_unseen_mail_count, EMAIL_ERROR_INVALID_PARAM);
 
-       } else {
-               *total = total_count;
-               *unseen = unread;
+       if( (err = emstorage_write_conditional_clause_for_getting_mail_list(input_filter_list, input_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;
        }
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
 
+       if ((err = emstorage_query_mail_count(conditional_clause_string, true, &total_count, &unread)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed [%d]", err);
+               goto FINISH_OFF;
+       }
 
+       *output_total_mail_count = total_count;
+       *output_unseen_mail_count = unread;
 
-EXPORT_API int  email_count_message_all_mailboxes(emf_mailbox_t* mailbox, int* total, int* unseen)
-{
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
-       
-       int total_count = 0;
-       int unread = 0;
-       int err = EMF_ERROR_NONE;
-               
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(unseen, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
-
-    if (!emstorage_get_mail_count(mailbox->account_id,  NULL, &total_count, &unread, true, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
+FINISH_OFF:
 
-       } else {
-               *total = total_count;
-               *unseen = unread;
-       }
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
 
-
-EXPORT_API int email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int num, int from_server)
+EXPORT_API int email_delete_mail(int input_mailbox_id, int *input_mail_ids, int input_num, int input_from_server)
 {
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%p], num[%d], from_server[%d]", mailbox, mail_ids, num, from_server);
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_mail_ids[%p], input_num[%d], input_from_server[%d]", input_mailbox_id, input_mail_ids, input_num, input_from_server);
 
-       char* mailbox_stream = NULL;
-       int size = 0;
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = NULL;
 
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
+       EM_IF_NULL_RETURN_VALUE(input_mail_ids, EMAIL_ERROR_INVALID_PARAM);
        
-       if (num <= 0) {
-               EM_DEBUG_EXCEPTION("num = %d", num);
-               err = EMF_ERROR_INVALID_PARAM;          
+       if (input_mailbox_id <= 0) {
+               EM_DEBUG_EXCEPTION("input_mailbox_id = %d", input_mailbox_id);
+               err = EMAIL_ERROR_INVALID_PARAM;
+               return err;
+       }
+
+       if (input_num <= 0) {
+               EM_DEBUG_EXCEPTION("input_num = %d", input_num);
+               err = EMAIL_ERROR_INVALID_PARAM;                
                return err;
        }
 
@@ -472,49 +431,41 @@ EXPORT_API int email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int n
        
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
-       /* mailbox */
-       mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
-
-       if(!mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-       
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+       /* mailbox id*/
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Number of mail_ids */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_num, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* set of mail_ids */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)input_mail_ids, input_num * sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* from-server */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&from_server, sizeof(int))) {
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_server, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
 
@@ -524,56 +475,47 @@ FINISH_OFF:
        if(hAPI)
                emipc_destroy_email_api(hAPI);
 
-       EM_SAFE_FREE(mailbox_stream); 
-
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
 
-EXPORT_API int email_delete_all_message_in_mailbox(emf_mailbox_t* mailbox, int from_server)
+EXPORT_API int email_delete_all_mails_in_mailbox(int input_mailbox_id, int input_from_server)
 {
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], from_server[%d]", mailbox, from_server);
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_from_server[%d]", input_mailbox_id, input_from_server);
 
-       char* mailbox_stream = NULL;
-       int size = 0;
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = NULL;
        
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
+       if(input_mailbox_id <= 0) {
+               EM_DEBUG_EXCEPTION("input_mailbox_id = %d", input_mailbox_id);
+               err = EMAIL_ERROR_INVALID_PARAM;
+               return err;
+       }
        
-       hAPI =emipc_create_email_api(_EMAIL_API_DELETE_ALL_MAIL);       
+       hAPI = emipc_create_email_api(_EMAIL_API_DELETE_ALL_MAIL);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
-
-       if(!mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
        
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&from_server, sizeof(int))){
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_server, sizeof(int))){
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;             
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;           
                goto FINISH_OFF;
        }
        
@@ -583,8 +525,6 @@ FINISH_OFF:
 
        if(hAPI)        
                emipc_destroy_email_api(hAPI);
-
-       EM_SAFE_FREE(mailbox_stream);
        
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
@@ -592,81 +532,62 @@ FINISH_OFF:
 
 
 
-EXPORT_API int email_add_attachment( emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment)
+EXPORT_API int email_add_attachment(int mail_id, email_attachment_data_t* attachment)
 {
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment[%p]", mailbox, mail_id, attachment);
-       int err = EMF_ERROR_NONE;
-       char* mailbox_stream = NULL;
-       char* pAttchStream = NULL;
+       EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment[%p]", mail_id, attachment);
+       int err = EMAIL_ERROR_NONE;
+       char *attchment_stream = NULL;
        int size = 0;
        HIPC_API hAPI = NULL;
        
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(attachment, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(attachment, EMAIL_ERROR_INVALID_PARAM);
        
        hAPI = emipc_create_email_api(_EMAIL_API_ADD_ATTACHMENT);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       /* Mailbox */
-       mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
-
-       if(!mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
        /* mail_id */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Attachment */
-       pAttchStream = em_convert_attachment_info_to_byte_stream(attachment, &size);
+       attchment_stream = em_convert_attachment_data_to_byte_stream(attachment, 1, &size);
 
-       if(!pAttchStream) {
-               EM_DEBUG_EXCEPTION("em_convert_attachment_info_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
+       if(!attchment_stream) {
+               EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pAttchStream, size)){
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, attchment_stream, size)){
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;             
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;           
                goto FINISH_OFF;
        }
 
        emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
        
-       if(EMF_ERROR_NONE == err) {
+       if(EMAIL_ERROR_NONE == err) {
                emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &attachment->attachment_id);
        }
 
 FINISH_OFF:
-       EM_SAFE_FREE(mailbox_stream);
-       EM_SAFE_FREE(pAttchStream);
+       EM_SAFE_FREE(attchment_stream);
        
        if(hAPI)
                emipc_destroy_email_api(hAPI);
@@ -676,60 +597,33 @@ FINISH_OFF:
  }
 
 
-EXPORT_API int email_delete_attachment(emf_mailbox_t * mailbox, int mail_id, const char *attachment_id)
+EXPORT_API int email_delete_attachment(int attachment_id)
 {
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s]", mailbox, mail_id, attachment_id);
-       int err = EMF_ERROR_NONE;
-       char* mailbox_stream = NULL;
-       int size = 0;
-
+       EM_DEBUG_FUNC_BEGIN("attachment_id[%d]", attachment_id);
+       int err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = NULL;
        
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(attachment_id, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(attachment_id, EMAIL_ERROR_INVALID_PARAM);
        
        hAPI = emipc_create_email_api(_EMAIL_API_DELETE_ATTACHMENT);
        
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       /* Mailbox */
-       mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
-
-       if(!mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-
-       /* mail_id */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
-       /* attachment_id */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)attachment_id, strlen(attachment_id))) {
+       /* attachment_index */
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&attachment_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;             
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;           
                goto FINISH_OFF;
        }
 
@@ -739,8 +633,6 @@ FINISH_OFF:
        if(hAPI)
                emipc_destroy_email_api(hAPI);
 
-       EM_SAFE_FREE(mailbox_stream);
-
        return err;
 }
 
@@ -748,15 +640,15 @@ FINISH_OFF:
                                              Mail Search API
     -----------------------------------------------------------*/
 
-EXPORT_API int email_query_mails(char *conditional_clause_string, emf_mail_data_t** mail_list,  int *result_count)
+EXPORT_API int email_query_mails(char *conditional_clause_string, email_mail_data_t** mail_list,  int *result_count)
 {
        EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t *result_mail_tbl;
        
-       EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMAIL_ERROR_INVALID_PARAM);
 
        if (!emstorage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, result_count, &err)) {
                EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err);
@@ -777,18 +669,17 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_query_message_ex(char *conditional_clause_string, emf_mail_list_item_t** mail_list,  int *result_count)
+EXPORT_API int email_query_mail_list(char *input_conditional_clause_string, email_mail_list_item_t** output_mail_list,  int *output_result_count)
 {
-       EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
+       EM_DEBUG_FUNC_BEGIN("input_conditional_clause_string [%s], output_mail_list [%p], output_result_count [%p]", input_conditional_clause_string, output_mail_list, output_result_count);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        
-       EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(input_conditional_clause_string, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_result_count, EMAIL_ERROR_INVALID_PARAM);
 
-       if (!emstorage_query_mail_list(conditional_clause_string, true, mail_list, result_count, &err)) {
+       if (!emstorage_query_mail_list(input_conditional_clause_string, true, output_mail_list, output_result_count, &err)) {
                EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err);
-
                goto FINISH_OFF;
        }
 
@@ -801,93 +692,66 @@ FINISH_OFF:
 /* -----------------------------------------------------------
                                              Mail Get Info API
     -----------------------------------------------------------*/
-EXPORT_API int email_get_attachment_info(emf_mailbox_t* mailbox, int mail_id, const char* attachment_id, emf_attachment_info_t** attachment)
+EXPORT_API int email_get_attachment_data(int attachment_id, email_attachment_data_t** attachment)
 {
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s], attachment[%p]", mailbox, mail_id, attachment_id, attachment);
+       EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p]", attachment_id, attachment);
        
-       int err = EMF_ERROR_NONE;
-       int size = 0;
+       int err = EMAIL_ERROR_NONE;
        int nSize = 0;
-       char* mailbox_stream = NULL;
-       char* pAttchStream = NULL;
-       emf_attachment_info_t* pAttch = NULL;
-       
+       int attachment_count = 0;
+       char* attchment_stream = NULL;
+       email_attachment_data_t* attachment_data = NULL;
+
+       EM_IF_NULL_RETURN_VALUE(attachment_id, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(attachment, EMAIL_ERROR_INVALID_PARAM);
 
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(attachment_id, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(attachment, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
        
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_ATTACHMENT);
 
-       EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
-
-       /* Mailbox */
-       mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
-
-       if(!mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
+       EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
 
-       /* mail_id */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-
-       
        /* attachment_id */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)attachment_id, strlen(attachment_id))) {
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&attachment_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;             
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;           
                goto FINISH_OFF;
        }
 
        emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
 
-       if(EMF_ERROR_NONE == err) {
+       if(EMAIL_ERROR_NONE == err) {
                nSize = emipc_get_parameter_length(hAPI, ePARAMETER_OUT, 1);
                if(nSize > 0) {
-                       pAttchStream = (char*)em_malloc(nSize+1);
+                       attchment_stream = (char*)em_malloc(nSize+1);
 
-                       if(!pAttchStream) {
+                       if(!attchment_stream) {
                                EM_DEBUG_EXCEPTION("em_malloc failed");
-                               err = EMF_ERROR_OUT_OF_MEMORY;          
+                               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                                goto FINISH_OFF;
                        }       
                
-                       emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, nSize, pAttchStream);
-                       em_convert_byte_stream_to_attachment_info(pAttchStream, 1, &pAttch);
+                       emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, nSize, attchment_stream);
+                       em_convert_byte_stream_to_attachment_data(attchment_stream, nSize, &attachment_data, &attachment_count);
                }
                
-               if(!pAttch) {
-                       EM_DEBUG_EXCEPTION("EMF_ERROR_NULL_VALUE");
-                       err = EMF_ERROR_NULL_VALUE;             
+               if(!attachment_data) {
+                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_NULL_VALUE");
+                       err = EMAIL_ERROR_NULL_VALUE;           
                        goto FINISH_OFF;
                }
 
-               *attachment = pAttch;
+               *attachment = attachment_data;
        }
 
 FINISH_OFF:
-       EM_SAFE_FREE(pAttchStream);
+       EM_SAFE_FREE(attchment_stream);
 
        if(hAPI)
                emipc_destroy_email_api(hAPI);
@@ -897,12 +761,12 @@ FINISH_OFF:
 
 }
 
-EXPORT_API int email_get_attachment_data_list(int input_mail_id, emf_attachment_data_t **output_attachment_data, int *output_attachment_count)
+EXPORT_API int email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
 {
        EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_attachment_data[%p], output_attachment_count[%p]", input_mail_id, output_attachment_data, output_attachment_count);
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        
-       if((err = emcore_get_attachment_data_list(input_mail_id, output_attachment_data, output_attachment_count)) != EMF_ERROR_NONE) {
+       if((err = emcore_get_attachment_data_list(input_mail_id, output_attachment_data, output_attachment_count)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err);
        }
 
@@ -910,57 +774,75 @@ EXPORT_API int email_get_attachment_data_list(int input_mail_id, emf_attachment_
        return err;
 }
 
-EXPORT_API int email_free_attachment_info(emf_attachment_info_t** atch_info)
+EXPORT_API int email_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count)
 {
-       EM_DEBUG_FUNC_BEGIN("atch_info[%p]", atch_info);        
+       EM_DEBUG_FUNC_BEGIN("attachment_data_list[%p], attachment_data_count[%d]", attachment_data_list, attachment_data_count);        
        
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
-       if (!atch_info || !*atch_info)
-               return EMF_ERROR_INVALID_PARAM;
-       
-       emf_attachment_info_t* p = *atch_info;
-       emf_attachment_info_t* t;
+       emcore_free_attachment_data(attachment_data_list, attachment_data_count, &err);
        
-       while (p)  {
-               EM_SAFE_FREE(p->name);
-               EM_SAFE_FREE(p->savename);
-               t = p->next;
-               EM_SAFE_FREE(p);
-               p = t;
-       }
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
-EXPORT_API int email_free_attachment_data(emf_attachment_data_t **attachment_data_list, int attachment_data_count)
+EXPORT_API int email_get_mail_list_ex(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, email_mail_list_item_t** output_mail_list, int *output_result_count)
 {
-       EM_DEBUG_FUNC_BEGIN("attachment_data_list[%p], attachment_data_count[%d]", attachment_data_list, attachment_data_count);        
-       
-       int err = EMF_ERROR_NONE;
+       EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d], input_sorting_rule_list[%p], input_sorting_rule_count [%d], input_start_index [%d], input_limit_count [%d], output_mail_list [%p], output_result_count [%p]", input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, output_mail_list, output_result_count);
+
+       int err = EMAIL_ERROR_NONE;
+       char *conditional_clause_string = NULL;
+
+       EM_IF_NULL_RETURN_VALUE(output_mail_list, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_result_count, EMAIL_ERROR_INVALID_PARAM);
+
+       if( (err = emstorage_write_conditional_clause_for_getting_mail_list(input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
+               goto FINISH_OFF;
+       }
+
+       EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
+
+       if(!emstorage_query_mail_list(conditional_clause_string, true, output_mail_list, output_result_count, &err)) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mail_list [%d]", err);
+               goto FINISH_OFF;
+       }
+
+FINISH_OFF:
+       EM_SAFE_FREE(conditional_clause_string);
 
-       emcore_free_attachment_data(attachment_data_list, attachment_data_count, &err);
-       
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
+EXPORT_API int email_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count)
+{
+       EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d]", input_filter_list, input_filter_count);
+       int err = EMAIL_ERROR_NONE;
+
+       EM_IF_NULL_RETURN_VALUE(input_filter_list, EMAIL_ERROR_INVALID_PARAM);
+
+       err = emstorage_free_list_filter(input_filter_list, input_filter_count);
 
-EXPORT_API int email_get_mails(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_data_t** mail_list,  int* result_count)
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+EXPORT_API int email_get_mails(int account_id , int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_mail_data_t** mail_list,  int* result_count)
 {
        EM_DEBUG_FUNC_BEGIN();
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t *mail_tbl_list = NULL;
-       EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
 
        if( account_id < ALL_ACCOUNT) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               err = EMF_ERROR_INVALID_PARAM ;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM ;
                goto FINISH_OFF;
        }
 
-       if (!emstorage_get_mails(account_id, (char*)mailbox_name, NULL, thread_id, start_index, limit_count, sorting, true, &mail_tbl_list, result_count, &err))  {
+       if (!emstorage_get_mails(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, sorting, true, &mail_tbl_list, result_count, &err))  {
                EM_DEBUG_EXCEPTION("emstorage_get_mails failed [%d]", err);
 
                goto FINISH_OFF;
@@ -979,20 +861,20 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_get_mail_list_ex(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list,  int* result_count)
+EXPORT_API int email_get_mail_list(int account_id , int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_mail_list_item_t** mail_list,  int* result_count)
 {
        EM_DEBUG_FUNC_BEGIN();
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        
-       EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
 
        if( account_id < ALL_ACCOUNT) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
-       if (!emstorage_get_mail_list(account_id, (char*) mailbox_name, NULL, thread_id, start_index, limit_count, 0, NULL, sorting, true, mail_list, result_count, &err))  {
+       if (!emstorage_get_mail_list(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, 0, NULL, sorting, true, mail_list, result_count, &err))  {
                EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err);
 
                goto FINISH_OFF;
@@ -1003,64 +885,24 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_find_mail (int account_id , const char *mailbox_name, int thread_id, 
-       int search_type, char *search_value, int start_index, int limit_count,
-       emf_sort_type_t sorting, emf_mail_list_item_t** mail_list,  int* result_count)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       
-       int err = EMF_ERROR_NONE;
-       int search_num = 0;
-       emf_mail_list_item_t* mail_list_item = NULL;
-
-       EM_IF_NULL_RETURN_VALUE(mail_list, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(search_value, EMF_ERROR_INVALID_PARAM);
-
-       switch ( search_type ) {
-               case EMF_SEARCH_FILTER_SUBJECT:
-               case EMF_SEARCH_FILTER_SENDER:
-               case EMF_SEARCH_FILTER_RECIPIENT:
-               case EMF_SEARCH_FILTER_ALL:
-                       break;
-               default:
-                       EM_DEBUG_EXCEPTION("Invalid search filter type[%d]", search_type);
-                       err = EMF_ERROR_INVALID_PARAM;
-                       return err;
-       }
-
-       if (!emstorage_get_searched_mail_list(account_id, (char*)mailbox_name, thread_id, search_type, search_value,  start_index, limit_count, sorting, true, &mail_list_item, &search_num, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_search_mails -- Failed [%d]", err);
-
-               goto FINISH_OFF;
-       }
-
-       *mail_list = mail_list_item;
-       *result_count = search_num;
-       
-FINISH_OFF:    
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
-EXPORT_API int email_get_mail_by_address(int account_id , const char *mailbox_name, emf_email_address_list_t* addr_list, 
-                                                                       int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list,  int* result_count)
+EXPORT_API int email_get_mail_by_address(int account_id , int mailbox_id, email_email_address_list_t* addr_list,
+                                                                       int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, email_mail_list_item_t** mail_list,  int* result_count)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
-       emf_mail_list_item_t* mail_list_item = NULL;
+       email_mail_list_item_t* mail_list_item = NULL;
        
-       EM_IF_NULL_RETURN_VALUE(mail_list, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(mail_list, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
 
        if( account_id < ALL_ACCOUNT) {
                EM_DEBUG_EXCEPTION("Invalid account id param");
-               err = EMF_ERROR_INVALID_PARAM ;
+               err = EMAIL_ERROR_INVALID_PARAM ;
                return err;
        }
 
-       if (!emstorage_get_mail_list(account_id, (char*)mailbox_name, addr_list, EMF_LIST_TYPE_NORMAL, start_index, limit_count, search_type, search_value, sorting, true, &mail_list_item, result_count, &err)) {
+       if (!emstorage_get_mail_list(account_id, mailbox_id, addr_list, EMAIL_LIST_TYPE_NORMAL, start_index, limit_count, search_type, search_value, sorting, true, &mail_list_item, result_count, &err)) {
                EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err);
 
                goto FINISH_OFF;
@@ -1073,13 +915,13 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, emf_mail_data_t** thread_info)
+EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, email_mail_data_t** thread_info)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t *mail_table_data = NULL;
        
-       EM_IF_NULL_RETURN_VALUE(thread_info, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(thread_info, EMAIL_ERROR_INVALID_PARAM);
 
        if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
                EM_DEBUG_EXCEPTION("emstorage_get_thread_information  failed [%d]", err);
@@ -1100,35 +942,35 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_get_thread_information_ex(int thread_id, emf_mail_list_item_t** thread_info)
+EXPORT_API int email_get_thread_information_ex(int thread_id, email_mail_list_item_t** thread_info)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t *mail_table_data = NULL;
-       emf_mail_list_item_t *temp_thread_info = NULL;
+       email_mail_list_item_t *temp_thread_info = NULL;
        
-       EM_IF_NULL_RETURN_VALUE(thread_info, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(thread_info, EMAIL_ERROR_INVALID_PARAM);
 
        if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
                EM_DEBUG_EXCEPTION("emstorage_get_thread_information -- failed [%d]", err);
                goto FINISH_OFF;
        }
 
-       temp_thread_info = em_malloc(sizeof(emf_mail_list_item_t));
+       temp_thread_info = em_malloc(sizeof(email_mail_list_item_t));
 
        if(!temp_thread_info) {
                EM_DEBUG_EXCEPTION("em_malloc failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
-       EM_SAFE_STRNCPY(temp_thread_info->mailbox_name       , mail_table_data->mailbox_name, STRING_LENGTH_FOR_DISPLAY);
        EM_SAFE_STRNCPY(temp_thread_info->from               , mail_table_data->full_address_from, STRING_LENGTH_FOR_DISPLAY);
        EM_SAFE_STRNCPY(temp_thread_info->from_email_address , mail_table_data->email_address_sender, MAX_EMAIL_ADDRESS_LENGTH);
        EM_SAFE_STRNCPY(temp_thread_info->recipients         , mail_table_data->email_address_recipient, STRING_LENGTH_FOR_DISPLAY);
        EM_SAFE_STRNCPY(temp_thread_info->subject            , mail_table_data->subject, STRING_LENGTH_FOR_DISPLAY);
        EM_SAFE_STRNCPY(temp_thread_info->previewBodyText    , mail_table_data->preview_text, MAX_PREVIEW_TEXT_LENGTH);
        temp_thread_info->mail_id                            = mail_table_data->mail_id;
+       temp_thread_info->mailbox_id                         = mail_table_data->mailbox_id;
        temp_thread_info->account_id                         = mail_table_data->account_id;
        temp_thread_info->date_time                          = mail_table_data->date_time;
        temp_thread_info->is_text_downloaded                 = mail_table_data->body_download_status;
@@ -1154,12 +996,12 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data)
+EXPORT_API int email_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        
-       if ( ((err = emcore_get_mail_data(input_mail_id, output_mail_data)) != EMF_ERROR_NONE) || !output_mail_data) 
+       if ( ((err = emcore_get_mail_data(input_mail_id, output_mail_data)) != EMAIL_ERROR_NONE) || !output_mail_data) 
                EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);    
                
        EM_DEBUG_FUNC_END("err [%d]", err);     
@@ -1170,156 +1012,81 @@ EXPORT_API int email_get_mail_data(int input_mail_id, emf_mail_data_t **output_m
 /* -----------------------------------------------------------
                                              Mail Flag API
     -----------------------------------------------------------*/
-EXPORT_API int email_modify_mail_flag(int mail_id, emf_mail_flag_t new_flag, int onserver)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], on_server [ %d] ", mail_id, onserver);
-       
-       int err = EMF_ERROR_NONE;
-
-       int i_flag, sticky = 0;
-               
-       if ( mail_id <= 0 || (onserver != 0 && onserver != 1) ) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;                 
-       }
-       
-       HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_MAIL_FLAG);
-
-       if(!hAPI) {
-               EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       /* Mail ID */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-
-       /* new_flag */
-       if(!em_convert_mail_flag_to_int(new_flag, &i_flag, &err))  {
-               EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_int failed ");
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(i_flag), sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-
-       sticky = new_flag.sticky;
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(sticky), sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-       
-       /* onserver  */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-       
-       
-       /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
-               EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_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_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver)
 {
        EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d],seen_flag[%d], on_server [ %d]", mail_ids, num, seen_flag, onserver);
-       EM_DEBUG_FUNC_END("EMF_ERROR_NOT_IMPLEMENTED");
-       return EMF_ERROR_NOT_IMPLEMENTED;
+       EM_DEBUG_FUNC_END("EMAIL_ERROR_NOT_IMPLEMENTED");
+       return EMAIL_ERROR_NOT_IMPLEMENTED;
 }
 
-EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, emf_flags_field_type field_type, int value, int onserver)
+EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, email_flags_field_type field_type, int value, int onserver)
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], num[%d], field_type [%d], seen_flag[%d], on_server [ %d]", account_id, mail_ids, num, field_type, value, onserver);
        
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
                
-       EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(mail_ids, EMAIL_ERROR_INVALID_PARAM);
        if (account_id == 0 || num <= 0 || (onserver != 0 && onserver != 1)) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;                 
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;                       
        }
        
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_FLAGS_FIELD);
        
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
        
        /* account_id*/
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Number of mail_ids */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* set of mail_ids */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* field_type */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&field_type, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* value */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&value, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* onserver  */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
        
@@ -1333,132 +1100,69 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_modify_extra_mail_flag(int mail_id, emf_extra_flag_t new_flag)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
-       
-       int size = 0;
-       int err = EMF_ERROR_NONE;
-       char* pMailExtraFlagsStream = NULL;
-
-               
-       EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
-
-       pMailExtraFlagsStream = em_convert_extra_flags_to_byte_stream(new_flag, &size);
-       
-       HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_MAIL_EXTRA_FLAG);
-
-       if(!hAPI) {
-               EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       /* Mail ID */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-       /*  Flag */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pMailExtraFlagsStream, size)) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
-       }
-
-       /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
-               EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;
-               goto FINISH_OFF;
-       } 
-
-       emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
-
-FINISH_OFF:
-       emipc_destroy_email_api(hAPI);
-       EM_SAFE_FREE(pMailExtraFlagsStream);
-
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-
-}
-
-
 
 /* -----------------------------------------------------------
                                              Mail Move API
     -----------------------------------------------------------*/
-EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, emf_mailbox_t* mailbox)
+EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id)
 {
-       EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num [%d], mailbox[%p]",  mail_ids, num, mailbox);
+       EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num [%d], input_target_mailbox_id[%d]",  mail_ids, num, input_target_mailbox_id);
        
-       int size = 0;
-       char* mailbox_stream =  NULL;
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = NULL;
 
-
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
+       if(input_target_mailbox_id <= 0) {
+               EM_DEBUG_EXCEPTION("input_target_mailbox_id is invalid parameter");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               return err;
+       }
+       EM_IF_NULL_RETURN_VALUE(mail_ids, EMAIL_ERROR_INVALID_PARAM);
        
        if (num <= 0)  {
                EM_DEBUG_LOG("num = %d", num);
-               err = EMF_ERROR_INVALID_PARAM;
+               err = EMAIL_ERROR_INVALID_PARAM;
                return err;
        }
-       
+
        hAPI = emipc_create_email_api(_EMAIL_API_MOVE_MAIL);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
        
        /* Number of mail_ids */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* set of mail_ids */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
-       /* Mailbox */
-       mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
-
-       if(!mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+       /* input_target_mailbox_id */
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_target_mailbox_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;             
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;           
                goto FINISH_OFF;
        }
 
        emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
 
 FINISH_OFF:            
-       EM_SAFE_FREE(mailbox_stream); 
-
        if(hAPI)
                emipc_destroy_email_api(hAPI);
 
@@ -1467,165 +1171,64 @@ FINISH_OFF:
 }
 
 
-EXPORT_API int  email_move_all_mails_to_mailbox(emf_mailbox_t* src_mailbox, emf_mailbox_t* new_mailbox)
+EXPORT_API int  email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id)
 {
-       EM_DEBUG_FUNC_BEGIN("src_mailbox[%p] , new_mailbox[%p]",  src_mailbox, new_mailbox);
+       EM_DEBUG_FUNC_BEGIN("input_source_mailbox_id[%d] , input_target_mailbox_id[%d]",  input_source_mailbox_id, input_target_mailbox_id);
        
-       int size = 0;
-       int err = EMF_ERROR_NONE;
-       char *dest_mailbox_stream = NULL;
-       char *source_mailbox_stream = NULL;
+       int err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = NULL;
        
-
-       EM_IF_NULL_RETURN_VALUE(src_mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_ACCOUNT_ID_NULL(new_mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
-       EM_IF_ACCOUNT_ID_NULL(src_mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
+       if(input_source_mailbox_id <= 0 || input_target_mailbox_id <= 0) {
+               EM_DEBUG_EXCEPTION("mailbox_id is invalid parameter");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               return err;
+       }
        
        hAPI = emipc_create_email_api(_EMAIL_API_MOVE_ALL_MAIL);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
        
-       /* Src Mailbox Information */
-       source_mailbox_stream = em_convert_mailbox_to_byte_stream(src_mailbox, &size);
-
-       if(!source_mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, source_mailbox_stream, size)) {
+       /* input_source_mailbox_id */
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_source_mailbox_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
-
-       size = 0;
        
-       /* Dst Mailbox Information */
-       dest_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
-
-       if(!dest_mailbox_stream) {
-               EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
-               err = EMF_ERROR_NULL_VALUE;             
-               goto FINISH_OFF;
-       }
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, dest_mailbox_stream, size)) {
+       /* input_target_mailbox_id */
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_target_mailbox_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
-       
+
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;             
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;           
                goto FINISH_OFF;
        }
 
        emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
 
 FINISH_OFF:
-       EM_SAFE_FREE(source_mailbox_stream);
-       EM_SAFE_FREE(dest_mailbox_stream); 
-
        if(hAPI)
                emipc_destroy_email_api(hAPI);
        
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
-
-
-EXPORT_API int email_count_message_with_draft_flag(emf_mailbox_t* mailbox, int* total)
-{
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p]", mailbox, total);
-       
-       int err = EMF_ERROR_NONE;
-       int total_count = 0;
-               
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
 
-    if (!emstorage_get_mail_count_with_draft_flag(mailbox->account_id,  mailbox->name, &total_count, false, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
-
-       } else {
-               *total = total_count;
-       }
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
-
-EXPORT_API int email_count_message_on_sending(emf_mailbox_t* mailbox, int* total)
-{
-       EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p]", mailbox, total);
-       int err = EMF_ERROR_NONE;
-       int total_count = 0;
-       
-               
-       EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
-
-       if (!emstorage_get_mail_count_on_sending(mailbox->account_id,  mailbox->name, &total_count, false, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
-
-       } else
-               *total = total_count;
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
-/**
  
- * @open
- * @fn email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
- * @brief      Get the Mail Flag information based on the account id and Mail Id.
- * 
- * @param[in] account_id       Specifies the Account ID
- * @param[in] mail_id          Specifies the Mail id for which  Flag details need to be fetched
- * @param[in/out] mail_flag    Specifies the Pointer to the structure emf_mail_flag_t.
- * @remarks N/A
- * @return True on Success, False on Failure.
- */
-EXPORT_API int email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       
-       int err = EMF_ERROR_NONE;
-
-       if (account_id < FIRST_ACCOUNT_ID|| mail_id < 1 || mail_flag == NULL) {
-               EM_DEBUG_EXCEPTION("Invalid Param");
-               err = EMF_ERROR_INVALID_PARAM ;
-               goto FINISH_OFF;
-       }
-
-       /* Fetch the flag Information */
-       if (!emcore_fetch_flags(account_id, mail_id, mail_flag, &err)) {        
-               EM_DEBUG_EXCEPTION("emcore_fetch_flags Failed [%d]", err);
-               goto FINISH_OFF;
-       }
-FINISH_OFF:
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-
-}
-
-EXPORT_API int email_free_mail_data(emf_mail_data_t** mail_list, int count)
+EXPORT_API int email_free_mail_data(email_mail_data_t** mail_list, int count)
 {
        EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d]", mail_list, count);
-       int err = EMF_ERROR_NONE;
-       emcore_free_mail_data(mail_list, count, &err);
+       int err = EMAIL_ERROR_NONE;
+       emcore_free_mail_data_list(mail_list, count);
        EM_DEBUG_FUNC_END("err [%d]", err);     
        return err;
 }
@@ -1633,26 +1236,26 @@ EXPORT_API int email_free_mail_data(emf_mail_data_t** mail_list, int count)
 /* Convert Modified UTF-7 mailbox name to UTF-8 */
 /* returns modified UTF-8 Name if success else NULL */
 
-EXPORT_API int email_cancel_send_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, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
        
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        int account_id = 0;
-       emf_mail_data_t* mail_data = NULL;
+       email_mail_data_t* mail_data = NULL;
 
        HIPC_API hAPI = NULL;
        
        
-       if ((err = emcore_get_mail_data(mail_id, &mail_data)) != EMF_ERROR_NONE)  {
+       if ((err = emcore_get_mail_data(mail_id, &mail_data)) != EMAIL_ERROR_NONE)  {
                EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
                goto FINISH_OFF;
        }
 
        if (!mail_data) {
                EM_DEBUG_EXCEPTION("mail_data is null");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
@@ -1662,28 +1265,28 @@ EXPORT_API int email_cancel_send_mail( int mail_id)
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
        /* Account_id */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Mail ID */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
        
@@ -1693,30 +1296,24 @@ FINISH_OFF:
        if(hAPI)
                emipc_destroy_email_api(hAPI);
 
-       if  ( !emcore_free_mail_data(&mail_data, 1, &err))
-               EM_DEBUG_EXCEPTION("emcore_free_mail_data Failed [%d ] ", err);
+       emcore_free_mail_data_list(&mail_data, 1);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 
 }
-/**
-  * EmfSendCancel - Callback function for cm popup. We set the status as EMF_MAIL_STATUS_NONE 
-  *
-  **/
 
-
-EXPORT_API int email_retry_send_mail( int mail_id, int timeout_in_sec)
+EXPORT_API int email_retry_sending_mail( int mail_id, int timeout_in_sec)
 {
        EM_DEBUG_FUNC_BEGIN();
        
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
 
-       EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
        if( timeout_in_sec < 0 )  {
                EM_DEBUG_EXCEPTION("Invalid timeout_in_sec");
-               err = EMF_ERROR_INVALID_PARAM;
+               err = EMAIL_ERROR_INVALID_PARAM;
                return err;
        }
        
@@ -1724,28 +1321,28 @@ EXPORT_API int email_retry_send_mail( int mail_id, int timeout_in_sec)
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
        /* Mail ID */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* timeout */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(timeout_in_sec), sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
        
@@ -1758,67 +1355,13 @@ FINISH_OFF:
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 
- }
-
-EXPORT_API int email_get_mailbox_name_by_mail_id(int mail_id, char **pMailbox_name)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       
-       int err = EMF_ERROR_NONE;
-       char* mailbox_name = NULL;
-       emstorage_mail_tbl_t* mail_table_data = NULL;
-       
-       if(mail_id <= 0) {
-               EM_DEBUG_EXCEPTION("mail_id is not valid");
-               err= EMF_ERROR_INVALID_PARAM;
-               goto FINISH_OFF;
-       }       
-       EM_IF_NULL_RETURN_VALUE(pMailbox_name, EMF_ERROR_INVALID_PARAM);
-       
-       if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) {
-               EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
-
-               goto FINISH_OFF;
-       }
-
-       if(mail_table_data->mailbox_name)
-               mailbox_name = strdup(mail_table_data->mailbox_name);
-       
-       *pMailbox_name = mailbox_name;
-
-FINISH_OFF:
-       if(mail_table_data) {
-               emstorage_free_mail(&mail_table_data, 1, &err); 
-
-       }
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
-
-EXPORT_API int email_get_latest_unread_mail_id(int account_id, int *pMailID)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       
-       int err = EMF_ERROR_NONE;
-
-       if( (!pMailID) ||(account_id <= 0 &&  account_id != -1)) {              
-               err = EMF_ERROR_INVALID_PARAM;
-               return err;
-       }
-       if(!emstorage_get_latest_unread_mailid(account_id,pMailID, &err)) {
-               EM_DEBUG_LOG("emstorage_get_latest_unread_mailid - failed");
-
-       }
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
 }
 
 EXPORT_API int email_get_max_mail_count(int *Count)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int err = EMF_ERROR_NONE;
-       EM_IF_NULL_RETURN_VALUE(Count, EMF_ERROR_INVALID_PARAM);
+       int err = EMAIL_ERROR_NONE;
+       EM_IF_NULL_RETURN_VALUE(Count, EMAIL_ERROR_INVALID_PARAM);
        *Count = emstorage_get_max_mail_count();
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
@@ -1830,9 +1373,9 @@ EXPORT_API int email_get_max_mail_count(int *Count)
 EXPORT_API int email_get_disk_space_usage(unsigned long *total_size)
 {
        EM_DEBUG_FUNC_BEGIN("total_size[%p]", total_size);
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
-       EM_IF_NULL_RETURN_VALUE(total_size, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(total_size, EMAIL_ERROR_INVALID_PARAM);
 
        if (!emstorage_mail_get_total_diskspace_usage(total_size,true,&err))  {
                EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage failed [%d]", err);
@@ -1844,140 +1387,18 @@ FINISH_OFF :
        return err;
 }
 
-EXPORT_API int email_get_recipients_list(int account_id, const char *mailbox_name, emf_sender_list_t **recipients_list)
-{
-       EM_DEBUG_FUNC_BEGIN("recipients_list[%p]",  recipients_list);
-
-       int number_of_mails, index;
-       int number_of_recipients;
-       int ret=0, err = 0;
-
-       emf_sender_list_t *temp_recipients_list = NULL;
-       emf_sender_list_t *p_recipients_list = NULL;
-       GList *addr_list = NULL, *temp_addr_list = NULL;
-       emstorage_mail_tbl_t *mail_table_data = NULL;
-
-       if (!emstorage_get_mails(account_id, (char*)mailbox_name, NULL, EMF_LIST_TYPE_NORMAL, -1, -1, EMF_SORT_SENDER_HIGH, true, &mail_table_data, &number_of_mails, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mails failed");
-
-               goto FINISH_OFF;
-       }
-
-       for (index = 0; index < number_of_mails; index++) {
-               addr_list = emcore_get_recipients_list(addr_list, mail_table_data[index].full_address_to, &err);
-               addr_list = emcore_get_recipients_list(addr_list, mail_table_data[index].full_address_cc, &err);
-               addr_list = emcore_get_recipients_list(addr_list, mail_table_data[index].full_address_bcc, &err);
-       }
-
-       number_of_recipients = g_list_length(addr_list);
-
-       p_recipients_list = (emf_sender_list_t *)malloc(sizeof(emf_sender_list_t) * number_of_recipients);
-       if (p_recipients_list == NULL) {
-               EM_DEBUG_EXCEPTION("malloc for emf_sender_list_t failed...");
-               err = EMF_ERROR_OUT_OF_MEMORY;
-               ret = err;
-               goto FINISH_OFF;
-       }       
-       memset(p_recipients_list, 0x00, sizeof(emf_sender_list_t) * number_of_recipients);
-       
-       temp_addr_list = g_list_first(addr_list);
-       index = 0;
-       while (temp_addr_list != NULL) {
-               temp_recipients_list = (emf_sender_list_t *)temp_addr_list->data;
-               p_recipients_list[index].address = temp_recipients_list->address;
-               p_recipients_list[index].display_name = temp_recipients_list->display_name;
-               p_recipients_list[index].total_count = temp_recipients_list->total_count + 1;
-               EM_DEBUG_LOG("address[%s], display_name[%s], total_count[%d]", p_recipients_list[index].address, p_recipients_list[index].display_name, p_recipients_list[index].total_count);
-               temp_addr_list = g_list_next(temp_addr_list);
-               index++;
-       }
-
-       ret = true;     
-FINISH_OFF:
-       if (ret == true && recipients_list)
-               *recipients_list = p_recipients_list; else if (p_recipients_list != NULL) {
-               email_free_sender_list(&p_recipients_list, number_of_recipients);
-       }
-
-       EM_DEBUG_FUNC_END();
-       return ret;
-}
-
-EXPORT_API int email_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
-{
-       EM_DEBUG_FUNC_BEGIN("sender_list[%p],sender_count[%p], sorting[%d]",  sender_list, sender_count, sorting);
-
-       int err = EMF_ERROR_NONE;
-
-       emf_sender_list_t *temp_sender_list = NULL;
-
-       EM_IF_NULL_RETURN_VALUE(sender_list, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(sender_count, EMF_ERROR_INVALID_PARAM);
-       if( account_id < ALL_ACCOUNT) {
-               EM_DEBUG_EXCEPTION(" Invalid Account Id Param ");
-               err = EMF_ERROR_INVALID_PARAM ;
-               return err;
-       }
-       
-       if ( !emstorage_get_sender_list(account_id, mailbox_name, search_type, search_value, sorting, &temp_sender_list, sender_count, &err) ) { 
-               EM_DEBUG_EXCEPTION("emstorage_get_sender_list failed [%d]", err);
-
-               goto FINISH_OFF;
-       }
-
-       if ( sender_list )
-               *sender_list = temp_sender_list;
-
-FINISH_OFF:
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
-EXPORT_API int email_get_sender_list_ex(int account_id, const char *mailbox_name, int start_index, int limit_count, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
-{
-       return EMF_ERROR_NONE;
-}
-
-EXPORT_API int email_free_sender_list(emf_sender_list_t **sender_list, int count)
-{
-       EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count);
-
-       int err = EMF_ERROR_NONE;
-       
-       if (count > 0)  {
-               if (!sender_list || !*sender_list)  {
-                       EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count);                   
-                       err = EMF_ERROR_INVALID_PARAM;
-                       return err;
-               }
-               
-               emf_sender_list_t* p = *sender_list;
-               int i = 0;
-               
-               for (; i < count; i++)  {
-                       EM_SAFE_FREE(p[i].address);
-                       EM_SAFE_FREE(p[i].display_name);
-               }
-               
-               EM_SAFE_FREE(p); 
-               *sender_list = NULL;
-       }       
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
-}
-
-EXPORT_API int email_get_address_info_list(int mail_id, emf_address_info_list_t** address_info_list)
+EXPORT_API int email_get_address_info_list(int mail_id, email_address_info_list_t** address_info_list)
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
-       emf_address_info_list_t *temp_address_info_list = NULL;
+       email_address_info_list_t *temp_address_info_list = NULL;
 
-       EM_IF_NULL_RETURN_VALUE(address_info_list, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(address_info_list, EMAIL_ERROR_INVALID_PARAM);
        if( mail_id <= 0) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               err = EMF_ERROR_INVALID_PARAM ;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM ;
                return err;
        }
        
@@ -1999,30 +1420,30 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_free_address_info_list(emf_address_info_list_t **address_info_list)
+EXPORT_API int email_free_address_info_list(email_address_info_list_t **address_info_list)
 {
        EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
-       if ( (err = emstorage_free_address_info_list(address_info_list)) != EMF_ERROR_NONE ) {
+       if ( (err = emstorage_free_address_info_list(address_info_list)) != EMAIL_ERROR_NONE ) {
                EM_DEBUG_EXCEPTION("address_info_list[%p] free failed.", address_info_list);
        }
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
-EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, emf_convert_struct_type_e type)
+EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, email_convert_struct_type_e type)
 {
        EM_DEBUG_FUNC_BEGIN("encoded_string[%s], struct_var[%p], type[%d]", encoded_string, struct_var, type);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        void * temp_struct = NULL;
 
-       EM_IF_NULL_RETURN_VALUE(encoded_string, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(struct_var, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(encoded_string, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(struct_var, EMAIL_ERROR_INVALID_PARAM);
 
-       if ( (err = emcore_convert_string_to_structure((char*)encoded_string, &temp_struct, type)) != EMF_ERROR_NONE )  {
+       if ( (err = emcore_convert_string_to_structure((char*)encoded_string, &temp_struct, type)) != EMAIL_ERROR_NONE )  {
                EM_DEBUG_EXCEPTION("emcore_convert_string_to_structure failed[%d]", err);
                goto FINISH_OFF;
        }
@@ -2035,18 +1456,18 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_get_meeting_request(int mail_id, emf_meeting_request_t **meeting_req)
+EXPORT_API int email_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req)
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d],meeting_req[%p]",  mail_id, meeting_req);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
-       emf_meeting_request_t *temp_meeting_req = NULL;
+       email_meeting_request_t *temp_meeting_req = NULL;
 
-       EM_IF_NULL_RETURN_VALUE(meeting_req, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(meeting_req, EMAIL_ERROR_INVALID_PARAM);
        if( mail_id <= 0 ) {
                EM_DEBUG_EXCEPTION(" Invalid Mail Id Param ");
-               err = EMF_ERROR_INVALID_PARAM ;
+               err = EMAIL_ERROR_INVALID_PARAM ;
                return err;
        }
        
@@ -2064,59 +1485,66 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_free_meeting_request(emf_meeting_request_t** meeting_req, int count)
+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 ) {
+               EM_DEBUG_EXCEPTION("NULL PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
 
-       int err = EMF_ERROR_NONE;
+       int i = 0;
+       email_meeting_request_t *cur = *meeting_req;
+       for ( ; i < count ; i++ )
+               emstorage_free_meeting_request(cur + i);
 
-       emstorage_free_meeting_request(meeting_req, count, &err);
+       EM_SAFE_FREE(*meeting_req);
 
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
+       EM_DEBUG_FUNC_END();
+       return EMAIL_ERROR_NONE;
 }
 
-EXPORT_API int email_move_thread_to_mailbox(int thread_id, char *target_mailbox_name, int move_always_flag)
+EXPORT_API int email_move_thread_to_mailbox(int thread_id, int target_mailbox_id, int move_always_flag)
 {
-       EM_DEBUG_FUNC_BEGIN("thread_id[%d], target_mailbox_name[%p], move_always_flag[%d]", thread_id, target_mailbox_name, move_always_flag);
-       int err = EMF_ERROR_NONE;
+       EM_DEBUG_FUNC_BEGIN("thread_id[%d], target_mailbox_id[%d], move_always_flag[%d]", thread_id, target_mailbox_id, move_always_flag);
+       int err = EMAIL_ERROR_NONE;
        
 
-       EM_IF_NULL_RETURN_VALUE(target_mailbox_name, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(target_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
        
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MOVE_THREAD_TO_MAILBOX);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
        /* thread_id */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* target mailbox information */
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, target_mailbox_name, strlen(target_mailbox_name))){
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
-               goto FINISH_OFF;
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&target_mailbox_id, sizeof(int))){
+                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
        }
 
        /* move_always_flag */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&move_always_flag, sizeof(int))){
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
        
@@ -2133,34 +1561,34 @@ FINISH_OFF:
 EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag)
 {
        EM_DEBUG_FUNC_BEGIN("thread_id[%d], delete_always_flag[%d]", thread_id, delete_always_flag);
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
 
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_THREAD);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
        /* thread_id */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* delete_always_flag */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&delete_always_flag, sizeof(int))){
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
        
@@ -2177,40 +1605,40 @@ FINISH_OFF:
 EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server)
 {
        EM_DEBUG_FUNC_BEGIN("thread_id[%d], seen_flag[%d], on_server[%d]", thread_id, seen_flag, on_server);
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD);
 
        if(!hAPI) {
                EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
-               err = EMF_ERROR_NULL_VALUE;             
+               err = EMAIL_ERROR_NULL_VALUE;           
                goto FINISH_OFF;
        }
 
        /* thread_id */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* seen_flag */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&seen_flag, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
 
        /* on_server */
        if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&on_server, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-               err = EMF_ERROR_OUT_OF_MEMORY;          
+               err = EMAIL_ERROR_OUT_OF_MEMORY;                
                goto FINISH_OFF;
        }
        
        /* Execute API */
-       if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
+       if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
-               err = EMF_ERROR_IPC_SOCKET_FAILURE;     
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;   
                goto FINISH_OFF;
        }
        
@@ -2223,3 +1651,99 @@ FINISH_OFF:
        return err;
 }
 
+EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, unsigned *output_handle)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_on_server[%d], output_handle[%p]", input_mailbox_id, input_on_server, output_handle);
+       int err = EMAIL_ERROR_NONE;
+       int return_value = 0;
+       HIPC_API hAPI = NULL;
+       emstorage_mailbox_tbl_t *mailbox_tbl_data = NULL;
+
+       if( (err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl_data)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed[%d]", err);
+               goto FINISH_OFF;
+       }
+
+       email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
+       ASNotiData as_noti_data;
+
+       memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
+
+       if ( em_get_account_server_type_by_account_id(mailbox_tbl_data->account_id, &account_server_type, true, &err) == false ) {
+               EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
+               goto FINISH_OFF;
+       }
+
+       if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_on_server == true) {
+               int as_handle = 0;
+
+               if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
+                       EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
+                       goto FINISH_OFF;
+               }
+
+               /*  noti to active sync */
+               as_noti_data.expunge_mails_deleted_flagged.handle        = as_handle;
+               as_noti_data.expunge_mails_deleted_flagged.mailbox_id    = input_mailbox_id;
+               as_noti_data.expunge_mails_deleted_flagged.on_server     = input_on_server;
+
+               return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED, &as_noti_data);
+
+               if ( return_value == 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
+       {
+               hAPI = emipc_create_email_api(_EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED);
+
+               if(!hAPI) {
+                       EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
+                       err = EMAIL_ERROR_NULL_VALUE;
+                       goto FINISH_OFF;
+               }
+
+               /* input_mailbox_id */
+               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
+                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
+
+               /* input_on_server */
+               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_on_server, sizeof(int))) {
+                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
+
+               /* Execute API */
+               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);
+               if (err == EMAIL_ERROR_NONE) {
+                       if(output_handle)
+                               emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle);
+               }
+       }
+
+FINISH_OFF:
+       if(hAPI)
+               emipc_destroy_email_api(hAPI);
+
+       if(mailbox_tbl_data) {
+               emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL);
+       }
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}