Update the email-service
authorSunghyun Kwon <sh0701.kwon@samsung.com>
Mon, 8 Oct 2012 02:44:16 +0000 (11:44 +0900)
committerSunghyun Kwon <sh0701.kwon@samsung.com>
Mon, 8 Oct 2012 02:44:16 +0000 (11:44 +0900)
58 files changed:
email-api/email-api-account.c
email-api/email-api-etc.c
email-api/email-api-mail.c
email-api/email-api-mailbox.c
email-api/email-api-network.c
email-api/email-api-smime.c
email-api/include/email-api-account.h
email-api/include/email-api-etc.h
email-api/include/email-api-init.h
email-api/include/email-api-mail.h
email-api/include/email-api-mailbox.h
email-api/include/email-api-network.h
email-api/include/email-api-smime.h
email-common-use/email-convert.c
email-common-use/email-utilities.c
email-common-use/include/email-convert.h
email-common-use/include/email-debug-log.h [changed mode: 0755->0644]
email-common-use/include/email-errors.h
email-common-use/include/email-internal-types.h
email-common-use/include/email-types.h
email-core/CMakeLists.txt
email-core/email-core-account.c
email-core/email-core-cert.c
email-core/email-core-event.c
email-core/email-core-mail.c
email-core/email-core-mailbox-sync.c
email-core/email-core-mime.c
email-core/email-core-smime.c
email-core/email-core-smtp.c
email-core/email-core-utils.c
email-core/email-network/email-network.c
email-core/email-storage/email-storage.c
email-core/email-storage/include/email-storage.h
email-core/include/email-core-cert.h
email-core/include/email-core-mail.h
email-core/include/email-core-mime.h
email-core/include/email-core-smtp.h
email-core/include/email-core-utils.h
email-daemon/CMakeLists.txt
email-daemon/email-daemon-account.c
email-daemon/email-daemon-auto-poll.c
email-daemon/email-daemon-init.c
email-daemon/email-daemon-mail.c
email-daemon/email-daemon-mailbox.c
email-daemon/include/email-daemon.h
email-daemon/main.c
email-ipc/email-ipc-api.c
email-ipc/email-ipc-api/include/email-ipc-api-info.h
email-ipc/email-ipc-proxy.c [changed mode: 0755->0644]
email-ipc/email-proxy/email-proxy-socket.c [changed mode: 0755->0644]
email-ipc/email-socket/email-ipc-socket.c
email-service_PG.h
packaging/email-service.spec
utilities/test-application/testapp-account.c
utilities/test-application/testapp-mail.c
utilities/test-application/testapp-mailbox.c
utilities/test-application/testapp-others.c
utilities/test-application/testapp-utility.c

index 7290261..f3d5e67 100755 (executable)
@@ -380,7 +380,7 @@ FINISH_OFF:
 
 }
 
-EXPORT_API int email_validate_account(int account_id, unsigned* handle)
+EXPORT_API int email_validate_account(int account_id, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p]", account_id, handle);
 
@@ -422,7 +422,7 @@ EXPORT_API int email_validate_account(int account_id, unsigned* handle)
 }
 
 
-EXPORT_API int email_add_account_with_validation(email_account_t* account, unsigned* handle)
+EXPORT_API int email_add_account_with_validation(email_account_t* account, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN("account[%p]", account);
        char* local_account_stream = NULL;
index 3502c72..9ecf479 100755 (executable)
 #include "email-ipc.h"
 #include "email-debug-log.h"
 #include "email-core-utils.h"
+#include "email-core-smtp.h"
 #include "email-core-mime.h"
+#include "email-convert.h"
+#include "email-utilities.h"
 
 EXPORT_API int email_show_user_message(int id, email_action_t action, int error_code)
 {
@@ -79,29 +82,113 @@ EXPORT_API int email_show_user_message(int id, email_action_t action, int error_
        return err;
 }
 
-EXPORT_API int email_open_eml_file(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
+EXPORT_API int email_parse_mime_file(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
 {
        EM_DEBUG_FUNC_BEGIN("eml_file_path : [%s], output_mail_data : [%p], output_attachment_data : [%p]", eml_file_path, output_mail_data, output_attachment_data);
        int err = EMAIL_ERROR_NONE;
 
        EM_IF_NULL_RETURN_VALUE(eml_file_path, EMAIL_ERROR_INVALID_PARAM);
 
-       if (!emcore_load_eml_file_to_mail(eml_file_path, output_mail_data, output_attachment_data, output_attachment_count, &err) || !*output_mail_data)
-               EM_DEBUG_EXCEPTION("emcore_load_eml_file_to_mail_data failed [%d]", err);
+       if (!emcore_parse_mime_file_to_mail(eml_file_path, output_mail_data, output_attachment_data, output_attachment_count, &err) || !*output_mail_data)
+               EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed [%d]", err);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
-EXPORT_API int email_delete_eml_data(email_mail_data_t *input_mail_data)
+EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, char **output_file_path)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p], input_attachment_data : [%p], input_attachment_count : [%d]", input_mail_data, input_attachment_data, input_attachment_count);
+
+       int err = EMAIL_ERROR_NONE;
+       int size = 0;
+       char *p_output_file_path = NULL;
+       char *mail_data_stream = NULL;
+       char *attachment_data_list_stream = NULL;
+       HIPC_API hAPI = NULL;
+
+       EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
+
+       hAPI = emipc_create_email_api(_EMAIL_API_WRITE_MIME_FILE);
+       if (!hAPI) {
+               EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
+               err = EMAIL_ERROR_NULL_VALUE;
+               goto FINISH_OFF;
+       }
+
+       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 = EMAIL_ERROR_NULL_VALUE;
+               goto FINISH_OFF;
+       }
+
+       if (!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
+               EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data, input_attachment_count, &size);
+       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 (*output_file_path && (size = strlen(*output_file_path)) > 0) {
+               EM_DEBUG_LOG("output_file_path : [%s] size : [%d]", *output_file_path, size);
+               size = size + 1;
+       } else {
+               size = 0;
+       }
+
+       if (!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, *output_file_path, size)) {
+               EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }       
+
+       if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
+               err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       size = emipc_get_parameter_length(hAPI, ePARAMETER_OUT, 0);
+       if (size > 0) {
+               p_output_file_path = (char *)em_malloc(size);
+               if (p_output_file_path == NULL) {
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
+
+               if ((err = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, size, p_output_file_path)) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION("emipc_get_parameter failed : [%d]", err);
+                       goto FINISH_OFF;
+               }
+       }
+       
+       *output_file_path = p_output_file_path; 
+
+FINISH_OFF:
+
+       if (err != EMAIL_ERROR_NONE)
+               EM_SAFE_FREE(p_output_file_path);
+
+       EM_DEBUG_FUNC_END("err : [%d]", err);
+       return err;
+}
+
+EXPORT_API int email_delete_parsed_data(email_mail_data_t *input_mail_data)
 {
        EM_DEBUG_FUNC_BEGIN("mail_data : [%p]", input_mail_data);
        int err = EMAIL_ERROR_NONE;
 
        EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
 
-       if (!emcore_delete_eml_data(input_mail_data, &err))
-               EM_DEBUG_EXCEPTION("emcore_load_eml_file_to_mail_data failed [%d]", err);
+       if (!emcore_delete_parsed_data(input_mail_data, &err))
+               EM_DEBUG_EXCEPTION("emcore_delete_parsed_data failed [%d]", err);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
index fe52b73..3df5343 100755 (executable)
@@ -79,7 +79,7 @@ EXPORT_API int email_add_mail(email_mail_data_t *input_mail_data, email_attachme
                }
 
                /* email_mail_data_t */
-               mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
+               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");
@@ -270,7 +270,7 @@ EXPORT_API int email_update_mail(email_mail_data_t *input_mail_data, email_attac
                }
 
                /* email_mail_data_t */
-               mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
+               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");
@@ -964,26 +964,26 @@ EXPORT_API int email_get_thread_information_ex(int thread_id, email_mail_list_it
                goto FINISH_OFF;
        }
 
-       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;
-       temp_thread_info->flags_seen_field                   = mail_table_data->flags_seen_field;
-       temp_thread_info->priority                           = mail_table_data->priority;
-       temp_thread_info->save_status                        = mail_table_data->save_status;
-       temp_thread_info->is_locked                          = mail_table_data->lock_status;
-       temp_thread_info->is_report_mail                     = mail_table_data->report_status;
-       temp_thread_info->has_attachment                     = mail_table_data->attachment_count;
-       temp_thread_info->has_drm_attachment                 = mail_table_data->DRM_status;
-       temp_thread_info->thread_id                          = mail_table_data->thread_id;
-       temp_thread_info->thread_item_count                  = mail_table_data->thread_item_count;
-       temp_thread_info->is_meeting_request                 = mail_table_data->meeting_request_status;
+       EM_SAFE_STRNCPY(temp_thread_info->full_address_from       , mail_table_data->full_address_from, STRING_LENGTH_FOR_DISPLAY);
+       EM_SAFE_STRNCPY(temp_thread_info->email_address_sender    , mail_table_data->email_address_sender, MAX_EMAIL_ADDRESS_LENGTH);
+       EM_SAFE_STRNCPY(temp_thread_info->email_address_recipient , 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->preview_text            , 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->body_download_status                    = mail_table_data->body_download_status;
+       temp_thread_info->flags_seen_field                        = mail_table_data->flags_seen_field;
+       temp_thread_info->priority                                = mail_table_data->priority;
+       temp_thread_info->save_status                             = mail_table_data->save_status;
+       temp_thread_info->lock_status                             = mail_table_data->lock_status;
+       temp_thread_info->report_status                           = mail_table_data->report_status;
+       temp_thread_info->attachment_count                        = mail_table_data->attachment_count;
+       temp_thread_info->DRM_status                              = mail_table_data->DRM_status;
+       temp_thread_info->thread_id                               = mail_table_data->thread_id;
+       temp_thread_info->thread_item_count                       = mail_table_data->thread_item_count;
+       temp_thread_info->meeting_request_status                  = mail_table_data->meeting_request_status;
 
        *thread_info = temp_thread_info;
 
@@ -1436,24 +1436,8 @@ EXPORT_API int email_free_address_info_list(email_address_info_list_t **address_
 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 = EMAIL_ERROR_NONE;
-       void * temp_struct = NULL;
-
-       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)) != EMAIL_ERROR_NONE )  {
-               EM_DEBUG_EXCEPTION("emcore_convert_string_to_structure failed[%d]", err);
-               goto FINISH_OFF;
-       }
-
-       if ( struct_var )
-               *struct_var = temp_struct;
-
-FINISH_OFF:
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;
+       EM_DEBUG_FUNC_END("err [%d]", EMAIL_ERROR_NOT_IMPLEMENTED);
+       return EMAIL_ERROR_NOT_IMPLEMENTED;
 }
 
 EXPORT_API int email_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req)
@@ -1651,7 +1635,7 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, unsigned *output_handle)
+EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *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;
index b89d4c4..f87a54f 100755 (executable)
@@ -41,7 +41,7 @@
 
 /* API - Create a mailbox */
 
-EXPORT_API int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, unsigned* handle)
+EXPORT_API int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN();
 
@@ -128,11 +128,13 @@ EXPORT_API int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, un
        }
 
 FINISH_OFF:
+       EM_SAFE_FREE(local_mailbox_stream);
+
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
 
-EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, unsigned *output_handle)
+EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, int *output_handle)
 {
        EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_name [%p], input_mailbox_alias [%p], input_on_server [%d], output_handle [%p]", input_mailbox_id, input_mailbox_name, input_mailbox_alias, input_on_server, output_handle);
 
@@ -227,7 +229,7 @@ FINISH_OFF:
 
 /* API - Delete a mailbox */
 
-EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, unsigned* output_handle)
+EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *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);
        
@@ -348,9 +350,42 @@ EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e
 
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
+}
+
+EXPORT_API int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_is_local_mailbox [%d]", input_mailbox_id, input_is_local_mailbox);
+       int err = EMAIL_ERROR_NONE;
+
+       EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
+
+       HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_LOCAL_MAILBOX);
+
+       EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
+
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_mailbox_id, sizeof(int))) {
+               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
+       }
 
+       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_is_local_mailbox, sizeof(int))) {
+               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
+       }
 
+       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, EMAIL_ERROR_IPC_SOCKET_FAILURE);
+       }
 
+       emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
+
+       EM_DEBUG_LOG("error VALUE [%d]", err);
+       emipc_destroy_email_api(hAPI);
+       hAPI = NULL;
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
 }
 
 EXPORT_API int email_get_sync_mailbox_list(int account_id, email_mailbox_t** mailbox_list, int* count)
@@ -497,7 +532,7 @@ EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_t
        EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM)  ;
 
 
-       if(mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS)
+       if(mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_USER_DEFINED)
                return EMAIL_ERROR_INVALID_PARAM;
        if (!emstorage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &local_mailbox, true, &err))  {
                EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
index 7aeb1d1..02cd106 100755 (executable)
 
 
 
-EXPORT_API int email_send_mail(int mail_id, email_option_t* sending_option, unsigned* handle)
+EXPORT_API int email_send_mail(int mail_id, int *handle)
 {
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], sending_option[%p], handle[%p]", mail_id, sending_option, handle);
+       EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, handle);
        
        char* pSendingOption = NULL;
-       int size = 0;
        int err = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t* mail_table_data = NULL;
+       email_account_server_t account_server_type;
+       HIPC_API hAPI = NULL;
+       ASNotiData as_noti_data;
 
        if(mail_id <= 0) {
                EM_DEBUG_EXCEPTION("mail_id is not valid");
@@ -66,9 +68,6 @@ EXPORT_API int email_send_mail(int mail_id, email_option_t* sending_option, unsi
 
        EM_DEBUG_LOG("mail_table_data->account_id[%d], mail_table_data->mailbox_name[%s]", mail_table_data->account_id, mail_table_data->mailbox_name);
 
-       email_account_server_t account_server_type;
-       HIPC_API hAPI = NULL;
-       ASNotiData as_noti_data;
        memset(&as_noti_data, 0x00, sizeof(ASNotiData));
 
        /*  check account bind type and branch off  */
@@ -87,11 +86,9 @@ EXPORT_API int email_send_mail(int mail_id, email_option_t* sending_option, unsi
                }
                
                /*  noti to active sync */
-               as_noti_data.send_mail.handle = as_handle;
+               as_noti_data.send_mail.handle     = as_handle;
                as_noti_data.send_mail.account_id = mail_table_data->account_id;
-               as_noti_data.send_mail.mail_id = mail_id;
-
-               memcpy(&as_noti_data.send_mail.options, sending_option, sizeof(email_option_t));
+               as_noti_data.send_mail.mail_id    = mail_id;
 
                if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEND_MAIL, &as_noti_data) == false) {
                        EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
@@ -113,19 +110,6 @@ EXPORT_API int email_send_mail(int mail_id, email_option_t* sending_option, unsi
                        EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
                }
 
-               /* sending options */
-               pSendingOption = em_convert_option_to_byte_stream(sending_option, &size);
-
-               if ( NULL == pSendingOption)     {
-                       EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
-               }
-
-               if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pSendingOption, size)){
-                       EM_DEBUG_EXCEPTION("email_send_mail--Add Param Sending_Option failed  ");
-                       EM_SAFE_FREE(pSendingOption);
-                       EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
-               }
-
                if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("email_send_mail--emipc_execute_proxy_api failed  ");
                        EM_SAFE_FREE(pSendingOption);
@@ -148,16 +132,14 @@ FINISH_OFF:
        return err;     
 }
 
-EXPORT_API int email_send_saved(int account_id, email_option_t* sending_option, unsigned* handle)
+EXPORT_API int email_send_saved(int account_id, int *handle)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], sending_option[%p], handle[%p]", account_id, sending_option, handle);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p]", account_id, handle);
        
        char* pOptionStream = NULL;
        int err = EMAIL_ERROR_NONE;
-       int size = 0;
        
        EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(sending_option, EMAIL_ERROR_INVALID_PARAM);
        EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM);
        
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_SAVED);
@@ -170,16 +152,6 @@ EXPORT_API int email_send_saved(int account_id, email_option_t* sending_option,
                EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
        }
 
-       /* Sending Option */
-       pOptionStream = em_convert_option_to_byte_stream(sending_option, &size);
-
-       EM_PROXY_IF_NULL_RETURN_VALUE(pOptionStream, hAPI, EMAIL_ERROR_NULL_VALUE);
-
-       if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pOptionStream, size)) {
-               EM_DEBUG_EXCEPTION("Add Param sending option failed");
-               EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
-       }
-
        /* Execute API */
        if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
@@ -197,7 +169,7 @@ EXPORT_API int email_send_saved(int account_id, email_option_t* sending_option,
        return err;
 }
 
-EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, unsigned* handle)
+EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mailbox_id[%d] handle[%p]", input_account_id, input_mailbox_id, handle);
        int err = EMAIL_ERROR_NONE;     
@@ -281,7 +253,7 @@ FINISH_OFF:
 }
 
 
-EXPORT_API int email_sync_header_for_all_account(unsigned* handle)
+EXPORT_API int email_sync_header_for_all_account(int *handle)
 {
        EM_DEBUG_FUNC_BEGIN("handle[%p]", handle);
        char* mailbox_stream = NULL;
@@ -375,7 +347,7 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_download_body(int mail_id, int with_attachment, unsigned* handle)
+EXPORT_API int email_download_body(int mail_id, int with_attachment, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d],with_attachment[%d]", mail_id, with_attachment);
        int err = EMAIL_ERROR_NONE;
@@ -482,7 +454,7 @@ FINISH_OFF:
 
 /* API - Downloads the Email Attachment Information [ INTERNAL ] */
 
-EXPORT_API int email_download_attachment(int mail_id, int nth, unsigned* handle)
+EXPORT_API int email_download_attachment(int mail_id, int nth, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], handle[%p]", mail_id, nth, handle);
        char* mailbox_stream = NULL;
@@ -786,7 +758,7 @@ EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving)
        return err;
 }
 
-EXPORT_API int email_sync_imap_mailbox_list(int account_id, unsigned* handle)
+EXPORT_API int email_sync_imap_mailbox_list(int account_id, int *handle)
 {
        EM_DEBUG_FUNC_BEGIN();
 
@@ -821,7 +793,7 @@ EXPORT_API int email_sync_imap_mailbox_list(int account_id, unsigned* handle)
        return err;
 }
 
-EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, unsigned *output_handle)
+EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle)
 {
        EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d], input_search_filter_list [%p], input_search_filter_count [%d], output_handle [%p]", input_account_id, input_mailbox_id, input_search_filter_list, input_search_filter_count, output_handle);
 
index cb3aba8..9b52a31 100755 (executable)
@@ -166,7 +166,7 @@ EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **
 
 EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
 {
-       EM_DEBUG_FUNC_BEGIN("mail_id : [%s]", mail_id);
+       EM_DEBUG_FUNC_BEGIN("mail_id : [%d]", mail_id);
        int err = EMAIL_ERROR_NONE;
        email_mail_data_t *p_output_mail_data = NULL;
        emstorage_account_tbl_t *p_account = NULL;
@@ -199,17 +199,14 @@ FINISH_OFF:
        return err;
 }
 
-EXPORT_API int email_verify_signature(char *certificate_path, int mail_id, int *verify)
+EXPORT_API int email_verify_signature(int mail_id, int *verify)
 {
-       EM_DEBUG_FUNC_BEGIN("Certificate path : [%s]", certificate_path);
+       EM_DEBUG_FUNC_BEGIN("mail_id : [%d]", mail_id);
        int result_from_ipc = 0;
        int err = EMAIL_ERROR_NONE;
        int p_verify = 0;
-       
-       if (!certificate_path) {
-               EM_DEBUG_EXCEPTION("Invalid parameter");
-               return EMAIL_ERROR_INVALID_PARAM;
-       }
+
+       EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);    
 
        HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VERIFY_SIGNATURE);
        if (hAPI == NULL) {
@@ -218,12 +215,6 @@ EXPORT_API int email_verify_signature(char *certificate_path, int mail_id, int *
                goto FINISH_OFF;
        }
 
-       if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, strlen(certificate_path)+1)) {
-               EM_DEBUG_EXCEPTION("emipc_add_parameter certificate_path[%s] failed", certificate_path);
-               err = EMAIL_ERROR_NULL_VALUE;
-               goto FINISH_OFF;
-       }
-
        if (!emipc_add_parameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int))) {
                EM_DEBUG_EXCEPTION("emipc_add_parameter pass_phrase[%d] failed", mail_id);
                err = EMAIL_ERROR_NULL_VALUE;
index f201782..efe15a7 100755 (executable)
@@ -262,7 +262,7 @@ EXPORT_API int email_free_account(email_account_t** account_list, int count);
 
 /**
  * @open
- * @fn email_validate_account(int account_id, unsigned* handle)
+ * @fn email_validate_account(int account_id, int *handle)
  * @brief      Validate account.This function is getting invoked  after adding one account to validate it.If account is not validated then user should retry once again to add the account .
  *
  * @param[in] account_id              Specifies the account Id to validate.
@@ -273,11 +273,11 @@ EXPORT_API int email_free_account(email_account_t** account_list, int count);
  * @see                none
  * @remarks N/A
  */
-EXPORT_API int email_validate_account(int account_id, unsigned* handle);
+EXPORT_API int email_validate_account(int account_id, int *handle);
 
 /**
  * @open
- * @fn email_add_account_with_validation(email_account_t* account, unsigned* handle)
+ * @fn email_add_account_with_validation(email_account_t* account, int *handle)
  * @brief      Add an account when the account is validated. This function is getting invoked when user want to validate an account. If account is not validated then user should retry once again to add the account.<br>
  *              Validation is executed without saving an account to DB
  *
@@ -286,7 +286,7 @@ EXPORT_API int email_validate_account(int account_id, unsigned* handle);
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-EXPORT_API int email_add_account_with_validation(email_account_t* account, unsigned* handle);
+EXPORT_API int email_add_account_with_validation(email_account_t* account, int *handle);
 
 
 /**
index 4123636..dc59dcf 100755 (executable)
@@ -64,9 +64,11 @@ extern "C" {
  */
 EXPORT_API int email_show_user_message(int id, email_action_t action, int error_code);
 
-EXPORT_API int email_open_eml_file(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count);
+EXPORT_API int email_parse_mime_file(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count);
 
-EXPORT_API int email_delete_eml_data(email_mail_data_t *input_mail_data);
+EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, char **output_file_path);
+
+EXPORT_API int email_delete_parsed_data(email_mail_data_t *input_mail_data);
 
 EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity);
 #ifdef __cplusplus
index 63fa085..82cab87 100755 (executable)
@@ -100,7 +100,7 @@ extern "C" {
 
  * @open
  * @fn email_init_storage(void)
- * @brief      Create all table for email. Exposed to External Application- core team.Creates all Email DB tables [ EXTERNAL]
+ * @brief      Create all tables for email.
  *
  * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure
  * @exception none
index 8b3b227..67fc164 100755 (executable)
@@ -205,7 +205,7 @@ EXPORT_API int email_add_mail(email_mail_data_t *input_mail_data, email_attachme
 
  /**
   * @open
-  * @fn email_add_read_receipt(int input_read_mail_id,  unsigned *output_handle)
+  * @fn email_add_read_receipt(int input_read_mail_id,  int *output_handle)
   * @brief     Add a read receipt mail. This function is invoked when user receives a mail with read report enable and wants to send a read report for the same.
   *
   * @return    This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
@@ -1413,7 +1413,7 @@ EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag);
 
 EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server);
 
-EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, unsigned *output_handle);
+EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle);
 
 #ifdef __cplusplus
 }
index 62a57f7..d48a2e1 100755 (executable)
@@ -59,7 +59,7 @@
  *             email_mailbox_t *mailbox_list = NULL;
  *             int count = 0;
  *             int mailbox_type;
- *             unsigned handle = 0;
+ *             int handle = 0;
  *             char *pMaiboxName;
  *             char *pParentMailbox;
  *
@@ -133,7 +133,7 @@ extern "C"
 
 /**
  * @open
- * @fn int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, unsigned* handle)
+ * @fn int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle)
  * @brief      Create a new mailbox or mailbox.This function is invoked when user wants to create a new mailbox for the specified account.
  *             If On_server is true then it will create the mailbox on server as well as in local also.
  *
@@ -145,7 +145,7 @@ extern "C"
  * @see        email_mailbox_t
   * @remarks N/A
  */
-EXPORT_API int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, unsigned* handle);
+EXPORT_API int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, int *handle);
 
 /**
  * @fn int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias)
@@ -162,11 +162,11 @@ EXPORT_API int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, un
  * @see        email_mailbox_t, email_mailbox_type_e
  * @remarks N/A
  */
-EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, unsigned *output_handle);
+EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, int *output_handle);
 
 /**
  * @open
- * @fn int email_delete_mailbox(int input_mailbox_id, int input_on_server, unsigned* output_handle)
+ * @fn int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_handle)
  * @brief      Delete a mailbox or mailbox.This function deletes the existing mailbox for specified account based on the option on_server.
  *             If the on_server is true then it deletes mailbox from server as well as locally.
  *
@@ -178,7 +178,7 @@ EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_na
  * @see        email_mailbox_t
  * @remarks N/A
  */
-EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, unsigned* output_handle);
+EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_handle);
 
 /**
  * @fn int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type)
@@ -194,6 +194,19 @@ EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, u
 EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type);
 
 /**
+ * @fn int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox)
+ * @brief      Change the attribute 'local' of email_mailbox_t. This function is invoked when user wants to change the attribute 'local'.
+ *
+ * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure.
+ * @param[in] input_mailbox_id                 Specifies the id of the mailbox.
+ * @param[in] input_is_local_mailbox   Specifies the value of the attribute 'local' of email_mailbox_t.
+ * @exception see email-errors.h
+ * @see                none
+ * @remarks N/A
+ */
+EXPORT_API int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox);
+
+/**
 
  * @open
  * @fn email_get_mailbox_list(int account_id, int mailbox_sync_type, email_mailbox_t** mailbox_list, int* count)
index c13c037..67d18ca 100755 (executable)
@@ -59,7 +59,6 @@
  *
  *             // Send a mail
  *             email_attachment_data_t attachment;
- *             email_option_t option;
  *             int account_id = 1;
  *             int mailbox_id = 0;
  *             int attachment_id = 0;
  *
  *             printf("Enter mail id\n");
  *             scanf("%d",&mail_id);
- *             option.keep_local_copy = 1;
  *
- *             if(EMAIL_ERROR_NONE == email_send_mail(mail_id, &option, &handle))
+ *             if(EMAIL_ERROR_NONE == email_send_mail(mail_id, &handle))
  *                     //success
  *             else
  *                     //failure
  *
  *             // Download header of new emails from mail server
- *             unsigned handle = 0;
+ *             int handle = 0;
  *
  *             mailbox.account_id = account_id;
  *             printf("Enter mailbox id\n");
@@ -168,23 +166,22 @@ extern "C" {
 
 /**
  * @open
- * @fn email_send_mail(int mail_id,    email_option_t* sending_option, unsigned* handle)
+ * @fn email_send_mail(int mail_id,    int *handle)
  * @brief      Send a mail.This function is invoked when user wants to send a composed mail.
  *
  * @return     This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
  * @param[in] mail_id                  Specifies the mail ID.
- * @param[in] sending_option           Specifies the sending option.
  * @param[out] handle          Specifies the sending handle.
  * @exception  none
  * @see        email_mailbox_t and email_option_t
  * @remarks N/A
  */
-EXPORT_API int email_send_mail(int mail_id,    email_option_t* sending_option, unsigned* handle);
+EXPORT_API int email_send_mail(int mail_id,    int *handle);
 
 
 /**
  * @open
- * @fn email_sync_header(int input_account_id, int input_mailbox_id, unsigned* handle)
+ * @fn email_sync_header(int input_account_id, int input_mailbox_id, int *handle)
  * @brief      Download header of new emails from mail server.This function is invoked when user wants to download only header of new mails.
  *
  * @return     This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
@@ -195,12 +192,12 @@ EXPORT_API int email_send_mail(int mail_id,       email_option_t* sending_option, unsi
  * @see        email_mailbox_t
  * @remarks N/A
  */
-EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, unsigned* handle);
+EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, int *handle);
 
 
 /**
  * @open
- * @fn email_sync_header_for_all_account(unsigned* handle)
+ * @fn email_sync_header_for_all_account(int *handle)
  * @brief      Download header of new emails from mail server for all emails.This function is invoked when user wants to download header of new mails for all accounts.
  *
  * @return     This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
@@ -209,12 +206,12 @@ EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, uns
  * @see        none
  * @remarks N/A
  */
-EXPORT_API int email_sync_header_for_all_account(unsigned* handle);
+EXPORT_API int email_sync_header_for_all_account(int *handle);
 
 
 /**
  * @open
- * @fn email_download_body(int mail_id, int with_attachment, unsigned* handle)
+ * @fn email_download_body(int mail_id, int with_attachment, int *handle)
  * @brief      Download email body from server.This function is invoked when user wants to download email body with/without attachment based on the option with_attachment
  *             from the server.
  *
@@ -226,7 +223,7 @@ EXPORT_API int email_sync_header_for_all_account(unsigned* handle);
  * @see email_mailbox_t
  * @remarks N/A
  */
-EXPORT_API int email_download_body(int mail_id, int with_attachment, unsigned* handle);
+EXPORT_API int email_download_body(int mail_id, int with_attachment, int *handle);
 
 
 
@@ -235,7 +232,7 @@ EXPORT_API int email_download_body(int mail_id, int with_attachment, unsigned* h
 
 /**
  * @open
- * @fn email_download_attachment(int mail_id, const char* nth, unsigned* handle);
+ * @fn email_download_attachment(int mail_id, const char* nth, int *handle);
  * @brief      Download a email nth-attachment from server.This function is invoked if user wants to download only specific attachment of a mail whose body is already downloaded.
  *
  * @return     This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
@@ -246,7 +243,7 @@ EXPORT_API int email_download_body(int mail_id, int with_attachment, unsigned* h
  * @see        email_mailbox_t
  * @remarks N/A
  */
-EXPORT_API int email_download_attachment(int mail_id, int nth, unsigned* handle);
+EXPORT_API int email_download_attachment(int mail_id, int nth, int *handle);
 
 
 /**
@@ -300,23 +297,22 @@ EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving);
 
 /**
  * @open
- * @fn email_send_saved(int account_id, email_option_t* sending_option, unsigned* handle)
+ * @fn email_send_saved(int account_id, int *handle)
  * @brief      Send all mails to been saved in Offline-mode.This function is invoked when user wants to send an email and after saving it.
  *             This will save the email in draft mailbox and then sends.
  *
  * @return     This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
  * @param[in] account_id                       Specifies the account ID.
- * @param[in] sending_option           Specifies the sending option.
  * @param[out] handle                          Specifies the handle for stopping sending.
  * @exception none
  * @see email_option_t
  * @remarks N/A
  */
-EXPORT_API int email_send_saved(int account_id, email_option_t* sending_option, unsigned* handle);
+EXPORT_API int email_send_saved(int account_id, int *handle);
 
 /**
  * @open
- * @fn email_sync_imap_mailbox_list(int account_id, unsigned* handle)
+ * @fn email_sync_imap_mailbox_list(int account_id, int *handle)
  *  @brief     fetch all the mailbox names from server and store the non-existing mailboxes in DB.This function is invoked when user wants to download all server mailboxes from IMAP server
  *
  * @return     This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
@@ -326,11 +322,11 @@ EXPORT_API int email_send_saved(int account_id, email_option_t* sending_option,
  * @see        none
  * @remarks N/A
  */
-EXPORT_API int email_sync_imap_mailbox_list(int account_id, unsigned* handle);
+EXPORT_API int email_sync_imap_mailbox_list(int account_id, int *handle);
 
 /**
  * @open
- * @fn email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, unsigned *output_handle)
+ * @fn email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle)
  * @brief      Search the mails on server.
  *
  * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure.
@@ -344,7 +340,7 @@ EXPORT_API int email_sync_imap_mailbox_list(int account_id, unsigned* handle);
  * @endcode
  * @remarks N/A
  */
-EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, unsigned *output_handle);
+EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle);
 
 EXPORT_API int email_clear_result_of_search_mail_on_server(int input_account_id);
 
index 2e46eed..7af32e3 100755 (executable)
@@ -36,7 +36,7 @@ EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **
 
 EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count);
 
-EXPORT_API int email_verify_signature(char *certificate_path, int mail_id, int *verify);
+EXPORT_API int email_verify_signature(int mail_id, int *verify);
 
 EXPORT_API int email_verify_certificate(char *certificate_path, int *verify);
 
index 36d482f..b06183a 100755 (executable)
 #define fATTACHMENT 0x40
 #define fFORWARD    0x80
 
-INTERNAL_FUNC int em_convert_mail_flag_to_int(email_mail_flag_t flag, int *i_flag, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("i_flag[%p], err_code[%p]", i_flag, err_code);
-       
-       if (!i_flag)  {
-               if (err_code != NULL)
-                       *err_code = EMAIL_ERROR_INVALID_PARAM;
-               return false;
-               
-       }
-
-       *i_flag =
-                       (flag.seen           ? fSEEN       : 0) |
-                       (flag.deleted        ? fDELETED    : 0) |
-                       (flag.flagged        ? fFLAGGED    : 0) |
-                       (flag.answered       ? fANSWERED   : 0) |
-                       (flag.recent         ? fOLD        : 0) |
-                       (flag.draft          ? fDRAFT      : 0) |
-                       (flag.has_attachment ? fATTACHMENT : 0) |
-                       (flag.forwarded      ? fFORWARD    : 0) ;
-
-       EM_DEBUG_FUNC_END();
-       return true;
-}
-
-INTERNAL_FUNC int em_convert_mail_int_to_flag(int i_flag, email_mail_flag_t* flag, int* err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("i_flag[0x%02x], flag[%p], err_code[%p]", i_flag, flag, err_code);
-
-       if (!flag) {
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
-               if (err_code != NULL)
-                       *err_code = EMAIL_ERROR_INVALID_PARAM;
-               return false;
-       }
-
-       flag->seen           = (i_flag & fSEEN ? 1 : 0);
-       flag->deleted        = (i_flag & fDELETED ? 1 : 0);
-       flag->flagged        = (i_flag & fFLAGGED ? 1 : 0);
-       flag->answered       = (i_flag & fANSWERED ? 1 : 0);
-       flag->recent         = (i_flag & fOLD ? 1 : 0);
-       flag->draft          = (i_flag & fDRAFT ? 1 : 0);
-       flag->has_attachment = (i_flag & fATTACHMENT ? 1 : 0);
-       flag->forwarded      = (i_flag & fFORWARD    ? 1 : 0);
-
-       EM_DEBUG_FUNC_END("FLAGS : seen[%d], deleted[%d], flagged[%d], answered[%d], recent[%d], draft[%d], has_attachment[%d], forwarded[%d]",
-               flag->seen, flag->deleted, flag->flagged, flag->answered, flag->recent, flag->draft, flag->has_attachment, flag->forwarded);
-
-    return true;
-}
-
 INTERNAL_FUNC int em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_tbl_data, int *result_mail_status, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], result_mail_status [%p], err_code[%p]", mail_tbl_data, result_mail_status, err_code);
        int ret = false, error_code = EMAIL_ERROR_NONE;
-       int has_attachment = 0;
+       int attachment_count = 0;
 
        if(!mail_tbl_data || !result_mail_status) {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -102,7 +51,7 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_
                goto FINISH_OFF;
        }
 
-       has_attachment = (mail_tbl_data->attachment_count > mail_tbl_data->inline_content_count) ? 1 : 0;
+       attachment_count = (mail_tbl_data->attachment_count > mail_tbl_data->inline_content_count) ? 1 : 0;
 
        *result_mail_status = (mail_tbl_data->flags_seen_field      ? fSEEN       : 0) |
                              (mail_tbl_data->flags_deleted_field   ? fDELETED    : 0) |
@@ -110,7 +59,7 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_
                              (mail_tbl_data->flags_answered_field  ? fANSWERED   : 0) |
                              (mail_tbl_data->flags_recent_field    ? fOLD        : 0) |
                              (mail_tbl_data->flags_draft_field     ? fDRAFT      : 0) |
-                             (has_attachment                       ? fATTACHMENT : 0) |
+                             (attachment_count                       ? fATTACHMENT : 0) |
                              (mail_tbl_data->flags_forwarded_field ? fFORWARD    : 0);
 
        ret = true;
@@ -150,64 +99,6 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tbl_data, email_mail_flag_t *result_flag, int* err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], result_flag [%p], err_code[%p]", mail_tbl_data, result_flag, err_code);
-       int ret = false, error_code = EMAIL_ERROR_NONE;
-
-       if(!mail_tbl_data || !result_flag) {
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
-               error_code = EMAIL_ERROR_INVALID_PARAM;
-               goto FINISH_OFF;
-       }
-
-       result_flag->seen           = mail_tbl_data->flags_seen_field;
-       result_flag->deleted        = mail_tbl_data->flags_deleted_field;
-       result_flag->flagged        = mail_tbl_data->flags_flagged_field;
-       result_flag->answered       = mail_tbl_data->flags_answered_field;
-       result_flag->recent         = mail_tbl_data->flags_recent_field;
-       result_flag->draft          = mail_tbl_data->flags_draft_field;
-       result_flag->has_attachment = (mail_tbl_data->attachment_count > mail_tbl_data->inline_content_count) ? 1 : 0;
-       result_flag->forwarded      = mail_tbl_data->flags_forwarded_field;
-
-       ret = true;
-FINISH_OFF:
-       if (err_code != NULL)
-               *err_code = error_code;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-}
-
-INTERNAL_FUNC int em_convert_mail_flag_to_mail_tbl(email_mail_flag_t *flag, emstorage_mail_tbl_t *result_mail_tbl_data,  int* err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("flag[%p], result_mail_tbl_data [%p], err_code[%p]", flag, result_mail_tbl_data, err_code);
-       int ret = false, error_code = EMAIL_ERROR_NONE;
-
-       if(!flag || !result_mail_tbl_data) {
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
-               error_code = EMAIL_ERROR_INVALID_PARAM;
-               goto FINISH_OFF;
-       }
-
-       result_mail_tbl_data->flags_seen_field           = flag->seen;
-       result_mail_tbl_data->flags_deleted_field        = flag->deleted;
-       result_mail_tbl_data->flags_flagged_field        = flag->flagged;
-       result_mail_tbl_data->flags_answered_field       = flag->answered;
-       result_mail_tbl_data->flags_recent_field         = flag->recent;
-       result_mail_tbl_data->flags_draft_field          = flag->draft;
-       result_mail_tbl_data->flags_forwarded_field      = flag->forwarded;
-
-       ret = true;
-FINISH_OFF:
-       if (err_code != NULL)
-               *err_code = error_code;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-}
-
-
 INTERNAL_FUNC int em_convert_account_to_account_tbl(email_account_t *account, emstorage_account_tbl_t *account_tbl)
 {
        EM_DEBUG_FUNC_BEGIN("account[%p], account_tbl[%p]", account, account_tbl);
@@ -406,6 +297,7 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_ta
                temp_mail_data[i].server_mailbox_name     = EM_SAFE_STRDUP(mail_table_data[i].server_mailbox_name);
                temp_mail_data[i].server_mail_id          = EM_SAFE_STRDUP(mail_table_data[i].server_mail_id);
                temp_mail_data[i].message_id              = EM_SAFE_STRDUP(mail_table_data[i].message_id);
+               temp_mail_data[i].reference_mail_id       = mail_table_data[i].reference_mail_id;
                temp_mail_data[i].full_address_from       = EM_SAFE_STRDUP(mail_table_data[i].full_address_from);
                temp_mail_data[i].full_address_reply      = EM_SAFE_STRDUP(mail_table_data[i].full_address_reply);
                temp_mail_data[i].full_address_to         = EM_SAFE_STRDUP(mail_table_data[i].full_address_to);
@@ -487,6 +379,7 @@ INTERNAL_FUNC int   em_convert_mail_data_to_mail_tbl(email_mail_data_t *mail_dat
                temp_mail_tbl[i].server_mailbox_name     = EM_SAFE_STRDUP(mail_data[i].server_mailbox_name);
                temp_mail_tbl[i].server_mail_id          = EM_SAFE_STRDUP(mail_data[i].server_mail_id);
                temp_mail_tbl[i].message_id              = EM_SAFE_STRDUP(mail_data[i].message_id);
+               temp_mail_tbl[i].reference_mail_id       = mail_data[i].reference_mail_id;
                temp_mail_tbl[i].full_address_from       = EM_SAFE_STRDUP(mail_data[i].full_address_from);
                temp_mail_tbl[i].full_address_reply      = EM_SAFE_STRDUP(mail_data[i].full_address_reply);
                temp_mail_tbl[i].full_address_to         = EM_SAFE_STRDUP(mail_data[i].full_address_to);
@@ -994,10 +887,9 @@ INTERNAL_FUNC void em_convert_byte_stream_to_account(char *stream, int stream_le
 #endif
 }
 
-#define EMAIL_MAIL_DATA_FMT  "S(" "iiiis" "iisss" "sssss" "sssss" "isssi"\
-                            "ccccc" "cciii" "iiiii" "isiii" "i" ")"
+#define EMAIL_MAIL_DATA_FMT  "S(" "iiiis" "iisss" "issss" "sssss" "sisss"\
+                            "icccc" "cccii" "iiiii" "iisii" "ii" ")"
 
-#if 0
 INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_data, int *stream_len)
 {
        EM_DEBUG_FUNC_END();
@@ -1019,9 +911,7 @@ INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_
        EM_DEBUG_FUNC_END();
        return (char*) buf;
 
-#endif
-INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *input_mail_data, int input_mail_data_count, int *output_stream_size)
-{
+#if 0
        EM_DEBUG_FUNC_BEGIN("input_mail_data [%p], input_mail_data_count[%d], output_stream_size[%p]", input_mail_data, input_mail_data_count, output_stream_size);
 
        char *result_stream = NULL;
@@ -1044,6 +934,7 @@ INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *input
                result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].server_mailbox_name);
                result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].server_mail_id);
                result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].message_id);
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].reference_mail_id), sizeof(int));
                result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_from);
                result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_reply);
                result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_to);
@@ -1086,8 +977,9 @@ INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *input
 
        EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
        return result_stream;
+#endif
 }
-#if 0
+
 INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *stream, int stream_len, email_mail_data_t *mail_data)
 {
        EM_NULL_CHECK_FOR_VOID(stream);
@@ -1101,9 +993,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *stream, int stream_
        tpl_free(tn);
 
        EM_DEBUG_FUNC_END();
-#endif
-INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, email_mail_data_t **output_mail_data, int *output_mail_data_count) 
-{
+#if 0
        EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_mail_data[%p], output_mail_data_count[%p]", input_stream, output_mail_data, output_mail_data_count);
 
        int stream_offset = 0;
@@ -1140,6 +1030,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, email
                fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].server_mailbox_name);
                fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].server_mail_id);
                fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].message_id);
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].reference_mail_id);
                fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_from);
                fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_reply);
                fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_to);
@@ -1179,6 +1070,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, email
        }
 
        EM_DEBUG_FUNC_END();
+#endif
 }
 
 
@@ -1186,7 +1078,6 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, email
 
 INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(email_attachment_data_t *attachment, int attachment_count, int* stream_len)
 {
-#if 0
        EM_DEBUG_FUNC_BEGIN();
        EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
        if(!attachment) {
@@ -1220,43 +1111,42 @@ INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(email_attachment_d
 
        EM_DEBUG_FUNC_END();
        return (char*) buf;
-#endif
 
-       EM_DEBUG_FUNC_BEGIN("attachment [%p], input_attachment_count [%d], output_stream_size [%p]", attachment, attachment_count, stream_len);
+#if 0
+       EM_DEBUG_FUNC_BEGIN("input_attachment_data [%p], input_attachment_count [%d], output_stream_size [%p]", input_attachment_data, input_attachment_count, output_stream_size);
 
        char *result_stream = NULL;
        int stream_size = 0;
        int i = 0;
 
-       if(attachment_count > 0)
-               EM_IF_NULL_RETURN_VALUE(attachment, NULL);
-       EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
+       if(input_attachment_count > 0)
+               EM_IF_NULL_RETURN_VALUE(input_attachment_data, NULL);
+       EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
 
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment_count, sizeof(int));
-
-       for(i = 0; i < attachment_count; i++) {
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].attachment_id, sizeof(int));
-               result_stream = append_string_to_stream(result_stream, &stream_size, attachment[i].attachment_name);
-               result_stream = append_string_to_stream(result_stream, &stream_size, attachment[i].attachment_path);
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].attachment_size, sizeof(int));
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].mail_id, sizeof(int));
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].account_id, sizeof(int));
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].mailbox_id, sizeof(int));
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].save_status, sizeof(int));
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].drm_status, sizeof(int));
-               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&attachment[i].inline_content_status,sizeof(int));
+       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_count, sizeof(int));
+
+       for(i = 0; i < input_attachment_count; i++) {
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].attachment_id, sizeof(int));
+               result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_data[i].attachment_name);
+               result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_data[i].attachment_path);
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].attachment_size, sizeof(int));
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].mail_id, sizeof(int));
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].account_id, sizeof(int));
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].mailbox_id, sizeof(int));
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].save_status, sizeof(int));
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].drm_status, sizeof(int));
+               result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].inline_content_status,sizeof(int));
        }
 
-       *stream_len = stream_size;
+       *output_stream_size = stream_size;
 
        EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
        return result_stream;
-
+#endif
 }
 
 INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *stream, int stream_len, email_attachment_data_t **attachment_data, int *attachment_count)
 {
-#if 0
        EM_DEBUG_FUNC_BEGIN();
        EM_NULL_CHECK_FOR_VOID(stream);
        EM_NULL_CHECK_FOR_VOID(attachment_data);
@@ -1300,46 +1190,47 @@ INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *stream, int s
        *attachment_count = count;
        *attachment_data = attached;
        EM_DEBUG_FUNC_END();
-#endif
-       EM_DEBUG_FUNC_BEGIN("stream [%p], attachment_data[%p]", stream, attachment_data);
+#if 0
+       EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_attachment_data[%p]", input_stream, output_attachment_data);
 
        int stream_offset = 0;
        int i = 0;
 
-       EM_NULL_CHECK_FOR_VOID(stream);
-       EM_NULL_CHECK_FOR_VOID(attachment_data);
-       EM_NULL_CHECK_FOR_VOID(attachment_count);
+       EM_NULL_CHECK_FOR_VOID(input_stream);
+       EM_NULL_CHECK_FOR_VOID(output_attachment_data);
+       EM_NULL_CHECK_FOR_VOID(output_attachment_count);
 
-       fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)attachment_count);
+       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)output_attachment_count);
 
-       EM_DEBUG_LOG("*attachment_count [%d]", *attachment_count);
+       EM_DEBUG_LOG("*output_attachment_count [%d]", *output_attachment_count);
 
-       if(attachment_count <= 0) {
+       if(output_attachment_count <= 0) {
                EM_DEBUG_EXCEPTION("no attachment data.");
                return;
        }
 
-       *attachment_data = (email_attachment_data_t*)em_malloc(sizeof(email_attachment_data_t) * (*attachment_count));
+       *output_attachment_data = (email_attachment_data_t*)em_malloc(sizeof(email_attachment_data_t) * (*output_attachment_count));
 
-       if(!*attachment_data) {
+       if(!*output_attachment_data) {
                EM_DEBUG_EXCEPTION("em_malloc failed");
                return;
        }
 
-       for(i = 0; i < *attachment_count; i++) {
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].attachment_id));
-               fetch_string_from_stream(stream, &stream_offset, &(*attachment_data)[i].attachment_name);
-               fetch_string_from_stream(stream, &stream_offset, &(*attachment_data)[i].attachment_path);
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].attachment_size));
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].mail_id));
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].account_id));
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].mailbox_id));
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].save_status));
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].drm_status));
-               fetch_sized_data_from_stream(stream, &stream_offset, sizeof(int), (char*)&((*attachment_data)[i].inline_content_status));
+       for(i = 0; i < *output_attachment_count; i++) {
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].attachment_id));
+               fetch_string_from_stream(input_stream, &stream_offset, &(*output_attachment_data)[i].attachment_name);
+               fetch_string_from_stream(input_stream, &stream_offset, &(*output_attachment_data)[i].attachment_path);
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].attachment_size));
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].mail_id));
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].account_id));
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].mailbox_id));
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].save_status));
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].drm_status));
+               fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].inline_content_status));
        }
 
        EM_DEBUG_FUNC_END();
+#endif
 }
 
 
@@ -1607,70 +1498,6 @@ INTERNAL_FUNC void em_convert_byte_stream_to_rule(char *stream, int stream_len,
 #endif
 }
 
-
-#if 0
-INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(email_extra_flag_t extra_flag, int *stream_len)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       char *result_stream = NULL;
-       int   stream_size = 0;
-       int   extra_flag_field = 0;
-
-       EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
-
-       extra_flag_field = input_extra_flag.priority;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-       extra_flag_field = input_extra_flag.status;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-       extra_flag_field = input_extra_flag.noti;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-       extra_flag_field = input_extra_flag.lock;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-       extra_flag_field = input_extra_flag.report;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-       extra_flag_field = input_extra_flag.drm;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-       extra_flag_field = input_extra_flag.text_download_yn;
-       result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
-
-       *output_stream_size = stream_size;
-
-       EM_DEBUG_FUNC_END();
-
-       return result_stream;
-}
-
-
-INTERNAL_FUNC void em_convert_byte_stream_to_extra_flags(char *input_stream, email_extra_flag_t *output_extra_flag)
-{
-       EM_DEBUG_FUNC_BEGIN();
-
-       int stream_offset = 0;
-       int extra_flag_field = 0;
-
-       EM_NULL_CHECK_FOR_VOID(input_stream);
-       EM_NULL_CHECK_FOR_VOID(output_extra_flag);
-
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->priority = extra_flag_field;
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->status = extra_flag_field;
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->noti = extra_flag_field;
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->lock = extra_flag_field;
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->report = extra_flag_field;
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->drm = extra_flag_field;
-       fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
-       output_extra_flag->text_download_yn = extra_flag_field;
-
-       EM_DEBUG_FUNC_END();
-}
-#endif
-
-
 #define EMAIL_MEETING_REQUEST_FMT   "iiBBs" "sic#Bi" "c#Bi"
 
 INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(email_meeting_request_t *meeting_req, int *stream_len)
index d5ba501..2b37520 100755 (executable)
@@ -477,7 +477,7 @@ INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extensio
 {
        EM_DEBUG_FUNC_BEGIN("extension_string[%s]", extension_string);
        int i = 0, err = EMAIL_ERROR_NONE, result_content_type = TYPEAPPLICATION;
-       char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , NULL};
+       char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , "p7s", "p7m", NULL};
 
        if (!extension_string) {
                EM_DEBUG_EXCEPTION("Invalid Parameter");
@@ -488,11 +488,32 @@ INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extensio
        while(image_extension[i]) {
                EM_DEBUG_LOG("image_extension[%d] [%s]", i, image_extension[i]);
                if(strcasecmp(image_extension[i], extension_string) == 0) {
-                       result_content_type = TYPEIMAGE;
                        break;
                }
                i++;
        }
+       
+       switch (i) {
+       case EXTENSION_JPEG:
+       case EXTENSION_JPG:
+       case EXTENSION_PNG:
+       case EXTENSION_GIF:
+       case EXTENSION_BMP:
+       case EXTENSION_PIC:
+       case EXTENSION_AGIF:
+       case EXTENSION_TIF:
+       case EXTENSION_WBMP:
+               result_content_type = TYPEIMAGE;
+               break;
+       case EXTENSION_P7S:
+               result_content_type = TYPEPKCS7_SIGN;
+               break;
+       case EXTENSION_P7M:
+               result_content_type = TYPEPKCS7_MIME;
+               break;
+       default:
+               break;
+       }
 
 FINISH_OFF:
        if (err_code)
@@ -861,7 +882,6 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
        DBusConnection     *connection;
        DBusMessage        *signal = NULL;
        DBusError           error;
-       const char         *nullString = "";
        int                 i = 0;
 
        dbus_error_init (&error);
@@ -878,42 +898,10 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
                        EM_DEBUG_LOG("handle:[%d]", data->send_mail.handle);
                        EM_DEBUG_LOG("account_id:[%d]", data->send_mail.account_id);
                        EM_DEBUG_LOG("mail_id:[%d]", data->send_mail.mail_id);
-                       EM_DEBUG_LOG("options.priority:[%d]", data->send_mail.options.priority);
-                       EM_DEBUG_LOG("options.keep_local_copy:[%d]", data->send_mail.options.keep_local_copy);
-                       EM_DEBUG_LOG("options.req_delivery_receipt:[%d]", data->send_mail.options.req_delivery_receipt);
-                       EM_DEBUG_LOG("options.req_read_receipt:[%d]", data->send_mail.options.req_read_receipt);
-                       /* download_limit, block_address, block_subject might not be needed */
-                       EM_DEBUG_LOG("options.download_limit:[%d]", data->send_mail.options.download_limit);
-                       EM_DEBUG_LOG("options.block_address:[%d]", data->send_mail.options.block_address);
-                       EM_DEBUG_LOG("options.block_subject:[%d]", data->send_mail.options.block_subject);
-                       EM_DEBUG_LOG("options.display_name_from:[%s]", data->send_mail.options.display_name_from);
-                       EM_DEBUG_LOG("options.reply_with_body:[%d]", data->send_mail.options.reply_with_body);
-                       EM_DEBUG_LOG("options.forward_with_files:[%d]", data->send_mail.options.forward_with_files);
-                       EM_DEBUG_LOG("options.add_myname_card:[%d]", data->send_mail.options.add_myname_card);
-                       EM_DEBUG_LOG("options.add_signature:[%d]", data->send_mail.options.add_signature);
-                       EM_DEBUG_LOG("options.signature:[%s]", data->send_mail.options.signature);
 
                        dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.handle), DBUS_TYPE_INVALID);
                        dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.account_id), DBUS_TYPE_INVALID);
                        dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.mail_id), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.priority), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.keep_local_copy), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_delivery_receipt), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_read_receipt), DBUS_TYPE_INVALID);
-                       if ( data->send_mail.options.display_name_from == NULL )
-                               dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
-                       else
-                               dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.display_name_from), DBUS_TYPE_INVALID);
-
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.reply_with_body), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.forward_with_files), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_myname_card), DBUS_TYPE_INVALID);
-                       dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_signature), DBUS_TYPE_INVALID);
-                       if ( data->send_mail.options.signature == NULL )
-                               dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
-                       else
-                               dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.signature), DBUS_TYPE_INVALID);
-
                        break;
                case ACTIVE_SYNC_NOTI_SEND_SAVED:                               /*  publish a send notification to ASE (active sync engine) */
                        EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_SAVED]", subType);
index 646b711..0488eb4 100755 (executable)
@@ -35,8 +35,8 @@ INTERNAL_FUNC int   em_convert_account_tbl_to_account(emstorage_account_tbl_t *a
 
 
 /* Mail */
-INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_data, int input_mail_data_count, int *stream_size);
-INTERNAL_FUNC void  em_convert_byte_stream_to_mail_data(char *stream, email_mail_data_t **mail_data, int *output_mail_data_count);
+INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_data, int *stream_size);
+INTERNAL_FUNC void  em_convert_byte_stream_to_mail_data(char *stream, int stream_len, email_mail_data_t *mail_data);
 
 INTERNAL_FUNC int   em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_table_data, int item_count, email_mail_data_t **mail_data, int *error);
 INTERNAL_FUNC int   em_convert_mail_data_to_mail_tbl(email_mail_data_t *mail_data, int item_count, emstorage_mail_tbl_t **mail_table_data, int *error);
@@ -65,20 +65,12 @@ INTERNAL_FUNC void em_convert_byte_stream_to_option(char *stream, int stream_len
 INTERNAL_FUNC int   em_convert_string_to_time_t(char *input_datetime_string, time_t *output_time);
 INTERNAL_FUNC int   em_convert_time_t_to_string(time_t *input_time, char **output_datetime_string);
 
-/* email_extra_flag_t */
-INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(email_extra_flag_t new_flag, int* StreamSize);
-INTERNAL_FUNC void  em_convert_byte_stream_to_extra_flags(char* pStream, email_extra_flag_t* new_flag);
-
 /* email_meeting_request_t */
 INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(email_meeting_request_t* meeting_req, int* nStreamSize);
 INTERNAL_FUNC void  em_convert_byte_stream_to_meeting_req(char* stream, int stream_len, email_meeting_request_t* meeting_req);
 
-INTERNAL_FUNC int   em_convert_mail_flag_to_int(email_mail_flag_t flag, int* i_flag, int* err_code);
-INTERNAL_FUNC int   em_convert_mail_int_to_flag(int i_flag, email_mail_flag_t* flag, int* err_code);
 INTERNAL_FUNC int   em_convert_mail_status_to_mail_tbl(int mail_status, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code);
 INTERNAL_FUNC int   em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_tbl_data, int *result_mail_status, int* err_code);
-INTERNAL_FUNC int   em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tbl_data, email_mail_flag_t *result_flag, int* err_code);
-INTERNAL_FUNC int   em_convert_mail_flag_to_mail_tbl(email_mail_flag_t *flag, emstorage_mail_tbl_t *result_mail_tbl_data,  int* err_code);
 
 /* Search filter options */
 INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_stream_size);
old mode 100755 (executable)
new mode 100644 (file)
index 84dffbe..5a3f39a
@@ -40,6 +40,7 @@ extern "C"
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <dlog.h>
 #include <errno.h>
 
index 491c916..2b5fa87 100755 (executable)
 #define EMAIL_ERROR_NETWORK_NOT_AVAILABLE               -1800    /*  WIFI not availble*/
 #define EMAIL_ERROR_CANNOT_STOP_THREAD                  -2000
 #define EMAIL_ERROR_SECURED_STORAGE_FAILURE             -2100    /*  Error from secured storage */
+#define EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE            -3000    /*  Cannot load the certificate */
+#define EMAIL_ERROR_INVALID_CERTIFICATE                 -3001    /*  invalid certificate */
 #define EMAIL_ERROR_UNKNOWN                             -8000    /*  unknown error */
 
 #endif /* __EMAIL_ERRORS_H__ */
index d0116c9..cf81578 100755 (executable)
@@ -45,6 +45,7 @@ extern "C"
 
 /* ----------------------------------------------------------------------------- */
 /*  Feature definitions */
+#define __FEATURE_USING_ACCOUNT_SVC__
 #define __FEATURE_BACKUP_ACCOUNT__
 #define __FEATURE_MOVE_TO_OUTBOX_FIRST__
 /*  #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */
@@ -60,9 +61,12 @@ extern "C"
 #define __FEATURE_DEBUG_LOG__
 #define __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
 #define __FEATURE_XLIST_SUPPORT__
+#define __FEATURE_SUPPORT_REPORT_MAIL__
 /*  #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
 /*  #define __FEATURE_IMAP_IDLE__ */
 
+#define _TIZEN_PUBLIC_ /* __FEATURE_WDS_SUPPORT__ and __FEATURE_NOTIFICATION_FOR_NEW_MAIL__ and MDM_PHASE_2*/
+
 /* ----------------------------------------------------------------------------- */
 /*  Macro */
 #ifndef NULL
@@ -179,6 +183,18 @@ typedef pthread_t thread_t;
 #define VCONF_KEY_LATEST_MAIL_ID        "db/private/email-service/latest_mail_id"
 #define VCONF_KEY_DEFAULT_ACCOUNT_ID    "db/private/email-service/default_account_id"
 
+#define OUTMODE "wb"
+#define INMODE "rb"
+#define READMODE "r"
+
+#define TYPEPKCS7_SIGN 10      
+#define TYPEPKCS7_MIME 11
+
+/* __FEATURE_LOCAL_ACTIVITY__ supported
+#define BULK_OPERATION_COUNT              50
+#define ALL_ACTIVITIES                    0
+*/
+
 /* ----------------------------------------------------------------------------- */
 /*  Type */
 typedef enum
@@ -222,6 +238,21 @@ enum
 } ;
 #endif /* __FEATURE_KEEP_CONNECTION__ */
 
+enum 
+{
+       EXTENSION_JPEG   = 0,
+       EXTENSION_JPG    = 1,
+       EXTENSION_PNG    = 2,
+       EXTENSION_GIF    = 3,
+       EXTENSION_BMP    = 4,
+       EXTENSION_PIC    = 5,
+       EXTENSION_AGIF   = 6,
+       EXTENSION_TIF    = 7,
+       EXTENSION_WBMP   = 8,
+       EXTENSION_P7S    = 9,
+       EXTENSION_P7M    = 10
+};
+
 /*  event information */
 typedef struct 
 {
index 4a56377..af550a5 100755 (executable)
@@ -57,16 +57,16 @@ extern "C"
 /*  Macros                                                                   */
 /*****************************************************************************/
 
-#define MAILBOX_NAME_LENGTH             256
-#define MAX_EMAIL_ADDRESS_LENGTH        320                                    /*  64(user name) + 1(@) + 255(host name */
-#define MAX_DATETIME_STRING_LENGTH      20
-#define MAX_PREVIEW_TEXT_LENGTH         512
-#define STRING_LENGTH_FOR_DISPLAY       100
-#define MEETING_REQ_OBJECT_ID_LENGTH    256
+#define MAILBOX_NAME_LENGTH               256
+#define MAX_EMAIL_ADDRESS_LENGTH          320                                    /*  64(user name) + 1(@) + 255(host name */
+#define MAX_DATETIME_STRING_LENGTH        20
+#define MAX_PREVIEW_TEXT_LENGTH           512
+#define STRING_LENGTH_FOR_DISPLAY         100
+#define MEETING_REQ_OBJECT_ID_LENGTH      256
 
-#define ALL_ACCOUNT                     0
-#define NEW_ACCOUNT_ID                  0xFFFFFFFE
-#define ALL_MAIL                        -1
+#define ALL_ACCOUNT                       0
+#define NEW_ACCOUNT_ID                    0xFFFFFFFE
+#define ALL_MAIL                          -1
 
 #define EMAIL_SEARCH_FILTER_NONE          0x00
 #define EMAIL_SEARCH_FILTER_SUBJECT       0x01
@@ -74,7 +74,7 @@ extern "C"
 #define EMAIL_SEARCH_FILTER_RECIPIENT     0x04
 #define EMAIL_SEARCH_FILTER_ALL           0x07                                   /*  EMAIL_SEARCH_FILTER_SUBJECT + EMAIL_SEARCH_FILTER_SENDER + EMAIL_SEARCH_FILTER_RECIPIEN */
 
-#define EMAIL_SUCCESS                     0                                      /*  we need to modify the success return valu */
+#define EMAIL_SUCCESS                     0                                      /*  we need to modify the success return value */
 
 #define EMAIL_ACC_GET_OPT_DEFAULT         0x01                                   /**< Default values without account name */
 #define EMAIL_ACC_GET_OPT_ACCOUNT_NAME    0x02                                   /**< Account name */
@@ -82,13 +82,13 @@ extern "C"
 #define EMAIL_ACC_GET_OPT_OPTIONS         0x08                                   /**< Account options : email_option_t */
 #define EMAIL_ACC_GET_OPT_FULL_DATA       0xFF                                   /**< With all data of account */
 
-#define GET_FULL_DATA                   (EMAIL_ACC_GET_OPT_FULL_DATA)
-#define GET_FULL_DATA_WITHOUT_PASSWORD  (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME | EMAIL_ACC_GET_OPT_OPTIONS )
-#define WITHOUT_OPTION                  (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME )
-#define ONLY_OPTION                     (EMAIL_ACC_GET_OPT_OPTIONS)
+#define GET_FULL_DATA                     (EMAIL_ACC_GET_OPT_FULL_DATA)
+#define GET_FULL_DATA_WITHOUT_PASSWORD    (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME | EMAIL_ACC_GET_OPT_OPTIONS )
+#define WITHOUT_OPTION                    (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME )
+#define ONLY_OPTION                       (EMAIL_ACC_GET_OPT_OPTIONS)
 
-#define THREAD_TYPE_RECEIVING           0                                      /**< for function 'email_activate_pdp' */
-#define THREAD_TYPE_SENDING             1                                      /**< for function 'email_activate_pdp' */
+#define THREAD_TYPE_RECEIVING             0                                      /**< for function 'email_activate_pdp' */
+#define THREAD_TYPE_SENDING               1                                      /**< for function 'email_activate_pdp' */
 
 #define EMAIL_IMAP_PORT                   143                                    /**< Specifies the default IMAP port.*/
 #define EMAIL_POP3_PORT                   110                                    /**< Specifies the default POP3 port.*/
@@ -114,29 +114,24 @@ extern "C"
 
 #define EMAIL_SEARCH_RESULT_MAILBOX_NAME  "_`S1!E2@A3#R4$C5^H6&R7*E8(S9)U0-L=T_" /**< Specifies the name of search result mailbox.*/
 
-#define SYNC_STATUS_FINISHED            0                                      /* BIN 00000000 */
-#define SYNC_STATUS_SYNCING             1                                      /* BIN 00000001 */
-#define SYNC_STATUS_HAVE_NEW_MAILS      2                                      /* BIN 00000010 */
+#define SYNC_STATUS_FINISHED              0                                      /* BIN 00000000 */
+#define SYNC_STATUS_SYNCING               1                                      /* BIN 00000001 */
+#define SYNC_STATUS_HAVE_NEW_MAILS        2                                      /* BIN 00000010 */
 
 
-#define FAILURE                         -1
-#define SUCCESS                         0
+#define FAILURE                           -1
+#define SUCCESS                           0
 
-#define DAEMON_EXECUTABLE_PATH          "/usr/bin/email-service"
+#define DAEMON_EXECUTABLE_PATH            "/usr/bin/email-service"
 
 #ifndef EXPORT_API
-#define EXPORT_API                      __attribute__((visibility("default")))
+#define EXPORT_API                        __attribute__((visibility("default")))
 #endif
 
 #ifndef DEPRECATED
-#define DEPRECATED                      __attribute__((deprecated))
+#define DEPRECATED                        __attribute__((deprecated))
 #endif
 
-/* __FEATURE_LOCAL_ACTIVITY__ supported
-#define BULK_OPERATION_COUNT            50
-#define ALL_ACTIVITIES                  0
-*/
-
 /*****************************************************************************/
 /*  Enumerations                                                             */
 /*****************************************************************************/
@@ -181,10 +176,10 @@ enum {
        /* Mailbox */
        _EMAIL_API_ADD_MAILBOX                             = 0x01200000,
        _EMAIL_API_DELETE_MAILBOX                          = 0x01200001,
-       _EMAIL_API_UPDATE_MAILBOX                          = 0x01200002,
        _EMAIL_API_SET_MAIL_SLOT_SIZE                      = 0x01200007,
        _EMAIL_API_RENAME_MAILBOX                          = 0x01200008,
        _EMAIL_API_SET_MAILBOX_TYPE                        = 0x01200009,
+       _EMAIL_API_SET_LOCAL_MAILBOX                       = 0x0120000A,
 
        /* Network */
        _EMAIL_API_SEND_MAIL                               = 0x01300000,
@@ -218,6 +213,7 @@ enum {
        _EMAIL_API_PING_SERVICE                            = 0x01500000,
        _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL = 0x01500001,
        _EMAIL_API_SHOW_USER_MESSAGE                       = 0x01500002,
+       _EMAIL_API_WRITE_MIME_FILE                         = 0x01500003,
 
        /* Smime */
        _EMAIL_API_ADD_CERTIFICATE                         = 0x01600000,
@@ -228,10 +224,11 @@ enum {
 
 typedef enum
 {
-       EMAIL_DELETE_LOCALLY = 0,                      /**< Specifies Mail Delete local only */
+       EMAIL_DELETE_LOCALLY                     = 0,  /**< Specifies Mail Delete local only */
        EMAIL_DELETE_LOCAL_AND_SERVER,                 /**< Specifies Mail Delete local & server */
        EMAIL_DELETE_FOR_SEND_THREAD,                  /**< Created to check which activity to delete in send thread */
        EMAIL_DELETE_FROM_SERVER,
+       EMAIL_DELETE_MAIL_AND_MEETING_FOR_EAS,         /**< Delete mails and meetings on an EAS account. */
 } email_delete_option_t;
 
 typedef enum
@@ -444,10 +441,12 @@ typedef enum
  */
 typedef enum
 {
-       EMAIL_MAIL_REPORT_NONE           = 0,          /**< The mail isn't report mail.*/
-       EMAIL_MAIL_REPORT_DSN,                         /**< The mail is a delivery-status report mail.*/
-       EMAIL_MAIL_REPORT_MDN,                         /**< The mail is a read-status report mail.*/
-       EMAIL_MAIL_REPORT_REQUEST,                     /**< The mail require a read-status report mail.*/
+       EMAIL_MAIL_REPORT_NONE           = 0x00,       /**< The mail isn't report mail.*/
+       EMAIL_MAIL_REPORT_REQUEST        = 0x03,       /* Deprecated */
+       EMAIL_MAIL_REPORT_DSN            = 0x04,       /**< The mail is a Delivery Status Notifications mail.*/
+       EMAIL_MAIL_REPORT_MDN            = 0x08,       /**< The mail is a Message Disposition Notifications mail.*/
+       EMAIL_MAIL_REQUEST_DSN           = 0x10,       /**< The mail requires Delivery Status Notifications.*/
+       EMAIL_MAIL_REQUEST_MDN           = 0x20,       /**< The mail requires Message Disposition Notifications.*/
 } email_mail_report_t;
 
 /**
@@ -462,7 +461,7 @@ typedef enum
 } email_attachment_drm_t;
 
 /**
- * This enumeration specifies the meeting request type
+ * This enumeration specifies the mail type
  */
 typedef enum
 {
@@ -946,8 +945,8 @@ typedef enum {
        EMAIL_FLAG_NONE                  = 0,
        EMAIL_FLAG_FLAGED                = 1,
        EMAIL_FLAG_TASK_STATUS_CLEAR     = 2,
-       EMAIL_FLAG_TASK_STATUS_ACTIVE    = 3,
-       EMAIL_FLAG_TASK_STATUS_COMPLETE  = 4,
+       EMAIL_FLAG_TASK_STATUS_COMPLETE  = 3,
+       EMAIL_FLAG_TASK_STATUS_ACTIVE    = 4,
 } email_flagged_type;
 
 typedef enum {
@@ -1005,35 +1004,36 @@ typedef enum {
        EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME     =  8,  /* string type */
        EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID          =  9,  /* string type */
        EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID              = 10,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_FROM                    = 11,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_TO                      = 12,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_CC                      = 13,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_BCC                     = 14,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS    = 15,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN         = 16,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML          = 17,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_FILE_SIZE               = 18,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD        = 19,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD     = 20,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD     = 21,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD    = 22,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD      = 23,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD       = 24,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD   = 25,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_DRM_STATUS              = 26,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_PRIORITY                = 27,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS             = 28,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS             = 29,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS           = 30,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT        = 31,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT    = 32,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_THREAD_ID               = 33,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT       = 34,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT            = 35,  /* string type */
-       EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS  = 36,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS           = 37,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE             = 38,  /* integer type */
-       EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE              = 39,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID       = 11,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FROM                    = 12,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_TO                      = 13,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_CC                      = 14,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_BCC                     = 15,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS    = 16,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN         = 17,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML          = 18,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_FILE_SIZE               = 19,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD        = 20,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD     = 21,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD     = 22,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD    = 23,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD      = 24,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD       = 25,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD   = 26,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_DRM_STATUS              = 27,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_PRIORITY                = 28,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS             = 29,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS             = 30,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS           = 31,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT        = 32,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT    = 33,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_THREAD_ID               = 34,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT       = 35,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT            = 36,  /* string type */
+       EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS  = 37,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS           = 38,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE             = 39,  /* integer type */
+       EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE              = 40,  /* integer type */
        EMAIL_MAIL_ATTRIBUTE_END                         
 } email_mail_attribute_type;
 
@@ -1063,10 +1063,13 @@ typedef enum {
        EMAIL_MESSAGE_CLASS_SHARING,
        EMAIL_MESSAGE_CLASS_NOTE_EXCHANGE_ACTIVE_SYNC_REMOTE_WIPE_CONFIRMATION,
        EMAIL_MESSAGE_CLASS_VOICE_MAIL,
-       EMAIL_MESSAGE_CLASS_REPORT_DELIVERY_RECEIPT                                 = 0x80000000,
-       EMAIL_MESSAGE_CLASS_REPORT_NON_DELIVERY_RECEIPT                             = 0x40000000,
-       EMAIL_MESSAGE_CLASS_REPORT_READ_REPORT                                      = 0x20000000,
-    EMAIL_MESSAGE_CLASS_REPORT_NOT_READ_REPORT                                  = 0x10000000
+       EMAIL_MESSAGE_CLASS_SMS,
+       EMAIL_MESSAGE_CLASS_SMART_REPLY                                         = 0x01000000,
+       EMAIL_MESSAGE_CLASS_SMART_FORWARD                                       = 0x02000000,
+       EMAIL_MESSAGE_CLASS_REPORT_NOT_READ_REPORT                              = 0x10000000,
+       EMAIL_MESSAGE_CLASS_REPORT_READ_REPORT                                  = 0x20000000,
+       EMAIL_MESSAGE_CLASS_REPORT_NON_DELIVERY_RECEIPT                         = 0x40000000,
+       EMAIL_MESSAGE_CLASS_REPORT_DELIVERY_RECEIPT                             = 0x80000000,
 } email_message_class; 
 
 typedef enum{
@@ -1251,20 +1254,21 @@ typedef struct
        char                 *server_mailbox_name;     /**< Specifies the server mailbox.*/
        char                 *server_mail_id;          /**< Specifies the Server Mail ID.*/
        char                 *message_id;              /**< Specifies the message id */
-       char                 *full_address_from;       /**< Specifies the From Addr.*/
-       char                 *full_address_reply;      /**< Specifies the Reply to addr */
-       char                 *full_address_to;         /**< Specifies the To addr.*/
-       char                 *full_address_cc;         /**< Specifies the CC addr.*/
-       char                 *full_address_bcc;        /**< Specifies the BCC addr*/
+       int                   reference_mail_id;       /**< Specifies the reference mail id */
+       char                 *full_address_from;       /**< Specifies the From address.*/
+       char                 *full_address_reply;      /**< Specifies the Reply to address */
+       char                 *full_address_to;         /**< Specifies the To address.*/
+       char                 *full_address_cc;         /**< Specifies the CC address.*/
+       char                 *full_address_bcc;        /**< Specifies the BCC address*/
        char                 *full_address_return;     /**< Specifies the return Path*/
        char                 *email_address_sender;    /**< Specifies the email address of sender.*/
        char                 *email_address_recipient; /**< Specifies the email address of recipients.*/
        char                 *alias_sender;            /**< Specifies the alias of sender. */
        char                 *alias_recipient;         /**< Specifies the alias of recipients. */
-       int                   body_download_status;    /**< Specifies the Text donwloaded or not.*/
+       int                   body_download_status;    /**< Specifies the Text downloaded or not.*/
        char                 *file_path_plain;         /**< Specifies the path of text mail body.*/
        char                 *file_path_html;          /**< Specifies the path of HTML mail body.*/
-       char                 *file_path_mime_entity;   /**< Specifies the path of mime entity. */
+       char                 *file_path_mime_entity;   /**< Specifies the path of MIME entity. */
        int                   mail_size;               /**< Specifies the Mail Size.*/
        char                  flags_seen_field;        /**< Specifies the seen flags*/
        char                  flags_deleted_field;     /**< Specifies the deleted flags*/
@@ -1274,19 +1278,19 @@ typedef struct
        char                  flags_draft_field;       /**< Specifies the draft flags*/
        char                  flags_forwarded_field;   /**< Specifies the forwarded flags*/
        int                   DRM_status;              /**< Has the mail DRM content? (1 : true, 0 : false) */
-       email_mail_priority_t priority;                /**< Specifies the priority of the mail.*/
-       int                   save_status;             /**< Specifies the save status*/
-       int                   lock_status;             /**< Specifies the Locked*/
-       int                   report_status;           /**< Specifies the Mail Report.*/
+       email_mail_priority_t priority;                /**< Specifies the priority of the mail.*/ /* email_mail_priority_t */
+       email_mail_status_t   save_status;             /**< Specifies the save status*/ /* email_mail_status_t */
+       int                   lock_status;             /**< Specifies the mail is locked*/
+       email_mail_report_t   report_status;           /**< Specifies the Mail Report.*/ /* email_mail_report_t */
        int                   attachment_count;        /**< Specifies the attachment count. */
        int                   inline_content_count;    /**< Specifies the inline content count. */
        int                   thread_id;               /**< Specifies the thread id for thread view. */
        int                   thread_item_count;       /**< Specifies the item count of specific thread. */
        char                 *preview_text;            /**< Specifies the preview body. */
-       int                   meeting_request_status;  /**< Specifies the status of meeting request. */
-       email_message_class   message_class;
-       email_digest_type     digest_type;             /**< Sepeifies the digest algorithm*/
-       email_smime_type      smime_type;              /**< Specifies the smime type. */
+       email_mail_type_t     meeting_request_status;  /**< Specifies the status of meeting request. */ /* email_mail_type_t */
+       int                   message_class;           /**< Specifies the class of message for EAS. */ /* email_message_class */
+       email_digest_type     digest_type;             /**< Specifies the digest algorithm*/ /* email_digest_type */
+       email_smime_type      smime_type;              /**< Specifies the SMIME type. */ /* email_smime_type */
 } email_mail_data_t;
 
 /**
@@ -1294,35 +1298,35 @@ typedef struct
  */
 typedef struct
 {
-       int    mail_id;                                          /**< Specifies the mail id.*/
-       int    account_id;                                       /**< Specifies the account id.*/
-       int    mailbox_id;                                       /**< Specifies the mailbox id.*/
-       char   from[STRING_LENGTH_FOR_DISPLAY];                  /**< Specifies the from display name.*/
-       char   from_email_address[MAX_EMAIL_ADDRESS_LENGTH];     /**< Specifies the from email address.*/
-       char   recipients[STRING_LENGTH_FOR_DISPLAY];            /**< Specifies the recipients display name.*/
-       char   subject[STRING_LENGTH_FOR_DISPLAY];               /**< Specifies the subject.*/
-       int    is_text_downloaded;                               /**< Specifies the text donwloaded or not.*/
-       time_t date_time;                                        /**< Specifies the date time.*/
-       char   flags_seen_field;                                 /**< Specifies the seen flags*/
-       char   flags_deleted_field;                              /**< Specifies the deleted flags*/
-       char   flags_flagged_field;                              /**< Specifies the flagged flags*/
-       char   flags_answered_field;                             /**< Specifies the answered flags*/
-       char   flags_recent_field;                               /**< Specifies the recent flags*/
-       char   flags_draft_field;                                /**< Specifies the draft flags*/
-       char   flags_forwarded_field;                            /**< Specifies the forwarded flags*/
-       int    priority;                                         /**< Specifies the priority of Mails.*/
-       int    save_status;                                      /**< Specifies the save status*/
-       int    is_locked;                                        /**< Specifies the locked*/
-       int    is_report_mail;                                   /**< Specifies the mail report.*/
-       int    recipients_count;                                 /**< Specifies the number of to Recipients*/
-       int    has_attachment;                                   /**< the mail has attachments or not[ 0: none, 1: over one] */
-       int    has_drm_attachment;                               /**< the mail has drm attachment or not*/
-       char   previewBodyText[MAX_PREVIEW_TEXT_LENGTH];         /**< text for preview body*/
-       int    thread_id;                                        /**< thread id for thread view*/
-       int    thread_item_count;                                /**< item count of specific thread */
-       int    is_meeting_request;                               /**< Whether the mail is a meeting request or not */
-       int    message_class;                                    /**< Specifies the message class */
-       int    smime_type;                                       /**< Specifies the smime type */
+       int                   mail_id;                                            /**< Specifies the mail id.*/
+       int                   account_id;                                         /**< Specifies the account id.*/
+       int                   mailbox_id;                                         /**< Specifies the mailbox id.*/
+       char                  full_address_from[STRING_LENGTH_FOR_DISPLAY];       /**< Specifies the from display name.*/
+       char                  email_address_sender[MAX_EMAIL_ADDRESS_LENGTH];     /**< Specifies the sender email address.*/
+       char                  email_address_recipient[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the recipients display name.*/
+       char                  subject[STRING_LENGTH_FOR_DISPLAY];                 /**< Specifies the subject.*/
+       int                   body_download_status;                               /**< Specifies the text donwloaded or not.*/
+       time_t                date_time;                                          /**< Specifies the date time.*/
+       char                  flags_seen_field;                                   /**< Specifies the seen flags*/
+       char                  flags_deleted_field;                                /**< Specifies the deleted flags*/
+       char                  flags_flagged_field;                                /**< Specifies the flagged flags*/
+       char                  flags_answered_field;                               /**< Specifies the answered flags*/
+       char                  flags_recent_field;                                 /**< Specifies the recent flags*/
+       char                  flags_draft_field;                                  /**< Specifies the draft flags*/
+       char                  flags_forwarded_field;                              /**< Specifies the forwarded flags*/
+       int                   DRM_status;                                         /**< Has the mail DRM content? (1 : true, 0 : false) */
+       email_mail_priority_t priority;                                           /**< Specifies the priority of Mails.*/ /* email_mail_priority_t*/
+       email_mail_status_t   save_status;                                        /**< Specifies the save status*/ /* email_mail_status_t */
+       int                   lock_status;                                        /**< Specifies the locked*/
+       email_mail_report_t   report_status;                                      /**< Specifies the mail report.*/ /* email_mail_report_t */
+       int                   attachment_count;                                   /**< Specifies the attachment count. */
+       int                   inline_content_count;                               /**< Specifies the inline content count. */
+       char                  preview_text[MAX_PREVIEW_TEXT_LENGTH];              /**< text for preview body*/
+       int                   thread_id;                                          /**< thread id for thread view*/
+       int                   thread_item_count;                                  /**< item count of specific thread */
+       email_mail_type_t     meeting_request_status;                             /**< Whether the mail is a meeting request or not */ /* email_mail_type_t */
+       int                   message_class;                                      /**< Specifies the message class */ /* email_message_class */
+       email_smime_type      smime_type;                                         /**< Specifies the smime type */ /* email_smime_type */
 } email_mail_list_item_t;
 
 /**
@@ -1351,7 +1355,7 @@ typedef struct
        unsigned int  answered       : 1; /**< Reserved.*/
        unsigned int  recent         : 1; /**< Reserved.*/
        unsigned int  draft          : 1; /**< Specifies the draft email.*/
-       unsigned int  has_attachment : 1; /**< Reserved.*/
+       unsigned int  attachment_count : 1; /**< Reserved.*/
        unsigned int  forwarded      : 1; /**< Reserved.*/
        unsigned int  sticky         : 1; /**< Sticky flagged mails cannot be deleted */
 } email_mail_flag_t /* DEPRECATED */;
@@ -1372,7 +1376,7 @@ typedef struct
        unsigned int  report           : 2; /**< Specifies the MDN/DSN mail. The value is a value of enumeration email_mail_report_t.*/
        unsigned int  drm              : 1; /**< Specifies the drm mail.*/
        unsigned int  text_download_yn : 2; /**< body download y/n*/
-} email_extra_flag_t /* DEPRECATED */;
+} email_extra_flag_t DEPRECATED;
 
 /**
  * This structure is used to save the information of attachment.
@@ -1578,7 +1582,6 @@ typedef union
                int             handle;
                int             account_id;
                int             mail_id;
-               email_option_t  options;
        } send_mail;
 
        struct _send_mail_saved
index 3b38b85..a3183b4 100755 (executable)
@@ -167,7 +167,7 @@ INCLUDE_DIRECTORIES(
 
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf contacts-service secure-storage openssl accounts-svc mm-player mm-session devman_haptic alarm-service notification libcurl libxml-2.0 cert-svc)
+pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf contacts-service secure-storage openssl accounts-svc mm-player mm-session devman_haptic alarm-service notification libcurl libxml-2.0 cert-svc cert-svc-vcore)
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${core_pkgs_CFLAGS})
index 04c84a7..d52c4cc 100755 (executable)
 #include "email-core-mailbox.h"
 #include "email-core-imap-mailbox.h"
 
+#ifdef __FEATURE_USING_ACCOUNT_SVC__
+#include "account.h"
+#endif /*  __FEATURE_USING_ACCOUNT_SVC__ */
+
 char *g_default_mbox_alias[MAILBOX_COUNT] =
 {
        EMAIL_INBOX_DISPLAY_NAME,
@@ -320,6 +324,23 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code)
 
 #endif
 
+#ifdef __FEATURE_USING_ACCOUNT_SVC__
+       {
+               int error_code;
+               email_account_t *account_to_be_deleted;
+
+               account_to_be_deleted = emcore_get_account_reference(account_id);
+               if (account_to_be_deleted && account_to_be_deleted->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
+                       EM_DEBUG_LOG("Calling account_svc_delete with account_svc_id[%d]", account_to_be_deleted->account_svc_id);
+                       error_code = account_connect();
+                       EM_DEBUG_LOG("account_connect returns [%d]", error_code);
+                       error_code = account_delete_from_db_by_id(account_to_be_deleted->account_svc_id);
+                       EM_DEBUG_LOG("account_delete_from_db_by_id returns [%d]", error_code);
+                       error_code = account_disconnect();
+                       EM_DEBUG_LOG("account_disconnect returns [%d]", error_code);
+               }
+       }
+#endif
        if (emcore_cancel_all_threads_of_an_account(account_id) < EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("There are some remaining jobs. I couldn't stop them.");
                err = EMAIL_ERROR_CANNOT_STOP_THREAD;
@@ -985,7 +1006,6 @@ FINISH_OFF:
 
 #endif /*  __FEATURE_BACKUP_ACCOUNT_ */
 
-
 INTERNAL_FUNC int emcore_query_server_info(const char* domain_name, email_server_info_t **result_server_info)
 {
        EM_DEBUG_FUNC_BEGIN("domain_name [%s], result_server_info [%p]", domain_name, result_server_info);
@@ -1142,10 +1162,14 @@ INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, ema
 {
        EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_set_operator [%d], input_sync_status [%d]", input_account_id, input_set_operator, input_sync_status);
        int err = EMAIL_ERROR_NONE;
+       emstorage_account_tbl_t *account_tbl_data = NULL;
 
        if (!emstorage_update_sync_status_of_account(input_account_id, input_set_operator, input_sync_status, true, &err))
                EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err);
 
+       if (account_tbl_data)
+               emstorage_free_account(&account_tbl_data, 1, NULL);
+
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
index e685770..7fb3a0b 100644 (file)
 #include <openssl/err.h>
 #include <cert-service.h>
 #include <glib.h>
+#include <cert-svc/ccert.h>
+#include <cert-svc/cstring.h>
+#include <cert-svc/cpkcs12.h>
+#include <cert-svc/cinstance.h>
+#include <cert-svc/cprimitives.h>
 
 #include "email-core-cert.h"
 #include "email-core-mail.h"
+#include "email-core-utils.h"
 #include "email-utilities.h"
 #include "email-storage.h"
 #include "email-debug-log.h"
 #define READ_MODE "r"
 #define WRITE_MODE "w"
 
-#define EMAIL_ERROR_CERTIFICATE_LOAD_FAIL 2300
-#define EMAIL_ERROR_FILE_NOT_OPEN 2301
-#define EMAIL_ERROR_INVALID_CERTIFICATE 2302
-
 #define TRUSTED_USER "trusteduser/email/"
 
 typedef enum {
@@ -131,119 +133,7 @@ static GList *emcore_make_glist_from_string(char *email_address_list)
 
        return email_list;      
 }
-*/
-static int emcore_load_public_of_p7s(CERT_CONTEXT *context, char *public_cert_path, STACK_OF(X509) **certificates, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       
-       int ret = false;
-       int err = EMAIL_ERROR_NONE;
-       int cert_size = 0;
-       unsigned char *cert_string = NULL;
-       PKCS7 *pkcs7 = NULL;
-       BIO *infile = NULL;
-       X509 *cert = NULL;
-       STACK_OF(X509) *certs = NULL;
-       
-       if (public_cert_path == NULL) {
-               EM_DEBUG_EXCEPTION("Invalid parameter");
-               err = EMAIL_ERROR_INVALID_PARAM;
-               goto FINISH_OFF;
-       }
 
-       OpenSSL_add_all_algorithms();
-       
-       /* Open p7s file */
-       infile = BIO_new_file(public_cert_path, READ_MODE);
-       if (infile == NULL) {
-               EM_DEBUG_EXCEPTION("File open failed [%s]", public_cert_path);
-               err = EMAIL_ERROR_FILE_NOT_FOUND;
-               goto FINISH_OFF;
-       }
-
-       /* Load the p7s file */
-       pkcs7 = d2i_PKCS7_bio(infile, NULL);
-       if (pkcs7 == NULL) {
-               EM_DEBUG_EXCEPTION("smime.p7s load failed");
-               err = EMAIL_ERROR_CERTIFICATE_LOAD_FAIL;
-               goto FINISH_OFF;
-       }
-
-       /* Extract the signature in pkcs7 */
-       certs = PKCS7_get0_signers(pkcs7, NULL, 0);
-       if (certs == NULL) {
-               EM_DEBUG_EXCEPTION("smime.p7s extract failed");
-               err = EMAIL_ERROR_CERTIFICATE_LOAD_FAIL;
-               goto FINISH_OFF;
-       }
-       
-       /* Change from the p7s to the pem file */
-       if (sk_X509_num(certs) > 1) {
-               EM_DEBUG_EXCEPTION("Has one or more signature.\nIt is not support");
-               err = EMAIL_ERROR_UNKNOWN;
-               goto FINISH_OFF;
-       }
-
-       cert = sk_X509_value(certs, 0);
-       cert_size = i2d_X509(cert, &cert_string);
-       if (cert_size < 0) {
-               EM_DEBUG_EXCEPTION("Fail to convert certificate");
-               err = EMAIL_ERROR_UNKNOWN;
-               goto FINISH_OFF;
-       }
-
-       /* Initilize the certificate and CERT_CONTEXT buffer */
-       cert_string = (unsigned char *)em_malloc(sizeof(unsigned char *) * cert_size);
-       if (cert_string == NULL) {
-               EM_DEBUG_EXCEPTION("em_malloc failed");
-               err = EMAIL_ERROR_OUT_OF_MEMORY;
-               goto FINISH_OFF;
-       }
-
-       context->certBuf = (cert_svc_mem_buff *)em_malloc(sizeof(cert_svc_mem_buff));
-       if (context->certBuf == NULL) {
-               EM_DEBUG_EXCEPTION("em_malloc failed");
-               err = EMAIL_ERROR_OUT_OF_MEMORY;
-               goto FINISH_OFF;
-       }
-
-       /* Set CERT_CONTEXT structure */
-       context->certBuf->data = cert_string;
-       context->certBuf->size = cert_size;
-       
-       ret = true;
-
-FINISH_OFF:
-
-       if (infile) 
-               BIO_free(infile);
-       
-       if (pkcs7)
-               PKCS7_free(pkcs7);
-       
-       if (cert)
-               X509_free(cert);
-
-       if (ret) {
-               if (certificates != NULL)
-                       *certificates = certs;
-
-               if (err_code != NULL)
-                       *err_code = err;
-       } else {
-               if (certs)
-                       sk_X509_free(certs);
-
-               EM_SAFE_FREE(cert_string);
-       }
-
-       EVP_cleanup();
-
-       EM_DEBUG_FUNC_END();
-
-       return ret;
-}
-/*
 static char *emcore_store_public_certificate(STACK_OF(X509) *certificates, char *email_address, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
@@ -263,7 +153,7 @@ static char *emcore_store_public_certificate(STACK_OF(X509) *certificates, char
        outfile = BIO_new_file(file_path, WRITE_MODE);
        if (outfile == NULL) {
                EM_DEBUG_EXCEPTION("File open failed[write mode]");
-               err = EMAIL_ERROR_FILE_NOT_OPEN;
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -327,7 +217,122 @@ FINISH_OFF:
 
        return ret;     
 }
+#if 0
+INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("certificate : [%s]", certificate);
+       int err = EMAIL_ERROR_NONE;
+       int ret = false;
+       int key_size = 0;
+       char *private_key = NULL;
+
+       /* Variable for certificate */
+       X509 *t_cert = NULL;
+//     STACK_OF(X509) *t_ca = NULL;
+       
+       /* Variable for private key */
+       EVP_PKEY *t_pri_key = NULL;
+       PKCS8_PRIV_KEY_INFO *p8inf = NULL;
+       const unsigned char *cu_private_key = NULL;
+       
+       CertSvcString csstring;
+       CertSvcInstance cert_instance;
+       CertSvcCertificate csc_cert;
+       CertSvcCertificateList certificate_list;
+
+       if (certificate == NULL) {
+               EM_DEBUG_EXCEPTION("Invalid parameter");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       /* Create instance */
+       err = certsvc_instance_new(&cert_instance);
+       if (err != CERTSVC_SUCCESS) {
+               EM_DEBUG_EXCEPTION("certsvc_instance_new failed : [%d]", err);
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       /* Make the pfxID string */
+       err = certsvc_string_new(cert_instance, certificate, strlen(certificate), &csstring);
+       if (err != CERTSVC_SUCCESS) {
+               EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err);
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       /* Load the certificate list of pkcs12 type */
+       err = certsvc_pkcs12_load_certificate_list(cert_instance, csstring, &certificate_list);
+       if (err != CERTSVC_SUCCESS) {
+               EM_DEBUG_EXCEPTION("certsvc_pkcs12_load_certificate_list failed : [%d]", err);
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       /* Get a certificate */
+       err = certsvc_certificate_list_get_one(certificate_list, 0, &csc_cert);
+       if (err != CERTSVC_SUCCESS) {
+               EM_DEBUG_EXCEPTION("certsvc_certificate_list_get_one failed : [%d]", err);
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       /* Convert from char to X509 */
+       err = certsvc_certificate_dup_x509(csc_cert, &t_cert);
+       if (t_cert == NULL || err != CERTSVC_SUCCESS) {
+               EM_DEBUG_EXCEPTION("certsvc_certificate_dup_x509 failed");
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       /* Get the private key */
+       err = certsvc_pkcs12_private_key_dup(cert_instance, csstring, &private_key, &key_size);
+       if (err != CERTSVC_SUCCESS) {
+               EM_DEBUG_EXCEPTION("certsvc_pkcs12_private_key_dup failed : [%d]", err);
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       EM_DEBUG_LOG("private_key : [%s], key_size : [%d]", private_key, key_size);
+
+       /* Convert char to pkey */
+       cu_private_key = (const unsigned char *)private_key;
+       p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &cu_private_key, key_size);
+       if (p8inf == NULL) {
+               EM_DEBUG_EXCEPTION("d2i_PKCS8_PRIV_KEY_INFO failed");
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+               goto FINISH_OFF;
+       }
+       t_pri_key = EVP_PKCS82PKEY(p8inf);
+
+       ret = true;
+       
+FINISH_OFF:
+
+       if (true) {
+               if (cert)
+                       *cert = t_cert;
+
+               if (pri_key)
+                       *pri_key = t_pri_key;
+       } else {
+               X509_free(t_cert);
+               EVP_PKEY_free(t_pri_key);
+       }
+
+       if (p8inf)
+               PKCS8_PRIV_KEY_INFO_free(p8inf);
+
+       if (private_key)
+               EM_SAFE_FREE(private_key);
+
+       if (err_code)
+               *err_code = err;
 
+       return ret;
+}
+#endif
 INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *save_name, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("Path [%s], filename [%s]", public_cert_path, save_name);
@@ -507,102 +512,72 @@ FINISH_OFF:
 
 INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity, int *validity, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("path[%s], mime_entiy[%s]", p7s_file_path, mime_entity);
+       EM_DEBUG_FUNC_BEGIN("path : [%s], mime_entity : [%s]", p7s_file_path, mime_entity);
        int ret = false;
        int err = EMAIL_ERROR_NONE;
-       int i = 0, j = 0;
+       int t_validity = 0;
+       int flags = PKCS7_NOVERIFY;
 
-       int p_validity = 0;
-       int msg_len = 0;
-       unsigned char *msg = NULL;
-       int sig_len = 0;
-       unsigned char *sig = NULL;
-       unsigned char *tmp_sig = NULL;
-       FILE *fp_msg = NULL;
-       FILE *fp_sig = NULL;
-       size_t f_size = 0;
+       BIO *bio_p7s = NULL;
 
-       CERT_CONTEXT *context = NULL;
+       BIO *bio_indata = NULL;
 
-       context = cert_svc_cert_context_init();
+       PKCS7 *pkcs7_p7s = NULL;
 
-       if (!emcore_load_public_of_p7s(context, p7s_file_path, NULL, &err)) {
-               EM_DEBUG_EXCEPTION("emcore_load_public_of_p7s failed");
-               goto FINISH_OFF;
-       }
+       /* Initialize */
+       OpenSSL_add_all_algorithms();
 
-       fp_msg = fopen(mime_entity, "rb");
-       fseek(fp_msg, 0L, SEEK_END);
-       msg_len = ftell(fp_msg);
-       fseek(fp_msg, 0L, SEEK_SET);
-       msg = (unsigned char *)em_malloc(sizeof(unsigned char) * (msg_len + 1));
-       if (msg == NULL) {
-               EM_DEBUG_EXCEPTION("em_malloc failed");
-               err = EMAIL_ERROR_OUT_OF_MEMORY;
+       /* Open p7s file */
+       bio_p7s = BIO_new_file(p7s_file_path, INMODE);
+       if (!bio_p7s) {
+               EM_DEBUG_EXCEPTION("File open failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
-       if ((f_size = fread(msg, sizeof(unsigned char), msg_len, fp_msg)) < 0) {
-               EM_DEBUG_EXCEPTION("File read failed");
-               goto FINISH_OFF;                
-       }
-
-       fp_sig = fopen(p7s_file_path, "rb");
-       fseek(fp_sig, 0L, SEEK_END);
-       sig_len = ftell(fp_sig);
-       fseek(fp_sig, 0L, SEEK_SET);
-       sig = (unsigned char *)em_malloc(sizeof(unsigned char) * (sig_len + 1));
-       if (sig == NULL) {
-               EM_DEBUG_EXCEPTION("em_malloc failed");
-               err = EMAIL_ERROR_OUT_OF_MEMORY;
-               goto FINISH_OFF;
-       }
-       tmp_sig = (unsigned char *)em_malloc(sizeof(unsigned char) * (sig_len + 1));
-       if (tmp_sig == NULL) {
-               EM_DEBUG_EXCEPTION("em_malloc failed");
-               err = EMAIL_ERROR_OUT_OF_MEMORY;
+       /* Open input data file */
+       bio_indata = BIO_new_file(mime_entity, INMODE);
+       if (!bio_p7s) {
+               EM_DEBUG_EXCEPTION("File open failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
-       if ((f_size = fread(sig, sizeof(unsigned char), sig_len, fp_sig)) < 0) {
-               EM_DEBUG_EXCEPTION("File read failed");
+       /* Load the p7s file */
+       pkcs7_p7s = d2i_PKCS7_bio(bio_p7s, NULL);
+       if (!pkcs7_p7s) {
+               EM_DEBUG_EXCEPTION("d2i_PKCS7_bio failed");
+               err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
                goto FINISH_OFF;
        }
 
-       for(i = 0; i < sig_len; i++) {
-               if(sig[i] != '\n') {
-                       tmp_sig[j] = sig[i];
-                       j++;
-               }
-       }
-       
-       err = cert_svc_verify_signature(context, msg, msg_len, tmp_sig, NULL, &p_validity);
-       if (err != CERT_SVC_ERR_NO_ERROR) {
-               EM_DEBUG_EXCEPTION("Verify signature failed");
+       if (!PKCS7_verify(pkcs7_p7s, NULL, NULL, bio_indata, NULL, flags)) {
+               EM_DEBUG_EXCEPTION("PKCS7_verify failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
+       t_validity = 1;
+
        ret = true;
 
 FINISH_OFF:
 
-       EM_SAFE_FREE(tmp_sig);
+       EVP_cleanup();
 
-       EM_SAFE_FREE(sig);
+       if (pkcs7_p7s)
+               PKCS7_free(pkcs7_p7s);
 
-       EM_SAFE_FREE(msg);
+       if (bio_p7s)
+               BIO_free(bio_p7s);
 
-       if (fp_sig != NULL)
-               fclose(fp_sig);
-       
-       if (fp_msg != NULL)
-               fclose(fp_msg);
+       if (bio_indata)
+               BIO_free(bio_indata);
 
-       cert_svc_cert_context_final(context);
+       if (validity)
+               *validity = t_validity;
 
-       
-
-       if (err_code != NULL)
+       if (err_code)
                *err_code = err;
 
        EM_DEBUG_FUNC_END();
index e3b13f4..4ad920b 100755 (executable)
@@ -1002,7 +1002,6 @@ void* thread_func_branch_command_for_sending_mails(void *arg)
                        EM_DEBUG_LOG(">>>>>>>>>>>>>>Got SEND event_data>>>>>>>>>>>>>>>>");
                        send_thread_run = 1;
                        g_client_run = 1;
-                       email_option_t *option = NULL;
 
                        if (!emnetwork_check_network_status( &err))  {
                                EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);
@@ -1017,104 +1016,94 @@ void* thread_func_branch_command_for_sending_mails(void *arg)
                                
                                case EMAIL_EVENT_SEND_MAIL: 
                                        emdevice_set_dimming_on_off(false, NULL);
-                                       option = (email_option_t *)event_data.event_param_data_1;
                                        
-                                       if (!emcore_send_mail(event_data.account_id, event_data.event_param_data_5, event_data.event_param_data_4, option, &err))
+                                       if (!emcore_send_mail(event_data.account_id, event_data.event_param_data_5, event_data.event_param_data_4, &err))
                                                EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", err);
                                        
-                                       if (option)
-                                               EM_SAFE_FREE(option->display_name_from);
                                        emdevice_set_dimming_on_off(true, NULL);
                                        break;
                                        
-                               case EMAIL_EVENT_SEND_MAIL_SAVED:  /* send mails to been saved in offline-mode */
+                               case EMAIL_EVENT_SEND_MAIL_SAVED:  /* send mails to been saved in off-line mode */
                                        emdevice_set_dimming_on_off(false, NULL);
-                                       
-                                       email_option_t *option = (email_option_t *)event_data.event_param_data_1;
                                                
-                                       if (!emcore_send_saved_mail(event_data.account_id, event_data.event_param_data_3, option, &err))
+                                       if (!emcore_send_saved_mail(event_data.account_id, event_data.event_param_data_3, &err))
                                                EM_DEBUG_EXCEPTION("emcore_send_saved_mail failed - %d", err);
-                                       
-                                       if (option)
-                                               EM_SAFE_FREE(option->display_name_from);
                                                                                
                                        emdevice_set_dimming_on_off(true, NULL);
                                        break;
+
 #ifdef __FEATURE_LOCAL_ACTIVITY__
                                        
-                                       case EMAIL_EVENT_LOCAL_ACTIVITY: {
-                                               emdevice_set_dimming_on_off(false, NULL);
-                                               emstorage_activity_tbl_t *local_activity = NULL;
-                                               int activity_id_count = 0;
-                                               int activity_chunk_count = 0;
-                                               int *activity_id_list = NULL;
-                                               int i = 0;
-
-                                               if (false == emstorage_get_activity_id_list(event_data.account_id, &activity_id_list, &activity_id_count, ACTIVITY_SAVEMAIL, ACTIVITY_DELETEMAIL_SEND, true, &err)) {
-                                                       EM_DEBUG_EXCEPTION("emstorage_get_activity_id_list failed [%d]", err);
-                                               }
-                                               else {  
-                                                       for (i = 0; i < activity_id_count; ++i) {
-                                                               if ((false == emstorage_get_activity(event_data.account_id, activity_id_list[i], &local_activity, &activity_chunk_count, true,  &err)) || (NULL == local_activity) || (0 == activity_chunk_count)) {
-                                                                       EM_DEBUG_EXCEPTION(" emstorage_get_activity Failed [ %d] or local_activity is NULL [%p] or activity_chunk_count is 0[%d]", err, local_activity, activity_chunk_count);
-                                                               }
-                                                               else {                                                  
-                                                                       EM_DEBUG_LOG("Found local activity type - %d", local_activity[0].activity_type);
-                                                                       switch (local_activity[0].activity_type) {                                                                      
-                                                                               case ACTIVITY_SAVEMAIL:  {
-                                                                                       if (!emcore_sync_mail_from_client_to_server(event_data.account_id, local_activity[0].mail_id, &err)) {
-                                                                                               EM_DEBUG_EXCEPTION("emcore_sync_mail_from_client_to_server failed - %d ", err);
-                                                                                       }
-                                                                               }
-                                                                               break;
-                                                                               
-                                                                               case ACTIVITY_DELETEMAIL_SEND:                          /* New Activity Type Added for Race Condition and Crash Fix */ {
-                                                                                       if (!emcore_delete_mail(local_activity[0].account_id, 
-                                                                                                                                       &local_activity[0].mail_id, 
-                                                                                                                                       EMAIL_DELETE_FOR_SEND_THREAD, 
-                                                                                                                                       true, 
-                                                                                                                                       EMAIL_DELETED_BY_COMMAND,
-                                                                                                                                       false,
-                                                                                                                                       &err))  {
-                                                                                               EM_DEBUG_LOG("\t emcore_delete_mail failed - %d", err);
-                                                                                       }
+                               case EMAIL_EVENT_LOCAL_ACTIVITY: {
+                                       emdevice_set_dimming_on_off(false, NULL);
+                                       emstorage_activity_tbl_t *local_activity = NULL;
+                                       int activity_id_count = 0;
+                                       int activity_chunk_count = 0;
+                                       int *activity_id_list = NULL;
+                                       int i = 0;
+
+                                       if (false == emstorage_get_activity_id_list(event_data.account_id, &activity_id_list, &activity_id_count, ACTIVITY_SAVEMAIL, ACTIVITY_DELETEMAIL_SEND, true, &err)) {
+                                               EM_DEBUG_EXCEPTION("emstorage_get_activity_id_list failed [%d]", err);
+                                       }
+                                       else {
+                                               for (i = 0; i < activity_id_count; ++i) {
+                                                       if ((false == emstorage_get_activity(event_data.account_id, activity_id_list[i], &local_activity, &activity_chunk_count, true,  &err)) || (NULL == local_activity) || (0 == activity_chunk_count)) {
+                                                               EM_DEBUG_EXCEPTION(" emstorage_get_activity Failed [ %d] or local_activity is NULL [%p] or activity_chunk_count is 0[%d]", err, local_activity, activity_chunk_count);
+                                                       }
+                                                       else {
+                                                               EM_DEBUG_LOG("Found local activity type - %d", local_activity[0].activity_type);
+                                                               switch (local_activity[0].activity_type) {
+                                                                       case ACTIVITY_SAVEMAIL:  {
+                                                                               if (!emcore_sync_mail_from_client_to_server(event_data.account_id, local_activity[0].mail_id, &err)) {
+                                                                                       EM_DEBUG_EXCEPTION("emcore_sync_mail_from_client_to_server failed - %d ", err);
                                                                                }
-                                                                               break;
-                                                                               
-                                                                               default:  {
-                                                                                       EM_DEBUG_LOG(">>>> No such Local Activity Handled by this thread [ %d ] >>> ", local_activity[0].activity_type);
+                                                                       }
+                                                                       break;
+
+                                                                       case ACTIVITY_DELETEMAIL_SEND:                          /* New Activity Type Added for Race Condition and Crash Fix */ {
+                                                                               if (!emcore_delete_mail(local_activity[0].account_id,
+                                                                                                                               &local_activity[0].mail_id,
+                                                                                                                               EMAIL_DELETE_FOR_SEND_THREAD,
+                                                                                                                               true,
+                                                                                                                               EMAIL_DELETED_BY_COMMAND,
+                                                                                                                               false,
+                                                                                                                               &err))  {
+                                                                                       EM_DEBUG_LOG("\t emcore_delete_mail failed - %d", err);
                                                                                }
-                                                                               break;
                                                                        }
+                                                                       break;
                                                                        
-                                                                       emstorage_free_local_activity(&local_activity, activity_chunk_count, NULL);
-                                                                       
-                                                                       if (g_save_local_activity_run == 1) {
-                                                                               EM_DEBUG_LOG(" Network event_data found.. Local sync Stopped..! ");
-                                                                               break;
+                                                                       default:  {
+                                                                               EM_DEBUG_LOG(">>>> No such Local Activity Handled by this thread [ %d ] >>> ", local_activity[0].activity_type);
                                                                        }
+                                                                       break;
                                                                }
                                                                
+                                                               emstorage_free_local_activity(&local_activity, activity_chunk_count, NULL);
+
+                                                               if (g_save_local_activity_run == 1) {
+                                                                       EM_DEBUG_LOG(" Network event_data found.. Local sync Stopped..! ");
+                                                                       break;
+                                                               }
                                                        }
-                                                       if (false == emstorage_free_activity_id_list(activity_id_list, &err)) {
-                                                               EM_DEBUG_LOG("emstorage_free_activity_id_list failed");
-                                                       }
-                                               }
 
-                                               emdevice_set_dimming_on_off(true, NULL);
+                                               }
+                                               if (false == emstorage_free_activity_id_list(activity_id_list, &err)) {
+                                                       EM_DEBUG_LOG("emstorage_free_activity_id_list failed");
+                                               }
                                        }
-                                       break;
+
+                                       emdevice_set_dimming_on_off(true, NULL);
+                               }
+                               break;
 #endif /* __FEATURE_LOCAL_ACTIVITY__ */                                        
                                default:  
-                                       EM_DEBUG_LOG("Others not supported by Send Thread..! ");
+                                       EM_DEBUG_LOG("Others not supported by Send Thread..! [%d]", event_data.type);
                                        break;
-
                        }
                                                
                        ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
-                       
                        memset(g_send_event_que+g_send_active_que, 0x00, sizeof(email_event_t));
-
                        LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
 
 FINISH_OFF: 
@@ -1126,7 +1115,7 @@ FINISH_OFF:
        if (!emstorage_close(&err)) 
                EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err);
 
-       EM_DEBUG_FUNC_END();
+       EM_DEBUG_FUNC_END("err [%d]", err);
        return NULL;
 }
 
@@ -1276,12 +1265,15 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo
                                }
                                
                                for (counter = 0; counter < mailbox_count; counter++) {
+
+                                       EM_DEBUG_LOG("maiblox_name [%s], mailbox_id [%d], mailbox_type [%d]", mailbox_tbl_list[counter].mailbox_name, mailbox_tbl_list[counter].mailbox_id, mailbox_tbl_list[counter].mailbox_type);
+
                                        if ( mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_ALL_EMAILS  
                                                        || mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_TRASH  
                                                /*|| mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX */)
                                                EM_DEBUG_LOG("Skipped for all emails or trash");
                                        else if (!mailbox_tbl_list[counter].local_yn) {
-                                               EM_DEBUG_LOG("..........syncing %s mailbox( mailbox_id = %d)......", mailbox_tbl_list[counter].mailbox_name, mailbox_tbl_list[counter].mailbox_id);
+                                               EM_DEBUG_LOG("[%s] Syncing...", mailbox_tbl_list[counter].mailbox_name);
 #ifdef __FEATURE_KEEP_CONNECTION__
                                                if (!emcore_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, NULL, &uid_list, &unread, &err)) {
 #else /*  __FEATURE_KEEP_CONNECTION__ */
@@ -2082,14 +2074,21 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c
                                        EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>");
                                goto FINISH_OFF;
                        }
-                       
-                       if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &search_mailbox, false, &err))  {
-                               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
+               
+                       search_mailbox = em_malloc(sizeof(emstorage_mailbox_tbl_t));
+                       if (search_mailbox == NULL) {
+                               EM_DEBUG_EXCEPTION("em_malloc failed");
+                               err = EMAIL_ERROR_OUT_OF_MEMORY;
                                if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err))
                                        EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>");
                                goto FINISH_OFF;
                        }
 
+                       search_mailbox->account_id = account_id;
+                       search_mailbox->mailbox_id = mailbox_id;
+                       search_mailbox->mailbox_name = EM_SAFE_STRDUP(EMAIL_SEARCH_RESULT_MAILBOX_NAME);
+                       search_mailbox->mailbox_type = EMAIL_MAILBOX_TYPE_SEARCH_RESULT;
+       
                        if ((err = emcore_add_mail_to_mailbox(search_mailbox, new_mail_tbl_data, &mail_id, &thread_id)) != EMAIL_ERROR_NONE) {
                                EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox failed [%d]", err);
                                if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err))
@@ -2315,7 +2314,7 @@ void* thread_func_branch_command(void *arg)
                                                break;
 
                                        case EMAIL_EVENT_DELETE_MAIL:  /*  delete mails */
-                                               event_handler_EMAIL_EVENT_DELETE_MAIL(event_data.account_id, (int  *)event_data.event_param_data_3, event_data.event_param_data_4, &err);
+                                               event_handler_EMAIL_EVENT_DELETE_MAIL(event_data.account_id, (int*)event_data.event_param_data_3, event_data.event_param_data_4, &err);
                                                EM_SAFE_FREE(event_data.event_param_data_3);
                                                break;
 
index 5ad0936..271cbd4 100755 (executable)
@@ -2805,7 +2805,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in
                                                PARAMETER *param = body->disposition.parameter;
 
                                                while (param)  {
-                                                               EM_DEBUG_LOG("param->attribute [%s], param->value [%s]", param->attribute, param->value);
+                                                       EM_DEBUG_LOG("param->attribute [%s], param->value [%s]", param->attribute, param->value);
 
                                                        if (!strcasecmp(param->attribute, "filename"))  {       /* attribute is "filename" */
                                                                strncpy(filename, param->value, MAX_PATH);
@@ -2831,8 +2831,8 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in
                                }
                                else {
                                        /*  download all */
-                               EM_DEBUG_LOG("%d :  body->size.bytes[%ld]", counter+1, body->size.bytes);
-                               multi_part_body_size = multi_part_body_size + body->size.bytes;
+                                       EM_DEBUG_LOG("%d :  body->size.bytes[%ld]", counter+1, body->size.bytes);
+                                       multi_part_body_size = multi_part_body_size + body->size.bytes;
                                }
                                part_child = part_child->next;
                                counter++;
@@ -3305,9 +3305,6 @@ int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server,
                goto FINISH_OFF;
        }
 
-       if (account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC)
-               from_server = EMAIL_DELETE_LOCALLY;
-
        FINISH_OFF_IF_CANCELED;
 
        if (from_server == EMAIL_DELETE_LOCALLY) /* Delete mails from local storage*/ {
@@ -3449,7 +3446,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_ids[%p], num [%d], noti_param_1 [%d], noti_param_2 [%d], err_code[%p]", account_id, mail_ids, num, noti_param_1, noti_param_2, num, err_code);
        int ret = false, err = EMAIL_ERROR_NONE, i;
-       emstorage_mail_tbl_t *result_mail_list;
+       emstorage_mail_tbl_t *result_mail_list = NULL;
        char mail_id_string[10], *noti_param_string = NULL, buf[512] = {0, };
 
        /* Getting mail list by using select mail_id [in] */
@@ -3548,7 +3545,7 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account,
        int mail_id = 0;
        int msgno = 0;
        void *stream = NULL;
-       email_internal_mailbox_t mailbox_data;
+       email_internal_mailbox_t mailbox_data = { 0, };
        emstorage_mail_tbl_t    *mail_tbl_data = NULL;
        
        if (!input_account || !input_mail_ids) {
@@ -3573,14 +3570,14 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account,
                }
 
                if (stream == NULL)  {
-                       if (!emcore_connect_to_remote_mailbox(input_account->account_id, mail_tbl_data->mailbox_id , (void **)&stream, &err))  {
+                       if (!emcore_connect_to_remote_mailbox(input_account->account_id, 0, (void **)&stream, &err))  {
                                EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
                                goto FINISH_OFF;
                        }
 
                        mailbox_data.mail_stream  = stream;
                        mailbox_data.account_id   = input_account->account_id;
-                       mailbox_data.mailbox_id = mail_tbl_data->mailbox_id;
+                       mailbox_data.mailbox_id   = mail_tbl_data->mailbox_id;
                }
 
                if (mailbox_data.user_data != NULL) {
@@ -3763,6 +3760,7 @@ FINISH_OFF:
        if(filter_list)
                emstorage_free_list_filter(&filter_list, filter_count);
 
+       EM_SAFE_FREE(conditional_clause_string);
        EM_SAFE_FREE(result_mail_id_list);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
@@ -3830,6 +3828,7 @@ FINISH_OFF:
                emstorage_free_list_filter(&filter_list, filter_count);
 
        EM_SAFE_FREE(result_mail_id_list);
+       EM_SAFE_FREE(conditional_clause_string);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
 
@@ -4807,8 +4806,8 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
                        EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err);
                        goto FINISH_OFF2;
                }
-               EM_SAFE_FREE(input_mail_data->file_path_html);
-               input_mail_data->file_path_html = EM_SAFE_STRDUP(filename_buf);
+               EM_SAFE_FREE(input_mail_data->file_path_mime_entity);
+               input_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(filename_buf);
        }
 
        if (input_attachment_data_list && input_attachment_count)  {
@@ -4943,101 +4942,6 @@ FINISH_OFF2:
        return err;
 }
 
-INTERNAL_FUNC int emcore_fetch_flags(int account_id, int mail_id, email_mail_flag_t *mail_flag, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN();
-
-       int ret = false;
-       int err = 0;
-       emstorage_mail_tbl_t *mail = NULL;
-       
-       EM_IF_NULL_RETURN_VALUE(mail_flag, false);
-       if (account_id < FIRST_ACCOUNT_ID || mail_id < 1) {
-               EM_DEBUG_EXCEPTION("emcore_fetch_flags :  Invalid Param ");
-               goto FINISH_OFF;
-       }
-
-       if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail)  {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_id failed - %d ", err);
-
-               goto FINISH_OFF;
-       }
-
-       if (!em_convert_mail_tbl_to_mail_flag(mail, mail_flag, &err))  {
-               EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_int failed - %d ", err);
-               goto FINISH_OFF;
-       }
-
-       ret = true;
-
-FINISH_OFF:
-       if(mail)
-               emstorage_free_mail(&mail, 1, &err);
-
-       if (err_code != NULL)
-               *err_code = err;
-
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return ret;
-}
-/* description :  modify flag of msgno.
-   return 1(success), 0(failure)
-   */
-INTERNAL_FUNC int emcore_modify_flag(int mail_id, email_mail_flag_t new_flag, int sticky_flag, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
-
-       int ret = false;
-       int err = EMAIL_ERROR_NONE;
-       int old_seen, new_seen;
-
-       emstorage_mail_tbl_t *mail = NULL;
-       email_mail_flag_t old_flag;
-
-       if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail)  {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_id failed [%d]", err);
-
-               goto FINISH_OFF;
-       }
-
-       if (!em_convert_mail_tbl_to_mail_flag(mail, &old_flag, &err))  {
-               EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_flag failed [%d]", err);
-               goto  FINISH_OFF;
-       }
-
-       old_seen = mail->flags_seen_field;
-       new_seen = new_flag.seen;
-
-       if (!em_convert_mail_flag_to_mail_tbl(&new_flag, mail, &err))  {
-               EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_mail_tbl failed [%d]", err);
-               goto FINISH_OFF;
-       }
-
-               mail->lock_status = sticky_flag;
-               
-       if (!emstorage_change_mail_field(mail_id, UPDATE_FLAG, mail, true, &err)) {
-                       EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
-               
-
-                       goto FINISH_OFF;
-               }
-
-       if (old_seen != new_seen && new_seen == 0)
-               emcore_delete_notification_for_read_mail(mail_id);
-
-       emcore_check_unread_mail();
-
-       ret = true;
-
-FINISH_OFF:
-       if (mail)
-               emstorage_free_mail(&mail, 1, NULL);
-
-       if (err_code)
-               *err_code = err;
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return ret;
-}
 
 INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code)
 {
@@ -5073,43 +4977,6 @@ FINISH_OFF:
        return ret;
 }
 
-
-/* description :  modify extra flag of msgno.
-   return 0(success), -1(failure)
-   */
-INTERNAL_FUNC int emcore_modify_extra_flag(int mail_id, email_extra_flag_t new_flag, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
-       
-       int ret = false;
-       int err = EMAIL_ERROR_NONE;
-       emstorage_mail_tbl_t mail;
-       
-       memset(&mail, 0x00, sizeof(emstorage_mail_tbl_t));
-
-       mail.mail_id    = mail_id;
-       mail.save_status = new_flag.status;
-       mail.lock_status = new_flag.report;
-       mail.lock_status        = new_flag.lock;
-       mail.priority   = new_flag.priority;
-       mail.DRM_status  = new_flag.drm;
-
-       if (!emstorage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, &mail, false, &err))  {
-               EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
-
-               goto FINISH_OFF;
-       }
-       
-       ret = true;
-
-FINISH_OFF:
-       if (err_code != NULL)
-               *err_code = err;
-       EM_DEBUG_FUNC_END("err [%d]", err);
-       return ret;
-}
-
-
 int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, int *downloded_size, int *result_total_body_size, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("stream[%p], msgno[%d], limited_size[%d], err_code[%p]", stream, msgno, limited_size, err_code);
@@ -5256,7 +5123,6 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code)
        email_account_t *ref_account = NULL;
        int account_id = 0;
        int msgno = 0;
-       email_mail_flag_t new_flag = {0};
        char set_flags[100] = { 0, };
        char clear_flags[100] = { 0, };
        char tmp[100] = { 0, };
@@ -5273,7 +5139,6 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code)
        }
 
        account_id = mail->account_id;
-       em_convert_mail_tbl_to_mail_flag(mail, &new_flag, NULL);
 
        if (!(ref_account = emcore_get_account_reference(account_id)))   {
                EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
@@ -5311,22 +5176,22 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code)
                
        sprintf (tmp, "%d", msgno);
 
-       if (new_flag.seen)
+       if (mail->flags_seen_field)
                sprintf(set_flags, "\\Seen");
        else
                sprintf(clear_flags, "\\Seen");
 
-       if (new_flag.answered)
+       if (mail->flags_answered_field)
                sprintf(set_flags, "%s \\Answered", set_flags);
        else
                sprintf(clear_flags, "%s \\Answered", clear_flags);
                
-       if (new_flag.flagged)
+       if (mail->flags_flagged_field)
                sprintf(set_flags, "%s \\Flagged", set_flags);
        else
                sprintf(clear_flags, "%s \\Flagged", clear_flags);
 
-       if (new_flag.forwarded)
+       if (mail->flags_forwarded_field)
                sprintf(set_flags, "%s $Forwarded", set_flags);
        else
                sprintf(clear_flags, "%s $Forwarded", clear_flags);
@@ -5364,8 +5229,11 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code)
 
 FINISH_OFF: 
        
-       if (stream) emcore_close_mailbox(account_id, stream);
-       if (mail) emstorage_free_mail(&mail, 1, NULL);
+       if (stream)
+               emcore_close_mailbox(account_id, stream);
+
+       if (mail)
+               emstorage_free_mail(&mail, 1, NULL);
 
        if (err_code != NULL)
                *err_code = err;
@@ -5392,7 +5260,6 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int
        email_account_t *ref_account = NULL;
        int account_id = 0;
        int msgno = 0;
-       email_mail_flag_t new_flag;
        char set_flags[100];
        char clear_flags[100];
        char tmp[100];
@@ -5442,9 +5309,6 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int
                        goto FINISH_OFF;
                }
                
-               /* account_id = mail->account_id; */
-               em_convert_mail_tbl_to_mail_flag(mail, &new_flag, NULL);
-               
                if (!emcore_check_thread_status())  {
                        err = EMAIL_ERROR_CANCELLED;
                        goto FINISH_OFF;
@@ -5462,7 +5326,7 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int
                memset(set_flags, 0x00, 100);
                memset(clear_flags, 0x00, 100);
 
-               if (new_flag.seen)
+               if (mail->flags_seen_field)
                        sprintf(set_flags, "\\Seen");
                else
                        sprintf(clear_flags, "\\Seen");
index 3c4e2d8..60f168a 100755 (executable)
@@ -1447,7 +1447,7 @@ int emcore_make_mail_tbl_data_from_envelope(MAILSTREAM *mail_stream, ENVELOPE *i
        temp_mail_tbl_data->flags_draft_field     = mail_cache_element->draft;
        temp_mail_tbl_data->flags_forwarded_field = input_uid_elem->flag.forwarded;
        temp_mail_tbl_data->priority              = priority;
-       temp_mail_tbl_data->report_status         = (req_read_receipt ?  :  0);
+       temp_mail_tbl_data->report_status         = (req_read_receipt ? EMAIL_MAIL_REQUEST_MDN :  0);
        temp_mail_tbl_data->attachment_count      = 0;
 
        emcore_fill_address_information_of_mail_tbl(temp_mail_tbl_data);
@@ -2323,7 +2323,6 @@ int emcore_free_uids(emcore_uid_list *uid_list, int *err_code)
        
        if (!uid_list) {
                EM_DEBUG_EXCEPTION(" uid_list[%p]\n", uid_list);
-               
                err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
@@ -2910,7 +2909,7 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c
 
 /*  Content-Type:  IMAGE/octet-stream; name = Default.png */
 /*  Content-Transfer-Encoding:  BASE64 */
-/*  Content-ID:  <4b0d6810b17291f9438783a8eb9d5228@org.tizen.email> */
+/*  Content-ID:  <4b0d6810b17291f9438783a8eb9d5228@com.tizen.email> */
 /*  Content-Disposition:  inline; filename = Default.png */
 
 static int emcore_parse_image_part_for_partial_body(char *header_start_string, char *start_header, char *boundary_string, char *bufsendforparse, email_image_data *image_data, int body_size)
@@ -3166,7 +3165,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i
        int j = 0;
        int i32_index = 0, temp_string_index = 0;
        int no_alternative_part_flag = 0;
-       int dec_len = 0, response_buffer_length = 0, mailparselen = 0, image_length = 0, tempmailparselen = 0;
+       int dec_len = 0, response_buffer_length = 0, image_length = 0, tempmailparselen = 0;
        int temp_count = 0, total_mail_size = 0, attachment_num, body_size = 0, total_mail_size_except_attach = 0;
        int total_parsed_len_per_uid = 0, total_parsed_len = 0;
        unsigned long uidno = 0;
@@ -3338,10 +3337,10 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i
                        int no_html = 0;
                        char *temp_alternative_plain_header = NULL;
                        
-                       p = (char *)strstr(response_buffer, " {");
+                       p = (char *)strstr(response_buffer, "> {");
                        if (p  != NULL){
                                EM_DEBUG_LOG("Getting the body size");
-                               p += strlen(" {");
+                               p += strlen("> {");
                                s = p;
 
                                temp_string_index = 0;
@@ -3365,11 +3364,9 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i
                                /* goto FINISH_OFF; */
                        }
                                        
-                       /*  Find next line */
-                       tempmailparselen = 0;
-                       while (tempmailparselen < response_buffer_length && response_buffer[tempmailparselen] != LF)
-                               tempmailparselen++;
-                       tempmailparselen++;
+                       /*  Find data line : 2 is CRLF, 1 is } */
+                       EM_DEBUG_LOG("temp_string_index : [%d]", temp_string_index);
+                       tempmailparselen = (p - response_buffer) + temp_string_index + 2 + 1;
 
                        if (imap_response->buflen < (total_parsed_len + body_size)){
                                err = EMAIL_ERROR_CONNECTION_BROKEN;
@@ -3477,17 +3474,9 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i
 
                                }
                
-                               /*  Find next line. */
-                               mailparselen = 0;
-                               
-                               while (mailparselen < response_buffer_length && response_buffer[mailparselen] != LF)
-                                       mailparselen++;
-                               
-                               mailparselen++;
-       
                                /*  Removed the response header and send the buffer for parsing */
-                               response_buffer        = response_buffer + mailparselen;
-                               response_buffer_length = response_buffer_length - mailparselen;
+                               response_buffer        = response_buffer + tempmailparselen;
+                               response_buffer_length = response_buffer_length - tempmailparselen;
 
                                bufsendforparse = em_malloc(body_size + 1); /*  old */
                                /*  bufsendforparse = em_malloc(response_buffer_length + 1); */ /* new */
@@ -3548,8 +3537,8 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i
                                }
                                else{   /*  Partial body has headers with Content-Type: text/html or Content-Type: text/plain */
                                        no_alternative_part_flag = 0;
-                                       if (((temp_alternative_plain_header = (char *)strcasestr(p, "Content-type: multipart/alternative"))  != NULL)){ /*  Found 'alternative' */
-                                               if (((temp_content_type1 = (char *)strcasestr(p, "Content-type: text/plain"))  != NULL)){   
+                                       if (((temp_alternative_plain_header = (char *)strcasestr(p, "Content-type: multipart/alternative")) != NULL)) { /*  Found 'alternative' */
+                                               if (((temp_content_type1 = (char *)strcasestr(p, "Content-type: text/plain")) != NULL)) {   
                                                        if (temp_content_type1 < temp_alternative_plain_header) /*  This part is text/plain not alternative. */
                                                                no_html = 1;
                                                        no_alternative_part_flag = 1;
@@ -3760,8 +3749,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i
                                if (!emstorage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err))
                                        EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err);
                                
-NEXTUIDPARSING: 
-
+NEXTUIDPARSING:
                                response_buffer = response_buffer + body_size; /*  Set pointer for next mail body.  */
        
                                /*  Find end of body */
@@ -3774,9 +3762,10 @@ NEXTUIDPARSING:
                                        response_buffer = response_buffer + 3;
                                        total_parsed_len_per_uid = body_size+tempmailparselen + 3;
                                }
-                               else
+                               else {                          
                                        EM_DEBUG_EXCEPTION("Mail response end could not found, - %c : %c : %c", response_buffer[0], response_buffer[1], response_buffer[2]);
-                       
+                               }
+
                                EM_SAFE_FREE(bufsendforparse);
                                
                                memset(text_html, 0, input_download_size+1);
@@ -3940,6 +3929,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
        int bytes_copied = 0;
        int temp_body_buffer_size = 0;
        int flags = 0;
+       int count = 0;
        int allocated_buffer_size = (BULK_PARTIAL_BODY_DOWNLOAD_COUNT + 2) * input_download_size ;
 
        retPartialBuffer = (email_partial_buffer *)em_malloc(sizeof(email_partial_buffer));
@@ -3957,7 +3947,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
                return NIL;
        }
 
-       while (nstream){        
+       while (nstream){
                if (!(pline = net_getline(nstream))) {
                        EM_DEBUG_EXCEPTION("net_getline failed...");
                        EM_SAFE_FREE(retPartialBuffer->buffer);
@@ -3965,12 +3955,15 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
 
                        return NIL;
                }
-       
                linelen = strlen(pline);
                
                if (strcasestr(pline, "BODYSTRUCTURE") != NULL) {
                        temp_body_buffer_size = 0;
                        flags = 0;
+                       count++;
+               } else if (strstr(pline, "> {") != NULL) {
+                       temp_body_buffer_size = 0;
+                       flags = 0;
                } else {
                        temp_body_buffer_size = temp_body_buffer_size + linelen + 2;
                }
@@ -3982,6 +3975,15 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
                }       
 
                if (temp_body_buffer_size <= input_download_size) {
+                       if (allocated_buffer_size < (bytes_copied + linelen)) {
+                               allocated_buffer_size = allocated_buffer_size + (BULK_PARTIAL_BODY_DOWNLOAD_COUNT - count) * input_download_size;
+                               retPartialBuffer->buffer = (char *)realloc(retPartialBuffer->buffer, allocated_buffer_size);
+                               if (NULL == retPartialBuffer->buffer) {
+                                       EM_DEBUG_EXCEPTION("realloc failed");
+                                       EM_SAFE_FREE(retPartialBuffer);
+                                       return NIL;
+                               }                       
+                       }
                        memcpy(retPartialBuffer->buffer + bytes_copied, pline, linelen);
                        bytes_copied  += linelen;
                        memcpy(retPartialBuffer->buffer + bytes_copied, CRLF_STRING, 2);
index 3c170d5..297bf40 100755 (executable)
@@ -505,7 +505,7 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf
 
        memset(mmsg, 0x00, sizeof(struct _m_mesg));
 
-       /*  1. parse the first found heade */
+       /*  1. parse the first found header */
        EM_DEBUG_LOG(">>>>>> 1. parse the first found header");
        if (!emcore_mime_parse_header(stream, is_file, &mmsg->rfc822header, &mmsg->header, err_code)) {
                EM_SAFE_FREE(mmsg);
@@ -518,7 +518,7 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf
                return false;
        }
        
-       /*  2. parse bod */
+       /*  2. parse body */
        EM_DEBUG_LOG(">>>>>> 2. parse body");
        if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter)  {
                EM_DEBUG_LOG("name[%s]", mmsg->header->part_header->parameter->name);
@@ -531,7 +531,7 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf
                return false; 
        }
 
-       /*  3. free memor */
+       /*  3. free memory */
        EM_DEBUG_LOG(">>>>>> 3. free memory");
        if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter)  {
                EM_DEBUG_LOG("name[%s]", mmsg->header->part_header->parameter->name);
@@ -821,7 +821,10 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru
                                if (cnt_info->file) {
                                        cnt_info->file->type = 2;
                                        cnt_info->file->name = EM_SAFE_STRDUP(attachment_name);
-                                       emcore_mime_get_content_data(stream, is_file, false, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+                                       if (!emcore_mime_get_content_data(stream, is_file, false, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
+                                               EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code);
+                                               return false;
+                                       }
                                        cnt_info->file->save = holder;
                                        cnt_info->file->size = size;
                                }
@@ -831,7 +834,10 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru
                        if (cnt_info->grab_type & GRAB_TYPE_TEXT)  {
                                /* EM_DEBUG_LINE */
                                /*  get content data. content data is saved in file */
-                               emcore_mime_get_content_data(stream, is_file, true, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+                               if (!emcore_mime_get_content_data(stream, is_file, true, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
+                                       EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code);
+                                       return false;
+                               }
                                
                                EM_DEBUG_LOG("After emcore_mime_get_content_data");
                                
@@ -1031,20 +1037,21 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par
                                                if (!attachment_name)
                                                        attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_ID, err_code);
                                                if (!attachment_name)
-                                                       attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_LOCATION, err_code);
+                                                       attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
 
                                                content_disposition_type = 1;
                                        } else if (!strcasecmp(content_disposition, "attachment")) {
-                                               if (!attachment_name)  {
+                                               if (!attachment_name)  
+                                                       attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
+                                               if (!attachment_name)
                                                        attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code);
-                                                       EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name  :  NIL);
-                                               }
+
                                                content_disposition_type = 2;
                                        }
                                } else if (strstr(content_type, "PKCS7")) {
                                        attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
                                        EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name  :  NIL);
-                       }
+                               }
 
                                if (!emcore_check_thread_status())  {
                                        if (err_code != NULL)
@@ -1054,11 +1061,15 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par
                                        return false;
                                }
 
+                               EM_DEBUG_LOG("attachment_name : [%s]", attachment_name);
                                /*  get content and content information */
                                if (!attachment_name)  {        /*  text */
-                                       /*  get content by buffe */
+                                       /*  get content by buffer */
                                        EM_DEBUG_LOG_MIME("attachment_name is NULL. It's a text message"); 
-                                       emcore_mime_get_content_data(stream, is_file, true, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+                                       if (!emcore_mime_get_content_data(stream, is_file, true, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
+                                               EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code);
+                                               return false;
+                                       }
 
                                        EM_DEBUG_LOG("After emcore_mime_get_content_data");
                                        
@@ -1123,13 +1134,22 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par
                                                if ( (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) || (*file)->type == 1)  {
                                                        /*  get content by file */
                                                        EM_DEBUG_LOG_MIME("Trying to get content"); 
-                                                       emcore_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+                                                       if (!emcore_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
+                                                               EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code);
+                                                               EM_DEBUG_FUNC_END("false");
+                                                               return false;
+                                                       }
                                                        (*file)->save = holder;
                                                }
                                                else  {
                                                        /*  only get content size */
                                                        EM_DEBUG_LOG_MIME("Pass downloading"); 
-                                                       emcore_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_SIZE, NULL, &size, NULL, err_code);
+                                                       if (!emcore_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_SIZE, NULL, &size, NULL, err_code)) {
+                                                               EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code);
+                                                               EM_DEBUG_FUNC_END("false");
+                                                               return false;
+                                                       }
+
                                                        (*file)->save = NULL;
                                                }
                                                
@@ -1158,12 +1178,12 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par
                                }
 
                                if (!emcore_check_thread_status())  {
-                       if (err_code != NULL)
-                               *err_code = EMAIL_ERROR_CANCELLED;
+                                       if (err_code != NULL)
+                                               *err_code = EMAIL_ERROR_CANCELLED;
                                        EM_DEBUG_EXCEPTION("EMAIL_ERROR_CANCELLED");
                                        EM_DEBUG_FUNC_END("false");
-                       return false;
-               }
+                                       return false;
+                               }
 
                                if (!nested->body) 
                                        nested->body = tmp_body;
@@ -1318,6 +1338,38 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name
                                else  {   /*  Content-Type Parameter (format :  "name =value" */
                                        if (emcore_mime_get_param_from_str(p_val, &p, err_code))        
                                                emcore_mime_add_param_to_list(&((*header)->parameter), p, err_code);
+                                       else /* name= CRLF value */ {
+                                               struct _parameter *t = (*header)->parameter;
+                                               while (t && t->next) {
+                                                       t = t->next;
+                                               }
+
+                                               EM_DEBUG_LOG("name : [%s]", t->name);
+                                               EM_DEBUG_LOG("value : [%s]", t->value);
+
+                                               if (t->value == NULL) {
+                                                       char *pointer = NULL;
+
+                                                       if (strlen(p_val) > 0)  {
+                                                               if ((pointer = strchr(p_val, '\"')))  {
+                                                                       p_val = pointer + 1;
+                                                                       if (!*p_val) return false;
+                                                               }
+                                                               if ((pointer = strchr(p_val, '\"')))
+                                                                       *pointer = '\0';
+                                                               
+                                                               /*  = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */
+                                                               int err = EMAIL_ERROR_NONE;
+                                                               char *utf8_text = NULL;
+                                                               
+                                                               if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) 
+                                                                       EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err);
+                                                               EM_DEBUG_LOG("utf8_text : [%s]", utf8_text);
+                                                               t->value = EM_SAFE_STRDUP(utf8_text);
+                                                       }
+                                               }
+                                       }
+                                                       
                                }
                                
                                /*  repeatedly get paramete */
@@ -1377,7 +1429,7 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name
        return true;
 }
  
-/*  get header parameter from strin */
+/*  get header parameter from string */
 int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("str[%s], param[%p], err_code[%p]", str, param, err_code);
@@ -1386,7 +1438,7 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er
 
        *param = NULL;
 
-       /*  Parameter Chec */
+       /*  Parameter Check */
        if (!(p = strchr(str, '=')))    return false;
        
        *p = '\0';
@@ -1399,22 +1451,25 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er
        
        if (!*p_name) return false;
 
-       em_trim_left(p_val);
-       em_trim_right(p_val);
-       
-       if (!*p_val) return false;
-
        if (!(*param = em_malloc(sizeof(struct _parameter)))) return false;
        
        (*param)->next = NULL;
 
-       /*  Name se */
-       /*  check string lengt */
+       /*  Name set */
+       /*  Check string length */
        if (strlen(p_name) > 0)  {
                em_upper_string(p_name);
                (*param)->name = EM_SAFE_STRDUP(p_name);
        }
 
+       em_trim_left(p_val);
+       em_trim_right(p_val);
+       
+       if (!*p_val)  {
+               EM_DEBUG_LOG("Parameter value is NULL");
+               return true;
+       }
+
        if (strlen(p_val) > 0)  {
                if ((p = strchr(p_val, '\"')))  {
                        p_val = p + 1;
@@ -1664,11 +1719,15 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b
        
                if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &error)) || 
                (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, &error)))  {
-                       if (error == EMAIL_ERROR_NO_MORE_DATA)
-                               EM_DEBUG_EXCEPTION("End of data");
-                       else
+                       if (error != EMAIL_ERROR_NO_MORE_DATA) {
                                EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed");
-                               *end_of_parsing = 1;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
+                               goto FINISH_OFF;
+                       }
+
+                       EM_DEBUG_LOG("This mail is partial body");
+
+                       *end_of_parsing = 1;
                                
                        ret = true;
                        goto FINISH_OFF; 
@@ -1870,9 +1929,10 @@ char *emcore_mime_get_save_file_name(int *err_code)
 char *emcore_get_line_from_file(void *stream, char *buf, int size, int *err_code)
 {
        if (!fgets(buf, size, (FILE *)stream))  {
-               if (feof((FILE *)stream))
+               if (feof((FILE *)stream)) {
+                       *err_code = EMAIL_ERROR_NO_MORE_DATA;
                        return NULL;
-               else
+               else
                        return NULL;
        }
        return buf;
@@ -2185,8 +2245,10 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru
                case TYPEMODEL:
                case TYPEOTHER:
 
+                       EM_DEBUG_LOG("g_inline_count [%d], body->id [%s], body->location [%s], body->disposition.type[%s]", g_inline_count, body->id, body->location, body->disposition.type);
+
                        /* Form list of attachment followed by list of inline images */
-                       if (body->id || body->location || body->disposition.type) {
+                       if (body->id && (g_inline_count || body->location || body->disposition.type)) {
 
                                char filename[512] = {0, };
                                struct attachment_info **ai = NULL;
@@ -5113,7 +5175,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emcore_load_eml_file_to_mail(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code)
+INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("eml_file_path : [%s], output_mail_data : [%p]", eml_file_path, output_mail_data);
 
@@ -5190,7 +5252,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emcore_delete_eml_data(email_mail_data_t *input_mail_data, int *err_code)
+INTERNAL_FUNC int emcore_delete_parsed_data(email_mail_data_t *input_mail_data, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
        int err = EMAIL_ERROR_NONE;
@@ -5241,11 +5303,14 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in
        int err = EMAIL_ERROR_NONE;
        int is_file = 1;
        int search = 0;
+       long start_mime_entity = 0;
+       long end_mime_entity = 0;
        char buf[MIME_LINE_LEN] = {0x00, };
        char *mime_entity_path = NULL;
        char *content_type = NULL;
        char boundary[BOUNDARY_LEN] = {0x00,};
        char *boundary_string = NULL;
+       char *p_mime_entity = NULL;
        FILE *fp_read = NULL;
        FILE *fp_write = NULL;
        struct _m_mesg *mmsg = NULL;
@@ -5305,19 +5370,44 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in
        while (TRUE) {
                if (!emcore_get_line_from_file((void *)fp_read, buf, MIME_LINE_LEN, &err)) {
                        EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_file failed [%d]", err);
+                       EM_DEBUG_LOG("this mail is partial body");
+                       err = EMAIL_ERROR_INVALID_MAIL;
                        break;
                }
                
                if (!strcmp(buf, boundary)) {
                        search++;
-               } else if (search == 1) {
-                       EM_DEBUG_LOG("Buf : [%s]", buf);
-                       fprintf(fp_write, "%s", buf);   
-               } else if (search == 2) {
-                       break;
+                       if (search == 1) {
+                               start_mime_entity = ftell(fp_read);
+                       } else if (search == 2) {
+                               end_mime_entity = ftell(fp_read);
+                               break;
+                       }
                }
        }
 
+       p_mime_entity = em_malloc(end_mime_entity - start_mime_entity);
+       if (p_mime_entity == NULL) {
+               EM_DEBUG_EXCEPTION("em_malloc failed");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       if (fseek(fp_read, start_mime_entity, SEEK_SET)) {
+               EM_DEBUG_EXCEPTION("fseek failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       /* +2 : CRLF line */
+       if ((ret = fread(p_mime_entity, 1, end_mime_entity - (start_mime_entity + strlen(boundary) + 2), fp_read)) < 0) {
+               EM_DEBUG_EXCEPTION("fread failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
+               goto FINISH_OFF;
+       }
+
+       fprintf(fp_write, "%s", p_mime_entity);
+       
        ret = true;
 
 FINISH_OFF:
@@ -5337,6 +5427,8 @@ FINISH_OFF:
        if (err_code)
                *err_code = err;
 
+       EM_SAFE_FREE(p_mime_entity);
+
        EM_DEBUG_FUNC_END();
        return ret;
 }
index 9ec6d60..1bd5a26 100755 (executable)
 #define SMIME_SIGNED_FILE "smime.p7s"
 #define SMIME_ENCRYPT_FILE "smime.p7m"
 
-#define OUTMODE "wb"
-#define INMODE "rb"
-#define READMODE "r"
-
 /* If not present then the default digest algorithm for signing key will be used SHA1 */
 static const EVP_MD *emcore_get_digest_algorithm(email_digest_type digest_type)
 {
@@ -306,25 +302,33 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *passw
        smime_attachment = BIO_new_file(temp_smime_filepath, OUTMODE);
        if (!smime_attachment) {
                EM_DEBUG_EXCEPTION("Cannot open output file %s", temp_smime_filepath);
-               err = EMAIL_ERROR_FILE_NOT_FOUND;
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
        /* Load certificate for getting the certificate and private key */
+
        if (!emcore_load_PFX_file(certificate, password, &private_key, &cert, &other_certs, &err)) {
                EM_DEBUG_EXCEPTION("Load the private certificate failed : [%d]", err);
                goto FINISH_OFF;
        }
-
+/*
+       if (!emcore_load_PFX_file(certificate, &private_key, &cert, &other_certs, &err)) {
+               EM_DEBUG_EXCEPTION("Load the private certificate failed : [%d]", err);
+               goto FINISH_OFF;
+       }
+*/
        bio_mime_entity = BIO_new_file(mime_entity, READMODE);
        if (!bio_mime_entity) {
                EM_DEBUG_EXCEPTION("Cannot open file[%s]", mime_entity);
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
        signed_message = PKCS7_sign(NULL, NULL, other_certs, bio_mime_entity, flags);
        if (!signed_message) {
                EM_DEBUG_EXCEPTION("Error creating PKCS#7 structure");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
        
@@ -333,11 +337,13 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *passw
 
        if (!PKCS7_sign_add_signer(signed_message, cert, private_key, digest, flags)) {
                EM_DEBUG_EXCEPTION("PKCS7_sign_add_signer failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
        if (!PKCS7_final(signed_message, bio_mime_entity, flags)) {
                EM_DEBUG_EXCEPTION("PKCS7_final failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -410,7 +416,7 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m
        smime_attachment = BIO_new_file(temp_smime_filepath, OUTMODE);
        if (!smime_attachment) {
                EM_DEBUG_EXCEPTION("Cannot open output file %s", temp_smime_filepath);
-               err = EMAIL_ERROR_FILE_NOT_FOUND;
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -431,6 +437,7 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m
        encrypt_message = PKCS7_encrypt(recipient_certs, bio_mime_entity, cipher, flags);
        if (encrypt_message == NULL) {
                EM_DEBUG_EXCEPTION("PKCS7_encrypt failed [%ld]", ERR_get_error());
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -513,21 +520,28 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
        smime_attachment = BIO_new_file(temp_smime_filepath, OUTMODE);
        if (!smime_attachment) {
                EM_DEBUG_EXCEPTION("Cannot open output file %s", temp_smime_filepath);
-               err = EMAIL_ERROR_FILE_NOT_FOUND;
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
        /* Signing the mail */
        /* 1. Load the private certificate */
+
        if (!emcore_load_PFX_file(certificate, password, &private_key, &cert, &other_certs, &err)) {
                EM_DEBUG_EXCEPTION("Load the certificate failed : [%d]", err);
                goto FINISH_OFF;
        }
-
+/*
+       if (!emcore_load_PFX_file(certificate, &private_key, &cert, &other_certs, &err)) {
+               EM_DEBUG_EXCEPTION("Load the private certificate failed : [%d]", err);
+               goto FINISH_OFF;
+       }
+*/
        /* 2. Read mime entity */
        bio_mime_entity = BIO_new_file(mime_entity, READMODE);
        if (!bio_mime_entity) {
                EM_DEBUG_EXCEPTION("Cannot open file[%s]", mime_entity);
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -535,6 +549,7 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
        signed_message = PKCS7_sign(NULL, NULL, other_certs, bio_mime_entity, flags);
        if (!signed_message) {
                EM_DEBUG_EXCEPTION("Error creating PKCS#7 structure");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
        
@@ -544,12 +559,14 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
        /* 5. Apply a digest algorithm */
        if (!PKCS7_sign_add_signer(signed_message, cert, private_key, digest, flags)) {
                EM_DEBUG_EXCEPTION("PKCS7_sign_add_signer failed");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
        /* 6. Create signing message */
        if (!SMIME_write_PKCS7(bio_signed_message, signed_message, bio_mime_entity, flags | SMIME_OLDMIME | SMIME_CRLFEOL)) {
                EM_DEBUG_EXCEPTION("SMIME_write_PKCS7 error");
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -579,6 +596,7 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
        encrypt_message = PKCS7_encrypt(recipient_certs, bio_signed_message, cipher, flags);
        if (encrypt_message == NULL) {
                EM_DEBUG_EXCEPTION("PKCS7_encrypt failed [%ld]", ERR_get_error());
+               err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
        
@@ -792,7 +810,7 @@ FINISH_OFF:
 }
 */
 
-static char *emcore_get_mime_entity(char *mime_path)
+static char *emcore_set_mime_entity(char *mime_path)
 {
        EM_DEBUG_FUNC_BEGIN("mime_path : [%s]", mime_path);
        FILE *fp_read = NULL;
@@ -878,6 +896,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
        
        if (!input_mail_data || !(input_mail_data->account_id) || !(input_mail_data->mailbox_id)) {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -903,11 +922,11 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
 #endif
        
        if (!emcore_make_rfc822_file(input_mail_data, input_attachment_data_list, attachment_count, &rfc822_file, &err))  {
-               EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err);
+               EM_DEBUG_EXCEPTION("emcore_make_rfc822_file failed [%d]", err);
                goto FINISH_OFF;
        }
 
-       mime_entity = emcore_get_mime_entity(rfc822_file);
+       mime_entity = emcore_set_mime_entity(rfc822_file);
 
        smime_type = input_mail_data->smime_type;
        if (!smime_type) 
@@ -926,8 +945,6 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
 
                new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
                new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
-               new_attachment_data.attachment_size = 1;
-               new_attachment_data.save_status = 1;
 
                attachment_count += 1;
 
@@ -952,13 +969,11 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
 
                new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
                new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
-               new_attachment_data.attachment_size = 1;
-               new_attachment_data.save_status = 1;
 
-               attachment_count += 1;
+               attachment_count = 1;
 
                break;
-       case EMAIL_SMIME_SIGNED_AND_ENCRYPTED:                  /* Signed and Encryption message */
+       default:                        /* Signed and Encryption message */
                address_length = EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc);
 
                other_certificate_list = em_malloc(address_length + 3);
@@ -978,15 +993,20 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
 
                new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
                new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
-               new_attachment_data.attachment_size = 1;
-               new_attachment_data.save_status = 1;
 
                attachment_count = 1;
 
                break;
-       default:
-               break;
        }
+/*
+       if (!emcore_get_file_size(smime_file_path, &size, &err)) {
+               EM_DEBUG_EXCEPTION("emcore_get_file_size failed : [%d]", err);
+               goto FINISH_OFF;
+       }
+*/
+       new_attachment_data.attachment_size = 1;
+       new_attachment_data.save_status = 1;
+
 
        temp_attachment_data = (email_attachment_data_t *)em_malloc(sizeof(email_attachment_data_t) * attachment_count);
        if (input_attachment_data_list != NULL)
@@ -1016,7 +1036,7 @@ FINISH_OFF:
 #ifdef SMIME_DEBUG
        if (password)
                EM_SAFE_FREE(password);
-#endif
+#endif // SMIME_DEBUG
        
        return ret;                             
 }
index 08fe465..fe25943 100755 (executable)
@@ -51,6 +51,7 @@
 #ifdef __FEATURE_SUPPORT_REPORT_MAIL__
 static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body, int *err_code);
 #endif
+static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, ENVELOPE **output_envelope);
 static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id,  int *err_code);
 
 /* Functions from uw-imap-toolkit */
@@ -184,14 +185,127 @@ FINISH_OFF:
        return result_string;
 }
 
+static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN();
+       char *file_path = NULL;
+       char buf[RFC822_STRING_BUFFER_SIZE + 1] = {0, };
+       char *img_tag_pos = NULL;
+       char *p = NULL;
+       char *replaced_string = NULL;
+       int fd, nread, nwrite, error = EMAIL_ERROR_NONE;
+       unsigned long len;
+       
+       file_path = body->sparep;
+
+       if (!file_path || strlen(file_path) == 0)  {
+               EM_DEBUG_LOG("There is no file path");
+               switch (body->encoding)  {
+                       case 0:
+                               break;
+                       default:
+                               p = cpystr((const char *)body->contents.text.data);
+                               len = body->contents.text.size;
+                               break;
+               }
+               
+               if (p)  {       
+                       EM_DEBUG_LOG("p[%s]", p);
+                       fprintf(fp, "%s"CRLF_STRING CRLF_STRING, p);
+                       EM_SAFE_FREE(p);
+               }
+               
+               EM_SAFE_FREE(body->sparep);
+               EM_DEBUG_FUNC_END();
+               return true;
+       }
+       
+       EM_DEBUG_LOG("Opening a file[%s]", file_path);
+       fd = open(file_path, O_RDONLY);
+
+       if (fd < 0) {
+               EM_DEBUG_EXCEPTION("open(\"%s\") failed...", file_path);
+               return false;
+       }
+               
+       while (1) {
+               nread = read(fd, buf, (body->encoding == ENCBASE64 ? 57 : RFC822_READ_BLOCK_SIZE - 2));
+
+               if (nread <= 0)  {
+                       EM_DEBUG_LOG("Can't read anymore");
+                       break;
+               }
+
+               p = NULL;
+               len = nread;
+
+               /* EM_DEBUG_LOG("body->type[%d], body->subtype[%c]", body->type, body->subtype[0]); */
+
+               if (body->type == TYPETEXT && (body->subtype && (body->subtype[0] == 'H' || body->subtype[0] == 'h'))) {   
+                       EM_DEBUG_LOG("HTML Part");
+                       img_tag_pos = emcore_find_img_tag(buf);
+
+                       if (img_tag_pos) {
+                               replaced_string = emcore_replace_inline_image_path_with_content_id(buf, html_body, &error);
+                               if (replaced_string) {
+                                       EM_DEBUG_LOG("emcore_replace_inline_image_path_with_content_id succeeded");
+                                       strcpy(buf, replaced_string);
+                                       nread = len = strlen(buf);
+                                       EM_DEBUG_LOG("buf[%s], nread[%d], len[%d]", buf, nread, len);
+                               }
+                               else
+                                       EM_DEBUG_LOG("emcore_replace_inline_image_path_with_content_id failed[%d]", error);
+                       }
+               }
+               /* EM_DEBUG_LOG("body->encoding[%d]", body->encoding); */
+//             if (body->subtype[0] != 'S' || body->subtype[0] != 's') {
+               switch (body->encoding)  {
+                       case ENCQUOTEDPRINTABLE:
+                               p = (char *)rfc822_8bit((unsigned char *)buf, (unsigned long)nread, (unsigned long *)&len);
+                               break;
+                       case ENCBASE64:
+                               p = (char *)rfc822_binary((void *)buf, (unsigned long)nread, (unsigned long *)&len);
+                               break;
+                       default:
+                               buf[len] = '\0';
+                               break;
+               }
+//             }       
+       
+               nwrite = fprintf(fp, "%s", (p ? p : buf));
+               
+               if (nwrite != len)  {
+                       fclose(fp);
+                       close(fd);
+                       EM_SAFE_FREE(p);
+                       EM_DEBUG_EXCEPTION("fprintf failed nwrite[%d], len[%d]", nwrite, len);
+                       return false;
+               }
+               EM_SAFE_FREE(p);
+       }
+       
+       if (body->encoding == ENCQUOTEDPRINTABLE || body->encoding == ENCBASE64)
+               fprintf(fp, CRLF_STRING);
+       
+       fprintf(fp, CRLF_STRING);
+       
+       if (body->sparep)  {
+               free(body->sparep);
+               body->sparep = NULL;
+       }
+       
+       EM_DEBUG_FUNC_END();
+       return true;
+}
+
 static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("body[%p], html_body[%p], fp[%p], err_code[%p]", body, html_body, fp, err_code);
        
        PARAMETER *param = NULL;
        PART *part = NULL;
-       char *p = NULL, *bndry = NULL, buf[1025], *replaced_string = NULL;
-       int fd, nread, nwrite, error = EMAIL_ERROR_NONE;
+       char *p = NULL, *bndry = NULL, buf[1025];
+       int error = EMAIL_ERROR_NONE;
        
        switch (body->type)  {
                case TYPEMULTIPART:
@@ -211,8 +325,16 @@ static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int *
                                rfc822_write_body_header(&p, &part->body);
                                
                                fprintf(fp, "--%s"CRLF_STRING, bndry);
+                               if (body->subtype[0] == 'S' || body->subtype[0] == 's') {
+                                       if (!emcore_write_body(body, html_body, fp, &error)) {
+                                               EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error);
+                                               return false;
+                                       }
+                                       fprintf(fp, "--%s"CRLF_STRING, bndry);
+                               }
+
                                fprintf(fp, "%s"CRLF_STRING, buf);
-                               
+
                                emcore_write_rfc822_body(&part->body, html_body, fp, err_code);
                        } while ((part = part->next));
                        
@@ -222,111 +344,11 @@ static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int *
                default:  {
                        EM_DEBUG_LOG("body->type is not TYPEMULTIPART");
 
-                       char *file_path = body->sparep;
-                       char buf[RFC822_STRING_BUFFER_SIZE + 1] = { 0, }, *img_tag_pos = NULL;
-                       unsigned long len;
-                       
-                       p = NULL;
-                       
-                       if (!file_path || strlen(file_path) == 0)  {
-                               EM_DEBUG_LOG("There is no file path");
-                               switch (body->encoding)  {
-                                       case 0:
-                                               break;
-                                       default:
-                                               p = cpystr((const char *)body->contents.text.data);
-                                               len = body->contents.text.size;
-                                               break;
-                               }
-                               
-                               if (p)  {       
-                                       EM_DEBUG_LOG("p[%s]", p);
-                                       fprintf(fp, "%s"CRLF_STRING CRLF_STRING, p);
-                                       EM_SAFE_FREE(p);
-                               }
-                               
-                               EM_SAFE_FREE(body->sparep);
-                               EM_DEBUG_FUNC_END();
-                               return true;
-                       }
-                       
-                       EM_DEBUG_LOG("Opening a file[%s]", file_path);
-                       fd = open(file_path, O_RDONLY);
-
-                       if (fd < 0)  {
-                               EM_DEBUG_EXCEPTION("open(\"%s\") failed...", file_path);
+                       if (!emcore_write_body(body, html_body, fp, &error)) {
+                               EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error);
                                return false;
                        }
-                       
-                       while (1)  {
-                               nread = read(fd, buf, (body->encoding == ENCBASE64 ? 57 : RFC822_READ_BLOCK_SIZE - 2));
-
-                               if (nread < 0)  {
-                                       close(fd);
-                                       return false;
-                               }
-                               
-                               if (nread == 0) {
-                                       close(fd);
-                                       break;
-                               }
-                       
-                               p = NULL;
-                               len = nread;
-
-                               /*  EM_DEBUG_LOG("body->type[%d], body->subtype[%c]", body->type, body->subtype[0]); */
-                               if (body->type == TYPETEXT && (body->subtype && (body->subtype[0] == 'H' || body->subtype[0] == 'h'))) {   
-                                       EM_DEBUG_LOG("HTML Part");
-                                       img_tag_pos = emcore_find_img_tag(buf);
-
-                                       if (img_tag_pos) {
-                                               replaced_string = emcore_replace_inline_image_path_with_content_id(buf, html_body, &error);
-                                               if (replaced_string) {
-                                                       EM_DEBUG_LOG("emcore_replace_inline_image_path_with_content_id succeeded");
-                                                       strcpy(buf, replaced_string);
-                                                       nread = len = strlen(buf);
-                                                       EM_DEBUG_LOG("buf[%s], nread[%d], len[%d]", buf, nread, len);
-                                               }
-                                               else
-                                                       EM_DEBUG_LOG("emcore_replace_inline_image_path_with_content_id failed[%d]", error);
-                                       }
-                               }
-
-                               switch (body->encoding)  {
-                                       case ENCQUOTEDPRINTABLE:
-                                               p = (char *)rfc822_8bit((unsigned char *)buf, (unsigned long)nread, (unsigned long *)&len);
-                                               break;
-                                       case ENCBASE64:
-                                               p = (char *)rfc822_binary((void *)buf, (unsigned long)nread, (unsigned long *)&len);
-                                               break;
-                                       default:
-                                               buf[len] = '\0';
-                                               break;
-                               }
-                               
-                               
-                               nwrite = fprintf(fp, "%s", (p ? p : buf));
-                               
-                               if (nwrite != len)  {
-                                       fclose(fp);
-                                       close(fd);
-                                       EM_SAFE_FREE(p);
-                                       EM_DEBUG_EXCEPTION("fprintf failed nwrite[%d], len[%d]", nwrite, len);
-                                       return false;
-                               }
-                               EM_SAFE_FREE(p);
-                       }
-                       
-                       if (body->encoding == ENCQUOTEDPRINTABLE || body->encoding == ENCBASE64)
-                               fprintf(fp, CRLF_STRING);
-                       
-                       fprintf(fp, CRLF_STRING);
-                       
-                       if (body->sparep)  {
-                               free(body->sparep);
-                               body->sparep = NULL;
-                       }
-                       
+               
                        break;
                }       /*  default: */
        }
@@ -334,7 +356,7 @@ static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int *
        return true;
 }
 
-static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email_extra_flag_t flag, char **data, int *err_code)
+static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email_mail_priority_t input_priority, email_mail_report_t input_report_flag, char **data, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("env[%p], body[%p], data[%p], err_code[%p]", env, body, data, err_code);
        
@@ -416,37 +438,36 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email
                *(p + strlen(p) - 2) = '\0';
        
 
-       if (flag.report)  {
+       if (input_report_flag)  {
                char buf[512] = {0x00, };
-               switch (flag.report)  {
-                       case EMAIL_MAIL_REPORT_DSN: /*  DSN (delivery status) */
-                               /*  change content-type */
-                               /*  Content-Type: multipart/report; */
-                               /*              report-type= delivery-status; */
-                               /*              boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */
-                               break;
-                       
-                       case EMAIL_MAIL_REPORT_MDN: /*  MDN (read receipt) */
-                               /*  Content-Type: multipart/report; */
-                               /*              report-type= disposition-notification; */
-                               /*              boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */
-                               break;
+
+               if(input_report_flag & EMAIL_MAIL_REPORT_DSN) {
+                       /*  DSN (delivery status) */
+                       /*  change content-type */
+                       /*  Content-Type: multipart/report; */
+                       /*              report-type= delivery-status; */
+                       /*              boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */
+               }
+
+               if(input_report_flag & EMAIL_MAIL_REPORT_MDN) {
+                       /*  MDN (read receipt) */
+                       /*  Content-Type: multipart/report; */
+                       /*              report-type= disposition-notification; */
+                       /*              boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */
+               }
                        
-                       case EMAIL_MAIL_REPORT_REQUEST: /*  require read status */
-                               rfc822_address(buf, env->from);
-                               if (strlen(buf))
-                                       SNPRINTF(p + strlen(p), p_len-(strlen(p)), "Disposition-Notification-To: %s"CRLF_STRING, buf);
-                               break;
-                               
-                       default:
-                               break;
+               if(input_report_flag & EMAIL_MAIL_REQUEST_MDN) {
+                       /*  require read status */
+                       rfc822_address(buf, env->from);
+                       if (strlen(buf))
+                               SNPRINTF(p + strlen(p), p_len-(strlen(p)), "Disposition-Notification-To: %s"CRLF_STRING, buf);
                }
        }
        
-       if (flag.priority)  {           /*  priority (1:high 3:normal 5:low) */
-               SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-Priority: %d"CRLF_STRING, flag.priority);
+       if (input_priority)  {          /*  priority (1:high 3:normal 5:low) */
+               SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-Priority: %d"CRLF_STRING, input_priority);
                
-               switch (flag.priority)  {
+               switch (input_priority)  {
                        case EMAIL_MAIL_PRIORITY_HIGH:
                                SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: HIgh"CRLF_STRING);
                                break;
@@ -521,7 +542,6 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
        int attachment_count = 0;
        email_mail_data_t *mail_data = NULL;
        email_attachment_data_t *attachment_data_list = NULL;
-
        emstorage_mail_tbl_t    *converted_mail_tbl = NULL;
        emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
        emstorage_attachment_tbl_t attachment_tbl = { 0 };
@@ -599,7 +619,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
                        goto FINISH_OFF;
                }
                
-               if (mail_data->report_status == EMAIL_MAIL_REPORT_MDN)  {       
+               if (mail_data->report_status & EMAIL_MAIL_REPORT_MDN)  {
                        /* check read-report mail */
                        if(!mail_data->full_address_to) { /* A report mail should have 'to' address */
                                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -663,6 +683,8 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
        if(mail_data->mail_size == 0)
                emcore_calc_mail_size(mail_data, attachment_data_list, attachment_count, &(mail_data->mail_size)); /*  Getting file size before file moved.  */
 
+       EM_DEBUG_LOG("input_from_eas [%d] mail_data->body_download_status [%d]", input_from_eas, mail_data->body_download_status);
+
        if (input_from_eas == 0|| mail_data->body_download_status) {
                if (!emstorage_create_dir(mail_data->account_id, mail_data->mail_id, 0, &err))  {
                        EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
@@ -932,10 +954,15 @@ FINISH_OFF:
 INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_receipt_mail_id)
 {
        EM_DEBUG_FUNC_BEGIN("input_read_mail_id [%d], output_receipt_mail_id [%p]", input_read_mail_id, output_receipt_mail_id);
-       int              err = EMAIL_ERROR_NONE;
-       email_mail_data_t *read_mail_data = NULL;
-       email_mail_data_t *receipt_mail_data = NULL;
+       int                      err = EMAIL_ERROR_NONE;
+       int                      attachment_count = 0;
+       ENVELOPE                *envelope = NULL;
+       email_mail_data_t       *read_mail_data = NULL;
+       email_mail_data_t       *receipt_mail_data = NULL;
+       emstorage_mail_tbl_t    *receipt_mail_tbl_data = NULL;
+       email_attachment_data_t *attachment_data = NULL;
        emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
+       BODY                    *root_body = NULL;
 
        if( (err = emcore_get_mail_data(input_read_mail_id, &read_mail_data)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
@@ -952,7 +979,7 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
 
        memcpy(receipt_mail_data, read_mail_data, sizeof(email_mail_data_t));
 
-       receipt_mail_data->full_address_to = EM_SAFE_STRDUP(read_mail_data->full_address_to);
+       receipt_mail_data->full_address_to = EM_SAFE_STRDUP(read_mail_data->full_address_from);
        receipt_mail_data->message_id      = EM_SAFE_STRDUP(read_mail_data->message_id);
 
        if (read_mail_data->subject)  {
@@ -963,26 +990,75 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
                        goto FINISH_OFF;
                }
 
-               SNPRINTF(receipt_mail_data->subject, strlen(read_mail_data->subject) + 7 - 1,  "Read: %s", read_mail_data->subject);
+               SNPRINTF(receipt_mail_data->subject, strlen(read_mail_data->subject) + 7,  "Read: %s", read_mail_data->subject);
        }
 
        if (!emstorage_get_mailbox_by_mailbox_type(receipt_mail_data->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_tbl, true, &err))  {
                EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
+               goto FINISH_OFF;
+       }
+
+       receipt_mail_data->mailbox_id           = mailbox_tbl->mailbox_id;
+       receipt_mail_data->mailbox_type         = EMAIL_MAILBOX_TYPE_OUTBOX;
+       receipt_mail_data->file_path_html       = NULL;
+       receipt_mail_data->flags_draft_field    = 1;
+       receipt_mail_data->body_download_status = 1;
+       receipt_mail_data->save_status          = (unsigned char)EMAIL_MAIL_STATUS_SENDING;
+       receipt_mail_data->report_status        = (unsigned char)EMAIL_MAIL_REPORT_MDN;
+
+       if (!em_convert_mail_data_to_mail_tbl(receipt_mail_data, 1, &receipt_mail_tbl_data, &err)) {
+               EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed [%d]", err);
+               goto FINISH_OFF;
+       }
 
+       if ( (err = emcore_make_envelope_from_mail(receipt_mail_tbl_data, &envelope)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emcore_make_envelope_from_mail failed [%d]", err);
                goto FINISH_OFF;
        }
 
-       receipt_mail_data->mailbox_id        = mailbox_tbl->mailbox_id;
-       receipt_mail_data->mailbox_type      = EMAIL_MAILBOX_TYPE_OUTBOX;
-       receipt_mail_data->flags_draft_field = 1;
-       receipt_mail_data->save_status       = (unsigned char)EMAIL_MAIL_STATUS_SENDING;
-       receipt_mail_data->report_status     = (unsigned char)EMAIL_MAIL_REPORT_MDN;
+       envelope->references = EM_SAFE_STRDUP(read_mail_data->message_id);
 
-       if ( (err = emcore_add_mail(receipt_mail_data, NULL, 0, NULL, 1)) != EMAIL_ERROR_NONE) {
+       if (!emcore_get_report_mail_body(envelope, &root_body, &err))  {
+               EM_DEBUG_EXCEPTION("emcore_get_report_mail_body failed [%d]", err);
+               goto FINISH_OFF;
+       }
+
+       receipt_mail_data->file_path_plain  = EM_SAFE_STRDUP(root_body->nested.part->body.sparep);
+
+       /* Report attachment */
+       /* Final-Recipient :  rfc822;digipop@gmail.com
+          Original-Message-ID:  <r97a77ag0jdhkvvxke58u9i5.1345611508570@email.android.com>
+          Disposition :  manual-action/MDN-sent-manually; displayed */
+
+       /*
+       receipt_mail_data->attachment_count = 1;
+       attachment_count                    = 1;
+
+       attachment_data = em_malloc(sizeof(email_attachment_data_t));
+       if (!attachment_data)  {
+               EM_DEBUG_EXCEPTION("em_malloc failed...");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       attachment_data->save_status     = 1;
+       attachment_data->attachment_path = EM_SAFE_STRDUP(root_body->nested.part->next->body.sparep);
+
+       if (!emcore_get_file_name(attachment_data->attachment_path, &p, &err))  {
+               EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", err);
+               goto FINISH_OFF;
+       }
+
+       attachment_data->attachment_name = cpystr(p);
+       */
+
+       if ( (err = emcore_add_mail(receipt_mail_data, attachment_data, attachment_count, NULL, 0)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err);
                goto FINISH_OFF;
        }
 
+       *output_receipt_mail_id = receipt_mail_data->mail_id;
+
 FINISH_OFF:
        if(receipt_mail_data) {
                EM_SAFE_FREE(receipt_mail_data->full_address_to);
@@ -997,6 +1073,12 @@ FINISH_OFF:
        if(read_mail_data)
                emcore_free_mail_data_list(&read_mail_data, 1);
 
+       if(attachment_data)
+               emcore_free_attachment_data(&attachment_data, 1, NULL);
+
+       if(receipt_mail_tbl_data)
+               emstorage_free_mail(&receipt_mail_tbl_data, 1, NULL);
+
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
@@ -1033,9 +1115,9 @@ FINISH_OFF:
 }
 
 /*  send a mail */
-INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mail_id, email_option_t *sending_option, int *err_code)
+INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mail_id, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], mail_id[%d], sending_option[%p], err_code[%p]", account_id, input_mailbox_id, mail_id, sending_option, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], mail_id[%d], err_code[%p]", account_id, input_mailbox_id, mail_id, err_code);
        EM_PROFILE_BEGIN(profile_emcore_send_mail);
        int ret = false;
        int err = EMAIL_ERROR_NONE, err2 = EMAIL_ERROR_NONE;
@@ -1102,11 +1184,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai
                goto FINISH_OFF;
        }
        
-       if (sending_option != NULL)
-               opt = sending_option;
-       else
-               opt = emcore_get_option(&err);
-       
+       opt = &(ref_account->options);
        
        /*Update status flag to DB*/
        
@@ -1118,7 +1196,6 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai
        
        if (!envelope || (!envelope->to && !envelope->cc && !envelope->bcc))  {
                EM_DEBUG_EXCEPTION(" no recipients found...");
-               
                err = EMAIL_ERROR_NO_RECIPIENT;
                goto FINISH_OFF;
        }
@@ -1173,12 +1250,15 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai
        }
        
        /*  set request of delivery status. */
-       if (opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON)  { 
+       EM_DEBUG_LOG("opt->req_delivery_receipt [%d]", opt->req_delivery_receipt);
+       EM_DEBUG_LOG("mail_tbl_data->report_status [%d]", mail_tbl_data->report_status);
+
+       if (opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON || (mail_tbl_data->report_status & EMAIL_MAIL_REQUEST_DSN))  {
+               EM_DEBUG_LOG("DSN is required.");
                stream->protocol.esmtp.dsn.want = 1;
                stream->protocol.esmtp.dsn.full = 0;
                stream->protocol.esmtp.dsn.notify.failure = 1;
                stream->protocol.esmtp.dsn.notify.success = 1;
-               EM_DEBUG_LOG("opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON");
        }
        
        mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING;
@@ -1349,9 +1429,9 @@ FINISH_OFF:
 }
 
 /*  send a saved all mails */
-INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_name, email_option_t *sending_option,  int *err_code)
+INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_name, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_name[%p], sending_option[%p], err_code[%p]", account_id, input_mailbox_name, sending_option, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_name[%p], err_code[%p]", account_id, input_mailbox_name, err_code);
        
        int ret = false;
        int err = EMAIL_ERROR_NONE;
@@ -1390,10 +1470,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
        
        FINISH_OFF_IF_CANCELED;
        
-       if (sending_option)
-               opt = sending_option;
-       else
-               opt = emcore_get_option(&err);
+       opt = &(ref_account->options);
        
        /*  search mail. */
        if (!emstorage_mail_search_start(NULL, account_id, input_mailbox_name, 0, &handle, &total, true, &err))  {
@@ -1646,6 +1723,8 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
        if (stream->protocol.esmtp.ok) {
                if (stream->protocol.esmtp.eightbit.ok && stream->protocol.esmtp.eightbit.want)
                        strncat (buf, " BODY=8BITMIME", sizeof(buf)-(strlen(buf)+1));
+
+               EM_DEBUG_LOG("stream->protocol.esmtp.dsn.ok [%d]", stream->protocol.esmtp.dsn.ok);
                
                if (stream->protocol.esmtp.dsn.ok && stream->protocol.esmtp.dsn.want) {
                        EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is required");
@@ -1654,7 +1733,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
                                SNPRINTF (buf + strlen (buf), sizeof(buf)-(strlen(buf)), " ENVID=%.100s", stream->protocol.esmtp.dsn.envid);
                }
                else
-                       EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required");
+                       EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required or DSN is not supported");
        }
        
        EM_PROFILE_BEGIN(profile_prepare_and_head);
@@ -2051,10 +2130,16 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char
                extension = em_get_extension_from_file_path(filename, NULL);
 
                part->body.type = em_get_content_type_from_extension_string(extension, NULL);
-               if(part->body.type == TYPEIMAGE)
+               if(part->body.type == TYPEIMAGE) {
                        part->body.subtype = strdup(extension);
-               else
-                       part->body.subtype = cpystr("octet-stream");
+               } else if (part->body.type == TYPEPKCS7_SIGN) {
+                       part->body.subtype = strdup("pkcs7-signature");
+                       part->body.type = TYPEAPPLICATION;
+               } else if (part->body.type == TYPEPKCS7_MIME) {
+                       part->body.subtype = strdup("pkcs7-mime");
+                       part->body.type = TYPEAPPLICATION;
+               } else
+                       part->body.subtype = strdup("octet-stream");
 
                part->body.encoding = ENCBINARY;
                part->body.size.bytes = data_len;
@@ -2111,8 +2196,8 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char
        else  {   
                /*  text body (plain/html) */
                part->body.type = TYPETEXT;
-               
                part->body.size.bytes = data_len;
+
                if (data)
                        part->body.sparep = EM_SAFE_STRDUP((char *)data); /*  file path */
                else
@@ -2388,112 +2473,102 @@ static void emcore_encode_rfc2047_address(ADDRESS *address, int *err_code)
 }
 
 #define DATE_STR_LENGTH 100
-/*  Description : Make RFC822 text file from mail_tbl data */
-/*  Parameters :  */
-/*                     input_mail_tbl_data :   */
-/*                     is_draft  :  this mail is draft mail. */
-/*                     file_path :  path of file that rfc822 data will be written to. */
-INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code)
+
+static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, ENVELOPE **output_envelope)
 {
-       EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], env[%p], file_path[%p], sending_option[%p], err_code[%p]", input_mail_tbl_data, env, file_path, sending_option, err_code);
-       
-       int       ret = false;
-       int       error = EMAIL_ERROR_NONE;
-       int       is_incomplete = 0;
-       int       i = 0;
-       ENVELOPE *envelope      = NULL;
-       BODY     *text_body     = NULL;
-       BODY     *html_body     = NULL;
-       BODY     *root_body     = NULL;
-       PART     *part_for_html = NULL;
-       PART     *part_for_text = NULL;
-       char     *pAdd = NULL;
-       char     *fname = NULL;
-       email_extra_flag_t extra_flag;
-       email_account_t *ref_account = NULL;
+       EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], output_envelope[%p]", input_mail_tbl_data, output_envelope);
 
-       if (!input_mail_tbl_data)  {
+       int       error                   = EMAIL_ERROR_NONE;
+       int       is_incomplete           = 0;
+       char     *pAdd                    = NULL;
+       char     *outgoing_server_address = NULL;
+       ENVELOPE *envelope                = NULL;
+       email_account_t *ref_account      = NULL;
+
+       if (!input_mail_tbl_data || !output_envelope)  {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
-       
-       if (input_mail_tbl_data->report_status != EMAIL_MAIL_REPORT_MDN && !input_mail_tbl_data->body_download_status) {
+
+       if ( (input_mail_tbl_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0 && !input_mail_tbl_data->body_download_status) {
                EM_DEBUG_EXCEPTION("input_mail_tbl_data->body_download_status[%p]", input_mail_tbl_data->body_download_status);
                error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
-       
-       ref_account = emcore_get_account_reference(input_mail_tbl_data->account_id);
 
-       if (!ref_account)  {    
-               EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", input_mail_tbl_data->account_id);
-               error = EMAIL_ERROR_INVALID_ACCOUNT;
-               goto FINISH_OFF;
+       if (input_mail_tbl_data->account_id) {
+               ref_account = emcore_get_account_reference(input_mail_tbl_data->account_id);
+
+               if (!ref_account)  {
+                       EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", input_mail_tbl_data->account_id);
+                       error = EMAIL_ERROR_INVALID_ACCOUNT;
+                       goto FINISH_OFF;
+               }
+
+               outgoing_server_address = EM_SAFE_STRDUP(ref_account->outgoing_server_address);
        }
-       
+
        if (!(envelope = mail_newenvelope()))  {
                EM_DEBUG_EXCEPTION("mail_newenvelope failed...");
                error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
-       
+
        is_incomplete = input_mail_tbl_data->flags_draft_field || (input_mail_tbl_data->save_status == EMAIL_MAIL_STATUS_SENDING);
-       
+
        if (is_incomplete)  {
                if (ref_account->user_email_address && ref_account->user_email_address[0] != '\0')  {
                        char *p = cpystr(ref_account->user_email_address);
-                       
+
                        if (p == NULL)  {
                                EM_DEBUG_EXCEPTION("cpystr failed...");
                                error = EMAIL_ERROR_OUT_OF_MEMORY;
                                goto FINISH_OFF;
                        }
-                       
-                       EM_DEBUG_LOG("Assign envelop->from");
+
+                       EM_DEBUG_LOG("Assign envelope->from");
 
                        if (input_mail_tbl_data->full_address_from) {
                                char *temp_address_string = NULL ;
                                em_skip_whitespace(input_mail_tbl_data->full_address_from , &temp_address_string);
                                EM_DEBUG_LOG("address[temp_address_string][%s]", temp_address_string);
-                               rfc822_parse_adrlist(&envelope->from, temp_address_string, ref_account->outgoing_server_address);
+                               rfc822_parse_adrlist(&envelope->from, temp_address_string, outgoing_server_address);
                                EM_SAFE_FREE(temp_address_string);
                                temp_address_string = NULL ;
                        }
                        else
                                envelope->from = rfc822_parse_mailbox(&p, NULL);
 
-                       EM_SAFE_FREE(p);                
+                       EM_SAFE_FREE(p);
                        if (!envelope->from)  {
                                EM_DEBUG_EXCEPTION("rfc822_parse_mailbox failed...");
                                error = EMAIL_ERROR_INVALID_ADDRESS;
-                               goto FINISH_OFF;                
+                               goto FINISH_OFF;
                        }
                        else  {
-
                                if (envelope->from->personal == NULL) {
-                                       if (sending_option && sending_option->display_name_from && sending_option->display_name_from[0] != '\0') 
-                                       envelope->from->personal = cpystr(sending_option->display_name_from);
-                               else
-                                       envelope->from->personal =
-                                               (ref_account->user_display_name && ref_account->user_display_name[0] != '\0') ?
-                                               cpystr(ref_account->user_display_name)  :  NULL;
+                                       if (ref_account->options.display_name_from && ref_account->options.display_name_from[0] != '\0')
+                                               envelope->from->personal = cpystr(ref_account->options.display_name_from);
+                                       else
+                                               envelope->from->personal =
+                                                               (ref_account->user_display_name && ref_account->user_display_name[0] != '\0') ?
+                                                               cpystr(ref_account->user_display_name)  :  NULL;
+                               }
                        }
                }
-       }
-               
-       if (ref_account->return_address && ref_account->return_address[0] != '\0')  {
-               char *p = cpystr(ref_account->return_address);
-               
-               if (p == NULL)  {
-                       EM_DEBUG_EXCEPTION("cpystr failed...");
-                       
-                       error = EMAIL_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
+
+               if (ref_account->return_address && ref_account->return_address[0] != '\0')  {
+                       char *p = cpystr(ref_account->return_address);
+
+                       if (p == NULL)  {
+                               EM_DEBUG_EXCEPTION("cpystr failed...");
+                               error = EMAIL_ERROR_OUT_OF_MEMORY;
+                               goto FINISH_OFF;
+                       }
+                       envelope->return_path = rfc822_parse_mailbox(&p, NULL);
+                       EM_SAFE_FREE(p);
                }
-               envelope->return_path = rfc822_parse_mailbox(&p, NULL);
-               EM_SAFE_FREE(p);
-       }
        }
        else  {
                if (!input_mail_tbl_data->full_address_from || !input_mail_tbl_data->full_address_to)  {
@@ -2501,54 +2576,54 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
                        error = EMAIL_ERROR_INVALID_MAIL;
                        goto FINISH_OFF;
                }
-               
+
                int i, j;
-               
+
                if (input_mail_tbl_data->full_address_from)  {
                        for (i = 0, j = strlen(input_mail_tbl_data->full_address_from); i < j; i++)  {
                                if (input_mail_tbl_data->full_address_from[i] == ';')
                                        input_mail_tbl_data->full_address_from[i] = ',';
                        }
                }
-               
+
                if (input_mail_tbl_data->full_address_return)  {
                        for (i = 0, j = strlen(input_mail_tbl_data->full_address_return); i < j; i++)  {
                                if (input_mail_tbl_data->full_address_return[i] == ';')
                                        input_mail_tbl_data->full_address_return[i] = ',';
                        }
                }
-                       em_skip_whitespace(input_mail_tbl_data->full_address_from , &pAdd);
+               em_skip_whitespace(input_mail_tbl_data->full_address_from , &pAdd);
                EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
-       
-               rfc822_parse_adrlist(&envelope->from, pAdd, ref_account->outgoing_server_address);
+
+               rfc822_parse_adrlist(&envelope->from, pAdd, outgoing_server_address);
                EM_SAFE_FREE(pAdd);
-                       pAdd = NULL ;
+               pAdd = NULL;
 
                em_skip_whitespace(input_mail_tbl_data->full_address_return , &pAdd);
                EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
-       
-               rfc822_parse_adrlist(&envelope->return_path, pAdd, ref_account->outgoing_server_address);
+
+               rfc822_parse_adrlist(&envelope->return_path, pAdd, outgoing_server_address);
                EM_SAFE_FREE(pAdd);
-               pAdd = NULL ;
+               pAdd = NULL;
        }
 
        {
                int i, j;
-               
+
                if (input_mail_tbl_data->full_address_to)  {
                        for (i = 0, j = strlen(input_mail_tbl_data->full_address_to); i < j; i++)  {
                                if (input_mail_tbl_data->full_address_to[i] == ';')
                                        input_mail_tbl_data->full_address_to[i] = ',';
                        }
                }
-               
+
                if (input_mail_tbl_data->full_address_cc)  {
                        for (i = 0, j = strlen(input_mail_tbl_data->full_address_cc); i < j; i++)  {
                                if (input_mail_tbl_data->full_address_cc[i] == ';')
                                        input_mail_tbl_data->full_address_cc[i] = ',';
                        }
                }
-               
+
                if (input_mail_tbl_data->full_address_bcc)  {
                        for (i = 0, j = strlen(input_mail_tbl_data->full_address_bcc); i < j; i++)  {
                                if (input_mail_tbl_data->full_address_bcc[i] == ';')
@@ -2559,21 +2634,21 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
 
        em_skip_whitespace(input_mail_tbl_data->full_address_to , &pAdd);
        EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
-       
-       rfc822_parse_adrlist(&envelope->to, pAdd, ref_account->outgoing_server_address);
+
+       rfc822_parse_adrlist(&envelope->to, pAdd, outgoing_server_address);
        EM_SAFE_FREE(pAdd);
        pAdd = NULL ;
-       
+
        EM_DEBUG_LOG("address[input_mail_tbl_data->full_address_cc][%s]", input_mail_tbl_data->full_address_cc);
        em_skip_whitespace(input_mail_tbl_data->full_address_cc , &pAdd);
        EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
-       
-       rfc822_parse_adrlist(&envelope->cc, pAdd, ref_account->outgoing_server_address);
+
+       rfc822_parse_adrlist(&envelope->cc, pAdd, outgoing_server_address);
        EM_SAFE_FREE(pAdd);
                pAdd = NULL ;
 
        em_skip_whitespace(input_mail_tbl_data->full_address_bcc , &pAdd);
-       rfc822_parse_adrlist(&envelope->bcc, pAdd, ref_account->outgoing_server_address);
+       rfc822_parse_adrlist(&envelope->bcc, pAdd, outgoing_server_address);
        EM_SAFE_FREE(pAdd);
                pAdd = NULL ;
 
@@ -2594,40 +2669,138 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
        if (!is_incomplete)  {
                char  localtime_string[DATE_STR_LENGTH] = { 0, };
                strftime(localtime_string, 128, "%a, %e %b %Y %H : %M : %S ", localtime(&input_mail_tbl_data->date_time));
-               /*  append last 5byes("+0900") */
+               /* append last 5byes("+0900") */
                g_strlcat(localtime_string, rfc822_date_string + (strlen(rfc822_date_string) -  5), DATE_STR_LENGTH);
                envelope->date = (unsigned char *)cpystr((const char *)localtime_string);
        }
        else {
                envelope->date = (unsigned char *)cpystr((const char *)rfc822_date_string);
        }
+
+       *output_envelope = envelope;
+
+FINISH_OFF:
+       if (outgoing_server_address)
+               EM_SAFE_FREE(outgoing_server_address);
+
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
+/*  Description : Make RFC822 text file from mail_tbl data */
+/*  Parameters :  */
+/*                     input_mail_tbl_data :   */
+/*                     is_draft  :  this mail is draft mail. */
+/*                     file_path :  path of file that rfc822 data will be written to. */
+INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], env[%p], file_path[%p], sending_option[%p], err_code[%p]", input_mail_tbl_data, env, file_path, sending_option, err_code);
        
-       /* memcpy(&extra_flag, &input_mail_tbl_data->info->extra_flags, sizeof(email_extra_flag_t)); */
+       int       ret = false;
+       int       error = EMAIL_ERROR_NONE;
+       int       i = 0;
+       ENVELOPE *envelope      = NULL;
+       BODY     *text_body     = NULL;
+       BODY     *html_body     = NULL;
+       BODY     *root_body     = NULL;
+       PART     *part_for_html = NULL;
+       PARAMETER *param = NULL;
+       PART     *part_for_text = NULL;
+       char     *fname = NULL;
+
+       if (!input_mail_tbl_data)  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               error = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
        
-       /*  check report input_mail_tbl_data */
-       if (input_mail_tbl_data->report_status != EMAIL_MAIL_REPORT_MDN)  {
-               /* Non-report input_mail_tbl_data */
-               EM_DEBUG_LOG("input_mail_tbl_data->file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
-               EM_DEBUG_LOG("input_mail_tbl_data->file_path_html[%s]", input_mail_tbl_data->file_path_html);
-               EM_DEBUG_LOG("input_mail_tbl_data->body->attachment_num[%d]", input_mail_tbl_data->attachment_count);
-               
+       if ( (input_mail_tbl_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0 && !input_mail_tbl_data->body_download_status) {
+               EM_DEBUG_EXCEPTION("input_mail_tbl_data->body_download_status[%p]", input_mail_tbl_data->body_download_status);
+               error = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       if ( (error = emcore_make_envelope_from_mail(input_mail_tbl_data, &envelope)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emcore_make_envelope_from_mail failed [%d]", error);
+               goto FINISH_OFF;
+       }
+       
+       EM_DEBUG_LOG("input_mail_tbl_data->file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
+       EM_DEBUG_LOG("input_mail_tbl_data->file_path_html[%s]", input_mail_tbl_data->file_path_html);
+       EM_DEBUG_LOG("input_mail_tbl_data->file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity);
+       EM_DEBUG_LOG("input_mail_tbl_data->body->attachment_num[%d]", input_mail_tbl_data->attachment_count);
+
+       if ((input_mail_tbl_data->attachment_count > 0) || (input_mail_tbl_data->file_path_plain && input_mail_tbl_data->file_path_html))  {
+               EM_DEBUG_LOG("attachment_num [%d]", input_mail_tbl_data->attachment_count);
+
+               root_body = mail_newbody();
+               param = mail_newbody_parameter();
+
+               if (root_body == NULL)  {
+                       EM_DEBUG_EXCEPTION("mail_newbody failed...");
+                       error = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
                
-               if ((input_mail_tbl_data->attachment_count > 0) || (input_mail_tbl_data->file_path_plain && input_mail_tbl_data->file_path_html))  {
-                       EM_DEBUG_LOG("attachment_num  :  %d", input_mail_tbl_data->attachment_count);
-                       root_body = mail_newbody();
+               if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE) {
 
-                       if (root_body == NULL)  {
-                               EM_DEBUG_EXCEPTION("mail_newbody failed...");
-                               error = EMAIL_ERROR_OUT_OF_MEMORY;
-                               goto FINISH_OFF;
-                       }
-                       
                        root_body->type               = TYPEMULTIPART;
                        root_body->subtype            = EM_SAFE_STRDUP("MIXED");
-                       root_body->contents.text.data = NULL;
-                       root_body->contents.text.size = 0;
-                       root_body->size.bytes         = 0;
 
+                       param = NULL;
+
+               } else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED) {
+                       PARAMETER *protocol_param     = mail_newbody_parameter();
+               
+                       root_body->type               = TYPEMULTIPART;
+                       root_body->subtype            = EM_SAFE_STRDUP("SIGNED");
+                       
+                       param->attribute       = cpystr("micalg");
+                       switch (input_mail_tbl_data->digest_type) {
+                       case DIGEST_TYPE_SHA1:
+                               param->value   = cpystr("sha1");
+                               break;
+                       case DIGEST_TYPE_MD5:
+                               param->value   = cpystr("md5");
+                               break;
+                       default:
+                               EM_DEBUG_EXCEPTION("Invalid digest type");
+                               break;
+                       }
+
+                       protocol_param->attribute   = cpystr("protocol");
+                       protocol_param->value       = cpystr("application/pkcs7-signature");
+                       protocol_param->next        = NULL;
+                       param->next                 = protocol_param;
+
+                       input_mail_tbl_data->file_path_plain = NULL;
+                       input_mail_tbl_data->file_path_html = NULL;
+
+                       input_attachment_tbl = input_attachment_tbl + (input_attachment_count - 1);
+
+                       input_attachment_count = 1;
+
+               } else {
+       
+                       root_body->type    = TYPEAPPLICATION;
+                       root_body->subtype = EM_SAFE_STRDUP("PKCS7-MIME");
+                       
+                       param->attribute = cpystr("name");
+                       param->value = cpystr("smime.p7m");
+                       param->next = NULL;
+
+                       input_mail_tbl_data->file_path_plain = NULL;
+                       input_mail_tbl_data->file_path_html = NULL;
+                       input_mail_tbl_data->file_path_mime_entity = NULL;
+
+                       input_attachment_count = 1;
+               }
+
+               root_body->contents.text.data = NULL;
+               root_body->contents.text.size = 0;
+               root_body->size.bytes         = 0;
+               root_body->parameter          = param;
+               
+               if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE) {
                        part_for_text = attach_mutipart_with_sub_type(root_body, "ALTERNATIVE", &error);
 
                        if (!part_for_text) {
@@ -2636,134 +2809,110 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
                        }
 
                        text_body = &part_for_text->body;
-                       
-                       if (input_mail_tbl_data->file_path_plain && strlen(input_mail_tbl_data->file_path_plain) > 0)  {
-                               EM_DEBUG_LOG("file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
-                               if (!attach_part(text_body, (unsigned char *)input_mail_tbl_data->file_path_plain, 0, NULL, NULL, false, &error))  {
-                                       EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
-                                       goto FINISH_OFF;
-                               }
+               } 
+
+               if (input_mail_tbl_data->file_path_plain && strlen(input_mail_tbl_data->file_path_plain) > 0)  {
+                       EM_DEBUG_LOG("file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
+                       if (!attach_part(text_body, (unsigned char *)input_mail_tbl_data->file_path_plain, 0, NULL, NULL, false, &error))  {
+                               EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+                               goto FINISH_OFF;
                        }
-                       
-                       if (input_mail_tbl_data->file_path_html && strlen(input_mail_tbl_data->file_path_html) > 0)  {
-                               EM_DEBUG_LOG("file_path_html[%s]", input_mail_tbl_data->file_path_html);
+               }
 
-                               part_for_html = attach_mutipart_with_sub_type(text_body, "RELATED", &error);
-                               if (!part_for_html) {
-                                       EM_DEBUG_EXCEPTION("attach_mutipart_with_sub_type [part_for_html] failed [%d]", error);
-                                       goto FINISH_OFF;
-                               }
+               if (input_mail_tbl_data->file_path_html && strlen(input_mail_tbl_data->file_path_html) > 0)  {
+                       EM_DEBUG_LOG("file_path_html[%s]", input_mail_tbl_data->file_path_html);
 
-                               if (!attach_part(&(part_for_html->body) , (unsigned char *)input_mail_tbl_data->file_path_html, 0, NULL, "html", false, &error))  {
-                                       EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
-                                       goto FINISH_OFF;
-                               }
+                       part_for_html = attach_mutipart_with_sub_type(text_body, "RELATED", &error);
+                       if (!part_for_html) {
+                               EM_DEBUG_EXCEPTION("attach_mutipart_with_sub_type [part_for_html] failed [%d]", error);
+                               goto FINISH_OFF;
                        }
+
+                       if (!attach_part(&(part_for_html->body) , (unsigned char *)input_mail_tbl_data->file_path_html, 0, NULL, "html", false, &error))  {
+                               EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+                               goto FINISH_OFF;
+                       }
+               }
+
+               if (input_mail_tbl_data->file_path_mime_entity && strlen(input_mail_tbl_data->file_path_mime_entity) > 0) {
+                       EM_DEBUG_LOG("file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity);
+                       root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_mime_entity);
+               }
+       
+               if (input_attachment_tbl && input_attachment_count)  {
+                       emstorage_attachment_tbl_t *temp_attachment_tbl = NULL;
+                       char *name = NULL;
+                       BODY *body_to_attach = NULL;
+                       struct stat st_buf;
                        
-                       if (input_attachment_tbl && input_attachment_count)  {
-                               emstorage_attachment_tbl_t *temp_attachment_tbl = NULL;
-                               char *name = NULL;
-                               BODY *body_to_attach = NULL; 
-                               struct stat st_buf;
-                               
-                               for(i = 0; i < input_attachment_count; i++) {
-                                       temp_attachment_tbl = input_attachment_tbl + i;
-                                       EM_DEBUG_LOG("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path);
-                                       if (stat(temp_attachment_tbl->attachment_path, &st_buf) == 0)  {
-                                               if (!temp_attachment_tbl->attachment_name)  {
-                                                       if (!emcore_get_file_name(temp_attachment_tbl->attachment_path, &name, &error))  {
-                                                               EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error);
-                                                               continue;
-                                                       }
-                                               }
-                                               else 
-                                                       name = temp_attachment_tbl->attachment_name;
-                                               EM_DEBUG_LOG("name[%s]", name);
-
-                                               if (temp_attachment_tbl->attachment_inline_content_status && part_for_html)
-                                                       body_to_attach = &(part_for_html->body);
-                                               else
-                                                       body_to_attach = root_body;
-                                               
-                                               if (!attach_part(body_to_attach, (unsigned char *)temp_attachment_tbl->attachment_path, 0, name, NULL, temp_attachment_tbl->attachment_inline_content_status, &error))  {
-                                                       EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+                       for(i = 0; i < input_attachment_count; i++) {
+                               temp_attachment_tbl = input_attachment_tbl + i;
+                               EM_DEBUG_LOG("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path);
+                               if (stat(temp_attachment_tbl->attachment_path, &st_buf) == 0)  {
+                                       if (!temp_attachment_tbl->attachment_name)  {
+                                               if (!emcore_get_file_name(temp_attachment_tbl->attachment_path, &name, &error))  {
+                                                       EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error);
                                                        continue;
                                                }
                                        }
+                                       else
+                                               name = temp_attachment_tbl->attachment_name;
+
+                                       EM_DEBUG_LOG("name[%s]", name);
+
+                                       if (temp_attachment_tbl->attachment_inline_content_status && part_for_html)
+                                               body_to_attach = &(part_for_html->body);
+                                       else
+                                               body_to_attach = root_body;
+
+                                       if (!attach_part(body_to_attach, (unsigned char *)temp_attachment_tbl->attachment_path, 0, name, NULL, temp_attachment_tbl->attachment_inline_content_status, &error))  {
+                                               EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+                                               continue;
+                                       }
                                }
                        }
-                       text_body = NULL; 
                }
-               else  {
-                       text_body = mail_newbody();
-                       
-                       if (text_body == NULL)  {
-                               EM_DEBUG_EXCEPTION("mail_newbody failed...");
-                               
-                               error = EMAIL_ERROR_OUT_OF_MEMORY;
-                               goto FINISH_OFF;
-                       }
-                       
-                       text_body->type = TYPETEXT;
-                       text_body->encoding = ENC8BIT;
-                       if (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)
-                               text_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_plain ? input_mail_tbl_data->file_path_plain  :  input_mail_tbl_data->file_path_html);
-                       else
-                               text_body->sparep = NULL;
+               text_body = NULL;
+       }
+       else  {
+               text_body = mail_newbody();
+
+               if (text_body == NULL)  {
+                       EM_DEBUG_EXCEPTION("mail_newbody failed...");
                        
-                       if (input_mail_tbl_data->file_path_html != NULL && input_mail_tbl_data->file_path_html[0] != '\0')
-                               text_body->subtype = EM_SAFE_STRDUP("html");
-                       if (text_body->sparep)
-                               text_body->size.bytes = strlen(text_body->sparep);
-                       else
-                               text_body->size.bytes = 0;
+                       error = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
                }
+
+               text_body->type = TYPETEXT;
+               text_body->encoding = ENC8BIT;
+               if (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)
+                       text_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_plain ? input_mail_tbl_data->file_path_plain  :  input_mail_tbl_data->file_path_html);
+               else
+                       text_body->sparep = NULL;
+
+               if (input_mail_tbl_data->file_path_html != NULL && input_mail_tbl_data->file_path_html[0] != '\0')
+                       text_body->subtype = EM_SAFE_STRDUP("html");
+               if (text_body->sparep)
+                       text_body->size.bytes = strlen(text_body->sparep);
+               else
+                       text_body->size.bytes = 0;
        }
-       else  { /*  Report mail */
+
+
+       if (input_mail_tbl_data->report_status & EMAIL_MAIL_REPORT_MDN) {
+               /*  Report mail */
                EM_DEBUG_LOG("REPORT MAIL");
                envelope->references = cpystr(input_mail_tbl_data->message_id);
-               /* Below codes should not be here. TODO : Move these to proper location. */
-#ifdef __FEATURE_SUPPORT_REPORT_MAIL__         
-               if (emcore_get_report_mail_body(envelope, &root_body, &error))  {
-                       if (!input_mail_tbl_data)  {
-                               input_mail_tbl_data->file_path_plain  = EM_SAFE_STRDUP(root_body->nested.part->body.sparep);
-                               input_mail_tbl_data->attachment_count = 1;
-                               input_attachment_count                = 1;
-                               
-                               if(input_attachment_tbl)
-                                       emstorage_free_attachment(&input_attachment_tbl, input_attachment_count, NULL);
-
-                               input_attachment_tbl = em_malloc(sizeof(emstorage_attachment_tbl_t));
-                               if (!input_attachment_tbl)  {
-                                       EM_DEBUG_EXCEPTION("malloc failed...");
-                                       EM_SAFE_FREE(input_mail_tbl_data->file_path_plain);
-                                       error = EMAIL_ERROR_OUT_OF_MEMORY;
-                                       goto FINISH_OFF;
-                               }
-                               
-                               input_mail_tbl_data->body->attachment->downloaded = 1;
-                               input_mail_tbl_data->body->attachment->savename = EM_SAFE_STRDUP(root_body->nested.part->next->body.sparep);
-                               
-                               char *p = NULL;
-                               
-                               if (!emcore_get_file_name(input_mail_tbl_data->body->attachment->savename, &p, &error))  {
-                                       EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error);
-                                       goto FINISH_OFF;
-                               }
-                               
-                               input_mail_tbl_data->body->attachment->name = cpystr(p);
-                       }
-               }
-#endif         
        }
        
        if (file_path)  {
-               EM_DEBUG_LOG("write rfc822  :  file_path[%s]", file_path);
+               EM_DEBUG_LOG("write rfc822 : file_path[%s]", file_path);
 
                if (part_for_html)
                        html_body = &(part_for_html->body);
 
-               if (!emcore_write_rfc822(envelope, root_body ? root_body  :  text_body, html_body, extra_flag, &fname, &error))  {
+               if (!emcore_write_rfc822(envelope, root_body ? root_body  :  text_body, html_body, input_mail_tbl_data->priority, input_mail_tbl_data->report_status, &fname, &error))  {
                        EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error);
                        goto FINISH_OFF;
                }
@@ -2787,6 +2936,7 @@ FINISH_OFF:
        
        if (err_code != NULL)
                *err_code = error;
+
        EM_DEBUG_FUNC_END("ret [%d]", ret);
        return ret;
 }
@@ -2809,8 +2959,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data
        char      temp_file_path_html[512];
        char     *pAdd                 = NULL;
        char     *fname                = NULL;
-       email_extra_flag_t extra_flag;
-       email_account_t *ref_account     = NULL;
+       emstorage_account_tbl_t *ref_account     = NULL;
 
        if (!input_mail_tbl_data)  {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -2818,13 +2967,16 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data
                goto FINISH_OFF;
        }
        
-       if (input_mail_tbl_data->report_status != EMAIL_MAIL_REPORT_MDN && !input_mail_tbl_data->body_download_status) {
+       if ( (input_mail_tbl_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0 && !input_mail_tbl_data->body_download_status) {
                EM_DEBUG_EXCEPTION("input_mail_tbl_data->body_download_status[%p]", input_mail_tbl_data->body_download_status);
                error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
-       ref_account = emcore_get_account_reference(input_mail_tbl_data->account_id);
+       if (!emstorage_get_account_by_id(input_mail_tbl_data->account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &ref_account, true, &error)) {
+               EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", error);
+               goto FINISH_OFF;        
+       }
 
        if (!ref_account)  {    
                EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", input_mail_tbl_data->account_id);
@@ -2999,7 +3151,6 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data
        else {
                envelope->date = (unsigned char *)cpystr((const char *)rfc822_date_string);
        }
-       /* memcpy(&extra_flag, &input_mail_tbl_data->info->extra_flags, sizeof(email_extra_flag_t)); */
        /*  check report input_mail_tbl_data */
        
        /* Non-report input_mail_tbl_data */
@@ -3021,7 +3172,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data
                memset(temp_file_path_html, 0x00, sizeof(temp_file_path_html));
                SNPRINTF(temp_file_path_html, sizeof(temp_file_path_html), "%s%s%s%s%s", MAILHOME, DIR_SEPERATOR, MAILTEMP, DIR_SEPERATOR, "UTF-8.htm");
 
-               if (!emstorage_copy_file(input_mail_tbl_data->file_path_plain, temp_file_path_html, 0, &error)) {
+               if (!emstorage_copy_file(input_mail_tbl_data->file_path_html, temp_file_path_html, 0, &error)) {
                        EM_DEBUG_EXCEPTION("emstorage_copy_file failed : [%d]", error);
                        goto FINISH_OFF;
                }
@@ -3139,7 +3290,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data
                if (part_for_html)
                        html_body = &(part_for_html->body);
 
-               if (!emcore_write_rfc822(envelope, root_body ? root_body  :  text_body, html_body, extra_flag, &fname, &error))  {
+               if (!emcore_write_rfc822(envelope, root_body ? root_body  :  text_body, html_body, input_mail_tbl_data->priority, input_mail_tbl_data->report_status, &fname, &error))  {
                        EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error);
                        goto FINISH_OFF;
                }
@@ -3230,10 +3381,12 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body
                err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
-       
-       if (envelope->from->personal) 
+
+       /*
+       if (envelope->from->personal)
                SNPRINTF(buf, sizeof(buf), "%s <%s@%s>", envelope->from->personal, envelope->from->mailbox, envelope->from->host);
-       else 
+       else
+       */
                SNPRINTF(buf, sizeof(buf), "%s@%s", envelope->from->mailbox, envelope->from->host);
        
        fprintf(fp, "Your message has been read by %s"CRLF_STRING, buf);
@@ -3248,7 +3401,7 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body
        
        text_body->type = TYPETEXT;
        text_body->encoding = ENC8BIT;
-       text_body->sparep = fname;
+       text_body->sparep = EM_SAFE_STRDUP(fname);
        text_body->size.bytes = (unsigned long)sz;
        
        if (!emcore_get_temp_file_name(&fname, &err))  {
@@ -3276,7 +3429,7 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body
        
        memset(&temp_attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t));
        
-       temp_attachment_tbl.attachment_path = fname;
+       temp_attachment_tbl.attachment_path = EM_SAFE_STRDUP(fname);
        
        if (!emcore_get_file_size(fname, &temp_attachment_tbl.attachment_size, &err))  {
                EM_DEBUG_EXCEPTION(" emcore_get_file_size failed [%d]", err);
@@ -3303,9 +3456,9 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body
                goto FINISH_OFF;
        }
        
-       param->attribute = EM_SAFE_STRDUP("report-type");
-       param->value = EM_SAFE_STRDUP("disposition-notification");
-       param->next = m_body->parameter;
+       param->attribute  = EM_SAFE_STRDUP("report-type");
+       param->value      = EM_SAFE_STRDUP("disposition-notification");
+       param->next       = m_body->parameter;
        
        m_body->parameter = param;
        
@@ -3314,8 +3467,8 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body
        p_body = &m_body->nested.part->next->body;
        
        /*  set content-type to message/disposition-notification */
-       p_body->type = TYPEMESSAGE;
-       p_body->encoding = ENC7BIT;
+       p_body->type      = TYPEMESSAGE;
+       p_body->encoding  = ENC7BIT;
        
        EM_SAFE_FREE(p_body->subtype);
        
@@ -3347,7 +3500,8 @@ FINISH_OFF:
        
        if (err_code != NULL)
                *err_code = err;
-       
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
        return ret;
 }
 #endif
index 91fda52..3b6a318 100755 (executable)
@@ -79,9 +79,6 @@
 #define EMAIL_CH_SPACE            ' '
 #define EMAIL_NOTI_ICON_PATH      "/opt/data/email/res/image/Q02_Notification_email.png"
 
-static char _g_display[G_DISPLAY_LENGTH];
-
-
 typedef struct  _em_transaction_info_type_t {
        int mail_id;
        int     handle; 
@@ -91,21 +88,8 @@ typedef struct  _em_transaction_info_type_t {
 
 em_transaction_info_type_t  *g_transaction_info_list;
 
-static email_option_t g_mail_option = 
-{
-       0, /* priority                  */
-       1, /* keep_local_copy */
-       0, /* req_delivery_receipt */
-       0, /* req_read_receipt */
-       0, /* download_limit */
-       0, /* block_address */
-       0, /* block_subject */
-       NULL, /*  diplay name */
-};
-
 static email_session_t g_session_list[SESSION_MAX] = { {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},};
 
-
 typedef struct emcore_account_list_t emcore_account_list_t;
 struct emcore_account_list_t {
        email_account_t *account;
@@ -126,48 +110,6 @@ INTERNAL_FUNC int emcore_set_account_reference(emcore_account_list_t **account_l
        return 1;
 }
 
-email_option_t *emcore_get_option(int *err_code)
-{
-       if (err_code != NULL)
-               *err_code = EMAIL_ERROR_NONE;
-
-       return &g_mail_option;
-}
-
-INTERNAL_FUNC int emcore_set_option(email_option_t *opt, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("opt[%p], err_code[%p]", opt, err_code);
-       
-       int err = EMAIL_ERROR_NONE;
-       
-       if (!opt) {
-               EM_DEBUG_EXCEPTION("opt[%p]", opt);
-               
-               if (err_code != NULL)
-                       *err_code = EMAIL_ERROR_INVALID_PARAM;
-               return false;
-       }
-       
-       memset(_g_display, 0, G_DISPLAY_LENGTH);
-       memcpy(&g_mail_option, opt, sizeof(g_mail_option));
-
-       if (opt->display_name_from && opt->display_name_from[0] != '\0')  {
-               strncpy(_g_display, opt->display_name_from, G_DISPLAY_LENGTH - 1);
-               g_mail_option.display_name_from = _g_display;
-       }
-       else
-               g_mail_option.display_name_from = NULL;
-       
-       if (err_code != NULL)
-               *err_code = err;
-       
-       return true;
-}
-
-       
-
-
-
 /*  in smtp case, path argument must be ENCODED_PATH_SMTP */
 int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
 {
@@ -1038,19 +980,19 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
 
        local_preview_buffer_length = input_preview_buffer_length * 2;
 
-       if (input_html_path != NULL) {  
+       if ( input_html_path != NULL) {
                /*      get preview text from html file */
                if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
                        goto FINISH_OFF;
                }
-               
+
                if (stat(input_html_path, &st_buf) < 0)  {
                        EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path);
                        err = EMAIL_ERROR_INVALID_MAIL;
                        goto FINISH_OFF;
                }
-               
+
                if (!(fp = fopen(input_html_path, "r")))        {
                        EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path);
                        err = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -1062,9 +1004,9 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
                        err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
-               
+
                byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp);
-               
+
                if (ferror(fp)) {
                        EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
                        err = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -1079,13 +1021,13 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
                result_strlen = EM_SAFE_STRLEN(local_preview_text);
        }
 
-       if (local_preview_text == NULL && input_plain_path != NULL) {   
+       if ( (local_preview_text == NULL || (local_preview_text && strlen(local_preview_text) == 0) ) && input_plain_path != NULL) {
                /*  get preview text from plain text file */
                if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
                        goto FINISH_OFF;
                }
-               
+
                if (!(fp = fopen(input_plain_path, "r")))  {
                        EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path);
                        err = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -1096,24 +1038,26 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
                        EM_DEBUG_EXCEPTION("em_malloc failed");
                        goto FINISH_OFF;
                }
-               
+
                byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp);
-               
+
                if (ferror(fp)) {
                        EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
                        err = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;
                }
 
-               reg_replace(local_preview_text, CR_STRING, "");
-               reg_replace(local_preview_text, LF_STRING, "");
-               reg_replace(local_preview_text, TAB_STRING, "");
-                       
+               reg_replace(local_preview_text, CR_STRING, " ");
+               reg_replace(local_preview_text, LF_STRING, " ");
+               reg_replace(local_preview_text, TAB_STRING, " ");
+
                result_strlen = EM_SAFE_STRLEN(local_preview_text);
-       }       
-       
+       }
+
+
 
        if(local_preview_text) {
+               em_trim_left(local_preview_text);
                if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
                        EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
                        utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
@@ -1341,10 +1285,10 @@ int emcore_strip_HTML(char *source_string)
        
        reg_replace(source_string, CR_STRING, " ");
        reg_replace(source_string, LF_STRING, " ");
-       reg_replace(source_string, TAB_STRING, " ");
        reg_replace(source_string, "<head[^>]*>", "<head>"); /*  "<()*head([^>])*>", "<head>" */
        reg_replace(source_string, "<*/head>", "</head>");  /*  "(<()*(/)()*head()*>)", "</head>" */
        reg_replace(source_string, "<head>.*</head>", ""); /*  "(<head>).*(</head>)", "" */
+       reg_replace(source_string, "<style[^>]*>.*</style>", "");
 
        reg_replace(source_string, "<*/p>", " ");
        reg_replace(source_string, "<br>", " ");
@@ -1390,352 +1334,6 @@ int emcore_strip_HTML(char *source_string)
        return result;
 }
 
-#define MAX_NOTI_STRING_LENGTH         8096
-
-INTERNAL_FUNC int emcore_convert_structure_to_string(void *struct_var, char **encoded_string, email_convert_struct_type_e type)
-{
-       EM_DEBUG_FUNC_BEGIN("Struct type[%d]", type);
-       
-       char *buf = NULL;
-       char delimiter[] = {0x01, 0x00};
-       int error_code = EMAIL_ERROR_NONE;
-
-       buf = (char *) malloc(MAX_NOTI_STRING_LENGTH * sizeof(char));
-       if (NULL == buf) {
-               error_code = EMAIL_ERROR_OUT_OF_MEMORY;
-               goto FINISH_OFF;                
-       }
-       switch (type) {
-               case EMAIL_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM: {
-                       email_mail_list_item_t *item = (email_mail_list_item_t *)struct_var;
-                       SNPRINTF(buf, MAX_NOTI_STRING_LENGTH, 
-                               "%d%c"  /*      int  mail_id                                    ; */
-                               "%d%c"  /*      int  account_id                                                                 ; */
-                               "%d%c"  /*      int  mailbox_id                                 ; */
-                               "%s%c"  /*      char from[STRING_LENGTH_FOR_DISPLAY]                    ; */
-                               "%s%c"  /*      char from_email_address[MAX_EMAIL_ADDRESS_LENGTH]; */
-                               "%s%c"  /*      char recipients[STRING_LENGTH_FOR_DISPLAY]      ; */
-                               "%s%c"  /*      char subject[STRING_LENGTH_FOR_DISPLAY]                 ; */
-                               "%d%c"  /*      int  is_text_downloaded                                                 ; */
-                               "%d%c"  /*      time_t date_time                                ; */
-                               "%d%c"  /*      int  flags_seen_field                           ; */
-                               "%d%c"  /*      int  priority                                                                   ; */
-                               "%d%c"  /*      int  save_status                                ; */
-                               "%d%c"  /*      int  is_locked                                                                  ; */
-                               "%d%c"  /*      int  is_report_mail                                                             ; */
-                               "%d%c"  /*      int  recipients_count                                                   ; */
-                               "%d%c"  /*      int  has_attachment                             ; */
-                               "%d%c"  /*      int  has_drm_attachment                                                 ; */
-                               "%s%c"  /*      char previewBodyText[MAX_PREVIEW_TEXT_LENGTH]   ; */
-                               "%d%c"  /*      int  thread_id                                                                  ; */
-                               "%d%c", /*      int  thread_item_count                                                  ; */
-
-                               item->mail_id,              delimiter[0],
-                               item->account_id,           delimiter[0],
-                               item->mailbox_id,           delimiter[0],
-                               item->from,                 delimiter[0],
-                               item->from_email_address,   delimiter[0],
-                               item->recipients,           delimiter[0],
-                               item->subject,              delimiter[0],
-                               item->is_text_downloaded,   delimiter[0],
-                               (unsigned int)item->date_time,       delimiter[0],
-                               item->flags_seen_field,     delimiter[0],
-                               item->priority,                         delimiter[0],
-                               item->save_status,          delimiter[0],
-                               item->is_locked,            delimiter[0],
-                               item->is_report_mail,       delimiter[0],
-                               item->recipients_count,     delimiter[0],
-                               item->has_attachment,       delimiter[0],
-                               item->has_drm_attachment,   delimiter[0],
-                               item->previewBodyText,      delimiter[0],
-                               item->thread_id,            delimiter[0],
-                               item->thread_item_count,    delimiter[0]
-                       );
-               }               
-                       break;
-       }
-
-FINISH_OFF:
-       if (encoded_string)
-               *encoded_string = buf;
-       EM_DEBUG_FUNC_END("Struct -> String:[%s]\n", buf);
-       return error_code;
-}
-
-INTERNAL_FUNC int emcore_convert_string_to_structure(const char *encoded_string, void **struct_var, email_convert_struct_type_e type)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       
-       int ret = false;
-       void *temp_struct = NULL;
-       char *buff = NULL;
-       char *current_pos = NULL;
-       char *found_pos = NULL;
-       char delimiter[] = {0x01, 0x00};
-       int error_code = EMAIL_ERROR_NONE;
-
-       EM_DEBUG_LOG("Struct Type[%d], String:[%s]", type, encoded_string);
-
-       buff = (char *)EM_SAFE_STRDUP(encoded_string);
-       if (NULL == buff) {
-               error_code = EMAIL_ERROR_OUT_OF_MEMORY;
-               goto FINISH_OFF;                
-       }
-       
-       switch (type) {
-               case EMAIL_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM: {
-                       email_mail_list_item_t *item = (email_mail_list_item_t *)malloc(sizeof(email_mail_list_item_t));
-                       if (NULL == item) {
-                               error_code = EMAIL_ERROR_OUT_OF_MEMORY;
-                               goto FINISH_OFF;                
-                       }
-                       temp_struct = (void *)item;
-
-                       current_pos = buff;
-
-                       /*  mail_id */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->mail_id = atoi(current_pos);
-                       EM_DEBUG_LOG("mail_id[%d]", item->mail_id);
-                       current_pos = found_pos + 1;
-
-                       /*  account_id */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->account_id = atoi(current_pos);
-                       EM_DEBUG_LOG("account_id[%d]", item->account_id);
-                       current_pos = found_pos + 1;
-
-                       /*  mailbox_id */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->mailbox_id = atoi(current_pos);
-                       EM_DEBUG_LOG("mailbox_id[%s]", item->mailbox_id);
-                       current_pos = found_pos + 1;
-
-                       /*  from */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       strncpy(item->from, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
-                       EM_DEBUG_LOG("from[%s]", item->from);
-                       current_pos = found_pos + 1;
-
-                       /*  from_email_address */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       strncpy(item->from_email_address, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
-                       EM_DEBUG_LOG("from_email_address[%s]", item->from_email_address);
-                       current_pos = found_pos + 1;
-
-                       /*  recipients */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       strncpy(item->recipients, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
-                       EM_DEBUG_LOG("recipients[%s]", item->recipients);
-                       current_pos = found_pos + 1;                    
-
-                       /*  subject */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       strncpy(item->subject, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
-                       EM_DEBUG_LOG("subject[%s]", item->subject);
-                       current_pos = found_pos + 1;                    
-
-                       /*  is_text_downloaded */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->is_text_downloaded = atoi(current_pos);
-                       EM_DEBUG_LOG("is_text_downloaded[%d]", item->is_text_downloaded);
-                       current_pos = found_pos + 1;
-
-                       /*  datatime */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->date_time = atoi(current_pos);
-                       EM_DEBUG_LOG("date_time[%d]", item->date_time);
-                       current_pos = found_pos + 1;
-
-                       /*  flags_seen_field */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->flags_seen_field = atoi(current_pos);
-                       EM_DEBUG_LOG("flags_seen_field[%d]", item->flags_seen_field);
-                       current_pos = found_pos + 1;
-
-                       /*  priority */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->priority = atoi(current_pos);
-                       EM_DEBUG_LOG("priority[%d]", item->priority);
-                       current_pos = found_pos + 1;                    
-
-                       /*  save_status */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->save_status = atoi(current_pos);
-                       EM_DEBUG_LOG("save_status[%d]", item->save_status);
-                       current_pos = found_pos + 1;    
-
-                       /*  is_locked */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->is_locked = atoi(current_pos);
-                       EM_DEBUG_LOG("is_locked[%d]", item->is_locked);
-                       current_pos = found_pos + 1;    
-
-                       /*  is_report_mail */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->is_report_mail = atoi(current_pos);
-                       EM_DEBUG_LOG("is_report_mail[%d]", item->is_report_mail);
-                       current_pos = found_pos + 1;    
-
-                       /*  recipients_count */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->recipients_count = atoi(current_pos);
-                       EM_DEBUG_LOG("is_report_mail[%d]", item->recipients_count);
-                       current_pos = found_pos + 1;                            
-
-                       /*  has_attachment */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->has_attachment = atoi(current_pos);
-                       EM_DEBUG_LOG("has_attachment[%d]", item->has_attachment);
-                       current_pos = found_pos + 1;                            
-
-                       /*  has_drm_attachment */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->has_drm_attachment = atoi(current_pos);
-                       EM_DEBUG_LOG("has_drm_attachment[%d]", item->has_drm_attachment);
-                       current_pos = found_pos + 1;                            
-
-                       /*  previewBodyText */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       strncpy(item->previewBodyText, current_pos, MAX_PREVIEW_TEXT_LENGTH-1);
-                       EM_DEBUG_LOG("previewBodyText[%s]", item->previewBodyText);
-                       current_pos = found_pos + 1;    
-
-                       /*  thread_id */
-                       found_pos = strstr(current_pos, delimiter);
-                       if (NULL == found_pos) {
-                               error_code = EMAIL_ERROR_INVALID_DATA;
-                               goto FINISH_OFF;                
-                       }
-                       *found_pos = NULL_CHAR;
-                       item->thread_id = atoi(current_pos);
-                       EM_DEBUG_LOG("thread_id[%d]", item->thread_id);
-                       current_pos = found_pos + 1;    
-
-                       /*  thread_item_count - the last item */
-                       item->thread_item_count = atoi(current_pos);
-                       EM_DEBUG_LOG("thread_item_count[%d]", item->thread_item_count);
-                       
-               }
-                       break;
-                       
-               default:
-                       EM_DEBUG_EXCEPTION("Unknown structure type");
-                       break;
-       }
-
-       ret = true;
-       
-FINISH_OFF:
-       EM_SAFE_FREE(buff);
-       if (ret == true) {
-               if (struct_var)
-                       *struct_var = temp_struct;
-       }
-       else {
-               switch (type) {
-                       case EMAIL_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM:
-                               EM_SAFE_FREE(temp_struct);
-                               break;
-                       default:
-                               break;
-               }
-       }
-       EM_DEBUG_FUNC_END();
-       return error_code;
-}
-
-
 /*  emcore_send_noti_for_new_mail is not used currently because DBUS could not send very long message.*/
 /*  But I think it can be used to notify incomming new mail for replacing NOTI_MAIL_ADD with some modification(uid should be replaced with mail_id).  */
 /*  This notification is including addtional information comparing NOTI_MAIL_ADD. */
@@ -1874,7 +1472,6 @@ INTERNAL_FUNC int emcore_delete_notification_for_read_mail(int mail_id)
 {
        EM_DEBUG_FUNC_BEGIN();
        int error_code = EMAIL_ERROR_NONE;
-
        EM_DEBUG_FUNC_END();
        return error_code;
 }
index b71ba96..0983388 100755 (executable)
@@ -140,27 +140,31 @@ INTERNAL_FUNC int emnetwork_check_network_status(int *err_code)
        }
 
        if(network_status == 0) {
-               if ( (err = _get_sim_status(&sim_status)) != EMAIL_ERROR_NONE) {
-                       EM_DEBUG_EXCEPTION("_get_sim_status failed [%d]", err);
+               EM_DEBUG_LOG("VCONFKEY_NETWORK_STATUS is 0");
+
+               if ( (err = _get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION("_get_wifi_status failed [%d]", err);
                        goto FINISH_OFF;
                }
 
-               if (sim_status != VCONFKEY_TELEPHONY_SIM_INSERTED) {
-                       EM_DEBUG_LOG("EMAIL_ERROR_NO_SIM_INSERTED");
-                       if ( (err = _get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) {
-                               EM_DEBUG_EXCEPTION("_get_wifi_status failed [%d]", err);
+               if (wifi_status == 0) {
+                       EM_DEBUG_LOG("Furthermore, WIFI is off");
+
+                       if ( (err = _get_sim_status(&sim_status)) != EMAIL_ERROR_NONE) {
+                               EM_DEBUG_EXCEPTION("_get_sim_status failed [%d]", err);
                                goto FINISH_OFF;
                        }
 
-                       if (wifi_status == 0) {
-                               EM_DEBUG_EXCEPTION("Furthermore, WIFI is off");
+                       if (sim_status != VCONFKEY_TELEPHONY_SIM_INSERTED) {
+                               EM_DEBUG_EXCEPTION("EMAIL_ERROR_NO_SIM_INSERTED");
                                err = EMAIL_ERROR_NO_SIM_INSERTED;
                                goto FINISH_OFF;
                        }
+
+                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_NETWORK_NOT_AVAILABLE");
+                       err = EMAIL_ERROR_NETWORK_NOT_AVAILABLE;
+                       goto FINISH_OFF;
                }
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_NETWORK_NOT_AVAILABLE");
-               err = EMAIL_ERROR_NETWORK_NOT_AVAILABLE;
-               goto FINISH_OFF;
        }
 
        EM_DEBUG_LOG("Data Network Mode is ON");
index 79db260..449c787 100755 (executable)
@@ -611,6 +611,7 @@ enum
        SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL,
        SERVER_MAIL_ID_IDX_IN_MAIL_TBL,
        MESSAGE_ID_IDX_IN_MAIL_TBL,
+       REFERENCE_ID_IDX_IN_MAIL_TBL,
        FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL,
        FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL,
        FULL_ADDRESS_TO_IDX_IN_MAIL_TBL,
@@ -798,29 +799,30 @@ static char *g_test_query[] = {
                "       server_mail_status, "
                "       server_mailbox_name, "
                "       server_mail_id, "
-               " message_id, "
+               "   message_id, "
+               "       reference_mail_id, "
                "   full_address_from, "
                "   full_address_reply, "
                "   full_address_to, "
                "   full_address_cc, "
                "   full_address_bcc, "
                "   full_address_return, "
-               " email_address_sender, "
-               " email_address_recipient, "
-               " alias_sender, "
-               " alias_recipient, "
+               "   email_address_sender, "
+               "   email_address_recipient, "
+               "   alias_sender, "
+               "   alias_recipient, "
                "       body_download_status, "
                "       file_path_plain, "
                "       file_path_html, "
                "   file_path_mime_entity, "
                "       mail_size, "
-               " flags_seen_field     ,"
-               " flags_deleted_field  ,"
-               " flags_flagged_field  ,"
-               " flags_answered_field ,"
-               " flags_recent_field   ,"
-               " flags_draft_field    ,"
-               " flags_forwarded_field,"
+               "   flags_seen_field     ,"
+               "   flags_deleted_field  ,"
+               "   flags_flagged_field  ,"
+               "   flags_answered_field ,"
+               "   flags_recent_field   ,"
+               "   flags_draft_field    ,"
+               "   flags_forwarded_field,"
                "       DRM_status, "
                "       priority, "
                "       save_status, "
@@ -1846,6 +1848,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", server_mailbox_name          VARCHAR(129) \n"
        ", server_mail_id               VARCHAR(129) \n"
        ", message_id                   VARCHAR(257) \n"
+       ", reference_mail_id            INTEGER \n"
        ", full_address_from            TEXT \n"
        ", full_address_reply           TEXT \n"
        ", full_address_to              TEXT \n"
@@ -2559,11 +2562,11 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
                        _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].mail_id), col_index++);
                        _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].account_id), col_index++);
                        _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].mailbox_id), col_index++);
-                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].from, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
-                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].from_email_address, MAX_EMAIL_ADDRESS_LENGTH, 1, col_index++);
-                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].recipients, STRING_LENGTH_FOR_DISPLAY,  1, col_index++);
+                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].full_address_from, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
+                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].email_address_sender, MAX_EMAIL_ADDRESS_LENGTH, 1, col_index++);
+                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].email_address_recipient, STRING_LENGTH_FOR_DISPLAY,  1, col_index++);
                        _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].subject, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].is_text_downloaded), col_index++);
+                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].body_download_status), col_index++);
                        _get_table_field_data_char(result, &(mail_list_item_from_tbl[i].flags_seen_field), col_index++);
                        _get_table_field_data_char(result, &(mail_list_item_from_tbl[i].flags_deleted_field), col_index++);
                        _get_table_field_data_char(result, &(mail_list_item_from_tbl[i].flags_flagged_field), col_index++);
@@ -2571,21 +2574,21 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
                        _get_table_field_data_char(result, &(mail_list_item_from_tbl[i].flags_recent_field), col_index++);
                        _get_table_field_data_char(result, &(mail_list_item_from_tbl[i].flags_draft_field), col_index++);
                        _get_table_field_data_char(result, &(mail_list_item_from_tbl[i].flags_forwarded_field), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].has_drm_attachment), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].priority), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].save_status), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].is_locked), col_index++);
+                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].DRM_status), col_index++);
+                       _get_table_field_data_int(result, (int*)&(mail_list_item_from_tbl[i].priority), col_index++);
+                       _get_table_field_data_int(result, (int*)&(mail_list_item_from_tbl[i].save_status), col_index++);
+                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].lock_status), col_index++);
                        _get_table_field_data_int(result, &local_attachment_count, col_index++);
                        _get_table_field_data_int(result, &local_inline_content_count, col_index++);
                        _get_table_field_data_time_t(result, &(mail_list_item_from_tbl[i].date_time), col_index++);
-                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].previewBodyText, MAX_PREVIEW_TEXT_LENGTH, 1, col_index++);
+                       _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].preview_text, MAX_PREVIEW_TEXT_LENGTH, 1, col_index++);
                        _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].thread_id), col_index++);
                        _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].thread_item_count), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].is_meeting_request), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].message_class), col_index++);
-                       _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].smime_type), col_index++);
+                       _get_table_field_data_int(result, (int*)&(mail_list_item_from_tbl[i].meeting_request_status), col_index++);
+                       _get_table_field_data_int(result, (int*)&(mail_list_item_from_tbl[i].message_class), col_index++);
+                       _get_table_field_data_int(result, (int*)&(mail_list_item_from_tbl[i].smime_type), col_index++);
 
-                       mail_list_item_from_tbl[i].has_attachment = ((local_attachment_count - local_inline_content_count)>0)?1:0;
+                       mail_list_item_from_tbl[i].attachment_count = ((local_attachment_count - local_inline_content_count)>0)?1:0;
                }
                EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d] >> ", count);
                EM_PROFILE_END(emstorage_query_mail_list_loop);
@@ -2611,6 +2614,9 @@ FINISH_OFF:
        }
 
        EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+
+       sqlite3_release_memory(-1);
+
        _DISCONNECT_DB;
        
        EM_SAFE_FREE(date_time_string);
@@ -2679,6 +2685,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
                _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++);
                _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++);
                _get_table_field_data_string(result, &(p_data_tbl[i].message_id), 0, col_index++);
+               _get_table_field_data_int   (result, &(p_data_tbl[i].reference_mail_id), col_index++);
                _get_table_field_data_string(result, &(p_data_tbl[i].full_address_from), 1, col_index++);
                _get_table_field_data_string(result, &(p_data_tbl[i].full_address_reply), 1, col_index++);
                _get_table_field_data_string(result, &(p_data_tbl[i].full_address_to), 1, col_index++);
@@ -2702,19 +2709,19 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
                _get_table_field_data_char  (result, &(p_data_tbl[i].flags_draft_field), col_index++);
                _get_table_field_data_char  (result, &(p_data_tbl[i].flags_forwarded_field), col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].DRM_status), col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].priority), col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].save_status), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].priority), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].save_status), col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].lock_status), col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].report_status), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].report_status), col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].attachment_count), col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].inline_content_count), col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].thread_id), col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].thread_item_count), col_index++);
                _get_table_field_data_string(result, &(p_data_tbl[i].preview_text), 1, col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].meeting_request_status), col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].message_class), col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].digest_type), col_index++);
-               _get_table_field_data_int   (result, &(p_data_tbl[i].smime_type), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].meeting_request_status), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].message_class), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].digest_type), col_index++);
+               _get_table_field_data_int   (result, (int*)&(p_data_tbl[i].smime_type), col_index++);
                /*  check real body file... */
                if (p_data_tbl[i].body_download_status) {
                        struct stat buf;
@@ -2751,6 +2758,9 @@ FINISH_OFF:
                EM_SAFE_FREE(p_data_tbl);
        
        EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+
+       sqlite3_release_memory(-1);
+
        _DISCONNECT_DB;
        
        if (err_code != NULL)
@@ -2760,9 +2770,9 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, int input_get_mail_count,  int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count)
+INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count,  int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count)
 {
-       EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_get_mail_count[%d], input_transaction[%d], output_mailbox_list[%p], output_mailbox_count[%d]", input_conditional_clause, input_get_mail_count, input_transaction, output_mailbox_list, output_mailbox_count);
+       EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_ordering_clause [%p], input_get_mail_count[%d], input_transaction[%d], output_mailbox_list[%p], output_mailbox_count[%d]", input_conditional_clause, input_ordering_clause, input_get_mail_count, input_transaction, output_mailbox_list, output_mailbox_count);
 
        int i = 0;
        int rc;
@@ -2786,7 +2796,7 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau
        }
        else {  /*  with read count and total count */
                col_index = 14;
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read  FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name %s", fields, input_conditional_clause);
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read  FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl %s GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name %s %s", fields, input_conditional_clause, input_conditional_clause, input_ordering_clause);
        }
 
        EM_DEBUG_LOG("query[%s]", sql_query_string);
@@ -4607,6 +4617,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email
        int ret = false;
        int error = EMAIL_ERROR_NONE;
        char conditional_clause_string[QUERY_SIZE] = {0, };
+       char ordering_clause_string[QUERY_SIZE] = {0, };
                
        if (account_id == ALL_ACCOUNT) {
                if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL)
@@ -4618,27 +4629,29 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email
                        SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND local_yn = %d ", local_yn);
        }
 
+       EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
+
        switch (sort_type) {
                case EMAIL_MAILBOX_SORT_BY_NAME_ASC :
-                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_name ASC");
+                       SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_name ASC");
                        break;
 
                case EMAIL_MAILBOX_SORT_BY_NAME_DSC :
-                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_name DESC");
+                       SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_name DESC");
                        break;
 
                case EMAIL_MAILBOX_SORT_BY_TYPE_ASC :
-                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_type ASC");
+                       SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_type ASC");
                        break;
 
                case EMAIL_MAILBOX_SORT_BY_TYPE_DSC :
-                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_type DEC");
+                       SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_type DEC");
                        break;
        }
 
-       EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
+       EM_DEBUG_LOG("ordering_clause_string[%s]", ordering_clause_string);
 
-       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, ordering_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
@@ -4662,6 +4675,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, in
        int error = EMAIL_ERROR_NONE;
        int where_clause_count = 0;
        char conditional_clause_string[QUERY_SIZE] = {0, };
+       char ordering_clause_string[QUERY_SIZE] = {0, };
 
        if (!select_num || !mailbox_list) {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -4683,10 +4697,11 @@ INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, in
                        SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND account_id = %d ", account_id);
        }
 
-       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY MBT.mailbox_name ");
+       SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY MBT.mailbox_name ");
        EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
+       EM_DEBUG_LOG("ordering_clause_string[%s]", ordering_clause_string);
 
-       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 1, 1, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, ordering_clause_string, 1, 1, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
@@ -4718,13 +4733,13 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_
        char conditional_clause_string[QUERY_SIZE] = {0, };
 
        if (parent_mailbox_name)
-               SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d  AND UPPER(mailbox_name) LIKE UPPER('%s/%%') ORDER BY mailbox_name", account_id, parent_mailbox_name);
+               SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d  AND UPPER(mailbox_name) LIKE UPPER('%s/%%')", account_id, parent_mailbox_name);
        else
-               SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d  AND (mailbox_name NOT LIKE '%%/%%') ORDER BY mailbox_name", account_id);
+               SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d  AND (mailbox_name NOT LIKE '%%/%%')", account_id);
 
        EM_DEBUG_LOG("conditional_clause_string", conditional_clause_string);
 
-       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, " ORDER BY mailbox_name", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
@@ -4756,10 +4771,10 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int loc
        int error = EMAIL_ERROR_NONE;
        char conditional_clause_string[QUERY_SIZE] = {0, };
        
-       SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND modifiable_yn = 0 ORDER BY mailbox_name", account_id);
+       SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND modifiable_yn = 0", account_id);
        EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
        
-       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, " ORDER BY mailbox_name", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
@@ -4868,7 +4883,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch
        
                EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
 
-               if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+               if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, "", 0, transaction, result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                        goto FINISH_OFF;
                }
@@ -4890,7 +4905,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
 
-       if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
+       if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_USER_DEFINED) || !mailbox_name) {
 
                EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
                
@@ -5004,7 +5019,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_ma
 
        EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
 
-       if( (ret = emstorage_query_mailbox_tbl(conditional_clause_string, false, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+       if( (ret = emstorage_query_mailbox_tbl(conditional_clause_string, "", false, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", ret);
                goto FINISH_OFF;
        }
@@ -5461,6 +5476,76 @@ FINISH_OFF:
        return ret;
 }
 
+INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox, int transaction)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], new_mailbox_type[%d], transaction[%d], err_code[%p]", input_mailbox_id, input_is_local_mailbox, transaction);
+
+       int rc, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       char sql_query_string[QUERY_SIZE] = {0, };
+
+       if (input_mailbox_id < 0)  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+       EM_DEBUG_LOG("emstorage_update_mailbox_type");
+
+       DB_STMT hStmt = NULL;
+       int i = 0;
+
+       /*  Update mail_box_tbl */
+       SNPRINTF(sql_query_string, sizeof(sql_query_string),
+               "UPDATE mail_box_tbl SET"
+               " local_yn = ?"
+               " WHERE mailbox_id = %d"
+               , input_mailbox_id);
+
+       EM_DEBUG_LOG("SQL(%s)", sql_query_string);
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+       _bind_stmt_field_data_int(hStmt, i++, input_is_local_mailbox);
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+               ("sqlite3_step fail:%d", rc));
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("sqlite3_step fail:%d", rc));
+
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+               hStmt = NULL;
+       }
+
+       ret = true;
+
+FINISH_OFF:
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+       _DISCONNECT_DB;
+
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
+
 
 INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, int transaction, int *err_code)
 {
@@ -7086,7 +7171,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
                        _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, 7);
                        _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, 8);
                        _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), 9);
-                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->save_status), 10);
+                       _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->save_status), 10);
                        _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), 11);
                        _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 12);
                        _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), 13);
@@ -7241,7 +7326,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
                                _get_table_field_data_string(result, &(p_data_tbl[i].file_path_plain), 0, col_index++);
                                _get_table_field_data_string(result, &(p_data_tbl[i].file_path_html), 0, col_index++);
                                _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++);
-                               _get_table_field_data_int(result, &(p_data_tbl[i].save_status), col_index++);
+                               _get_table_field_data_int(result, (int*)&(p_data_tbl[i].save_status), col_index++);
                                _get_table_field_data_int(result, &(p_data_tbl[i].lock_status), col_index++);
                                _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++);
                                _get_table_field_data_int(result, &(p_data_tbl[i].thread_item_count), col_index++);
@@ -7490,15 +7575,15 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                        _get_stmt_field_data_time_t(hStmt, &(p_data_tbl->date_time), DATETIME_IDX_IN_MAIL_TBL);
                        _get_stmt_field_data_char  (hStmt, &(p_data_tbl->flags_seen_field), FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL);
                        _get_stmt_field_data_int   (hStmt, &(p_data_tbl->DRM_status), DRM_STATUS_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->priority), PRIORITY_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->save_status), SAVE_STATUS_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->priority), PRIORITY_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->save_status), SAVE_STATUS_IDX_IN_MAIL_TBL);
                        _get_stmt_field_data_int   (hStmt, &(p_data_tbl->lock_status), LOCK_STATUS_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->report_status), REPORT_STATUS_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->report_status), REPORT_STATUS_IDX_IN_MAIL_TBL);
                        _get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->meeting_request_status), MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->message_class), MESSAGE_CLASS_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->digest_type), DIGEST_TYPE_IDX_IN_MAIL_TBL);
-                       _get_stmt_field_data_int   (hStmt, &(p_data_tbl->smime_type), SMIME_TYPE_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->meeting_request_status), MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->message_class), MESSAGE_CLASS_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->digest_type), DIGEST_TYPE_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_int   (hStmt, (int*)&(p_data_tbl->smime_type), SMIME_TYPE_IDX_IN_MAIL_TBL);
                                
                        if (type == RETRIEVE_ALL)  {
                                _get_stmt_field_data_int   (hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL);
@@ -7656,6 +7741,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
                ", server_mail_status = ?"
                ", server_mailbox_name = ?"
                ", server_mail_id = ?"
+               ", reference_mail_id = ?"
                ", full_address_from = ?"
                ", full_address_reply = ?"  /* 10 */
                ", full_address_to = ?"
@@ -7698,6 +7784,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
        _bind_stmt_field_data_int   (hStmt, i++, mail->server_mail_status);
        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->server_mailbox_name, 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->server_mail_id, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
+       _bind_stmt_field_data_int   (hStmt, i++, mail->reference_mail_id);
        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->full_address_to, 1, TO_LEN_IN_MAIL_TBL);
@@ -8158,6 +8245,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
                                ", report_status = ?"
                                ", DRM_status = ?"
                                ", file_path_html = ?"
+                               ", file_path_mime_entity = ?"
                                ", mail_size = ?"
                                ", preview_text = ?"
                                ", body_download_status = ?"
@@ -8198,6 +8286,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
                        _bind_stmt_field_data_int   (hStmt, i++, mail->report_status);
                        _bind_stmt_field_data_int   (hStmt, i++, mail->DRM_status);
                        _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+                       _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL);
                        _bind_stmt_field_data_int   (hStmt, i++, mail->mail_size);
                        _bind_stmt_field_data_string(hStmt, i++, (char*)mail->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
                        _bind_stmt_field_data_int   (hStmt, i++, mail->body_download_status);
@@ -8502,6 +8591,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
                ", ?" /*  server_mailbox_name */
                ", ?" /*  server_mail_id */
                ", ?" /*  message_id */
+               ", ?" /*  reference_mail_id */
                ", ?" /*  full_address_from */
                ", ?" /*  full_address_reply */
                ", ?" /*  full_address_to */
@@ -8555,6 +8645,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
        _bind_stmt_field_data_string(hStmt, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->server_mailbox_name, 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, SERVER_MAIL_ID_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->server_mail_id, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, MESSAGE_ID_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->message_id, 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
+       _bind_stmt_field_data_int   (hStmt, REFERENCE_ID_IDX_IN_MAIL_TBL, mail_tbl_data->reference_mail_id);
        _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_to, 1, TO_LEN_IN_MAIL_TBL);
@@ -10327,7 +10418,7 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s
                        if (nread > 0 && nread <= buf_size)  {          
                                EM_DEBUG_LOG("Nread Value [%d]", nread);
                                if ((nwritten = write(fp_dst, buf, nread)) != nread) {
-                                       EM_DEBUG_EXCEPTION("fwrite failed... : [%d], Error:[%s]", nwritten, strerror(errno));
+                                       EM_DEBUG_EXCEPTION("fwrite failed...[%d] : [%s]", errno, strerror(errno));
                                        error = EMAIL_ERROR_UNKNOWN;
                                        goto FINISH_OFF;
                                }
@@ -11072,6 +11163,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
                ", ?" /*  server_mail_status */
                ", ?" /*  server_mailbox_name */
                ", ?" /*  server_mail_id */
+               ", ?" /*  reference_mail_id */
                ", ?" /*  full_address_from */
                ", ?" /*  full_address_reply */
                ", ?" /*  full_address_to */
@@ -11132,6 +11224,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
        _bind_stmt_field_data_string(hStmt, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL, "", 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, SERVER_MAIL_ID_IDX_IN_MAIL_TBL, "", 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, MESSAGE_ID_IDX_IN_MAIL_TBL, "", 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
+       _bind_stmt_field_data_int(hStmt, REFERENCE_ID_IDX_IN_MAIL_TBL, 0);
        _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL, "<test08@streaming.s3glab.net>", 1, FROM_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL, "", 1, REPLY_TO_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL, full_address_to, 1, TO_LEN_IN_MAIL_TBL);
@@ -11213,7 +11306,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
        time_t   date_time = 0;
        char    *mailbox_name = NULL, *subject = NULL;
        char    *sql_query_string = NULL, *sql_account = NULL;
-       char    *sql_format = "SELECT thread_id, date_time, mail_id FROM mail_tbl WHERE subject like \'%%%q\' AND mailbox_type NOT IN (3, 5, 7, 8)";
+       char    *sql_format = "SELECT thread_id, date_time, mail_id FROM mail_tbl WHERE subject like \'%%%q\' AND mailbox_id = %d";
        char    *sql_format_account = " AND account_id = %d ";
        char    *sql_format_order_by = " ORDER BY date_time DESC ";
        char   **result = NULL;
@@ -11225,13 +11318,6 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
        EM_IF_NULL_RETURN_VALUE(result_latest_mail_id_in_thread, EMAIL_ERROR_INVALID_PARAM);
        EM_IF_NULL_RETURN_VALUE(thread_item_count, EMAIL_ERROR_INVALID_PARAM);
 
-       if (mail_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH ||
-           mail_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX ||
-           mail_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_ALL_EMAILS) {
-               EM_DEBUG_LOG("the mail in trash, spambox, all email could not be thread mail.");
-               goto FINISH_OFF;
-       }
-
        account_id   = mail_tbl->account_id;
        mailbox_name = mail_tbl->mailbox_name;
        subject      = mail_tbl->subject;
@@ -11274,7 +11360,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
                goto FINISH_OFF;
        }
 
-       sqlite3_snprintf(query_size, sql_query_string, sql_format, stripped_subject);
+       sqlite3_snprintf(query_size, sql_query_string, sql_format, stripped_subject, mail_tbl->mailbox_id);
 
        if (account_id > 0)
                strcat(sql_query_string, sql_account);
@@ -13910,6 +13996,7 @@ static char *_mail_field_name_list[] = {
                "server_mailbox_name",
                "server_mail_id",
                "message_id",
+               "reference_mail_id",
                "full_address_from",
                "full_address_to",
                "full_address_cc",
@@ -13997,6 +14084,7 @@ static int _get_key_value_string_for_list_filter_rule(email_list_filter_rule_t *
        case EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID              :
        case EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE            :
        case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS      :
+       case EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID       :
        case EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS    :
        case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN         :
        case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML          :
index 2843bd9..743b500 100755 (executable)
@@ -181,53 +181,54 @@ typedef struct
 
 typedef struct 
 {
-       int        mail_id;
-       int        account_id;
-       int        mailbox_id;
-       char      *mailbox_name;
-       int        mailbox_type;
-       char      *subject;
-       time_t     date_time;
-       int        server_mail_status;
-       char      *server_mailbox_name;
-       char      *server_mail_id;
-       char      *message_id;
-       char      *full_address_from;
-       char      *full_address_reply;
-       char      *full_address_to;
-       char      *full_address_cc;
-       char      *full_address_bcc;
-       char      *full_address_return;
-       char      *email_address_sender;
-       char      *email_address_recipient;
-       char      *alias_sender;
-       char      *alias_recipient;
-       int        body_download_status;
-       char      *file_path_plain;
-       char      *file_path_html;
-       char      *file_path_mime_entity;
-       int        mail_size;
-       char       flags_seen_field;
-       char       flags_deleted_field;
-       char       flags_flagged_field;
-       char       flags_answered_field;
-       char       flags_recent_field;
-       char       flags_draft_field;
-       char       flags_forwarded_field;
-       int        DRM_status;
-       int        priority;
-       int        save_status;
-       int        lock_status;
-       int        report_status;
-       int        attachment_count;
-       int        inline_content_count;
-       int        thread_id;
-       int        thread_item_count;
-       char      *preview_text;
-       int        meeting_request_status;
-       int        message_class;
-       int        digest_type;
-       int        smime_type;
+       int                    mail_id;
+       int                    account_id;
+       int                    mailbox_id;
+       char                  *mailbox_name;
+       int                    mailbox_type;
+       char                  *subject;
+       time_t                 date_time;
+       int                    server_mail_status;
+       char                  *server_mailbox_name;
+       char                  *server_mail_id;
+       char                  *message_id;
+       int                    reference_mail_id;
+       char                  *full_address_from;
+       char                  *full_address_reply;
+       char                  *full_address_to;
+       char                  *full_address_cc;
+       char                  *full_address_bcc;
+       char                  *full_address_return;
+       char                  *email_address_sender;
+       char                  *email_address_recipient;
+       char                  *alias_sender;
+       char                  *alias_recipient;
+       int                    body_download_status;
+       char                  *file_path_plain;
+       char                  *file_path_html;
+       char                  *file_path_mime_entity;
+       int                    mail_size;
+       char                   flags_seen_field;
+       char                   flags_deleted_field;
+       char                   flags_flagged_field;
+       char                   flags_answered_field;
+       char                   flags_recent_field;
+       char                   flags_draft_field;
+       char                   flags_forwarded_field;
+       int                    DRM_status;
+       email_mail_priority_t  priority;
+       email_mail_status_t    save_status;
+       int                    lock_status;
+       email_mail_report_t    report_status;
+       int                    attachment_count;
+       int                    inline_content_count;
+       int                    thread_id;
+       int                    thread_item_count;
+       char                  *preview_text;
+       email_mail_type_t      meeting_request_status;
+       email_message_class    message_class;
+       email_digest_type      digest_type;
+       email_smime_type       smime_type;
 } emstorage_mail_tbl_t;
 
 /* mail_attachment_tbl entity */
@@ -591,6 +592,15 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp
 INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code);
 
 /*
+ * emstorage_set_local_mailbox
+ *
+ * description :  change 'local' field on mailbox table.
+ * arguments :
+ * return  :
+ */
+INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox, int transaction);
+
+/*
  * emstorage_add_mailbox
  *
  * description :  add a local mailbox to local mailbox table
@@ -892,7 +902,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
  * description :  query mail box table information
  */
 
-INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, int input_get_mail_count,  int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count);
+INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count,  int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count);
 
 /*
  * emstorage_get_mail_list
index 78222c5..f9a70bf 100644 (file)
@@ -50,5 +50,7 @@ INTERNAL_FUNC int emcore_verify_certificate(char *certificate, int *validity, in
 INTERNAL_FUNC int emcore_free_certificate(email_certificate_t **certificate, int count, int *err_code);
 
 INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, char *password, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code);
-
+/*
+INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code);
+*/
 #endif
index 4170ad9..2860c78 100755 (executable)
@@ -149,7 +149,6 @@ INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **ou
 
 INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int sync_server);
 
-INTERNAL_FUNC int emcore_fetch_flags(int account_id, int mail_id, email_mail_flag_t *mail_flag, int *err_code);
 INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code);
 INTERNAL_FUNC int emcore_get_mail_msgno_by_uid(email_account_t *account, email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
 INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(int input_mailbox_id);
@@ -191,8 +190,6 @@ INTERNAL_FUNC int   emcore_move_mail_on_server(int account_id, int src_mailbox_i
 INTERNAL_FUNC int   emcore_sync_flag_with_server(int mail_id, int *err_code);
 INTERNAL_FUNC int   emcore_sync_seen_flag_with_server(int mail_ids[], int num, int *err_code);
 
-INTERNAL_FUNC int   emcore_modify_extra_flag(int mail_id, email_extra_flag_t new_flag, int *err_code);
-INTERNAL_FUNC int   emcore_modify_flag(int mail_id, email_mail_flag_t new_flag, int sticky_flag, int *err_code);
 INTERNAL_FUNC int   emcore_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
 INTERNAL_FUNC char* emcore_convert_mutf7_to_utf8(char *mailbox_name); 
 INTERNAL_FUNC int   emcore_convert_string_to_structure(const char *encoded_string, void **struct_var, email_convert_struct_type_e type);
index 3af71d7..756fac6 100755 (executable)
@@ -51,8 +51,8 @@ INTERNAL_FUNC int   emcore_get_body_structure(MAILSTREAM *stream, int msg_uid, B
 INTERNAL_FUNC char *emcore_decode_rfc2047_text(char *rfc2047_text, int *err_code);
 INTERNAL_FUNC int   emcore_decode_body_text(char *enc_buf, int enc_len, int enc_type, int *dec_len, int *err_code);
 INTERNAL_FUNC int   emcore_set_fetch_body_section(BODY *body, int enable_inline_list, int *total_mail_size, int *err_code);
-INTERNAL_FUNC int   emcore_load_eml_file_to_mail(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code);
-INTERNAL_FUNC int   emcore_delete_eml_data(email_mail_data_t *input_mail_data, int *err_code);
+INTERNAL_FUNC int   emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code);
+INTERNAL_FUNC int   emcore_delete_parsed_data(email_mail_data_t *input_mail_data, int *err_code);
 INTERNAL_FUNC int   emcore_get_mime_entity(char *mime_path, char **mime_entity, int *err_code);
 
 #ifdef __cplusplus
index 5b3e02a..ace6c5c 100755 (executable)
@@ -42,9 +42,9 @@ extern "C"
 #include "c-client.h"
 #include "email-internal-types.h"
 
-INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mail_id, email_option_t *sending_option, int *err_code);
+INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mail_id, int *err_code);
 
-INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *mailbox, email_option_t *sending_option, int *err_code);
+INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *mailbox, int *err_code);
 
 INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl_t, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code);
 
index 148635a..c5d3aba 100755 (executable)
@@ -66,7 +66,7 @@ int   emcore_get_long_encoded_path_with_account_info(email_account_t *account, c
 void  emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data);
 
 
-int   emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer);
+INTERNAL_FUNC int   emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer);
 int   reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string);
 int   emcore_strip_HTML(char *source_string);
 int   emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime);
@@ -77,9 +77,6 @@ int   emcore_get_empty_session(email_session_t **session);
 int   emcore_clear_session(email_session_t *session);
 int   emcore_get_current_session(email_session_t **session);
 
-INTERNAL_FUNC email_option_t *emcore_get_option(int *err_code);
-INTERNAL_FUNC int emcore_set_option(email_option_t *opt, int *err_code);
-
 INTERNAL_FUNC int emcore_check_unread_mail();
 INTERNAL_FUNC int emcore_set_network_error(int err_code);
 
index bf43bf1..4140f9b 100755 (executable)
@@ -39,6 +39,7 @@ INCLUDE_DIRECTORIES(
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0  db-util openssl uw-imap-toolkit vconf contacts-service alarm-service mm-player devman_haptic heynoti)
+# _TIZEN_PUBLIC_
 
 
 FOREACH(flag ${main_pkgs_CFLAGS})
index a9cf863..969fdda 100755 (executable)
@@ -159,7 +159,7 @@ static email_account_t* duplicate_account(email_account_t *src)
        return dst;
 }
 
-INTERNAL_FUNC int emdaemon_validate_account(int account_id, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_validate_account(int account_id, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p], err_code[%p]", account_id, handle, err_code);
 
@@ -200,7 +200,7 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_account, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_account, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account[%p], handle[%p], err_code[%p]", new_account, handle, err_code);
 
@@ -310,7 +310,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email_account_t* new_account_info, unsigned* handle,int *err_code)
+INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email_account_t* new_account_info, int *handle,int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account[%d], new_account_info[%p], handle[%p], err_code[%p]", old_account_id, new_account_info, handle, err_code);
 
index 28872b1..044fe15 100755 (executable)
@@ -165,12 +165,16 @@ INTERNAL_FUNC int emdaemon_check_auto_polling_started(int account_id)
        }
        return true;
 }
+
 INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t  alarm_id, void* user_param)
 {
        EM_DEBUG_FUNC_BEGIN();
 
-/*     tzset(); */
-        time_t ct = time(&ct);
+       email_mailbox_t mailbox = {0};
+       int account_id = 0, err = EMAIL_ERROR_NONE, timer_interval =0, alarmID =0,ret = false;
+       char* mailbox_name = NULL;
+
+       time_t ct = time(&ct);
        struct tm* lt = localtime(&ct);
        
        if (lt) {
@@ -178,11 +182,6 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t  alarm_id, void* user_par
                        lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
                        lt->tm_hour, lt->tm_min, lt->tm_sec);                           
        }
-       
-
-       email_mailbox_t mailbox = {0};
-       int account_id = 0, err = EMAIL_ERROR_NONE, timer_interval =0, alarmID =0,ret = false;
-       char* mailbox_name = NULL;
 
        if(!_emdaemon_get_polling_account_and_timeinterval(alarm_id,&account_id,&timer_interval)) {
                EM_DEBUG_EXCEPTION("email_get_polling_account failed");
@@ -206,13 +205,11 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t  alarm_id, void* user_par
        memset(&mailbox, 0x00, sizeof(email_mailbox_t));
        mailbox.account_id = account_id;
 
-               if (!emstorage_get_mailbox_name_by_mailbox_type(mailbox.account_id,EMAIL_MAILBOX_TYPE_INBOX,&mailbox_name, false, &err))  {
-                       EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
-                                               
-       
-                       goto FINISH_OFF;
-               }
-               mailbox.mailbox_name = mailbox_name;
+       if (!emstorage_get_mailbox_name_by_mailbox_type(mailbox.account_id,EMAIL_MAILBOX_TYPE_INBOX,&mailbox_name, false, &err))  {
+               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
+               goto FINISH_OFF;
+       }
+       mailbox.mailbox_name = mailbox_name;
 
        if (!emdaemon_sync_header(account_id, mailbox.mailbox_id, NULL, &err))  {
                EM_DEBUG_EXCEPTION("emdaemon_sync_header falied [%d]", err);            
@@ -221,6 +218,7 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t  alarm_id, void* user_par
 
        ret = true;
 FINISH_OFF :
+
        EM_SAFE_FREE(mailbox_name);
 
        return ret;
index 7365a1b..b42a53c 100755 (executable)
@@ -120,10 +120,11 @@ static void hibernation_leave_callback()
 static void callback_for_SYNC_ALL_STATUS_from_account_svc(keynode_t *input_node, void *input_user_data)
 {
        EM_DEBUG_FUNC_BEGIN("input_node [%p], input_user_data [%p]", input_node, input_user_data);
-       unsigned handle = 0;
+       int handle = 0;
        int i = 0;
        int err = EMAIL_ERROR_NONE;
        int account_count = 0;
+       int sync_start_toggle = 0;
        email_account_t         *account_list = NULL;
        emstorage_mailbox_tbl_t *mailbox_tbl_data = NULL;
 
@@ -132,18 +133,26 @@ static void callback_for_SYNC_ALL_STATUS_from_account_svc(keynode_t *input_node,
                goto FINISH_OFF;
        }
 
+       if(input_node)
+               sync_start_toggle = vconf_keynode_get_int(input_node);
+
        for(i = 0; i < account_count; i++) {
-               if(!emstorage_get_mailbox_by_mailbox_type(account_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_tbl_data, true, &err)) {
-                       EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type for [%d] failed [%d]", account_list[i].account_id, err);
-                       continue;
+               if(sync_start_toggle == 1) {
+                       if(!emstorage_get_mailbox_by_mailbox_type(account_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_tbl_data, true, &err)) {
+                               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type for [%d] failed [%d]", account_list[i].account_id, err);
+                               continue;
+                       }
+
+                       if(!emdaemon_sync_header(account_list[i].account_id, mailbox_tbl_data->mailbox_id, &handle, &err)) {
+                               EM_DEBUG_EXCEPTION("emdaemon_sync_header for [%d] failed [%d]", account_list[i].account_id, err);
+                       }
+                       if(mailbox_tbl_data)
+                               emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL);
+                       mailbox_tbl_data = NULL;
                }
-
-               if(!emdaemon_sync_header(account_list[i].account_id, mailbox_tbl_data->mailbox_id, &handle, &err)) {
-                       EM_DEBUG_EXCEPTION("emdaemon_sync_header for [%d] failed [%d]", account_list[i].account_id, err);
+               else {
+                       emcore_cancel_all_threads_of_an_account(account_list[i].account_id);
                }
-               if(mailbox_tbl_data)
-                       emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL);
-               mailbox_tbl_data = NULL;
        }
 
 FINISH_OFF:
index a665de2..57b5ad6 100755 (executable)
@@ -60,14 +60,13 @@ extern int g_save_local_activity_run;
 #endif
 static int _emdaemon_check_mail_id(int mail_id, int* err_code);
 
-INTERNAL_FUNC int emdaemon_send_mail(int mail_id, email_option_t* sending_option, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code)
 {      
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], sending_option[%p], handle[%p], err_code[%p]", mail_id, sending_option, handle, err_code);
+       EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p], err_code[%p]", mail_id, handle, err_code);
        
        int ret = false, err = EMAIL_ERROR_NONE, err_2 = EMAIL_ERROR_NONE;
        int  result_handle = 0, account_id = 0;
-       email_option_t* option = NULL;
-       email_event_t event_data;
+       email_event_t event_data = { 0, };
        emstorage_mail_tbl_t* mail_table_data = NULL;
        emstorage_mailbox_tbl_t* local_mailbox = NULL;
        int dst_mailbox_id = 0;
@@ -93,16 +92,6 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, email_option_t* sending_option
        
        account_id = mail_table_data->account_id;
        
-       if (sending_option != NULL) {
-               if (!(option = (email_option_t*)em_malloc(sizeof(email_option_t)))) {   
-                       EM_DEBUG_EXCEPTION("em_malloc for sending_option failed...");
-                       err = EMAIL_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
-               memcpy(option, sending_option, sizeof(email_option_t));
-               option->display_name_from = EM_SAFE_STRDUP(sending_option->display_name_from);
-       }
-       
        email_account_t* ref_account = emdaemon_get_account_reference(account_id);
 
        if (!ref_account) {
@@ -137,10 +126,8 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, email_option_t* sending_option
                goto FINISH_OFF;
        }
 
-       memset(&event_data, 0x00, sizeof(email_event_t));
        event_data.type               = EMAIL_EVENT_SEND_MAIL;
        event_data.account_id         = account_id;
-       event_data.event_param_data_1 = (char*)option;
        event_data.event_param_data_4 = mail_id;
        event_data.event_param_data_5 = mail_table_data->mailbox_id;
 
@@ -167,11 +154,6 @@ FINISH_OFF:
                        EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value [%d]",err);
 
                EM_SAFE_FREE(event_data.event_param_data_3);
-               
-               if(option != NULL) {    
-                       EM_SAFE_FREE(option->display_name_from);
-                       EM_SAFE_FREE(option);
-               }
        }
 
        if(!emcore_add_transaction_info(mail_id , result_handle , &err_2))
@@ -191,35 +173,21 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, email_option_t* sending_option,  unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err_code)
 {      
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], sending_option[%p], handle[%p], err_code[%p]", account_id, sending_option, handle, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d],handle[%p], err_code[%p]", account_id, handle, err_code);
        
        int ret = false;
        int err = EMAIL_ERROR_NONE;
-       email_option_t* option = NULL;
-       email_event_t event_data;
+       email_event_t event_data = { 0 , };
        char *mailbox_name = NULL;      
        
-       memset(&event_data, 0x00, sizeof(email_event_t));
-       
        if (account_id <= 0)  {
                EM_DEBUG_EXCEPTION("account_id = %d", account_id);
                err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
-       if (sending_option)  {
-               option = (email_option_t*)em_malloc(sizeof(email_option_t));
-               if (!option)  {
-                       EM_DEBUG_EXCEPTION("em_malloc failed...");
-                       err = EMAIL_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
-
-               memcpy(option, sending_option, sizeof(email_option_t));
-       }
-       
        email_account_t* ref_account = emdaemon_get_account_reference(account_id);
 
        if (!ref_account)  {
@@ -228,16 +196,14 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, email_option_t* sendi
                goto FINISH_OFF;
        }
 
-       
-       event_data.type = EMAIL_EVENT_SEND_MAIL_SAVED;
-
        if (!emstorage_get_mailbox_name_by_mailbox_type(account_id,EMAIL_MAILBOX_TYPE_OUTBOX,&mailbox_name, false, &err))  {
                EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
                goto FINISH_OFF;
        }
+
+       event_data.type               = EMAIL_EVENT_SEND_MAIL_SAVED;
+       event_data.account_id         = account_id;
        event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox_name);
-       event_data.account_id  = account_id;
-       event_data.event_param_data_1 = (char*)option;
 
        if (!emcore_insert_event(&event_data, (int*)handle, &err))  {
                EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
@@ -249,7 +215,6 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, email_option_t* sendi
 FINISH_OFF:
        if (ret == false)  {
                EM_SAFE_FREE(event_data.event_param_data_3);
-               EM_SAFE_FREE(option);
        }
 
        EM_SAFE_FREE(mailbox_name);
@@ -270,7 +235,8 @@ INTERNAL_FUNC int emdaemon_add_mail(email_mail_data_t *input_mail_data, email_at
        email_event_t event_data = { 0 };
        
        if (!input_mail_data || input_mail_data->account_id <= 0 ||
-               (input_mail_data->report_status == EMAIL_MAIL_REPORT_MDN && !input_mail_data->full_address_to))  {
+               ( ((input_mail_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0) && !input_mail_data->full_address_to))  {
+               EM_DEBUG_LOG("input_mail_data->report_status [%d]", input_mail_data->report_status);
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); 
                err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
@@ -337,7 +303,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbose, int with_attachment,  unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbose, int with_attachment,  int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], verbose[%d], with_attachment[%d], handle[%p], err_code[%p]", account_id, mail_id, verbose, with_attachment,  handle, err_code);
        
@@ -441,7 +407,7 @@ FINISH_OFF:
 
 int emdaemon_delete_mail_attachment(int attachment_id, int* err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("attachment_id[%s], err_code[%p]", attachment_id, err_code);
+       EM_DEBUG_FUNC_BEGIN("attachment_id[%d], err_code[%p]", attachment_id, err_code);
        
        /*  default variable */
        int ret = false;
@@ -467,7 +433,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int nth, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int nth, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%d], handle[%p], err_code[%p]", account_id, mail_id, nth, handle, err_code);
        
@@ -527,7 +493,8 @@ void* thread_func_to_delete_mail(void *thread_argument)
        int  mail_id_count = 0;
        int  account_id = 0;
        int  from_server = 0;
-       unsigned handle = 0;
+       int  noti_param_2 = 0;
+       int handle = 0;
        email_event_t *event_data = (email_event_t*)thread_argument;
 
        account_id         = event_data->account_id;
@@ -535,12 +502,12 @@ void* thread_func_to_delete_mail(void *thread_argument)
        mail_id_count      = event_data->event_param_data_4;
        from_server        = event_data->event_param_data_5;
 
-       if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_COMMAND, false, &err)) {
-               EM_DEBUG_EXCEPTION(" emcore_delete_mail falied [%d]", err);
+       if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_COMMAND, noti_param_2, &err)) {
+               EM_DEBUG_EXCEPTION(" emcore_delete_mail failed [%d]", err);
                goto FINISH_OFF;
        }
        
-       if (from_server != EMAIL_DELETE_LOCALLY) {
+       if (from_server == EMAIL_DELETE_LOCAL_AND_SERVER || from_server == EMAIL_DELETE_FROM_SERVER) {
                if (!emcore_insert_event(event_data, (int*)handle, &err)) {
                        EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
                        goto FINISH_OFF;
@@ -555,13 +522,14 @@ FINISH_OFF:
        return SUCCESS;
 }
 
-INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_ids_count, int from_server, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_ids_count, int from_server, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("mailbox_id[%d], mail_ids[%p], mail_ids_count[%d], from_server[%d], handle[%p], err_code[%p]", mailbox_id, mail_ids, mail_ids_count, from_server, handle, err_code);
        
        int ret = false;
        int err = EMAIL_ERROR_NONE;
        int* p = NULL, thread_error;
+       email_account_t *ref_account = NULL;
        email_event_t *event_data = NULL;
        emstorage_mailbox_tbl_t *mailbox_tbl_data = NULL;
        thread_t delete_thread;
@@ -592,6 +560,18 @@ INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_
                goto FINISH_OFF;
        }
 
+       ref_account = emcore_get_account_reference(mailbox_tbl_data->account_id);
+
+       if (!ref_account) {
+               EM_DEBUG_EXCEPTION("emcore_get_account_reference failed.");
+               err = EMAIL_ERROR_INVALID_ACCOUNT;
+               goto FINISH_OFF;
+       }
+
+       if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
+               from_server = EMAIL_DELETE_LOCALLY;
+       }
+
        event_data->type                   = EMAIL_EVENT_DELETE_MAIL;
        event_data->account_id             = mailbox_tbl_data->account_id;
        event_data->event_param_data_3     = (char*)p;
@@ -616,7 +596,7 @@ FINISH_OFF:
        return ret;
 }
 
-int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, unsigned *output_handle, int *output_err_code)
+int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *output_handle, int *output_err_code)
 {
        EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_from_server[%d], handle[%p], err_code[%p]", input_mailbox_id, input_from_server, output_handle, output_err_code);
        
@@ -725,7 +705,7 @@ void* thread_func_to_move_mail(void *thread_argument)
 {
        EM_DEBUG_FUNC_BEGIN();
        int *mail_ids = NULL, mail_ids_count, noti_param_1, noti_param_2, err;
-       unsigned handle = 0;
+       int handle = 0;
        email_event_t *event_data = (email_event_t*)thread_argument;
        char *dst_mailbox_name = NULL;
        int dst_mailbox_id = 0;
@@ -1010,103 +990,6 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_modify_flag(int mail_id, email_mail_flag_t new_flag, int onserver, int sticky_flag, int* err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], new_flag[%d], onserver[%d], sticky_flag[%d], err_code[%p]", mail_id, new_flag, onserver, sticky_flag, err_code);
-       
-       /*  default variable */
-       int ret = false;
-       int err = EMAIL_ERROR_NONE;
-       
-       if (!emcore_modify_flag(mail_id, new_flag, sticky_flag, &err))  {
-               EM_DEBUG_EXCEPTION(" emcore_modify_flag falled [%d]", err);
-               goto FINISH_OFF;
-       }
-       
-#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
-       if( onserver == 1)  {
-       email_event_t event_data;
-       unsigned handle = 0;
-       memset(&event_data, 0x00, sizeof(email_event_t));
-       
-       event_data.type = EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER;
-       event_data.event_param_data_1 = NULL;
-       event_data.event_param_data_4 = mail_id;
-       event_data.account_id = 0;      
-#ifdef __FEATURE_LOCAL_ACTIVITY__
-               emstorage_mail_tbl_t *mail_table_data = NULL;
-               if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, false, &err) || !mail_table_data)  {
-                       EM_DEBUG_LOG(" emstorage_get_mail_field_by_id failed [%d]", err);
-                       goto FINISH_OFF;
-               }
-               event_data.account_id = mail_table_data->account_id;
-               emstorage_free_mail(&mail_table_data,1,&err);
-
-               emstorage_activity_tbl_t        new_activity;
-               new_activity.activity_type = ACTIVITY_MODIFYFLAG;
-               new_activity.account_id    = event_data.account_id;
-               new_activity.mail_id       = event_data.event_param_data_4;
-               new_activity.dest_mbox     = NULL;
-               new_activity.server_mailid = NULL;
-               new_activity.src_mbox      = NULL;
-
-               if (false == emcore_get_next_activity_id(&new_activity.activity_id,&err)) {
-                       EM_DEBUG_EXCEPTION(" emcore_get_next_activity_id Failed - %d \n", err);
-               }
-
-               if (!emcore_add_activity(&new_activity, &err)) {
-                       EM_DEBUG_EXCEPTION(" emcore_add_activity [ACTIVITY_MODIFYFLAG] Failed - %d \n", err);
-               }
-               
-#endif /*  __FEATURE_LOCAL_ACTIVITY__ */
-       if (!emcore_insert_event(&event_data, (int*)&handle, &err)) {
-                       EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
-                       goto FINISH_OFF;
-       }
-
-#ifdef __FEATURE_LOCAL_ACTIVITY__      
-               EM_DEBUG_LOG("Setting g_local_activity_run ");
-               g_local_activity_run = 1;       
-#endif /*  __FEATURE_LOCAL_ACTIVITY__ */
-       }
-#endif /*  __FEATURE_SYNC_CLIENT_TO_SERVER__ */
-
-       ret = true;
-       
-FINISH_OFF:
-       if (err_code)
-               *err_code = err;
-       EM_DEBUG_FUNC_END();
-       return ret;
-}
-
-INTERNAL_FUNC int emdaemon_modify_extra_flag(int mail_id, email_extra_flag_t new_flag, int* err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
-
-       int ret = false;
-       int err = EMAIL_ERROR_NONE;
-               
-       if (!_emdaemon_check_mail_id(mail_id, &err))  {
-               EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err);
-                       goto FINISH_OFF;
-               }
-
-       if (!emcore_modify_extra_flag(mail_id, new_flag, &err))  {
-               EM_DEBUG_EXCEPTION("engine_mail_modify_extra_flag failed [%d]", err);
-                       goto FINISH_OFF;
-               }
-               
-       ret = true;
-
-FINISH_OFF:
-       if (err_code)
-               *err_code = err;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-               }
-
 INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int onserver, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("mail_ids[%d], num[%d], field_type [%d], value[%d], err_code[%p]", mail_ids[0], num, field_type, value, err_code);
@@ -1133,7 +1016,7 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n
        if( onserver && account_tbl->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 )  {
                int *mail_id_array = NULL;
                email_event_t event_data = {0};
-               unsigned handle = 0;
+               int handle = 0;
 
                mail_id_array = em_malloc(sizeof(int) * num);
               
@@ -1183,7 +1066,7 @@ INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email
        email_account_t *ref_account = NULL;
        
        if (!input_mail_data || input_mail_data->account_id <= 0 || input_mail_data->mail_id == 0 ||
-               (input_mail_data->report_status == EMAIL_MAIL_REPORT_MDN && !input_mail_data->full_address_to))  {
+               (((input_mail_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0) && !input_mail_data->full_address_to))  {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); 
                err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
@@ -1254,40 +1137,20 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emdaemon_send_mail_retry( int mail_id,  int timeout_in_sec, int* err_code)
+INTERNAL_FUNC int emdaemon_send_mail_retry(int mail_id,  int timeout_in_sec, int* err_code)
 {
        int ret = false;
        int err = EMAIL_ERROR_NONE;
        long nTimerValue = 0;
        char mail_id_string[10] = { 0, };
-       email_mailbox_t mailbox;
-       emstorage_mail_tbl_t* mail_table_data = NULL;
-       email_option_t opt;
-       
-       memset(&opt, 0x00, sizeof(email_option_t));
-       memset(&mailbox, 0x00, sizeof(email_mailbox_t));
 
        if (!_emdaemon_check_mail_id(mail_id, &err))  {
                EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err);
                goto FINISH_OFF;
        }       
-
-       if( ! emstorage_get_mail_by_id(mail_id, &mail_table_data, false, &err) && !mail_table_data)  {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-               goto FINISH_OFF;                
-       }
-       
-       mailbox.mailbox_name = EM_SAFE_STRDUP(mail_table_data->mailbox_name);
-
-       memcpy(&opt, emcore_get_option(&err), sizeof(email_option_t));
-
-       if( mail_table_data ) {
-               mailbox.account_id = mail_table_data->account_id;
-               opt.priority       = mail_table_data->priority;
-       }
        
        if ( timeout_in_sec == 0 ) {
-               if(!emdaemon_send_mail(mail_id, &opt, NULL, &err)) {
+               if(!emdaemon_send_mail(mail_id, NULL, &err)) {
                        EM_DEBUG_EXCEPTION("emdaemon_send_mail failed [%d]", err);
                        goto FINISH_OFF;
                }                       
@@ -1305,11 +1168,6 @@ INTERNAL_FUNC int emdaemon_send_mail_retry( int mail_id,  int timeout_in_sec, in
 FINISH_OFF:
        if (err_code)
                *err_code = err;
-
-       if(mail_table_data)
-               emstorage_free_mail(&mail_table_data, 1, NULL);
-
-       EM_SAFE_FREE(mailbox.mailbox_name);
        
        return ret;
 }
@@ -1319,13 +1177,7 @@ INTERNAL_FUNC void _OnMailSendRetryTimerCB( void* data )
 {
        EM_DEBUG_FUNC_BEGIN();
        int err = EMAIL_ERROR_NONE;
-       email_mailbox_t mailbox;
-       emstorage_mail_tbl_t* mail_table_data = NULL;   
        int mail_id = 0 ;
-       email_option_t opt;
-
-       memset( &opt, 0x00, sizeof(email_option_t));
-       memset( &mailbox, 0x00, sizeof(email_mailbox_t));
 
        if( !data ) {
                EM_DEBUG_LOG("Invalid param");
@@ -1334,35 +1186,17 @@ INTERNAL_FUNC void _OnMailSendRetryTimerCB( void* data )
 
        mail_id = atoi((char*)data);
        
-
        if (!_emdaemon_check_mail_id(mail_id, &err))  {
                EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err);
                goto FINISH_OFF;
        }       
        
-       if( ! emstorage_get_mail_by_id(mail_id, &mail_table_data, false, &err) && !mail_table_data) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-               goto FINISH_OFF;                
-       }
-
-       mailbox.mailbox_name = EM_SAFE_STRDUP(mail_table_data->mailbox_name);
-       memcpy(&opt, emcore_get_option(&err), sizeof(email_option_t));
-
-       if( mail_table_data ) {
-               opt.priority       = mail_table_data->priority;
-               mailbox.account_id = mail_table_data->account_id;
-       }
-       
-       if(!emdaemon_send_mail(mail_id, &opt, NULL, &err)) {
+       if(!emdaemon_send_mail(mail_id, NULL, &err)) {
                EM_DEBUG_EXCEPTION("emdaemon_send_mail failed [%d]", err);
                goto FINISH_OFF;
        }
 
 FINISH_OFF:
-       if(mail_table_data)
-               emstorage_free_mail(&mail_table_data, 1, NULL);
-
-       EM_SAFE_FREE(mailbox.mailbox_name);
        
        EM_DEBUG_FUNC_END();
        return;
@@ -1444,7 +1278,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_delete_mail_thread(int thread_id, int delete_always_flag, unsigned* handle, int *err_code)
+INTERNAL_FUNC int emdaemon_delete_mail_thread(int thread_id, int delete_always_flag, int *handle, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("thread_id [%d], delete_always_flag [%d], err_code [%p]", thread_id, delete_always_flag, err_code);
        int ret = false;
@@ -1496,7 +1330,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server, unsigned* handle, int *err_code)
+INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server, int *handle, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("thread_id [%d], seen_flag [%d], on_server [%d], handle [%p], err_code [%p]", thread_id, seen_flag, on_server, handle, err_code);
        int ret = false;
@@ -1544,7 +1378,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, unsigned *output_handle)
+INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *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;
index 491477d..f553f9b 100755 (executable)
@@ -46,7 +46,7 @@
 extern int g_local_activity_run;
 #endif
 
-INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d] mailbox[%p] err_code[%p]", account_id, mailbox, err_code);
 
@@ -164,7 +164,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("new_mailbox[%p], err_code[%p]", new_mailbox, err_code);
 
@@ -223,7 +223,7 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emdaemon_update_mailbox(email_mailbox_t* old_mailbox, email_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_update_mailbox(email_mailbox_t* old_mailbox, email_mailbox_t* new_mailbox, int on_server, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("old_mailbox[%p], new_mailbox[%p], on_server[%d], handle[%p], err_code[%p]", old_mailbox, new_mailbox, on_server, handle, err_code);
 
@@ -254,32 +254,6 @@ INTERNAL_FUNC int emdaemon_update_mailbox(email_mailbox_t* old_mailbox, email_ma
        email_event_t event_data;
        memset(&event_data, 0x00, sizeof(email_event_t));
 
-
-       /* Unsupport sync with server */
-       /*  on_server is allowed to be only 0 when server_type is EMAIL_SERVER_TYPE_ACTIVE_SYNC */
-       /*
-       if ( ref_account->receiving_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
-               on_server = 0;
-       }
-       if ( on_server ) {
-               event_data.type = EMAIL_EVENT_UPDATE_MAILBOX;
-               event_data.account_id = new_mailbox->account_id;
-               event_data.event_param_data_1 = ;
-               event_data.event_param_data_2 = ;
-               event_data.event_param_data_4 = on_server;
-               event_data.event_param_data_3 = GINT_TO_POINTER(new_mailbox->mailbox_type);
-               if(!emcore_insert_event(&event_data, handle, &err))  {
-                       EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
-                       goto FINISH_OFF;
-               }
-       }
-       else {
-               if (!emcore_modify(old_mailbox, new_mailbox, on_server, &err))  {
-                       EM_DEBUG_EXCEPTION("emcore_create failed [%d]", err);
-                       goto FINISH_OFF;
-               }
-       }
-       */
        /*  Update mailbox information only on local db */
        if (!emcore_update_mailbox(old_mailbox, new_mailbox, &err))  {
                EM_DEBUG_EXCEPTION("emcore_modify failed [%d]", err);
@@ -328,9 +302,32 @@ FINISH_OFF:
        return err;
 }
 
+INTERNAL_FUNC int emdaemon_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_type [%d]", input_mailbox_id, input_is_local_mailbox);
 
+       /*  default variable */
+       int err = EMAIL_ERROR_NONE;
+
+       if (input_mailbox_id <= 0)  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       if ( (err = emstorage_set_local_mailbox(input_mailbox_id, input_is_local_mailbox, true)) != EMAIL_ERROR_NONE)  {
+               EM_DEBUG_EXCEPTION("emstorage_set_local_mailbox failed [%d]", err);
+               goto FINISH_OFF;
+       }
+
+
+FINISH_OFF:
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
 
-INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], err_code[%p]", input_mailbox_id, err_code);
        
@@ -432,7 +429,7 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_id, unsigned* handle, int* err_code)
+INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_id, int *handle, int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mailbox_id[%d], handle[%p], err_code[%p]", input_account_id, input_mailbox_id, handle, err_code);
        
@@ -502,7 +499,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mailbox_id, int new_slot_size, unsigned* handle, int *err_code)
+INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mailbox_id, int new_slot_size, int *handle, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id[%d], handle[%p], err_code[%p]", account_id, mailbox_id, handle, err_code);
 
@@ -537,7 +534,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, int input_on_server, unsigned *output_handle)
+INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, int input_on_server, int *output_handle)
 {
        EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_path [%p], input_mailbox_alias[%p], input_on_server [%d], output_handle[%p]", input_mailbox_id, input_mailbox_path, input_mailbox_alias, input_on_server, output_handle);
 
index d54ab1d..a7b37ef 100755 (executable)
@@ -105,7 +105,7 @@ INTERNAL_FUNC int emdaemon_delete_account(int account_id, int* err_code);
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_validate_account(int account_id, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_validate_account(int account_id, int *handle, int* err_code);
 
 /**
  * Change the information of a email account.
@@ -128,7 +128,7 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email_account_t* new_account_info, unsigned* handle,int *err_code);
+INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email_account_t* new_account_info, int *handle,int *err_code);
 
 /**
  * Get a email account by ID.
@@ -247,27 +247,25 @@ INTERNAL_FUNC int emdaemon_free_filter (email_rule_t** filtering_set, int count,
  * Send a mail.
  *
  * @param[in] mail_id                          Specifies the mail ID.
- * @param[in] sending_option   Specifies the sending option.
  * @param[in] callback                 Specifies the callback function for retrieving sending information.
  * @param[in] handle                           Specifies the handle for stopping sending.
  * @param[out] err_code                Specifies the error code returned.
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_send_mail(int mail_id, email_option_t* sending_option,  unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code);
 
 /**
  * Send all mails to been saved in Offline-mode.
  *
  * @param[in] account_id                       Specifies the account ID.
- * @param[in] sending_option   Specifies the sending option.
  * @param[in] callback                         Specifies the callback function for retrieving sending information.
  * @param[in] handle                                   Specifies the handle for stopping sending.
  * @param[out] err_code                        Specifies the error code returned.
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, email_option_t* sending_option,  unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err_code);
 
 INTERNAL_FUNC int emdaemon_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);
 
@@ -287,7 +285,7 @@ INTERNAL_FUNC int emdaemon_add_meeting_request(int account_id, int input_mailbox
  * @return This function returns true on success or false on failure.
  */
 
-INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_id[], int num, int from_server,  unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_id[], int num, int from_server,  int *handle, int* err_code);
 
 /**
  * Delete all mail from a mailbox.
@@ -299,7 +297,7 @@ INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_id[], int num, i
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, unsigned *output_handle, int *output_err_code);
+INTERNAL_FUNC int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *output_handle, int *output_err_code);
 
 /**
  * Move a email to another mailbox.
@@ -362,7 +360,7 @@ INTERNAL_FUNC void _OnMailSendRetryTimerCB( void* data );
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbose, int with_attachment,  unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbose, int with_attachment,  int *handle, int* err_code);
 
 /**
  * Get a mail attachment.
@@ -388,7 +386,7 @@ INTERNAL_FUNC int emdaemon_get_attachment(int attachment_id, email_attachment_da
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int nth,  unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int nth,  int *handle, int* err_code);
 
 
 /**
@@ -424,30 +422,6 @@ INTERNAL_FUNC int emdaemon_delete_mail_attachment(int attachment_id, int* err_co
 INTERNAL_FUNC int emdaemon_free_attachment_data(email_attachment_data_t** atch_info, int* err_code);
 
 /**
- * Change email flag.
- *
- * @param[in] mailbox  Reserved.
- * @param[in] mail_id  Specifies the mail ID.
- * @param[in] new_flag Specifies the new email flag.
- * @param[out] err_code        Specifies the error code returned.
- * @remarks N/A
- * @return This function returns true on success or false on failure.
- */
-INTERNAL_FUNC int emdaemon_modify_flag(int mail_id, email_mail_flag_t new_flag, int onserver, int sticky_flag, int* err_code);
-
-/**
- * Change email extra flag.
- *
- * @param[in] mailbox  Reserved.
- * @param[in] mail_id  Specifies the mail ID.
- * @param[in] new_flag Specifies the new email extra flag.
- * @param[out] err_code        Specifies the error code returned.
- * @remarks N/A
- * @return This function returns true on success or false on failure.
- */
-INTERNAL_FUNC int emdaemon_modify_extra_flag(int mail_id, email_extra_flag_t new_flag, int* err_code);
-
-/**
  * Change email read/unread flag.
  * @param[in] account_id  Specifies the account id.
  * @param[in] mail_ids         Specifies the array of mail ID.
@@ -464,7 +438,7 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n
 /*****************************************************************************/
 /*  Mailbox                                                                  */
 /*****************************************************************************/
-INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, int *handle, int* err_code);
 
 /**
  * Download header of new emails from mail server.
@@ -476,7 +450,7 @@ INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox,
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_id, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_id, int *handle, int* err_code);
 
 
 /**
@@ -512,7 +486,7 @@ INTERNAL_FUNC int emdaemon_get_mailbox_list(int account_id, email_mailbox_t** ma
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle, int* err_code);
 
 /**
  * Delete a mailbox.
@@ -523,7 +497,7 @@ INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_serv
  * @remarks N/A
  * @return This function returns true on success or false on failure.
  */
-INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, int *handle, int* err_code);
 
 /**
  * Delete all sub-mailboxes from a specific mailbox.
@@ -656,29 +630,31 @@ INTERNAL_FUNC int emdaemon_insert_accountinfo_to_contact(email_account_t* accoun
 
 INTERNAL_FUNC int emdaemon_update_accountinfo_to_contact(email_account_t* old_account, email_account_t* new_account);
 
-INTERNAL_FUNC int emdaemon_update_mailbox(email_mailbox_t* old_mailbox, email_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_update_mailbox(email_mailbox_t* old_mailbox, email_mailbox_t* new_mailbox, int on_server, int *handle, int* err_code);
 
 INTERNAL_FUNC int emdaemon_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type);
 
+INTERNAL_FUNC int emdaemon_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox);
+
 INTERNAL_FUNC int emdaemon_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter, int input_search_filter_count, unsigned int *output_handle, int *err_code);
 
 INTERNAL_FUNC int emdaemon_clear_all_mail_data(int* err_code);
 
 INTERNAL_FUNC int emdaemon_send_mail_retry( int mail_id,  int timeout_in_sec, int* err_code);
 
-INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_account, unsigned* handle, int* err_code);
+INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_account, int *handle, int* err_code);
 
-INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mailbox_id, int new_slot_size, unsigned* handle, int *err_code);
+INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mailbox_id, int new_slot_size, int *handle, int *err_code);
 
-INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, int input_on_server, unsigned *output_handle);
+INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, int input_on_server, int *output_handle);
 
 INTERNAL_FUNC int emdaemon_move_mail_thread_to_mailbox(int thread_id, int target_mailbox_id, int move_always_flag, int *err_code);
 
-INTERNAL_FUNC int emdaemon_delete_mail_thread(int thread_id, int delete_always_flag, unsigned* handle, int *err_code);
+INTERNAL_FUNC int emdaemon_delete_mail_thread(int thread_id, int delete_always_flag, int *handle, int *err_code);
 
-INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server, unsigned* handle, int *err_code);
+INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server, int *handle, int *err_code);
 
-INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, unsigned *output_handle);
+INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle);
 
 #ifdef __cplusplus
 }
index a12a0cc..8c6e3db 100755 (executable)
@@ -166,7 +166,7 @@ void stb_update_account(HIPC_API a_hAPI)
        email_account_t new_account_info = {0};
        email_account_t old_account_info = {0};
        int err = EMAIL_ERROR_NONE;
-       unsigned int handle = 0;
+       int handle = 0;
 
        account_id = *((int*)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0));
 
@@ -267,7 +267,7 @@ void stb_validate_account(HIPC_API a_hAPI)
 
        /* account_id */
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
-       local_result = emdaemon_validate_account(account_id, (unsigned*)&handle,&err_code);
+       local_result = emdaemon_validate_account(account_id, &handle,&err_code);
 
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
                EM_DEBUG_LOG("emipc_add_parameter failed ");
@@ -340,149 +340,6 @@ void stb_get_account_list(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_END();
 }
 
-void stb_modify_mail_flag(HIPC_API a_hAPI)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       int err = EMAIL_ERROR_NONE;
-       int mail_id = 0;
-       int i_flag = 0;
-       int onserver = 0;
-       int sticky_flag = 0;
-       email_mail_flag_t new_flag = { 0 };
-
-       EM_DEBUG_LOG("mail_id");
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
-       EM_DEBUG_LOG("mail_id[%d]", mail_id);
-
-       EM_DEBUG_LOG("i_flag");
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &i_flag);
-       EM_DEBUG_LOG("i_flag[%d]", i_flag);
-
-       EM_DEBUG_LOG("Sticky flag");
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &sticky_flag);
-       EM_DEBUG_LOG(">>> STICKY flag Value [ %d] ", sticky_flag);
-
-       EM_DEBUG_LOG("onserver");
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &onserver);
-       EM_DEBUG_LOG("onserver[%d]", onserver);
-
-       EM_DEBUG_LOG("Flag Change 1>>> ");
-       if(!em_convert_mail_int_to_flag(i_flag, &new_flag, &err)) {
-               EM_DEBUG_EXCEPTION("em_convert_mail_int_to_flag failed");
-               return;
-       }
-       if(emdaemon_modify_flag(mail_id, new_flag, onserver, sticky_flag, &err))
-               EM_DEBUG_LOG("emdaemon_modify_flag - success");
-       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-               if (!emipc_execute_stub_api(a_hAPI))
-                       EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
-       EM_DEBUG_FUNC_END();
-}
-
-#if 0
-void stb_modify_mail_extra_flag(HIPC_API a_hAPI)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       int err = EMAIL_ERROR_NONE;
-       int mail_id = 0;
-       int buffer_size = 0;
-       email_extra_flag_t new_flag= { 0 };
-       char* local_stream = NULL;
-
-       EM_DEBUG_LOG("mail_id");
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
-
-       EM_DEBUG_LOG("extra_flag");
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
-
-       if(buffer_size > 0) {
-               local_stream = (char*)em_malloc(buffer_size);
-               EM_NULL_CHECK_FOR_VOID(local_stream);
-               if(local_stream) {
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, local_stream);
-                       em_convert_byte_stream_to_extra_flags(local_stream, &new_flag);
-                       EM_SAFE_FREE(local_stream);
-               }
-
-               if(emdaemon_modify_extra_flag(mail_id, new_flag, &err))
-                       EM_DEBUG_LOG("emdaemon_modify_extra_flag - success");
-
-               if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
-                               EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-
-                       if (!emipc_execute_stub_api(a_hAPI))
-                               EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
-
-       }
-       EM_DEBUG_FUNC_END();
-}
-
-
-void stb_get_mail_count_of_mailbox(HIPC_API a_hAPI)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       int buffer_size = 0;
-       int local_result = 0;
-       char* local_stream = NULL;
-       email_mailbox_t mailbox;
-       int total_count = 0;
-       int unseen= 0;
-
-       EM_DEBUG_LOG("mailbox");
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
-
-       if(buffer_size > 0)     {
-               local_stream = (char*)em_malloc(buffer_size);
-               if(!local_stream) {
-                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
-                       goto FINISH_OFF;
-               }
-               emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, buffer_size, local_stream);
-               em_convert_byte_stream_to_mailbox(local_stream, buffer_size, &mailbox);
-               EM_SAFE_FREE(local_stream);
-       }
-
-       /*get the Mailbox Count */
-       if (!emdaemon_get_mail_count_of_mailbox(&mailbox, &total_count, &unseen, NULL)) {
-               EM_DEBUG_EXCEPTION("emdaemon_get_mail_count_of_mailbox - failed");
-               goto FINISH_OFF;
-       }
-       else {
-               EM_DEBUG_LOG("emdaemon_get_mail_count_of_mailbox - success");
-               local_result = 1;
-       }
-
-FINISH_OFF:
-
-       if(local_result) {
-               if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-
-               /* Totol count of mails */
-               if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &total_count, sizeof(int)))
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed  ");
-
-               /* Unread Mail */
-               if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &unseen, sizeof(int)))
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed  ");
-
-               if (!emipc_execute_stub_api(a_hAPI))
-                       EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
-       }
-       else {
-               if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
-                       EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-               if (!emipc_execute_stub_api(a_hAPI))
-                       EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
-       }
-
-       emcore_free_mailbox(&mailbox);
-
-       EM_DEBUG_FUNC_END();
-}
-#endif
-
 /* sowmya.kr, 10-May-2010, changes for API improvement */
 void stb_sync_header(HIPC_API a_hAPI)
 {
@@ -499,7 +356,7 @@ void stb_sync_header(HIPC_API a_hAPI)
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &maibox_id);
        EM_DEBUG_LOG("maibox_id [%d]", maibox_id);
 
-       if(emdaemon_sync_header(account_id, maibox_id, (unsigned*)&handle, &err)) {
+       if(emdaemon_sync_header(account_id, maibox_id, &handle, &err)) {
                EM_DEBUG_LOG("emdaemon_sync_header success ");
        }
 
@@ -517,8 +374,8 @@ void stb_download_body(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_BEGIN();
        int err = EMAIL_ERROR_NONE;
        int mail_id = 0;
-       int has_attachment = 0;
-       unsigned int handle = 0;
+       int attachment_count = 0;
+       int handle = 0;
        int account_id = 0;
 
        /* Account Id */
@@ -528,10 +385,10 @@ void stb_download_body(HIPC_API a_hAPI)
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
 
        /* Has Attachment */
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &has_attachment);
+       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &attachment_count);
 
        /*Download Body */
-       if (!emdaemon_download_body(account_id, mail_id, 1, has_attachment, &handle, &err)) {
+       if (!emdaemon_download_body(account_id, mail_id, 1, attachment_count, &handle, &err)) {
                EM_DEBUG_EXCEPTION("emdaemon_download_body - failed");
                goto FINISH_OFF;
        }
@@ -554,12 +411,12 @@ FINISH_OFF:
 void stb_create_mailbox(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int             buffer_size                     = 0;
-       int             err = EMAIL_ERROR_NONE;
-       char            *local_stream  = NULL;
-       int             on_server               = 0;
+       int                 buffer_size                         = 0;
+       int                 err = EMAIL_ERROR_NONE;
+       char               *local_stream  = NULL;
+       int                 on_server           = 0;
        email_mailbox_t mailbox = {0};
-       int handle = 0; /* Added for cancelling mailbox creating  */
+       int             handle = 0; /* Added for cancelling mailbox creating  */
 
        buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
        EM_DEBUG_LOG("size [%d]", buffer_size);
@@ -576,7 +433,7 @@ void stb_create_mailbox(HIPC_API a_hAPI)
 
        on_server = *((int*)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1));
 
-       emdaemon_add_mailbox(&mailbox, on_server, (unsigned*)&handle, &err);
+       emdaemon_add_mailbox(&mailbox, on_server, &handle, &err);
 
 FINISH_OFF:
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
@@ -591,39 +448,6 @@ FINISH_OFF:
                return;
        }
 
-#if 0
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
-       EM_DEBUG_LOG("size [%d]", buffer_size);
-
-       if(buffer_size > 0) {
-               local_stream = (char*)em_malloc(buffer_size);
-               EM_NULL_CHECK_FOR_VOID(local_stream);
-               if(local_stream) {
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, buffer_size, local_stream);
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &on_server);
-                       em_convert_byte_stream_to_mailbox(local_stream, buffer_size, &mailbox);
-                       EM_SAFE_FREE(local_stream);
-
-                       if (mailbox.mailbox_name)
-                               EM_DEBUG_LOG("Mailbox name - %s", mailbox.mailbox_name);
-
-                       if(emdaemon_add_mailbox(&mailbox, on_server, (unsigned*)&handle, &err))
-                               err = EMAIL_ERROR_NONE;
-
-                       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
-                               EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
-                       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
-                               EM_DEBUG_EXCEPTION("emipc_add_parameter failed 2");
-                       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &mailbox.mailbox_id, sizeof(int)))
-                               EM_DEBUG_EXCEPTION("emipc_add_parameter failed 3");
-
-                       if (!emipc_execute_stub_api(a_hAPI)) {
-                               EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
-                               return;
-                       }
-               }
-       }
-#endif
        EM_DEBUG_FUNC_END();
 }
 
@@ -632,9 +456,9 @@ void stb_delete_mailbox(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
        int              err = EMAIL_ERROR_NONE;
-       int             on_server               = 0;
-       int handle = 0; /* Added for cancelling mailbox deleting */
-       int input_mailbox_id = 0;
+       int      on_server              = 0;
+       int      handle = 0; /* Added for cancelling mailbox deleting */
+       int      input_mailbox_id = 0;
 
        /* src_mailbox_id */
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &input_mailbox_id);
@@ -647,7 +471,7 @@ void stb_delete_mailbox(HIPC_API a_hAPI)
 
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &on_server);
 
-       if(emdaemon_delete_mailbox(input_mailbox_id, on_server, (unsigned*)&handle, &err))
+       if(emdaemon_delete_mailbox(input_mailbox_id, on_server, &handle, &err))
                err = EMAIL_ERROR_NONE;
 
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
@@ -661,105 +485,45 @@ void stb_delete_mailbox(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_END();
 }
 
-void stb_update_mailbox(HIPC_API a_hAPI)
+void stb_set_mailbox_type(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int             buffer_size                     = 0;
-       int              err = EMAIL_ERROR_NONE;
-       char    *old_mailbox_stream  = NULL;
-       char    *new_mailbox_stream  = NULL;
-       int             on_server               = 0;
-       email_mailbox_t *old_mailbox = NULL;
-       email_mailbox_t *new_mailbox = NULL;
-       int handle = 0; /* Added for cancelling mailbox updating */
-
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
-       EM_DEBUG_LOG("size [%d]", buffer_size);
-       if(buffer_size > 0)       {
-               old_mailbox_stream = (char*)em_malloc(buffer_size);
-               EM_NULL_CHECK_FOR_VOID(old_mailbox_stream);
-               if(old_mailbox_stream) {
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, buffer_size, old_mailbox_stream);
-                       old_mailbox = (email_mailbox_t*)em_malloc(sizeof(email_mailbox_t));
-                       if ( old_mailbox == NULL ) {
-                               EM_DEBUG_EXCEPTION("em_malloc failed.");
-                               err = EMAIL_ERROR_OUT_OF_MEMORY;
-                               goto FINISH_OFF;
-                       }
-
-                       em_convert_byte_stream_to_mailbox(old_mailbox_stream, buffer_size, old_mailbox);
-                       EM_SAFE_FREE(old_mailbox_stream);
-               }
-       }
-       else {
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
-               err = EMAIL_ERROR_INVALID_PARAM;
-               goto FINISH_OFF;
-       }
+       int     err = EMAIL_ERROR_NONE;
+       int mailbox_id = 0;
+       int mailbox_type = 0;
 
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
-       EM_DEBUG_LOG("size [%d]", buffer_size);
-       if(buffer_size > 0)       {
-               new_mailbox_stream = (char*)em_malloc(buffer_size);
-               EM_NULL_CHECK_FOR_VOID(new_mailbox_stream);
-               if(new_mailbox_stream) {
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, new_mailbox_stream);
-                       new_mailbox = (email_mailbox_t*)em_malloc(sizeof(email_mailbox_t));
-                       if ( new_mailbox == NULL ) {
-                               EM_DEBUG_EXCEPTION("em_malloc failed.");
-                               err = EMAIL_ERROR_OUT_OF_MEMORY;
-                               goto FINISH_OFF;
-                       }
-                       em_convert_byte_stream_to_mailbox(new_mailbox_stream, buffer_size, new_mailbox);
-                       EM_SAFE_FREE(new_mailbox_stream);
-               }
-       }
-       else {
-               EM_DEBUG_EXCEPTION("INVALID PARAM : old mailbox");
-               err = EMAIL_ERROR_INVALID_PARAM;
-               goto FINISH_OFF;
-       }
+       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
+       EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
 
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &on_server);
+       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_type);
+       EM_DEBUG_LOG("mailbox_type[%d]", mailbox_type);
 
-       if(emdaemon_update_mailbox(old_mailbox, new_mailbox, on_server, (unsigned*)&handle, &err))
+       if( (err = emdaemon_set_mailbox_type(mailbox_id, mailbox_type)) != EMAIL_ERROR_NONE)
                err = EMAIL_ERROR_NONE;
 
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
-               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+               EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
 
        if (!emipc_execute_stub_api(a_hAPI))
-               EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
-
-
-FINISH_OFF:
-       EM_SAFE_FREE(old_mailbox_stream);
-       EM_SAFE_FREE(new_mailbox_stream);
-
-       emcore_free_mailbox(old_mailbox);
-       EM_SAFE_FREE(old_mailbox);
-       emcore_free_mailbox(new_mailbox);
-       EM_SAFE_FREE(new_mailbox);
+               EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
 
        EM_DEBUG_FUNC_END();
 }
 
-void stb_set_mailbox_type(HIPC_API a_hAPI)
+void stb_set_local_mailbox(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
        int     err = EMAIL_ERROR_NONE;
        int mailbox_id = 0;
-       int mailbox_type = 0;
+       int is_local_mailbox = 0;
 
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
        EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
 
-       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_type);
-       EM_DEBUG_LOG("mailbox_type[%d]", mailbox_type);
+       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &is_local_mailbox);
+       EM_DEBUG_LOG("is_local_mailbox[%d]", is_local_mailbox);
 
-       if( (err = emdaemon_set_mailbox_type(mailbox_id, mailbox_type)) != EMAIL_ERROR_NONE)
+       if( (err = emdaemon_set_local_mailbox(mailbox_id, is_local_mailbox)) != EMAIL_ERROR_NONE)
                err = EMAIL_ERROR_NONE;
 
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
@@ -789,7 +553,7 @@ void stb_set_mail_slot_size_of_mailbox(HIPC_API a_hAPI)
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &mail_slot_size);
        EM_DEBUG_LOG("mail_slot_size[%d]", mail_slot_size);
 
-       if(emdaemon_set_mail_slot_size_of_mailbox(account_id, mailbox_id, mail_slot_size, (unsigned*)&handle, &err))
+       if(emdaemon_set_mail_slot_size_of_mailbox(account_id, mailbox_id, mail_slot_size, &handle, &err))
                err = EMAIL_ERROR_NONE;
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
@@ -836,7 +600,7 @@ void stb_rename_mailbox(HIPC_API a_hAPI)
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &on_server);
        EM_DEBUG_LOG("on_server[%d]", on_server);
 
-       if ((err = emdaemon_rename_mailbox(mailbox_id, mailbox_path, mailbox_alias, on_server, (unsigned*)&handle)) != EMAIL_ERROR_NONE) {
+       if ((err = emdaemon_rename_mailbox(mailbox_id, mailbox_path, mailbox_alias, on_server, &handle)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emdaemon_rename_mailbox failed [%d]", err);
        }
 
@@ -855,38 +619,16 @@ void stb_rename_mailbox(HIPC_API a_hAPI)
 void stb_send_mail(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int buffer_size = 0;
-       char* local_option_stream = NULL;
        char* local_stream = NULL;
-       email_mailbox_t* mailbox = NULL;
-       email_option_t sending_option;
        int mail_id;
        int handle;
        int err = EMAIL_ERROR_NONE;
-       char* mailbox_name = NULL;
 
        /* Mail_id */
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
        EM_DEBUG_LOG("mail_id [%d]", mail_id);
 
-       /* Sending Option */
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
-
-       if(buffer_size > 0) {
-               local_option_stream = (char*)em_malloc(buffer_size);
-
-               if(NULL == local_option_stream) {
-                       err = EMAIL_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
-
-               if(local_option_stream) {
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, local_option_stream);
-                       em_convert_byte_stream_to_option(local_option_stream, buffer_size, &sending_option);
-               }
-       }
-
-       if(emdaemon_send_mail(mail_id, &sending_option, (unsigned*)&handle, &err)) {
+       if(emdaemon_send_mail(mail_id, &handle, &err)) {
                err = EMAIL_ERROR_NONE;
                if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
                        EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
@@ -902,13 +644,7 @@ void stb_send_mail(HIPC_API a_hAPI)
                        EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
        }
 
-FINISH_OFF:
        EM_SAFE_FREE(local_stream);
-       EM_SAFE_FREE(local_option_stream);
-       EM_SAFE_FREE(mailbox);
-       EM_SAFE_FREE(mailbox_name);
-
-       emcore_free_option(&sending_option);
 
        EM_DEBUG_FUNC_END();
 }
@@ -1380,9 +1116,8 @@ void stb_add_mail(HIPC_API a_hAPI)
        int  result_attachment_data_count = 0;
        int  param_index = 0;
        int  sync_server = 0;
-       int  mail_count = 0;
        int  err = EMAIL_ERROR_NONE;
-       email_mail_data_t *result_mail_data = NULL;
+       email_mail_data_t result_mail_data = {0};
        email_attachment_data_t *result_attachment_data = NULL;
        email_meeting_request_t result_meeting_request = {0};
 
@@ -1394,7 +1129,7 @@ void stb_add_mail(HIPC_API a_hAPI)
        /* mail_data */
        if(buffer_size > 0)      {
                char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
-               em_convert_byte_stream_to_mail_data(stream, &result_mail_data, &mail_count);
+               em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
        }
 
        /* attachment */
@@ -1418,9 +1153,9 @@ void stb_add_mail(HIPC_API a_hAPI)
 
        /* meeting request */
        EM_DEBUG_LOG("email_meeting_request_t");
-       if ( result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
-               || result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
-               || result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+       if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
+               || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
+               || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
                buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
 
                if(buffer_size > 0) {
@@ -1432,7 +1167,7 @@ void stb_add_mail(HIPC_API a_hAPI)
        EM_DEBUG_LOG("sync_server");
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, sizeof(int), &sync_server);
 
-       if( (err = emdaemon_add_mail(result_mail_data, result_attachment_data, result_attachment_data_count, &result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) {
+       if( (err = emdaemon_add_mail(&result_mail_data, result_attachment_data, result_attachment_data_count, &result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emdaemon_add_mail failed [%d]", err);
                goto FINISH_OFF;
        }
@@ -1440,9 +1175,9 @@ void stb_add_mail(HIPC_API a_hAPI)
        local_result = 1;
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->mail_id), sizeof(int)))
+       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.mail_id, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->thread_id), sizeof(int)))
+       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.thread_id, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
        if (!emipc_execute_stub_api(a_hAPI))
                EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
@@ -1455,7 +1190,7 @@ FINISH_OFF:
                        EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
        }
 
-       emcore_free_mail_data(result_mail_data);
+       emcore_free_mail_data(&result_mail_data);
 
        if(result_attachment_data)
                emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
@@ -1582,10 +1317,9 @@ void stb_update_mail(HIPC_API a_hAPI)
        int  result_attachment_data_count = 0;
        int  param_index = 0;
        int  sync_server = 0;
-       int  mail_count = 0;
-       int *temp_buffer = NULL;
+       int  *temp_buffer = NULL;
        int  err = EMAIL_ERROR_NONE;
-       email_mail_data_t *result_mail_data = NULL;
+       email_mail_data_t result_mail_data = {0};
        email_attachment_data_t *result_attachment_data = NULL;
        email_meeting_request_t result_meeting_request = {0};
 
@@ -1594,10 +1328,11 @@ void stb_update_mail(HIPC_API a_hAPI)
 
        if(buffer_size > 0)      {
                char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
-               em_convert_byte_stream_to_mail_data(stream, &result_mail_data, &mail_count);
+               em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
        }
 
        buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
+
        EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size);
 
        if(buffer_size > 0)      {
@@ -1612,14 +1347,13 @@ void stb_update_mail(HIPC_API a_hAPI)
                        goto FINISH_OFF;
                }
        }
-
        param_index++;
 
        EM_DEBUG_LOG("email_meeting_request_t");
 
-       if ( result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
-               || result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
-               || result_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+       if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
+               || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
+               || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
                buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
 
                if(buffer_size > 0) {
@@ -1632,14 +1366,15 @@ void stb_update_mail(HIPC_API a_hAPI)
 
        temp_buffer = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
 
-       if (!temp_buffer) {
-               EM_DEBUG_EXCEPTION("emipc_get_nth_parameter_data[%d] failed ", param_index - 1);
+       if(!temp_buffer) {
+               EM_DEBUG_EXCEPTION("emipc_get_nth_parameter_data[%d] failed", param_index - 1);
+               err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
                goto FINISH_OFF;
        }
 
        sync_server = *temp_buffer;
 
-       if( (err = emdaemon_update_mail(result_mail_data, result_attachment_data,
+       if( (err = emdaemon_update_mail(&result_mail_data, result_attachment_data,
                        result_attachment_data_count, &result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emdaemon_update_mail failed [%d]", err);
                goto FINISH_OFF;
@@ -1648,9 +1383,9 @@ void stb_update_mail(HIPC_API a_hAPI)
        local_result = 1;
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->mail_id), sizeof(int)))
+       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.mail_id, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
-       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->thread_id), sizeof(int)))
+       if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.thread_id, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
        if (!emipc_execute_stub_api(a_hAPI))
                EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
@@ -1663,7 +1398,7 @@ FINISH_OFF:
                        EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
        }
 
-       emcore_free_mail_data(result_mail_data);
+       emcore_free_mail_data(&result_mail_data);
 
        if(result_attachment_data)
                emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
@@ -1715,7 +1450,7 @@ void stb_delete_thread(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_BEGIN();
 
        int thread_id = 0, delete_always_flag = 0;
-       unsigned int handle = 0;
+       int handle = 0;
        int err = EMAIL_ERROR_NONE;
 
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
@@ -1744,7 +1479,7 @@ void stb_modify_seen_flag_of_thread(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_BEGIN();
 
        int thread_id = 0, seen_flag = 0, on_server = 0;
-       unsigned int handle = 0;
+       int handle = 0;
        int err = EMAIL_ERROR_NONE;
 
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
@@ -1776,7 +1511,7 @@ void stb_expunge_mails_deleted_flagged(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_BEGIN();
 
        int mailbox_id = 0, on_server = 0;
-       unsigned int handle = 0;
+       int handle = 0;
        int err = EMAIL_ERROR_NONE;
 
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), (void*)&mailbox_id);
@@ -1947,7 +1682,7 @@ void stb_get_imap_mailbox_list(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_BEGIN();
        int err = EMAIL_ERROR_NONE;
        int account_id = 0;
-       unsigned int handle = 0;
+       int handle = 0;
 
        /* account_id */
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
@@ -1990,7 +1725,7 @@ void stb_download_attachment(HIPC_API a_hAPI)
        int err = EMAIL_ERROR_NONE;
        int mail_id = 0;
        int nth = 0;
-       unsigned int handle = 0;
+       int handle = 0;
        int account_id = 0;
 
        EM_DEBUG_LOG("account_id");
@@ -2030,32 +1765,14 @@ void stb_download_attachment(HIPC_API a_hAPI)
 void stb_mail_send_saved(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
-       int buffer_size = 0;
        int err = EMAIL_ERROR_NONE;
-       char* local_option_stream = NULL;
-       email_option_t sending_option;
        int account_id = 0;
-       /* unsigned *handle = NULL; */
 
        /* account_id */
        emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
 
-       /* Sending Option */
-       EM_DEBUG_LOG("Sending option");
-       buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
-
-       if(buffer_size > 0)  {
-               local_option_stream = (char*)em_malloc(buffer_size);
-               EM_NULL_CHECK_FOR_VOID(local_option_stream);
-               if(local_option_stream) {
-                       emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, local_option_stream);
-                       em_convert_byte_stream_to_option(local_option_stream, buffer_size, &sending_option);
-                       /* EM_SAFE_FREE(local_option_stream); */
-               }
-       }
-
        EM_DEBUG_LOG("calling emdaemon_send_mail_saved");
-       if(emdaemon_send_mail_saved(account_id, &sending_option, NULL, &err))
+       if(emdaemon_send_mail_saved(account_id, NULL, &err))
                err = EMAIL_ERROR_NONE;
 
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
@@ -2064,8 +1781,6 @@ void stb_mail_send_saved(HIPC_API a_hAPI)
        if (!emipc_execute_stub_api(a_hAPI))
                EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
 
-       emcore_free_option(&sending_option);
-
        EM_DEBUG_FUNC_END();
 }
 
@@ -2356,7 +2071,7 @@ void stb_create_account_with_validation(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_BEGIN();
        int buffer_size = 0;
        int local_result = 0;
-       unsigned int handle = 0;
+       int handle = 0;
        char* stream = NULL;
        email_account_t *account = NULL;
        int err = EMAIL_ERROR_NONE;
@@ -2593,29 +2308,41 @@ void stb_verify_signature(HIPC_API a_hAPI)
        int err = EMAIL_ERROR_NONE;
        int verify = 0;
        int mail_id = 0;
-       int cert_file_len = 0;
-       char *cert_file_path = 0;
+       int count = 0;
+       int attachment_tbl_count = 0;
        email_mail_data_t *mail_data = NULL;
+       emstorage_attachment_tbl_t *attachment_tbl_list = NULL;
 
-       cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
-       if (cert_file_len > 0) {
-               cert_file_path = em_malloc(cert_file_len + 1);
-               emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
-       }
-
-       err = emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
+       err = emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
        if (err != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
+               goto FINISH_OFF;
        }
 
        if (!emcore_get_mail_data(mail_id, &mail_data)) {
                EM_DEBUG_EXCEPTION("emcore_get_mail_data failed");
+               goto FINISH_OFF;
        }
 
-       if (!emcore_verify_signature(cert_file_path, mail_data->file_path_mime_entity, &verify, &err)) {
-               EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
+       if ((err = emstorage_get_attachment_list(mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed : [%d]", err);
+               goto FINISH_OFF;
        }
 
+       for (count = 0; count < attachment_tbl_count; count++) {
+               if (strcasestr(attachment_tbl_list[count].attachment_name, "p7s") == NULL)
+                       continue;
+
+               break;  
+       }
+
+       if (!emcore_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, &verify, &err)) {
+               EM_DEBUG_EXCEPTION("emcore_verify_signature failed");
+               goto FINISH_OFF;
+       }
+
+FINISH_OFF:
+
        if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &verify, sizeof(int)))
                EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
 
@@ -2626,7 +2353,13 @@ void stb_verify_signature(HIPC_API a_hAPI)
        if (!emipc_execute_stub_api(a_hAPI))
                EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed  ");
 
-       EM_SAFE_FREE(cert_file_path);           
+
+       if (attachment_tbl_list)
+               emstorage_free_attachment(&attachment_tbl_list, attachment_tbl_count, NULL);
+
+       if (mail_data)
+               emcore_free_mail_data(mail_data);
+
        EM_DEBUG_FUNC_END();    
 }
 
@@ -2727,6 +2460,135 @@ void stb_show_user_message(HIPC_API a_hAPI)
        EM_DEBUG_FUNC_END("err [%d]", err);
 }
 
+void stb_write_mime_file(HIPC_API a_hAPI)
+{
+       EM_DEBUG_FUNC_BEGIN();
+       int i = 0;
+       int exist_file_path = 0;
+       int buffer_size = 0;
+       int local_result = 0;
+       int result_attachment_data_count = 0;
+       int param_index = 0;
+       int err = EMAIL_ERROR_NONE;
+       char *file_path = NULL;
+       char *output_file_path = NULL;
+       email_mail_data_t result_mail_data = {0};
+       email_attachment_data_t *result_attachment_data = NULL;
+       emstorage_mail_tbl_t *input_mail_tbl_data = NULL;
+       emstorage_attachment_tbl_t *input_attachment_tbl_data = NULL;
+       
+       /* email_mail_data_t */;
+       buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
+       EM_DEBUG_LOG("email_mail_data_t buffer_size[%d]", buffer_size);
+
+       /* mail_data */
+       if(buffer_size > 0)      {
+               char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
+               em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
+       }
+
+       /* attachment */
+       buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
+       EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size);
+
+       if(buffer_size > 0)      {
+               char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index);
+               em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count);
+
+               EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
+
+               if(result_attachment_data_count && !result_attachment_data) {
+                       EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
+                       err = EMAIL_ERROR_ON_PARSING;
+                       goto FINISH_OFF;
+               }
+       }
+
+       param_index++;
+       
+       buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
+       if (buffer_size > 0) {
+               output_file_path = (char *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index);
+               EM_DEBUG_LOG("output_file_path : [%s]", output_file_path);
+       }
+
+       /* Convert mail_data to mail_tbl */
+       if (!em_convert_mail_data_to_mail_tbl(&result_mail_data, 1, &input_mail_tbl_data, &err)) {
+               EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed");
+               goto FINISH_OFF;
+       }
+
+       /* Convert attachment_data to attachment_tbl */
+       if (result_attachment_data_count > 0) {
+               input_attachment_tbl_data = (emstorage_attachment_tbl_t *)em_malloc(sizeof(emstorage_attachment_tbl_t) * result_attachment_data_count);
+               if (input_attachment_tbl_data == NULL) {
+                       EM_DEBUG_EXCEPTION("em_malloc failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
+       }
+
+       for (i = 0; i < result_attachment_data_count ; i++) {
+               input_attachment_tbl_data[i].attachment_id = result_attachment_data[i].attachment_id;
+               input_attachment_tbl_data[i].attachment_name = EM_SAFE_STRDUP(result_attachment_data[i].attachment_name);
+               input_attachment_tbl_data[i].attachment_path = EM_SAFE_STRDUP(result_attachment_data[i].attachment_path);
+               input_attachment_tbl_data[i].attachment_size = result_attachment_data[i].attachment_size;
+               input_attachment_tbl_data[i].mail_id = result_attachment_data[i].mail_id;
+               input_attachment_tbl_data[i].account_id = result_attachment_data[i].account_id;
+               input_attachment_tbl_data[i].mailbox_id = result_attachment_data[i].mailbox_id;
+               input_attachment_tbl_data[i].attachment_save_status = result_attachment_data[i].save_status;
+               input_attachment_tbl_data[i].attachment_drm_type = result_attachment_data[i].drm_status;
+               input_attachment_tbl_data[i].attachment_inline_content_status = result_attachment_data[i].inline_content_status;
+               input_attachment_tbl_data[i].attachment_mime_type = EM_SAFE_STRDUP(result_attachment_data[i].attachment_mime_type);
+       }
+
+
+       if (!emcore_make_rfc822_file_from_mail(input_mail_tbl_data, input_attachment_tbl_data, result_attachment_data_count, NULL, &file_path, NULL, &err)) {
+               EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed");
+               goto FINISH_OFF;
+       }
+
+       if (output_file_path) {
+               if (!emstorage_move_file(file_path, output_file_path, false, &err)) {
+                       EM_DEBUG_EXCEPTION("emstorage_move_file failed : [%d]", err);
+                       goto FINISH_OFF;
+               }
+       } else {
+               exist_file_path = 1;
+               output_file_path = EM_SAFE_STRDUP(file_path);
+       }
+
+
+       if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, (char *)output_file_path, strlen(output_file_path) + 1)) {
+               EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+               err = EMAIL_ERROR_NULL_VALUE;
+               goto FINISH_OFF;
+       }
+
+       local_result = 1;
+
+FINISH_OFF:
+       if ( local_result == 0 ) {
+               if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+                       EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
+       }
+
+       if (!emipc_execute_stub_api(a_hAPI))
+               EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
+       
+       emcore_free_mail_data(&result_mail_data);
+
+       if(result_attachment_data)
+               emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
+
+       EM_SAFE_FREE(file_path);
+       if (exist_file_path)
+               EM_SAFE_FREE(output_file_path);
+
+       em_flush_memory();
+       EM_DEBUG_FUNC_END();
+}
+
 void stb_API_mapper(HIPC_API a_hAPI)
 {
        EM_DEBUG_FUNC_BEGIN();
@@ -2745,14 +2607,14 @@ void stb_API_mapper(HIPC_API a_hAPI)
                        stb_delete_mailbox(a_hAPI);
                        break;
 
-               case _EMAIL_API_UPDATE_MAILBOX:
-                       stb_update_mailbox(a_hAPI);
-                       break;
-
                case _EMAIL_API_SET_MAILBOX_TYPE:
                        stb_set_mailbox_type(a_hAPI);
                        break;
 
+               case _EMAIL_API_SET_LOCAL_MAILBOX:
+                       stb_set_local_mailbox(a_hAPI);
+                       break;
+
                case _EMAIL_API_SET_MAIL_SLOT_SIZE:
                        stb_set_mail_slot_size_of_mailbox(a_hAPI);
                        break;
@@ -2765,12 +2627,6 @@ void stb_API_mapper(HIPC_API a_hAPI)
                        stb_send_mail(a_hAPI);
                        break;
 
-#if 0
-               case _EMAIL_API_GET_MAILBOX_COUNT:
-                       stb_get_mail_count_of_mailbox(a_hAPI);
-                       break;
-#endif
-
                case _EMAIL_API_GET_MAILBOX_LIST:
                        stb_get_mailbox_list(a_hAPI);
                        break;
@@ -2795,15 +2651,6 @@ void stb_API_mapper(HIPC_API a_hAPI)
                        stb_delete_mail(a_hAPI);
                        break;
 
-               case _EMAIL_API_MODIFY_MAIL_FLAG:
-                       stb_modify_mail_flag(a_hAPI);
-                       break;
-#if 0
-               case _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG:
-                       stb_modify_mail_extra_flag(a_hAPI);
-                       break;
-#endif
-
                case _EMAIL_API_ADD_RULE:
                        stb_add_rule(a_hAPI);
                        break;
@@ -2983,6 +2830,10 @@ void stb_API_mapper(HIPC_API a_hAPI)
                case _EMAIL_API_SHOW_USER_MESSAGE :
                        stb_show_user_message(a_hAPI);
                        break;
+
+               case _EMAIL_API_WRITE_MIME_FILE :
+                       stb_write_mime_file(a_hAPI);
+                       break;
        }
        EM_DEBUG_FUNC_END();
 }
index bdfe2dd..91676c6 100755 (executable)
@@ -86,7 +86,7 @@ EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction
        if (!parameters) {
                EM_DEBUG_EXCEPTION("emipc_get_api_parameters failed");
                return false;
-}
+       }
 
        return emipc_add_param_to_param_list(parameters, data, data_length);
 }
index a860b5e..2ce7aa4 100755 (executable)
@@ -69,15 +69,15 @@ EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info);
                        case _EMAIL_API_DELETE_MAILBOX:\
                                        s = "_EMAIL_API_DELETE_MAILBOX";\
                                        break;\
-                       case _EMAIL_API_UPDATE_MAILBOX:\
-                                       s = "_EMAIL_API_UPDATE_MAILBOX";\
-                                       break;\
                        case _EMAIL_API_RENAME_MAILBOX:\
                                        s = "_EMAIL_API_RENAME_MAILBOX";\
                                        break;\
                        case _EMAIL_API_SET_MAILBOX_TYPE:\
                                        s = "_EMAIL_API_SET_MAILBOX_TYPE";\
                                        break;\
+                       case _EMAIL_API_SET_LOCAL_MAILBOX:\
+                                       s = "_EMAIL_API_SET_LOCAL_MAILBOX";\
+                                       break;\
                        case _EMAIL_API_SET_MAIL_SLOT_SIZE:\
                                        s = "_EMAIL_API_SET_MAIL_SLOT_SIZE";\
                                        break;\
@@ -111,9 +111,6 @@ EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info);
                        case _EMAIL_API_MODIFY_MAIL_FLAG:\
                                        s = "_EMAIL_API_MODIFY_MAIL_FLAG";\
                                        break;\
-                       case _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG:\
-                                       s = "_EMAIL_API_MODIFY_MAIL_EXTRA_FLAG";\
-                                       break;\
                        case _EMAIL_API_ADD_RULE:\
                                        s = "_EMAIL_API_ADD_RULE";\
                                        break;\
@@ -222,6 +219,9 @@ EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info);
                        case _EMAIL_API_SHOW_USER_MESSAGE:\
                                        s = "_EMAIL_API_SHOW_USER_MESSAGE";\
                                        break;\
+                       case _EMAIL_API_WRITE_MIME_FILE:\
+                                       s = "_EMAIL_API_WRITE_MIME_FILE";\
+                                       break;\
                        default : \
                                        s = "UNKNOWN_APIID";\
                }\
old mode 100755 (executable)
new mode 100644 (file)
index 2d61de1..9c71a68
@@ -4,7 +4,7 @@
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-* 
+*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
@@ -30,8 +30,7 @@
 #include "email-api.h"
 #include "email-types.h"
 #include "email-internal-types.h"
-
-pthread_mutex_t proxy_mutex = PTHREAD_MUTEX_INITIALIZER;
+#include <glib.h>
 
 EXPORT_API int emipc_initialize_proxy()
 {
@@ -57,16 +56,15 @@ EXPORT_API int emipc_execute_proxy_api(HIPC_API api)
        emipc_email_api_info *api_info = (emipc_email_api_info *)api;
 
        EM_DEBUG_LOG("API [%p]", api_info);
-               
+
        if(api_info == NULL) {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                return EMAIL_ERROR_INVALID_PARAM;
        }
-               
+
        EM_DEBUG_LOG("APIID [%s], ResponseID [%d], APPID[%d]",
                                EM_APIID_TO_STR(api_info->api_id), api_info->response_id, api_info->app_id);
 
-       ENTER_CRITICAL_SECTION(proxy_mutex);
        ret = emipc_execute_api_of_proxy_main(api_info);
 
        /* connection retry */
@@ -88,9 +86,9 @@ EXPORT_API int emipc_execute_proxy_api(HIPC_API api)
                        goto FINISH_OFF;
                }
        }
-       
+
 FINISH_OFF:
-       LEAVE_CRITICAL_SECTION(proxy_mutex);
        EM_DEBUG_FUNC_END("err [%d]", err);
-       return err;     
+       return err;
 }
+
old mode 100755 (executable)
new mode 100644 (file)
index 4b739c9..f9cf318
 #include "email-ipc-socket.h"
 
 #include "email-debug-log.h"
+#include "email-internal-types.h"
+#include "email-utilities.h"
 #include <errno.h>
+#include <glib.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+typedef struct {
+       pid_t pid;
+       pthread_t tid;
+       int socket_fd;
+} thread_socket_t;
 
-static int proxy_socket_fd = 0;
+GList *socket_head = NULL;
+pthread_mutex_t proxy_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 EXPORT_API bool emipc_start_proxy_socket()
 {
        EM_DEBUG_FUNC_BEGIN();
        int ret = true;
+       int socket_fd = 0;
 
-       ret = emipc_init_email_socket(&proxy_socket_fd);
+       ret = emipc_init_email_socket(&socket_fd);
        if (!ret) {
+               EM_DEBUG_EXCEPTION("emipc_init_email_socket failed");
+               return false;
+       }
+
+       ret = emipc_connect_email_socket(socket_fd);
+       if( !ret ) {
+               EM_DEBUG_EXCEPTION("emipc_connect_email_socket failed");
                return false;
        }
 
-       ret = emipc_connect_email_socket(proxy_socket_fd);
+       thread_socket_t* cur = (thread_socket_t*) em_malloc(sizeof(thread_socket_t));
+       if(!cur) {
+               EM_DEBUG_EXCEPTION("em_malloc failed");
+               return false;
+       }
+
+       /* add a socket */
+       cur->pid = getpid();
+       cur->tid = pthread_self();
+       cur->socket_fd = socket_fd;
 
-       return ret;
+       ENTER_CRITICAL_SECTION(proxy_mutex);
+       socket_head = g_list_prepend(socket_head, cur);
+       LEAVE_CRITICAL_SECTION(proxy_mutex);
+
+       return true;
 }
 
 EXPORT_API bool emipc_end_proxy_socket()
 {
        EM_DEBUG_FUNC_BEGIN();
        EM_DEBUG_LOG("[IPCLib] emipc_end_proxy_socket_fd");
-       
-       if (proxy_socket_fd) {
-               emipc_close_email_socket(&proxy_socket_fd);
+
+       pid_t pid = getpid();
+
+       ENTER_CRITICAL_SECTION(proxy_mutex);
+       GList *cur = socket_head;
+       while( cur ) {
+               thread_socket_t* cur_socket = g_list_nth_data(cur,0);
+
+               /* close all sockets of the pid */
+               if( pid == cur_socket->pid ) {
+                       emipc_close_email_socket(&cur_socket->socket_fd);
+                       EM_SAFE_FREE(cur_socket);
+                       GList *del = cur;
+                       cur = g_list_next(cur);
+                       socket_head = g_list_remove_link(socket_head, del);
+                       continue;
+               }
+
+               cur = g_list_next(cur);
        }
+       LEAVE_CRITICAL_SECTION(proxy_mutex);
 
        return true;
 }
@@ -65,22 +116,46 @@ EXPORT_API bool emipc_end_proxy_socket()
 EXPORT_API int emipc_send_proxy_socket(unsigned char *data, int len)
 {
        EM_DEBUG_FUNC_BEGIN();
-       if (!proxy_socket_fd) {
-               EM_DEBUG_EXCEPTION("[IPCLib] emipc_send_proxy_socket_fd not connect");
-               return EMAIL_ERROR_IPC_SOCKET_FAILURE;
+       int socket_fd = emipc_get_proxy_socket_id();
+
+       /* if thread socket is not created */
+       if (!socket_fd) {
+               int ret = emipc_start_proxy_socket();
+               if(!ret ) {
+                       EM_DEBUG_EXCEPTION("[IPCLib] emipc_send_proxy_socket not connected");
+                       return EMAIL_ERROR_IPC_SOCKET_FAILURE;
+               }
+               socket_fd = emipc_get_proxy_socket_id();
        }
-       int send_len = emipc_send_email_socket(proxy_socket_fd, data, len);
+
+       int send_len = emipc_send_email_socket(socket_fd, data, len);
        if (send_len == 0) {
-               EM_DEBUG_EXCEPTION("[IPCLib] server closed connection %x", proxy_socket_fd);
-               emipc_close_email_socket(&proxy_socket_fd);
+               EM_DEBUG_EXCEPTION("[IPCLib] server closed connection %x", socket_fd);
+               emipc_end_proxy_socket();
        }
+
        return send_len;
 }
 
 EXPORT_API int emipc_get_proxy_socket_id()
 {
        EM_DEBUG_FUNC_BEGIN();
-       return proxy_socket_fd;
+       pthread_t tid = pthread_self();
+       int socket_fd = 0;
+
+       ENTER_CRITICAL_SECTION(proxy_mutex);
+       GList *cur = socket_head;
+       /* need to acquire lock */
+       for( ; cur ; cur = g_list_next(cur) ) {
+               thread_socket_t* cur_socket = g_list_nth_data(cur,0);
+               if( pthread_equal(tid, cur_socket->tid) ) {
+                       socket_fd = cur_socket->socket_fd;
+                       break;
+               }
+       }
+       LEAVE_CRITICAL_SECTION(proxy_mutex);
+       EM_DEBUG_LOG("tid %d, socket_fd %d", tid, socket_fd);
+       return socket_fd;
 }
 
 /* return true, when event occurred
@@ -114,21 +189,20 @@ static bool wait_for_reply (int fd)
 EXPORT_API int emipc_recv_proxy_socket(char **data)
 {
        EM_DEBUG_FUNC_BEGIN();
-
-       if (!proxy_socket_fd) {
-               EM_DEBUG_EXCEPTION("[IPCLib] proxy_socket_fd[%p] is not available or disconnected", proxy_socket_fd);
+       int socket_fd = emipc_get_proxy_socket_id();
+       if (!socket_fd) {
+               EM_DEBUG_EXCEPTION("[IPCLib] proxy_socket_fd[%p] is not available or disconnected", socket_fd);
                return EMAIL_ERROR_IPC_SOCKET_FAILURE;
        }
 
-       if( !wait_for_reply(proxy_socket_fd) ) {
-
+       if( !wait_for_reply(socket_fd) ) {
                return EMAIL_ERROR_IPC_SOCKET_FAILURE;
        }
 
-       int recv_len = emipc_recv_email_socket(proxy_socket_fd, data);
+       int recv_len = emipc_recv_email_socket(socket_fd, data);
        if (recv_len == 0) {
-               EM_DEBUG_EXCEPTION("[IPCLib] server closed connection %x", proxy_socket_fd);
-               emipc_close_email_socket(&proxy_socket_fd);
+               EM_DEBUG_EXCEPTION("[IPCLib] server closed connection %x", socket_fd);
+               emipc_end_proxy_socket();
        }
 
        return recv_len;
index d345d99..678693a 100755 (executable)
@@ -4,7 +4,7 @@
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-* 
+*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
@@ -51,13 +51,13 @@ EXPORT_API bool emipc_init_email_socket(int *fd)
 
        EM_DEBUG_LOG("Socket fd = %d", *fd);
 
-       return ret;     
+       return ret;
 }
 
 /*  Close */
 EXPORT_API void emipc_close_email_socket(int* fd)
 {
-       EM_DEBUG_LOG("fd %d removal done", fd);
+       EM_DEBUG_LOG("fd %d removal done", *fd);
        close(*fd);
        *fd = 0;
 }
@@ -99,7 +99,7 @@ EXPORT_API int emipc_send_email_socket(int fd, unsigned char *buf, int len)
        }
 
        EM_DEBUG_LOG("Sending %dB data to [fd = %d]", len, fd);
-       
+
        int write_len = emipc_writen(fd, (char*) buf, len);
        if ( write_len != len) {
                if ( write_len == 0 ) return 0;
@@ -137,7 +137,7 @@ static int emipc_readn(int fd, char *buf, int len)
 EXPORT_API int emipc_recv_email_socket(int fd, char **buf)
 {
        EM_DEBUG_FUNC_BEGIN();
-       
+
        if (!buf) {
                EM_DEBUG_LOG("Buffer must not null");
                return EMAIL_ERROR_INVALID_PARAM;
@@ -149,9 +149,9 @@ EXPORT_API int emipc_recv_email_socket(int fd, char **buf)
                EM_DEBUG_EXCEPTION("ioctl: %s", strerror(errno));
                return EMAIL_ERROR_IPC_SOCKET_FAILURE;
        }
-       /* server closed socket or is downed*/
+       /* when server or client closed socket */
        if ( read_len == 0 ) {
-               EM_DEBUG_EXCEPTION("[IPC Socket] server closed connection");
+               EM_DEBUG_LOG("[IPC Socket] connection is closed");
                return 0;
        }
 
@@ -161,7 +161,7 @@ EXPORT_API int emipc_recv_email_socket(int fd, char **buf)
                return EMAIL_ERROR_OUT_OF_MEMORY;
        }
        memset(*buf, 0x00, read_len);
-       
+
        EM_DEBUG_LOG("[IPC Socket] Receiving [%d] bytes", read_len);
        int len = emipc_readn(fd, *buf, read_len);
        if (read_len != len) {
@@ -178,12 +178,12 @@ EXPORT_API int emipc_recv_email_socket(int fd, char **buf)
 EXPORT_API int emipc_accept_email_socket(int fd)
 {
        EM_DEBUG_FUNC_BEGIN();
-       
+
        if (fd == -1) {
                EM_DEBUG_LOG("Server_socket not init");
                return EMAIL_ERROR_INVALID_PARAM;
        }
-       
+
        struct sockaddr_un remote;
        int remote_len = sizeof(remote);
        int client_fd = accept(fd, (struct sockaddr *)&remote, (socklen_t*) &remote_len);
@@ -193,7 +193,7 @@ EXPORT_API int emipc_accept_email_socket(int fd)
        }
 
        EM_DEBUG_LOG("%d is added", client_fd);
-       
+
        EM_DEBUG_FUNC_END();
        return client_fd;
 }
@@ -206,7 +206,7 @@ EXPORT_API int emipc_open_email_socket(int fd, const char *path)
                EM_DEBUG_LOG("Path is null");
                return EMAIL_ERROR_IPC_SOCKET_FAILURE;
        }
-       
+
        if (fd <= 0) {
                EM_DEBUG_LOG("Socket not created %d", fd);
                return EMAIL_ERROR_IPC_SOCKET_FAILURE;
@@ -259,7 +259,7 @@ EXPORT_API bool emipc_connect_email_socket(int fd)
        strcpy(server.sun_path, EM_SOCKET_PATH);
 
        int len = strlen(server.sun_path) + sizeof(server.sun_family);
-       
+
        if (connect(fd, (struct sockaddr *)&server, len) == -1) {
                EM_DEBUG_LOG("Cannot connect server %s", EM_STRERROR(errno));
                return false;
index 8b90f91..095d43d 100755 (executable)
@@ -189,7 +189,7 @@ email_account_t - refer to doxygen (SLP-SDK: http:/* slp-sdk.sec.samsung.net) */
 <tr><td>int email_free_account(email_account_t** account_list, int count) </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
   
-<tr><td>int email_validate_account(int account_id, unsigned* handle)</td>
+<tr><td>int email_validate_account(int account_id, int *handle)</td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
 </table> 
 
@@ -377,10 +377,10 @@ email_mailbox_t - refer to doxygen (SLP-SDK: http:/* slp-sdk.sec.samsung.net) */
 <table>
 <tr><td>API</td><td>Return Value / Exceptions</td></tr>
  
-<tr><td>int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, unsigned* handle) </td>
+<tr><td>int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle) </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks: -  Memory for param email_mailbox_t* new_mailbox should be allocated and deallocated by Application </td></tr>
  
-<tr><td>int email_delete_mailbox(email_mailbox_t* mailbox, int on_server,  unsigned* handle) </td>
+<tr><td>int email_delete_mailbox(email_mailbox_t* mailbox, int on_server,  int *handle) </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param email_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
 
 <tr><td>int email_update_mailbox(email_mailbox_t*old_mailbox, email_mailbox_t* new_mailbox)</td>
@@ -404,7 +404,7 @@ email_mailbox_t - refer to doxygen (SLP-SDK: http:/* slp-sdk.sec.samsung.net) */
 @li Create new mailbox
 @code
 email_mailbox_t *mailbox = NULL, *new_mailbox = NULL;
-unsigned handle = 0;
+int handle = 0;
 int on_server = 0;
  
 mailbox = malloc(sizeof(email_mailbox_t));
@@ -429,7 +429,7 @@ else
 @code
 email_mailbox_t *mailbox = NULL, *new_mailbox = NULL;
 int on_server = 0;
-unsigned handle = 0;
+int handle = 0;
 
 new_mailbox = malloc(sizeof(email_mailbox_t));
 memset(new_mailbox, 0x00, sizeof(email_mailbox_t));
@@ -518,14 +518,8 @@ email_mail_data_t
 <tr><td>int email_free_attachment_info(email_attachment_data_t** atch_info)  </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure.</td></tr>
  
-<tr><td>int email_modify_mail_flag(int mail_id, email_mail_flag_t new_flag, int onserver)  </td>
-<td>Returns EMAIL_ERROR_NONE on success or negative value on failure.</td></tr>
 <tr><td>int email_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver)  </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param int *mail_ids should be allocated and deallocated by Application</td></tr>
-
-<tr><td>int email_modify_extra_mail_flag(int mail_id, email_extra_flag_t new_flag)  </td>
-<td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
  
 <tr><td>int email_move_mail_to_mailbox(int *mail_ids, int num, email_mailbox_t* new_mailbox)  </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for params int *mail_ids and email_mailbox_t* new_mailbox should be allocated and deallocated by Application</td></tr>
@@ -544,9 +538,6 @@ email_mail_data_t
  
 <tr><td>int email_free_mailbox(email_mailbox_t** mailbox_list, int count)  </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
-   
-<tr><td>int email_get_mail_flag(int account_id, int mail_id, email_mail_flag_t* mail_flag)  </td>
-<td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
  
 <tr><td>int email_retry_sending_mail( int mail_id, int timeout_in_sec)  </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
@@ -690,37 +681,6 @@ else
       /* success   */
 @endcode
 
-@li Modify flag
-@code
-email_mail_flag_t newflag = {0};
-int mail_id = 0;
-int on_server = 0;
-/* Modify mail flag*/
-if(EMAIL_ERROR_NONE != email_modify_mail_flag(mail_id,newflag,on_server))
-       /* failure */
-else
-       /* success   */
-
-int mail_ids[] = {1, 2}; 
-int num = 2;
-int seen_flag = 0; 
-int on_server = 0;
-/* Modify seen flag*/
-if(EMAIL_ERROR_NONE != email_modify_seen_flag(mail_ids, num, seen_flag,on_server))
-       /* failure */
-else
-       /* success   */
-/* Modify extra flag*/
-int mail_id = 1;
-if(EMAIL_ERROR_NONE != email_modify_extra_mail_flag(mail_id, newflag))
-       /* failure */
-else
-       /* success   */
-@endcode
-
 
 @li Move mail
 @code 
@@ -890,19 +850,19 @@ email_option_t - refer to doxygen (SLP-SDK: http:/* slp-sdk.sec.samsung.net) */
 <tr><td>API</td>
 <td>Return Value / Exceptions</td></tr>
  
-<tr><td>int email_send_mail( email_mailbox_t* mailbox, int mail_id, email_option_t* sending_option, unsigned* handle)</td>
+<tr><td>int email_send_mail( email_mailbox_t* mailbox, int mail_id, int *handle)</td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks: 
 -# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
  
-<tr><td>int email_sync_header(email_mailbox_t* mailbox, unsigned* handle)</td>
+<tr><td>int email_sync_header(email_mailbox_t* mailbox, int *handle)</td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks:
 -# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
  
-<tr><td>int email_download_body(email_mailbox_t* mailbox, int mail_id, int with_attachment, unsigned* handle) </td>
+<tr><td>int email_download_body(email_mailbox_t* mailbox, int mail_id, int with_attachment, int *handle) </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks:
 -# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
  
-<tr><td>int email_download_attachment(email_mailbox_t* mailbox, int mail_id, const char* nth,  unsigned* handle)</td>
+<tr><td>int email_download_attachment(email_mailbox_t* mailbox, int mail_id, const char* nth,  int *handle)</td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure.</td></tr>
 
 <tr><td>int email_cancel_job(int account_id, int handle)</td>
@@ -914,11 +874,11 @@ email_option_t - refer to doxygen (SLP-SDK: http:/* slp-sdk.sec.samsung.net) */
 <tr><td>void email_get_network_status(int* on_sending, int* on_receiving) </td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure</td></tr>
  
-<tr><td>int email_send_saved(int account_id, email_option_t* sending_option, unsigned* handle)</td>
+<tr><td>int email_send_saved(int account_id, email_option_t* sending_option, int *handle)</td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure@n Remarks:
 -# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
  
-<tr><td>int email_sync_imap_mailbox_list(int account_id, const char* mailbox, unsigned* handle)</td>
+<tr><td>int email_sync_imap_mailbox_list(int account_id, const char* mailbox, int *handle)</td>
 <td>Returns EMAIL_ERROR_NONE on success or negative value on failure.</td></tr>
  
 <tr><td>int email_sync_local_activity(int account_id)</td>
@@ -937,7 +897,7 @@ email_option_t - refer to doxygen (SLP-SDK: http:/* slp-sdk.sec.samsung.net) */
 email_mailbox_t mailbox;
 int account_id = 1;
 int err = EMAIL_ERROR_NONE;
-unsigned handle = 0;
+int handle = 0;
  
 memset(&mailbox, 0x00, sizeof(email_mailbox_t));
  
@@ -969,7 +929,7 @@ email_mailbox_t mailbox;
 int mail_id = 1;
 int account_id = 1;     
 char arg[50]; /* Input attachment number need to be download */
-unsigned handle = 0;
+int handle = 0;
 int err = EMAIL_ERROR_NONE;
  
 memset(&mailbox, 0x00, sizeof(email_mailbox_t));
index 4daa1d9..1b7d01f 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       email-service
 Summary:    E-mail Framework Middleware package
-Version:    0.9.9
+Version:    0.10.1
 Release:    1
 Group:      System/Libraries
 License:    TBD
@@ -240,6 +240,7 @@ CREATE TABLE mail_tbl
        server_mailbox_name              VARCHAR(129),
        server_mail_id                   VARCHAR(129),
        message_id                       VARCHAR(257),
+       reference_mail_id                INTEGER,
        full_address_from                TEXT,
        full_address_reply               TEXT,
        full_address_to                  TEXT,
index c3d99c1..915981c 100755 (executable)
@@ -62,7 +62,7 @@ gboolean testapp_test_create_account_by_account_type(int account_type,int *accou
        char id_string[100] = { 0, }, password_string[100] = { 0, }, address_string[100]  = { 0, };
        int err_code = EMAIL_ERROR_NONE, samsung3g_account_index;
        int result_from_scanf = 0;
-       unsigned handle;
+       int handle;
 
        switch(account_type) {
                case 4 : 
@@ -424,7 +424,7 @@ static gboolean testapp_test_validate_account ()
        int account_id;
        email_account_t *account=NULL;
        int err_code = EMAIL_ERROR_NONE;
-       unsigned account_handle = 0;
+       int handle = 0;
        
        testapp_print("\n>> Enter Account No: ");
        result_from_scanf = scanf("%d",&account_id);
@@ -437,8 +437,8 @@ static gboolean testapp_test_validate_account ()
        else
                testapp_print ("email_get_account result account_name - %s \n", account->account_name);
 
-       if((err_code = email_validate_account(account_id, &account_handle)) == EMAIL_ERROR_NONE ) 
-               testapp_print ("email_validate_account successful  account_handle : %u\n",account_handle);
+       if((err_code = email_validate_account(account_id, &handle)) == EMAIL_ERROR_NONE )
+               testapp_print ("email_validate_account successful  handle : %u\n",handle);
        else
                testapp_print ("email_validate_account failed err_code: %d \n",err_code);
                
index b7870af..78db88d 100755 (executable)
@@ -36,6 +36,7 @@
 #include "email-api-mail.h"
 #include "email-api-mailbox.h"
 #include "email-api-etc.h"
+#include "email-api-smime.h"
 
 /* internal header */
 #include "testapp-utility.h"
@@ -86,19 +87,19 @@ static void testapp_test_print_mail_list_item(email_mail_list_item_t *mail_list_
                if (  mail_list_item[i].subject != NULL ) {
                        testapp_print(" >>> subject [ %s ] \n", mail_list_item[i].subject);
                }
-               testapp_print(" >>> text_download_yn [ %d ] \n", mail_list_item[i].is_text_downloaded);
+               testapp_print(" >>> text_download_yn [ %d ] \n", mail_list_item[i].body_download_status);
                testapp_print(" >>> date_time [ %d ] \n", mail_list_item[i].date_time);
                testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list_item[i].flags_seen_field);
                testapp_print(" >>> priority [ %d ] \n", mail_list_item[i].priority);
                testapp_print(" >>> save_status [ %d ] \n", mail_list_item[i].save_status);
-               testapp_print(" >>> lock [ %d ] \n", mail_list_item[i].is_locked);
-               testapp_print(" >>> is_report_mail [ %d ] \n", mail_list_item[i].is_report_mail);
+               testapp_print(" >>> lock [ %d ] \n", mail_list_item[i].lock_status);
+               testapp_print(" >>> report_status [ %d ] \n", mail_list_item[i].report_status);
                testapp_print(" >>> recipients_count [ %d ] \n", mail_list_item[i].recipients_count);
-               testapp_print(" >>> has_attachment [ %d ] \n", mail_list_item[i].has_attachment);
-               testapp_print(" >>> has_drm_attachment [ %d ] \n", mail_list_item[i].has_drm_attachment);
+               testapp_print(" >>> attachment_count [ %d ] \n", mail_list_item[i].attachment_count);
+               testapp_print(" >>> DRM_status [ %d ] \n", mail_list_item[i].DRM_status);
 
-               if (  mail_list_item[i].previewBodyText != NULL ) {
-                       testapp_print(" >>> previewBodyText [ %s ] \n", mail_list_item[i].previewBodyText);
+               if (  mail_list_item[i].preview_text != NULL ) {
+                       testapp_print(" >>> preview_text [ %s ] \n", mail_list_item[i].preview_text);
                }
 
                testapp_print(" >>> thread_id [ %d ] \n", mail_list_item[i].thread_id);
@@ -107,6 +108,84 @@ static void testapp_test_print_mail_list_item(email_mail_list_item_t *mail_list_
 }
 */
 
+static gboolean testapp_add_mail_for_sending (int *result_mail_id)
+{
+       int                    result_from_scanf = 0;
+       int                    i = 0;
+       int                    account_id = 0;
+       int                    err = EMAIL_ERROR_NONE;
+       int                    smime_type = 0;
+       char                   receipient_address[300] = { 0 , };
+       char                   from_address[300] = { 0 , };
+       const char            *body_file_path = MAIL_TEMP_BODY;
+       email_account_t       *account_data = NULL;
+       email_mailbox_t       *mailbox_data = NULL;
+       email_mail_data_t     *test_mail_data = NULL;
+       FILE                  *body_file;
+
+       testapp_print("\n > Enter account id : ");
+       result_from_scanf = scanf("%d", &account_id);
+
+       testapp_print("\n > Enter receipient address : ");
+       result_from_scanf = scanf("%s", receipient_address);
+
+       email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data);
+
+       email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_data);
+
+       test_mail_data = malloc(sizeof(email_mail_data_t));
+       memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
+
+       SNPRINTF(from_address, 300, "<%s>", account_data->user_email_address);
+
+       test_mail_data->account_id           = account_id;
+       test_mail_data->save_status          = 1;
+       test_mail_data->body_download_status = 1;
+       test_mail_data->flags_seen_field     = 1;
+       test_mail_data->file_path_plain      = strdup(body_file_path);
+       test_mail_data->mailbox_id           = mailbox_data->mailbox_id;
+       test_mail_data->mailbox_type         = mailbox_data->mailbox_type;
+       test_mail_data->full_address_from    = strdup(from_address);
+       test_mail_data->full_address_to      = strdup(receipient_address);
+       test_mail_data->subject              = strdup("Read receipt request from TIZEN");
+       test_mail_data->report_status        = EMAIL_MAIL_REQUEST_DSN | EMAIL_MAIL_REQUEST_MDN;
+
+       body_file = fopen(body_file_path, "w");
+
+       testapp_print("\n body_file [%p]\n", body_file);
+
+       if(body_file == NULL) {
+               testapp_print("\n fopen [%s]failed\n", body_file_path);
+               return FALSE;
+       }
+
+       for(i = 0; i < 100; i++)
+               fprintf(body_file, "Mail sending Test. [%d]\n", i);
+
+       fflush(body_file);
+       fclose(body_file);
+
+       testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt] : ");
+       result_from_scanf = scanf("%d", &smime_type);
+       test_mail_data->smime_type = smime_type;
+
+       if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE)
+               testapp_print("email_add_mail failed. [%d]\n", err);
+       else
+               testapp_print("email_add_mail success.\n");
+
+       testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
+
+       if(result_mail_id)
+               *result_mail_id = test_mail_data->mail_id;
+
+       email_free_mail_data(&test_mail_data, 1);
+       email_free_mailbox(&mailbox_data, 1);
+       email_free_account(&account_data, 1);
+
+       return FALSE;
+}
+
 static gboolean testapp_test_add_mail (int *result_mail_id)
 {
        int                    result_from_scanf = 0;
@@ -199,7 +278,7 @@ static gboolean testapp_test_add_mail (int *result_mail_id)
        }
        
        testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
-       result_from_scanf = scanf("%d", &(test_mail_data->meeting_request_status));
+       result_from_scanf = scanf("%d", (int*)&(test_mail_data->meeting_request_status));
        
        if ( test_mail_data->meeting_request_status == 1 
                || test_mail_data->meeting_request_status == 2 ) {
@@ -399,7 +478,7 @@ static gboolean testapp_test_get_mails()
                        testapp_print(" >>> lock_status [ %d ] \n", mails[i].lock_status);
                        testapp_print(" >>> attachment_count [ %d ] \n", mails[i].attachment_count);
                        if (  mails[i].preview_text != NULL )
-                               testapp_print(" >>> previewBodyText [ %s ] \n", mails[i].preview_text);
+                               testapp_print(" >>> preview_text [ %s ] \n", mails[i].preview_text);
                }
                free(mails);
        }
@@ -414,24 +493,17 @@ static gboolean testapp_test_mail_send (int *result_mail_id)
 {
        int                    added_mail_id = 0;
        int                    err = EMAIL_ERROR_NONE;
-       unsigned               handle = 0;
-       email_option_t           option = { 0 };
-       email_mailbox_t          mailbox_data = { 0 };
-       email_mail_data_t       *result_mail_data = NULL;
+       int                    handle = 0;
+       email_mail_data_t     *result_mail_data = NULL;
 
-       testapp_test_add_mail(&added_mail_id);
+       testapp_add_mail_for_sending(&added_mail_id);
        
-       if(result_mail_id) {
+       if(added_mail_id) {
                email_get_mail_data(added_mail_id, &result_mail_data);
 
-               memset(&mailbox_data, 0x00, sizeof(email_mailbox_t));
-               mailbox_data.account_id   = result_mail_data->account_id;
-               mailbox_data.mailbox_id   = result_mail_data->mailbox_id;
-               option.keep_local_copy    = 1;
-
                testapp_print("Calling email_send_mail...\n");
 
-               if( email_send_mail(added_mail_id, &option, &handle) < 0) {
+               if( email_send_mail(added_mail_id, &handle) < 0) {
                        testapp_print("Sending failed[%d]\n", err);
                }
                else  {
@@ -447,24 +519,28 @@ static gboolean testapp_test_mail_send (int *result_mail_id)
        return FALSE;
 }
 
-static gboolean testapp_test_get_mail_list()
+static gboolean testapp_test_get_mail_list_ex()
 {
        email_list_filter_t *filter_list = NULL;
        email_list_sorting_rule_t *sorting_rule_list = NULL;
        email_mail_list_item_t *result_mail_list = NULL;
+       int filter_rule_count = 0;
+       int sorting_rule_count = 0;
        int result_mail_count = 0;
        int err = EMAIL_ERROR_NONE;
        int i = 0;
 
-       filter_list = malloc(sizeof(email_list_filter_t) * 9);
-       memset(filter_list, 0 , sizeof(email_list_filter_t) * 9);
+       filter_rule_count = 1;
+
+       filter_list = malloc(sizeof(email_list_filter_t) * filter_rule_count);
+       memset(filter_list, 0 , sizeof(email_list_filter_t) * filter_rule_count);
 
        filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
-       filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
-       filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
-       filter_list[0].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
-       filter_list[0].list_filter_item.rule.case_sensitivity              = false;
+       filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE;
+       filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
+       filter_list[0].list_filter_item.rule.key_value.integer_type_value  = EMAIL_MAILBOX_TYPE_INBOX;
 
+       /*
        filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
        filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
 
@@ -500,6 +576,7 @@ static gboolean testapp_test_get_mail_list()
        filter_list[8].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
        filter_list[8].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
        filter_list[8].list_filter_item.rule.case_sensitivity              = false;
+       */
 
        /*
        filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
@@ -516,24 +593,21 @@ static gboolean testapp_test_get_mail_list()
        filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("INBOX");
        filter_list[2].list_filter_item.rule.case_sensitivity              = true;
        */
+       sorting_rule_count = 1;
 
-       sorting_rule_list = malloc(sizeof(email_list_sorting_rule_t) * 2);
-       memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * 2);
+       sorting_rule_list = malloc(sizeof(email_list_sorting_rule_t) * sorting_rule_count);
+       memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * sorting_rule_count);
 
-       sorting_rule_list[0].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT;
-       sorting_rule_list[0].sort_order                                    = EMAIL_SORT_ORDER_ASCEND;
-       sorting_rule_list[0].force_boolean_check                           = true;
+       sorting_rule_list[0].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_DATE_TIME;
+       sorting_rule_list[0].sort_order                                    = EMAIL_SORT_ORDER_DESCEND;
 
-       sorting_rule_list[1].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_DATE_TIME;
-       sorting_rule_list[1].sort_order                                    = EMAIL_SORT_ORDER_ASCEND;
-
-       err = email_get_mail_list_ex(filter_list, 9, sorting_rule_list, 2, -1, -1, &result_mail_list, &result_mail_count);
+       err = email_get_mail_list_ex(filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &result_mail_list, &result_mail_count);
 
        if(err == EMAIL_ERROR_NONE) {
                testapp_print("email_get_mail_list_ex succeed.\n");
 
                for(i = 0; i < result_mail_count; i++) {
-                       testapp_print("mail_id [%d], subject [%s], from [%s]\n", result_mail_list[i].mail_id, result_mail_list[i].subject, result_mail_list[i].from);
+                       testapp_print("mail_id [%d], subject [%s], full_address_from [%s]\n", result_mail_list[i].mail_id, result_mail_list[i].subject, result_mail_list[i].full_address_from);
                }
        }
        else {
@@ -717,7 +791,7 @@ static gboolean testapp_test_expunge_mails_deleted_flagged()
        int mailbox_id = 0;
        int on_server = 0;
        int err_code = EMAIL_ERROR_NONE;
-       unsigned handle = 0;
+       int handle = 0;
        int result_from_scanf = 0;
 
        testapp_print("\n >>> Input target mailbox id: ");
@@ -733,9 +807,51 @@ static gboolean testapp_test_expunge_mails_deleted_flagged()
        return 0;
 }
 
-static gboolean testapp_test_get_mail_list_ex()
+static gboolean testapp_test_send_read_receipt()
 {
-       testapp_print("\n >>> testapp_test_get_mail_list_ex : Entered \n");
+       int read_mail_id = 0;
+       int receipt_mail_id = 0;
+       int err_code = EMAIL_ERROR_NONE;
+       int result_from_scanf = 0;
+       int handle = 0;
+
+       testapp_print("\n >>> Input read mail id: ");
+       result_from_scanf = scanf("%d", &read_mail_id);
+
+       err_code = email_add_read_receipt(read_mail_id, &receipt_mail_id);
+
+       testapp_print("eamil_add_read_receipt returns receipt_mail_id [%d] - err[%d]\n", receipt_mail_id, err_code);
+       testapp_print("Calling email_send_mail...\n");
+
+       if( (err_code = email_send_mail(receipt_mail_id, &handle)) != EMAIL_ERROR_NONE) {
+               testapp_print("Sending failed[%d]\n", err_code);
+       }
+       else  {
+               testapp_print("Start sending. handle[%d]\n", handle);
+       }
+
+       return 0;
+}
+
+static gboolean testapp_test_delete_attachment()
+{
+       int attachment_id = 0;
+       int err_code = EMAIL_ERROR_NONE;
+       int result_from_scanf = 0;
+
+       testapp_print("\n >>> Input attachment id: ");
+       result_from_scanf = scanf("%d", &attachment_id);
+
+       if( (err_code = email_delete_attachment(attachment_id)) != EMAIL_ERROR_NONE) {
+               testapp_print("email_delete_attachment failed[%d]\n", err_code);
+       }
+
+       return 0;
+}
+
+static gboolean testapp_test_get_mail_list()
+{
+       testapp_print("\n >>> testapp_test_get_mail_list : Entered \n");
        email_mail_list_item_t *mail_list = NULL, **mail_list_pointer = NULL;
        int mailbox_id = 0;
        int count = 0, i = 0;
@@ -805,13 +921,13 @@ static gboolean testapp_test_get_mail_list_ex()
                        testapp_print(" >>> mailbox_id [ %d ] \n", mail_list[i].mailbox_id);
                        testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
                        testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
-                       if (  mail_list[i].from != NULL )
-                               testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
-                       if (  mail_list[i].recipients != NULL )
-                               testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
+                       if (  mail_list[i].full_address_from != NULL )
+                               testapp_print(" >>> full_address_from [ %s ] \n", mail_list[i].full_address_from);
+                       if (  mail_list[i].email_address_recipient != NULL )
+                               testapp_print(" >>> email_address_recipient [ %s ] \n", mail_list[i].email_address_recipient);
                        if (  mail_list[i].subject != NULL )
                                testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
-                       testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
+                       testapp_print(" >>> body_download_status [ %d ] \n", mail_list[i].body_download_status);
                        temp_time_info = localtime(&mail_list[i].date_time);
                        testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
                                                                temp_time_info->tm_year + 1900,
@@ -823,10 +939,10 @@ static gboolean testapp_test_get_mail_list_ex()
                        testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
                        testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
                        testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
-                       testapp_print(" >>> is_locked [ %d ] \n", mail_list[i].is_locked);
-                       testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
-                       if (  mail_list[i].previewBodyText != NULL )
-                               testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
+                       testapp_print(" >>> lock_status [ %d ] \n", mail_list[i].lock_status);
+                       testapp_print(" >>> attachment_count [ %d ] \n", mail_list[i].attachment_count);
+                       if (  mail_list[i].preview_text != NULL )
+                               testapp_print(" >>> preview_text [ %s ] \n", mail_list[i].preview_text);
                }
                free(mail_list);
        }
@@ -842,11 +958,20 @@ static gboolean testapp_test_get_mail_list_for_thread_view()
        email_mail_list_item_t *mail_list = NULL;
        int count = 0, i = 0;
        int account_id = 0;
+       int mailbox_id = 0;
+       int result_from_scanf;
        int err_code = EMAIL_ERROR_NONE;
        struct tm *time_info;
 
+       testapp_print("\nEnter account id\n");
+       result_from_scanf = scanf("%d",&account_id);
+
+       testapp_print("\nEnter mailbox id\n");
+       result_from_scanf = scanf("%d",&mailbox_id);
+
+
        /* Get mail list */
-       if ( email_get_mail_list(account_id, 0 , EMAIL_LIST_TYPE_THREAD, 0, 500, EMAIL_SORT_DATETIME_HIGH, &mail_list, &count) < 0)  {
+       if ( email_get_mail_list(account_id, mailbox_id , EMAIL_LIST_TYPE_THREAD, 0, 500, EMAIL_SORT_DATETIME_HIGH, &mail_list, &count) < 0)  {
                testapp_print("email_get_mail_list failed : %d\n",err_code);
                return FALSE;
        }
@@ -854,21 +979,21 @@ static gboolean testapp_test_get_mail_list_for_thread_view()
        if (mail_list) {
                for (i=0; i< count; i++) {
                        testapp_print(" i [%d]\n", i);
-                       testapp_print(" >>> Mail ID [ %d ] \n", mail_list[i].mail_id);
-                       testapp_print(" >>> Account ID [ %d ] \n", mail_list[i].account_id);
-                       testapp_print(" >>> Mailbox id [ %d ] \n", mail_list[i].mailbox_id);
-                       testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
-                       testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
+                       testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
+                       testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
+                       testapp_print(" >>> mailbox_id [ %d ] \n", mail_list[i].mailbox_id);
+                       testapp_print(" >>> full_address_from [ %s ] \n", mail_list[i].full_address_from);
+                       testapp_print(" >>> email_address_recipient [ %s ] \n", mail_list[i].email_address_recipient);
                        testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
-                       testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
+                       testapp_print(" >>> body_download_status [ %d ] \n", mail_list[i].body_download_status);
                        time_info = localtime(&mail_list[i].date_time);
                        testapp_print(" >>> date_time [ %s ] \n", asctime(time_info));
                        testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
                        testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
                        testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
-                       testapp_print(" >>> lock [ %d ] \n", mail_list[i].is_locked);
-                       testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
-                       testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
+                       testapp_print(" >>> lock [ %d ] \n", mail_list[i].lock_status);
+                       testapp_print(" >>> attachment_count [ %d ] \n", mail_list[i].attachment_count);
+                       testapp_print(" >>> preview_text [ %s ] \n", mail_list[i].preview_text);
                        testapp_print(" >>> thread_id [ %d ] \n", mail_list[i].thread_id);
                        testapp_print(" >>> thread__item_count [ %d ] \n", mail_list[i].thread_item_count);
                }
@@ -930,7 +1055,7 @@ static gboolean    testapp_test_set_flags_field ()
 static gboolean testapp_test_download_body ()
 {
        int mail_id = 0;
-       unsigned handle = 0, err;
+       int handle = 0, err;
        int result_from_scanf = 0;
 
        testapp_print("\n > Enter Mail Id: ");
@@ -951,7 +1076,7 @@ static gboolean testapp_test_cancel_download_body ()
        int mail_id = 0;
        int account_id = 0;
        int yes = 0;
-       unsigned handle = 0;
+       int handle = 0;
        int result_from_scanf = 0;
        
        email_mailbox_t mailbox;
@@ -985,7 +1110,7 @@ static gboolean testapp_test_download_attachment ()
 {
        int mail_id = 0;
        int attachment_no = 0;
-       unsigned handle = 0;
+       int handle = 0;
        int result_from_scanf = 0;
        
        testapp_print("\n > Enter Mail Id: ");
@@ -1241,7 +1366,7 @@ static gboolean testapp_test_test_get_thread_information()
                testapp_print("email_get_thread_information returns = %d\n", error_code);
                testapp_print("subject = %s\n", result_mail->subject);
                testapp_print("mail_id = %d\n", result_mail->mail_id);
-               testapp_print("from = %s\n", result_mail->from);
+               testapp_print("full_address_from = %s\n", result_mail->full_address_from);
                testapp_print("thrad_id = %d\n", result_mail->thread_id);
                testapp_print("count = %d\n", result_mail->thread_item_count);
        }
@@ -1320,7 +1445,7 @@ static gboolean testapp_test_search_mail_on_server()
        int result_from_scanf = 0;
        email_search_filter_type search_filter_type = 0;
        email_search_filter_t search_filter;
-       unsigned int handle = 0;
+       int handle = 0;
        char search_key_value_string[MAX_EMAIL_ADDRESS_LENGTH];
 
        testapp_print("input account id : ");
@@ -1473,7 +1598,7 @@ static gboolean testapp_test_add_mail_to_search_result_box()
        }
 
        testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
-       result_from_scanf = scanf("%d", &(test_mail_data->meeting_request_status));
+       result_from_scanf = scanf("%d", (int*)&(test_mail_data->meeting_request_status));
 
        if ( test_mail_data->meeting_request_status == 1
                || test_mail_data->meeting_request_status == 2 ) {
@@ -1521,7 +1646,7 @@ static gboolean testapp_test_add_mail_to_search_result_box()
        return FALSE;
 }
 
-static gboolean testapp_test_email_load_eml_file()
+static gboolean testapp_test_email_parse_mime_file()
 {
        email_mail_data_t *mail_data = NULL;
        email_attachment_data_t *mail_attachment_data = NULL;
@@ -1534,9 +1659,9 @@ static gboolean testapp_test_email_load_eml_file()
        testapp_print("Input eml file path : ");
        result_from_scanf = scanf("%s", eml_file_path);
 
-       if ((err = email_open_eml_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE)
+       if ((err = email_parse_mime_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE)
        {
-               testapp_print("email_open_eml_file failed : [%d]\n", err);
+               testapp_print("email_parse_mime_file failed : [%d]\n", err);
                return false;   
        }
        
@@ -1561,7 +1686,7 @@ static gboolean testapp_test_email_load_eml_file()
 
        testapp_print("Success : Open eml file\n");
        
-       if ((err = email_delete_eml_data(mail_data)) != EMAIL_ERROR_NONE) {
+       if ((err = email_delete_parsed_data(mail_data)) != EMAIL_ERROR_NONE) {
                testapp_print("email_delete_eml_data failed : [%d]\n", err);
                return false;
        }
@@ -1582,6 +1707,89 @@ static gboolean testapp_test_email_load_eml_file()
 
 }
 
+static gboolean testapp_test_email_write_mime_file()
+{
+       int err = EMAIL_ERROR_NONE;
+       int mail_id = 0;
+       int ret_scanf = 0;
+       int is_file_path = 0;
+       int attachment_count = 0;
+       int account_id = 0;
+       char *file_path = NULL;
+       email_mail_data_t *mail_data = NULL;
+       email_attachment_data_t *mail_attachment_data = NULL;
+
+       testapp_print("Is file path (0 or 1): ");
+       ret_scanf = scanf("%d", &is_file_path);
+       
+       if (is_file_path) {
+               file_path = malloc(512);
+               memset(file_path, 0x00, 512);
+
+               testapp_print("Input output file path : ");
+               ret_scanf = scanf("%s", file_path);     
+       }
+       testapp_print("Input mail id : ");
+       ret_scanf = scanf("%d", &mail_id);
+
+
+       err = email_get_mail_data(mail_id, &mail_data);
+       if (err != EMAIL_ERROR_NONE) {
+               testapp_print("email_get_mail_data failed : [%d]\n", err);
+               return false;
+       }
+
+       err = email_get_attachment_data_list(mail_id, &mail_attachment_data, &attachment_count);
+       if (err != EMAIL_ERROR_NONE) {
+               testapp_print("email_get_attachment_data_list failed : [%d]\n", err);
+               return false;
+       }
+
+       testapp_print("Input Account id : ");
+       ret_scanf = scanf("%d", &account_id);
+
+       mail_data->account_id = account_id;
+
+       err = email_write_mime_file(mail_data, mail_attachment_data, attachment_count, &file_path);
+       if (err != EMAIL_ERROR_NONE) {
+               testapp_print("email_write_mime_file failed : [%d]\n", err);
+               return false;
+       }
+
+       testapp_print("file path : [%s]\n", file_path);
+
+       if (mail_data)
+               email_free_mail_data(&mail_data, 1);
+       
+       if (mail_attachment_data)
+               email_free_attachment_data(&mail_attachment_data, attachment_count);
+
+       if (file_path)
+               free(file_path);
+
+       return true;
+}
+
+static gboolean testapp_test_smime_verify_signature()
+{
+       int mail_id = 0;
+       int ret_scanf = 0;
+       int verify = 0;
+       int err = EMAIL_ERROR_NONE;
+
+       testapp_print("input mail_id :");
+       ret_scanf = scanf("%d", &mail_id);
+       
+       err = email_verify_signature(mail_id, &verify);
+       if (err != EMAIL_ERROR_NONE) {
+               testapp_print("Failed Verify\n");
+               return false;
+       }
+
+       testapp_print("verify value : [%d]\n", verify); 
+       return true;
+}
+
 /* internal functions */
 static gboolean testapp_test_interpret_command (int menu_number)
 {
@@ -1595,7 +1803,7 @@ static gboolean testapp_test_interpret_command (int menu_number)
                        testapp_test_mail_send(NULL);
                        break;
                case 3:
-                       testapp_test_get_mail_list();
+                       testapp_test_get_mail_list_ex();
                        break;
                case 4:
                        testapp_test_add_attachment();
@@ -1606,6 +1814,12 @@ static gboolean testapp_test_interpret_command (int menu_number)
                case 6:
                        testapp_test_expunge_mails_deleted_flagged();
                        break;
+               case 7:
+                       testapp_test_send_read_receipt();
+                       break;
+               case 8:
+                       testapp_test_delete_attachment();
+                       break;
                case 9:
                        testapp_test_count();
                        break;
@@ -1655,7 +1869,7 @@ static gboolean testapp_test_interpret_command (int menu_number)
                        testapp_test_test_get_thread_information();
                        break;
                case 51:
-                       testapp_test_get_mail_list_ex();
+                       testapp_test_get_mail_list();
                        break;
                case 52:
                        testapp_test_get_address_info_list();
@@ -1676,7 +1890,13 @@ static gboolean testapp_test_interpret_command (int menu_number)
                        testapp_test_add_mail_to_search_result_box();
                        break;
                case 60:
-                       testapp_test_email_load_eml_file();
+                       testapp_test_email_parse_mime_file();
+                       break;
+               case 62:
+                       testapp_test_smime_verify_signature();
+                       break;
+               case 61:
+                       testapp_test_email_write_mime_file();
                        break;
                case 0:
                        go_to_loop = FALSE;
index ad7b961..ecbbf9c 100755 (executable)
@@ -77,7 +77,7 @@ static gboolean testapp_test_add_mailbox()
        int local_yn = 0;
        char arg[500];
        int ret;
-    unsigned handle;
+    int handle;
     int result_from_scanf = 0;
 
        memset(arg, 0x00, 500);
@@ -120,7 +120,7 @@ static gboolean testapp_test_delete_mailbox()
        int mailbox_id = 0;
        int on_server = 0;
        int ret;
-       unsigned handle;
+       int handle;
        int result_from_scanf = 0;
 
        testapp_print("\n> Enter mailbox id:");
@@ -150,7 +150,7 @@ static gboolean testapp_test_rename_mailbox()
        char mailbox_alias[500] = { 0, };
        int err;
        int result_from_scanf = 0;
-       unsigned handle = 0;
+       int handle = 0;
        
        testapp_print("> Enter mailbox id: ");
        result_from_scanf = scanf("%d", &mailbox_id);
@@ -175,7 +175,7 @@ static gboolean testapp_test_rename_mailbox()
 static gboolean testapp_test_get_imap_mailbox_list()
 {
        int account_id = 0;
-       unsigned handle = 0;
+       int handle = 0;
        int result_from_scanf = 0;
        
        testapp_print("> Enter account id: ");
@@ -188,6 +188,24 @@ static gboolean testapp_test_get_imap_mailbox_list()
 
 }
 
+static gboolean testapp_test_set_local_mailbox()
+{
+       int mailbox_id = 0;
+       int is_local_mailbox = 0;
+       int result_from_scanf = 0;
+
+       testapp_print("> Enter mailbox id: ");
+       result_from_scanf = scanf("%d", &mailbox_id);
+
+       testapp_print("> Enter local: ");
+       result_from_scanf = scanf("%d", &is_local_mailbox);
+
+       if( email_set_local_mailbox(mailbox_id, is_local_mailbox) < 0)
+               testapp_print("email_set_local_mailbox failed");
+
+       return FALSE;
+}
+
 static gboolean testapp_test_get_mailbox_by_type ()
 {
 
@@ -296,7 +314,7 @@ static gboolean testapp_test_sync_mailbox()
 {
        int result_from_scanf = 0;
        int account_id = 0;
-       unsigned handle = 0;
+       int handle = 0;
        int mailbox_id = 0;
 
        testapp_print("\n > Enter Account id (0: for all account) : ");
@@ -353,7 +371,11 @@ static gboolean testapp_test_interpret_command (int menu_number)
 
                case 4:
                        testapp_test_get_imap_mailbox_list();
-                       break;                  
+                       break;
+
+               case 5:
+                       testapp_test_set_local_mailbox();
+                       break;
 
                case 7:
                        testapp_test_get_mailbox_by_type();
index 1181d90..2d2a828 100755 (executable)
@@ -40,6 +40,7 @@
 #include "testapp-utility.h"
 #include "testapp-others.h"
 #include "email-ipc.h"
+#include "email-core-utils.h"
 
 static gboolean testapp_test_get_network_status()
 {
@@ -106,6 +107,22 @@ static gboolean testapp_test_get_dnet_proper_profile_type()
        return TRUE;
 }
 
+static gboolean testapp_test_get_preview_text_from_file()
+{
+       int   result_from_scanf;
+       char *preview_buffer = NULL;
+       char  html_file_path[1024] = { 0, };
+
+       testapp_print("\n > Enter file path : ");
+       result_from_scanf = scanf("%s", html_file_path);
+
+       emcore_get_preview_text_from_file(NULL, html_file_path, 1024, &preview_buffer);
+
+       testapp_print("\n result :\n %s ", preview_buffer);
+
+       return TRUE;
+}
+
 static gboolean testapp_test_print_receving_queue_via_debug_msg()
 {
        int err;
@@ -413,6 +430,9 @@ static gboolean testapp_test_interpret_command (int menu_number)
                case 6:
                        testapp_test_get_dnet_proper_profile_type();
                        break;
+               case 7:
+                       testapp_test_get_preview_text_from_file();
+                       break;
                case 11:
                        testapp_test_print_receving_queue_via_debug_msg();
                        break;
index 5ee0dfd..7783f55 100755 (executable)
@@ -51,7 +51,7 @@ void testapp_show_menu (eEMAIL_MENU menu)
                        testapp_print ("    Email test application \n");
                        testapp_print ("==========================================\n");
                        testapp_print ("1. Account Test\n");
-                       testapp_print ("2. Message Test\n");
+                       testapp_print ("2. Mail Test\n");
                        testapp_print ("3. Mailbox Test\n");
                        testapp_print ("5. Rule Test\n");
                        testapp_print ("6. Thread Test\n");
@@ -90,11 +90,13 @@ void testapp_show_menu (eEMAIL_MENU menu)
                        testapp_print ("    MAIL MENU\n");
                        testapp_print ("==========================================\n");
                        testapp_print ("1.  Get mails\n");
-                       testapp_print ("2.  Send a mail \n");
-                       testapp_print ("3.  Get mail list\n");
+                       testapp_print ("2.  Send a mail\n");
+                       testapp_print ("3.  Get mail list ex\n");
                        testapp_print ("4.  Add Attachment\n");
                        testapp_print ("5.  Set deleted flag\n");
                        testapp_print ("6.  Expunge deleted flagged mails\n");
+                       testapp_print ("7.  Send read receipt\n");
+                       testapp_print ("8.  Delete attachment\n");
                        testapp_print ("9.  Mail Count \n");
                        testapp_print ("14. Delete a mail \n");
                        testapp_print ("16. Download mail body\n");
@@ -109,15 +111,17 @@ void testapp_show_menu (eEMAIL_MENU menu)
                        testapp_print ("42. Storage test : (Input : to fields)\n");
                        testapp_print ("43. Send mail Cancel\n");
                        testapp_print ("44. Cancel Download Body\n");
+                       testapp_print ("46. Get thread list\n");
                        testapp_print ("48. Get thread information\n");
-                       testapp_print ("51. Get mail list ex\n");
+                       testapp_print ("51. Get mail list\n");
                        testapp_print ("52. Get address info list\n");
                        testapp_print ("55. Set a field of flags\n");
                        testapp_print ("56. Add mail\n");
                        testapp_print ("57. Update mail\n");
                        testapp_print ("58. Search on server\n");
                        testapp_print ("59. Add mail to search result table\n");
-                       testapp_print ("60. Open eml file\n");
+                       testapp_print ("60. Parse mime file\n");
+                       testapp_print ("61. Write mime file\n");
                        testapp_print ("0.  Go to Main Menu\n");
                        testapp_print ("------------------------------------------\n");
                        break;
@@ -130,6 +134,7 @@ void testapp_show_menu (eEMAIL_MENU menu)
                        testapp_print (" 2. Delete mailbox\n");
                        testapp_print (" 3. Raname mailbox\n");
                        testapp_print (" 4. Get IMAP mailbox List\n");
+                       testapp_print (" 5. Set local mailbox\n");
                        testapp_print (" 7. Get mailbox by mailbox type\n");
                        testapp_print (" 8. Set mailbox type\n");
                        testapp_print (" 9. Set mail slot size\n");
@@ -173,7 +178,7 @@ void testapp_show_menu (eEMAIL_MENU menu)
                        testapp_print ("3.  Cancel Job\n");
                        testapp_print ("5.  Set DNET Proper Profile Type\n");
                        testapp_print ("6.  Get DNET Proper Profile Type\n");
-                       testapp_print ("7.  Send mail cancel job\n");
+                       testapp_print ("7.  Get preview text\n");
                        testapp_print ("11. Print receiving event queue via debug msg\n");
                        testapp_print ("12. Create DB full\n");
                        testapp_print ("13. Encoding Test\n");