2.0_alpha release commit
[framework/messaging/email-service.git] / email-core / email-storage / email-storage.c
index 89b4072..cbf7fb6 100755 (executable)
@@ -67,8 +67,9 @@
 
 #define SETTING_MEMORY_TEMP_FILE_PATH "/tmp/email_tmp_file"
 
-#define EMF_STORAGE_CHANGE_NOTI       "User.Email.StorageChange"
-#define EMF_NETOWRK_CHANGE_NOTI       "User.Email.NetworkStatus"
+#define EMAIL_STORAGE_CHANGE_NOTI       "User.Email.StorageChange"
+#define EMAIL_NETOWRK_CHANGE_NOTI       "User.Email.NetworkStatus"
+#define EMAIL_RESPONSE_TO_API_NOTI      "User.Email.ResponseToAPI"
 
 #define CONTENT_DATA                  "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset="
 #define CONTENT_TYPE_DATA             "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
 
 #undef close
 
+#define ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL 256
+#define EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL      128
+#define SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL     1027
+#define FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL          256
+
 #define ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL            50
 #define RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL   50
 #define EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL              128
 #define THREAD_TOPIC_LEN_IN_MAIL_TBL                    256
 #define TEXT_1_LEN_IN_MAIL_TBL                          256
 #define TEXT_2_LEN_IN_MAIL_TBL                          256
+#define MIME_ENTITY_LEN_IN_MAIL_TBL                     256
 #define DATETIME_LEN_IN_MAIL_TBL                        128
 #define MESSAGE_ID_LEN_IN_MAIL_TBL                      256
 #define FROM_CONTACT_NAME_LEN_IN_MAIL_TBL               3999
 #define GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL        512
 #define STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL           32
 #define DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL           32
-#define PREVIEWBODY_LEN_IN_MAIL_TBL                     512 
+#define PREVIEWBODY_LEN_IN_MAIL_TBL                     512
+#define CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL        256 
 
 /*  this define is used for query to change data (delete, insert, update) */
 #define EMSTORAGE_START_WRITE_TRANSACTION(transaction_flag, error_code) \
                {\
                        if (emstorage_commit_transaction(NULL, NULL, NULL) == false)\
                        {\
-                               error_code = EMF_ERROR_DB_FAILURE;\
+                               error_code = EMAIL_ERROR_DB_FAILURE;\
                                result_code = false;\
                        }\
                }\
                else\
                {\
                        if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)\
-                               error_code = EMF_ERROR_DB_FAILURE;\
+                               error_code = EMAIL_ERROR_DB_FAILURE;\
                }\
                _unlockshm_mutex(&mapped_for_db_lock);\
        }
@@ -190,6 +198,8 @@ static pthread_mutex_t _transactionEndLock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _dbus_noti_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _db_handle_lock = PTHREAD_MUTEX_INITIALIZER;
 
+static int _get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type);
+
 #define        _MULTIPLE_DB_HANDLE
 
 #ifdef _MULTIPLE_DB_HANDLE
@@ -234,7 +244,7 @@ sqlite3 *emstorage_get_db_handle()
 int emstorage_set_db_handle(sqlite3 *db_handle)
 {      
        EM_DEBUG_FUNC_BEGIN();
-       int i, error_code = EMF_ERROR_MAX_EXCEEDED;
+       int i, error_code = EMAIL_ERROR_MAX_EXCEEDED;
        pthread_t current_thread_id = THREAD_SELF();
 
        ENTER_CRITICAL_SECTION(_db_handle_lock);
@@ -243,13 +253,13 @@ int emstorage_set_db_handle(sqlite3 *db_handle)
                        _db_handle_list[i].thread_id = current_thread_id;
                        _db_handle_list[i].db_handle = db_handle;
                        EM_DEBUG_LOG("current_thread_id [%d], index [%d]", current_thread_id, i);
-                       error_code =  EMF_ERROR_NONE;
+                       error_code =  EMAIL_ERROR_NONE;
                        break;
                }
        }
        LEAVE_CRITICAL_SECTION(_db_handle_lock);
 
-       if (error_code == EMF_ERROR_MAX_EXCEEDED)
+       if (error_code == EMAIL_ERROR_MAX_EXCEEDED)
                EM_DEBUG_EXCEPTION("Exceeded the limitation of db client. Can't find empty slot in _db_handle_list.");
 
        EM_DEBUG_FUNC_END("error_code [%d]", error_code);
@@ -259,7 +269,7 @@ int emstorage_set_db_handle(sqlite3 *db_handle)
 int emstorage_remove_db_handle()
 {      
        EM_DEBUG_FUNC_BEGIN();
-       int i, error_code = EMF_ERROR_MAX_EXCEEDED;
+       int i, error_code = EMAIL_ERROR_MAX_EXCEEDED;
        ENTER_CRITICAL_SECTION(_db_handle_lock);
        for (i = 0; i < MAX_DB_CLIENT; i++)
        {
@@ -268,13 +278,13 @@ int emstorage_remove_db_handle()
                        _db_handle_list[i].thread_id = 0;
                        _db_handle_list[i].db_handle = NULL;
                        EM_DEBUG_LOG("index [%d]", i);
-                       error_code = EMF_ERROR_NONE;
+                       error_code = EMAIL_ERROR_NONE;
                        break;
                }
        }
        LEAVE_CRITICAL_SECTION(_db_handle_lock);
        
-       if (error_code == EMF_ERROR_MAX_EXCEEDED)
+       if (error_code == EMAIL_ERROR_MAX_EXCEEDED)
                EM_DEBUG_EXCEPTION("Can't find proper thread_id");
 
        EM_DEBUG_FUNC_END("error_code [%d]", error_code);
@@ -296,7 +306,7 @@ int emstorage_reset_db_handle_list()
        LEAVE_CRITICAL_SECTION(_db_handle_lock)
        
        EM_DEBUG_FUNC_END();
-       return EMF_ERROR_NONE;
+       return EMAIL_ERROR_NONE;
 }
 
 sqlite3 *emstorage_get_db_connection()
@@ -350,8 +360,8 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
        EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
 
        if(!shm_file_name) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
        int fd = shm_open(shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /*  note: permission is not working */
@@ -361,13 +371,13 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
                EM_DEBUG_LOG("** Create SHM FILE **"); 
                if (ftruncate(fd, sizeof(mmapped_t)) != 0) {
                        EM_DEBUG_EXCEPTION("ftruncate failed: %s", strerror(errno));
-                       return EMF_ERROR_SYSTEM_FAILURE;
+                       return EMAIL_ERROR_SYSTEM_FAILURE;
                }
                
                mmapped_t *m = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
                if (m == MAP_FAILED) {
                        EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno));
-                       return EMF_ERROR_SYSTEM_FAILURE;
+                       return EMAIL_ERROR_SYSTEM_FAILURE;
                }
 
                m->data = 0;
@@ -375,31 +385,31 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
                pthread_mutexattr_t mattr; 
                pthread_mutexattr_init(&mattr);
                pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
-               pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+               pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP);
                pthread_mutex_init(&(m->mutex), &mattr);
                pthread_mutexattr_destroy(&mattr);
        }
        else {
                EM_DEBUG_EXCEPTION("shm_open failed: %s", strerror(errno));
-               return EMF_ERROR_SYSTEM_FAILURE;
+               return EMAIL_ERROR_SYSTEM_FAILURE;
        }
        close(fd);
        EM_DEBUG_FUNC_END();
-       return EMF_ERROR_NONE;
+       return EMAIL_ERROR_NONE;
 }
 
 int emstorage_shm_file_destroy(const char *shm_file_name)
 {
        EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
        if(!shm_file_name) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
        if (shm_unlink(shm_file_name) != 0)
                EM_DEBUG_EXCEPTION("shm_unlink failed: %s", strerror(errno));
        EM_DEBUG_FUNC_END();
-       return EMF_ERROR_NONE;
+       return EMAIL_ERROR_NONE;
 }
 
 static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_t **param_mapped)
@@ -407,8 +417,8 @@ static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, m
        EM_DEBUG_FUNC_BEGIN("shm_file_name [%p] param_shm_fd [%p], param_mapped [%p]", shm_file_name, param_shm_fd, param_mapped);
        
        if(!shm_file_name || !param_shm_fd || !param_mapped) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
        if (!(*param_mapped)) {
@@ -418,20 +428,20 @@ static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, m
                        *param_shm_fd = shm_open(shm_file_name, O_RDWR, 0);
                        if ((*param_shm_fd) == -1) {
                                EM_DEBUG_EXCEPTION("FAIL: shm_open(): %s", strerror(errno));
-                               return EMF_ERROR_SYSTEM_FAILURE;
+                               return EMAIL_ERROR_SYSTEM_FAILURE;
                        }
                }
                mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0);
                
                if (tmp == MAP_FAILED) {
                        EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno));
-                       return EMF_ERROR_SYSTEM_FAILURE;
+                       return EMAIL_ERROR_SYSTEM_FAILURE;
                }
                *param_mapped = tmp;
        }
 
        EM_DEBUG_FUNC_END();
-       return EMF_ERROR_NONE;
+       return EMAIL_ERROR_NONE;
 }
 
 static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
@@ -439,8 +449,8 @@ static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
        EM_DEBUG_FUNC_BEGIN("param_mapped [%p], sec [%d]", param_mapped, sec);
        
        if(!param_mapped) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
        struct timespec abs_time;       
@@ -450,7 +460,7 @@ static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
        int err = pthread_mutex_timedlock(&((*param_mapped)->mutex), &abs_time);
        
        if (err == EOWNERDEAD) {
-               err = pthread_mutex_consistent_np(&((*param_mapped)->mutex));
+               err = pthread_mutex_consistent(&((*param_mapped)->mutex));
                EM_DEBUG_EXCEPTION("Previous owner is dead with lock. Fix mutex : %s", EM_STRERROR(err));
        } 
        else if (err != 0) {
@@ -459,7 +469,7 @@ static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
        }
        
        EM_DEBUG_FUNC_END();
-       return EMF_ERROR_NONE;
+       return EMAIL_ERROR_NONE;
 }
 
 void _unlockshm_mutex(mmapped_t **param_mapped)
@@ -477,13 +487,16 @@ static int g_transaction = false;
 static int _get_password_file_name(int account_id, char *recv_password_file_name, char *send_password_file_name);
 static int _read_password_from_secure_storage(char *file_name, char **password);
 
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+static int _get_cert_password_file_name(int index, char *cert_password_file_name);
+#endif
 
 typedef struct {
        const char *object_name;
        unsigned int data_flag;
-} emf_db_object_t;
+} email_db_object_t;
 
-static const emf_db_object_t _g_db_tables[] =
+static const email_db_object_t _g_db_tables[] =
 {
        { "mail_read_mail_uid_tbl", 1},
        { "mail_tbl", 1},
@@ -491,7 +504,7 @@ static const emf_db_object_t _g_db_tables[] =
        { NULL,  0},
 };
 
-static const emf_db_object_t _g_db_indexes[] =
+static const email_db_object_t _g_db_indexes[] =
 {
        { "mail_read_mail_uid_idx1", 1},
        { "mail_idx1", 1},
@@ -514,6 +527,7 @@ enum
 #ifdef __FEATURE_LOCAL_ACTIVITY__
        CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL,
 #endif
+       CREATE_TABLE_MAIL_CERTIFICATE_TBL,
        CREATE_TABLE_MAX,
 };
 
@@ -524,56 +538,19 @@ enum
        FLAG_IDX_IN_MAIL_ACTIVITY_TBL,
 };
 
-
-enum 
+enum
 {
-       ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL = 0,
-       ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
-       RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL,
-       RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
-       EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
-       USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
-       PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL,
-       RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL,
-       PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL,
-       USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL,
-       SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL,
-       DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
-       REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
-       RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
-       ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL,
-       KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL,
-       FLAG1_IDX_IN_MAIL_ACCOUNT_TBL,
-       FLAG2_IDX_IN_MAIL_ACCOUNT_TBL,
-       POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL,
-       APOP_IDX_IN_MAIL_ACCOUNT_TBL,
-       LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL,
-       PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL,
-       TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL,
-       CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL,
-       PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL,
-       KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL,
-       REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL,
-       REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL,
-       DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL,
-       BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL,
-       BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL,
-       DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL,
-       REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL,
-       FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL,
-       ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL,
-       ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL,
-       SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL,
-       ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL,
-       MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL,
-       INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL,
-       SYNC_STATUS_IDX_IN_MAIL_ACCOUNT_TBL,
+       CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL = 0,
+       ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL,
+       ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL,
+       ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL,
+       EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL,
+       EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL,
+       EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, 
+       ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL,
+       EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL,
+       SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL,     
+       FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, 
 };
 
 enum
@@ -599,7 +576,7 @@ enum
 enum 
 {
        ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL = 0,
-       LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+       LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
        LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
        MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL,
        S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
@@ -616,7 +593,7 @@ enum
        TYPE_IDX_IN_MAIL_RULE_TBL,
        VALUE_IDX_IN_MAIL_RULE_TBL,
        ACTION_TYPE_IDX_IN_MAIL_RULE_TBL,
-       DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL,
+       TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL,
        FLAG1_IDX_IN_MAIL_RULE_TBL,
        FLAG2_IDX_IN_MAIL_RULE_TBL,
 };
@@ -647,6 +624,7 @@ enum
        BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL,
        FILE_PATH_PLAIN_IDX_IN_MAIL_TBL,
        FILE_PATH_HTML_IDX_IN_MAIL_TBL,
+       FILE_PATH_MIME_ENTITY_IDX_IN_MAIL_TBL,
        MAIL_SIZE_IDX_IN_MAIL_TBL,
        FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL,
        FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL,
@@ -666,7 +644,10 @@ enum
        THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL,
        PREVIEW_TEXT_IDX_IN_MAIL_TBL,
        MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL,
-       FIELD_COUNT_OF_EMF_MAIL_TBL,  /* End of mail_tbl */
+       MESSAGE_CLASS_IDX_IN_MAIL_TBL,
+       DIGEST_TYPE_IDX_IN_MAIL_TBL,
+       SMIME_TYPE_IDX_IN_MAIL_TBL,
+       FIELD_COUNT_OF_MAIL_TBL,  /* End of mail_tbl */
 };
 
 enum 
@@ -677,7 +658,7 @@ enum
        ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL,
        MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
        ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
-       MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL,
+       MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
        ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL,
        ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL,
        ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL,
@@ -716,35 +697,33 @@ typedef struct _em_mail_id_list {
 static char *g_test_query[] = {
                /*  1. select mail_account_tbl */
                "SELECT"
-               " account_bind_type, "
                " account_name, "
-               " receiving_server_type, "
-               " receiving_server_addr, "
-               " email_addr, "
-               " user_name, "
-               " password, "
+               " incoming_server_type, "
+               " incoming_server_address, "
+               " user_email_address, "
+               " incoming_server_user_name, "
+               " incoming_server_password, "
                " retrieval_mode, "
-               " port_num, "
-               " use_security, "
-               " sending_server_type, "
-               " sending_server_addr, "
-               " sending_port_num, "
-               " sending_auth, "
-               " sending_security, "
-               " sending_user, "
-               " sending_password, "
+               " incoming_server_port_number, "
+               " incoming_server_secure_connection, "
+               " outgoing_server_type, "
+               " outgoing_server_address, "
+               " outgoing_server_port_number, "
+               " outgoing_server_need_authentication, "
+               " outgoing_server_secure_connection, "
+               " outgoing_server_user_name, "
+               " outgoing_server_password, "
                " display_name, "
                " reply_to_addr, "
                " return_addr, "
                " account_id, "
-               " keep_on_server, "
+               " keep_mails_on_pop_server_after_download, "
                " flag1, "
                " flag2, "
                " pop_before_smtp, "
-               " apop"                    
+               " incoming_server_requires_apop"                           
                ", logo_icon_path, "
-               " preset_account, "
-               " target_storage, "
+               " is_preset_account, "
                " check_interval, "
                " priority, "
                " keep_local_copy, "
@@ -760,9 +739,14 @@ static char *g_test_query[] = {
                " add_signature, "
                " signature"
                ", add_my_address_to_bcc"
-               ", my_account_id "
+               ", account_svc_id "
                ", index_color "
                ", sync_status "
+               ", sync_disabled "
+               ", smime_type"
+               ", certificate_path"
+               ", cipher_type"
+               ", digest_type"
                " FROM mail_account_tbl",
                /*  2. select mail_box_tbl */
                "SELECT "
@@ -777,11 +761,12 @@ static char *g_test_query[] = {
                "   total_mail_count_on_server,  "
                "   has_archived_mails, "
                "   mail_slot_size "
+               "   last_sync_time "
                " FROM mail_box_tbl ",
                /*  3. select mail_read_mail_uid_tbl */
                "SELECT  "
                "   account_id,  "
-               "   local_mbox,  "
+               "   mailbox_id,  "
                "   local_uid,  "
                "   mailbox_name,  "
                "   s_uid,  "
@@ -797,7 +782,7 @@ static char *g_test_query[] = {
                "       type, "
                "       value, "
                "       action_type, "
-               "       dest_mailbox,   "
+               "       target_mailbox_id,      "
                "       flag1, "
                "       flag2 "
                " FROM mail_rule_tbl    ",
@@ -827,6 +812,7 @@ static char *g_test_query[] = {
                "       body_download_status, "
                "       file_path_plain, "
                "       file_path_html, "
+               "   file_path_mime_entity, "
                "       mail_size, "
                " flags_seen_field     ,"
                " flags_deleted_field  ,"
@@ -844,8 +830,11 @@ static char *g_test_query[] = {
                "       inline_content_count, "
                "       thread_id, "
                "       thread_item_count, "
-               "   preview_text"
+               "   preview_text"
                "       meeting_request_status, "
+               "   message_class, "
+               "   digest_type, "
+               "   smime_type "
                " FROM mail_tbl",
                /*  6. select mail_attachment_tbl */
                "SELECT "
@@ -855,7 +844,7 @@ static char *g_test_query[] = {
                "       attachment_size, "
                "       mail_id,  "
                "       account_id, "
-               "       mailbox_name, "
+               "       mailbox_id, "
                "       attachment_save_status,  "
                "       attachment_drm_type,  "
                "       attachment_drm_method,  "
@@ -870,6 +859,7 @@ static char *g_test_query[] = {
                "   server_mail_id, "
                "   activity_id, "
                "   activity_type, "
+               "   mailbox_id, "
                "   mailbox_name "
                " FROM mail_partial_body_activity_tbl ",
 #endif
@@ -877,7 +867,7 @@ static char *g_test_query[] = {
                "SELECT  "
                "   mail_id, "
                "   account_id, "
-               "   mailbox_name, "
+               "   mailbox_id, "
                "   meeting_response, "
                "   start_time, "
                "   end_time, "
@@ -910,8 +900,9 @@ static char *g_test_query[] = {
 /* ----------- Notification Changes ----------- */
 typedef enum
 {
-       _NOTI_TYPE_STORAGE,
-       _NOTI_TYPE_NETWORK
+       _NOTI_TYPE_STORAGE         = 0,
+       _NOTI_TYPE_NETWORK         = 1,
+       _NOTI_TYPE_RESPONSE_TO_API = 2,
 } enotitype_t;
 
 
@@ -938,7 +929,7 @@ INTERNAL_FUNC int emstorage_send_noti(enotitype_t notiType, int subType, int dat
        }
 
        if (notiType == _NOTI_TYPE_STORAGE) {
-               signal = dbus_message_new_signal("/User/Email/StorageChange", EMF_STORAGE_CHANGE_NOTI, "email");
+               signal = dbus_message_new_signal("/User/Email/StorageChange", EMAIL_STORAGE_CHANGE_NOTI, "email");
 
                if (signal == NULL) {
                        EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
@@ -956,7 +947,7 @@ INTERNAL_FUNC int emstorage_send_noti(enotitype_t notiType, int subType, int dat
                dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
        }
        else if (notiType == _NOTI_TYPE_NETWORK) {
-               signal = dbus_message_new_signal("/User/Email/NetworkStatus", EMF_NETOWRK_CHANGE_NOTI, "email");
+               signal = dbus_message_new_signal("/User/Email/NetworkStatus", EMAIL_NETOWRK_CHANGE_NOTI, "email");
 
                if (signal == NULL) {
                        EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
@@ -974,9 +965,23 @@ INTERNAL_FUNC int emstorage_send_noti(enotitype_t notiType, int subType, int dat
                dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
                dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
        }
+       else if (notiType == _NOTI_TYPE_RESPONSE_TO_API) {
+               signal = dbus_message_new_signal("/User/Email/ResponseToAPI", EMAIL_RESPONSE_TO_API_NOTI, "email");
+
+               if (signal == NULL) {
+                       EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
+                       goto FINISH_OFF;
+               }
+
+               EM_DEBUG_LOG("/User/Email/ResponseToAPI Signal is created by dbus_message_new_signal");
+
+               dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
+               dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
+               dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
+       }
        else {
                EM_DEBUG_EXCEPTION("Wrong notification type [%d]", notiType);
-               error = EMF_ERROR_IPC_CRASH;
+               error = EMAIL_ERROR_IPC_CRASH;
                goto FINISH_OFF;
        }
 
@@ -989,7 +994,7 @@ INTERNAL_FUNC int emstorage_send_noti(enotitype_t notiType, int subType, int dat
        }
                
 /*     EM_DEBUG_LOG("Before dbus_connection_flush");    */
-/*     dbus_connection_flush(connection); */
+/*     dbus_connection_flush(connection);               */
 /*     EM_DEBUG_LOG("After dbus_connection_flush");     */
        
        ret = true;
@@ -1004,18 +1009,24 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_notify_storage_event(emf_noti_on_storage_event transaction_type, int data1, int data2 , char *data3, int data4)
+INTERNAL_FUNC int emstorage_notify_storage_event(email_noti_on_storage_event transaction_type, int data1, int data2 , char *data3, int data4)
 {
        EM_DEBUG_FUNC_BEGIN("transaction_type[%d], data1[%d], data2[%d], data3[%p], data4[%d]", transaction_type, data1, data2, data3, data4);
        return emstorage_send_noti(_NOTI_TYPE_STORAGE, (int)transaction_type, data1, data2, data3, data4);
 }
 
-INTERNAL_FUNC int emstorage_notify_network_event(emf_noti_on_network_event status_type, int data1, char *data2, int data3, int data4)
+INTERNAL_FUNC int emstorage_notify_network_event(email_noti_on_network_event status_type, int data1, char *data2, int data3, int data4)
 {
        EM_DEBUG_FUNC_BEGIN("status_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", status_type, data1, data2, data3, data4);
        return emstorage_send_noti(_NOTI_TYPE_NETWORK, (int)status_type, data1, data3, data2, data4);
 }
 
+INTERNAL_FUNC int emstorage_notify_response_to_api(email_event_type_t event_type, int data1, int data2)
+{
+       EM_DEBUG_FUNC_BEGIN("event_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", event_type, data1, data2);
+       return emstorage_send_noti(_NOTI_TYPE_RESPONSE_TO_API, (int)event_type, data1, data2, NULL, 0);
+}
+
 /* ----------- Notification Changes End----------- */
 static int _get_table_field_data_char(char  **table, char *buf, int index)
 {
@@ -1223,6 +1234,29 @@ static int _get_stmt_field_data_string(DB_STMT hStmt, char **buf, int ucs2, int
        return false;
 }
 
+static void _get_stmt_field_data_blob(DB_STMT hStmt, void **buf, int index)
+{
+       if ((hStmt < 0) || (buf == NULL) || (index < 0))  {
+               EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], index[%d]", hStmt, buf, index);
+               return;
+       }
+
+       int sLen = 0;
+       sLen = sqlite3_column_bytes(hStmt, index);
+
+#ifdef _PRINT_STORAGE_LOG_
+       EM_DEBUG_LOG("_get_stmt_field_data_blob sqlite3_column_bytes sLen[%d]", sLen);
+#endif
+
+       if (sLen > 0) {
+               *buf = (char *) em_malloc(sLen);
+               memcpy(*buf, (void *)sqlite3_column_blob(hStmt, index), sLen);
+       }
+       else
+               *buf = NULL;
+
+}
+
 static int _get_stmt_field_data_string_without_allocation(DB_STMT hStmt, char *buf, int buffer_size, int ucs2, int index)
 {
        if ((hStmt < 0) || (buf == NULL) || (index < 0))  {
@@ -1326,6 +1360,32 @@ static int _bind_stmt_field_data_string(DB_STMT hStmt, int index, char *value, i
        return true;
 }
 
+
+static int _bind_stmt_field_data_blob(DB_STMT hStmt, int index, void *blob, int blob_size)
+{
+       if ((hStmt == NULL) || (index < 0)) {
+               EM_DEBUG_EXCEPTION("index[%d], blob_size[%d]", index, blob_size);
+               return false;
+       }
+
+#ifdef _PRINT_STORAGE_LOG_
+       EM_DEBUG_LOG("hStmt = %p, index = %d, blob_size = %d, blob = [%p]", hStmt, index, blob_size, blob);
+#endif
+
+       int ret = 0;
+       if (blob_size>0)
+               ret = sqlite3_bind_blob(hStmt, index+1, blob, blob_size, SQLITE_STATIC);
+       else
+               ret = sqlite3_bind_null(hStmt, index+1);
+
+       if (ret != SQLITE_OK)  {
+               EM_DEBUG_EXCEPTION("sqlite3_bind_blob fail [%d]", ret);
+               return false;
+       }
+       return true;
+}
+
+
 static int _delete_temp_file(const char *path)
 {
        EM_DEBUG_FUNC_BEGIN("path[%p]", path);
@@ -1380,7 +1440,7 @@ INTERNAL_FUNC int emstorage_close(int *err_code)
        EM_DEBUG_FUNC_BEGIN();
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
 
        emstorage_db_close(&error);             
        
@@ -1400,7 +1460,7 @@ static void *_emstorage_open_once(int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        mkdir(EMAILPATH, DIRECTORY_PERMISSION);
        mkdir(DATA_PATH, DIRECTORY_PERMISSION);
@@ -1414,7 +1474,7 @@ static void *_emstorage_open_once(int *err_code)
        
        g_transaction = false;
        
-       if (!emstorage_create_table(EMF_CREATE_DB_NORMAL, &error)) {
+       if (!emstorage_create_table(EMAIL_CREATE_DB_NORMAL, &error)) {
                EM_DEBUG_EXCEPTION(" emstorage_create_table failed - %d", error);
                goto FINISH_OFF;
        }
@@ -1429,25 +1489,25 @@ FINISH_OFF:
 
  /*  pData : a parameter which is registered when busy handler is registerd */
  /*  count : retry count */
-#define EMF_STORAGE_MAX_RETRY_COUNT    20
+#define EMAIL_STORAGE_MAX_RETRY_COUNT  20
 static int _callback_sqlite_busy_handler(void *pData, int count)
 {
        EM_DEBUG_LOG("Busy Handler Called!!: [%d]", count);
        usleep(200000);   /*   sleep time when SQLITE_LOCK */
 
        /*  retry will be stopped if  busy handler return 0 */
-       return EMF_STORAGE_MAX_RETRY_COUNT - count;   
+       return EMAIL_STORAGE_MAX_RETRY_COUNT - count;   
 }
 
 static int _delete_all_files_and_directories(int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
 
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int ret = false;
 
        if (!emstorage_delete_file(EMAIL_SERVICE_DB_FILE_PATH, &error)) {
-               if (error != EMF_ERROR_FILE_NOT_FOUND) {
+               if (error != EMAIL_ERROR_FILE_NOT_FOUND) {
                        EM_DEBUG_EXCEPTION("remove failed - %s", EMAIL_SERVICE_DB_FILE_PATH);
                        goto FINISH_OFF;        
                }
@@ -1471,7 +1531,7 @@ static int _recovery_from_malformed_db_file(int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
 
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int ret = false;
        
        /* Delete all files and directories */
@@ -1499,7 +1559,7 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        int rc = 0;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int ret = false;
 
        EM_DEBUG_LOG("*sqlite_handle[%p]", *sqlite_handle);
@@ -1510,7 +1570,7 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
                EMSTORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc);
                if (SQLITE_OK != rc) {
                        EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                        db_util_close(*sqlite_handle); 
                        *sqlite_handle = NULL; 
 
@@ -1525,7 +1585,7 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
                                EMSTORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc);
                                if (SQLITE_OK != rc) {
                                        EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
-                                       error = EMF_ERROR_DB_FAILURE;
+                                       error = EMAIL_ERROR_DB_FAILURE;
                                        db_util_close(*sqlite_handle); 
                                        *sqlite_handle = NULL; 
                                }
@@ -1540,7 +1600,7 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
                rc = sqlite3_busy_handler(*sqlite_handle, _callback_sqlite_busy_handler, NULL);  /*  Busy Handler registration, NULL is a parameter which will be passed to handler */
                if (SQLITE_OK != rc) {
                        EM_DEBUG_EXCEPTION("sqlite3_busy_handler fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                        db_util_close(*sqlite_handle); 
                        *sqlite_handle = NULL; 
                        goto FINISH_OFF;                
@@ -1567,7 +1627,7 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code)
        sqlite3 *_db_handle = NULL;
 #endif
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
 
        _initialize_shm_mutex(SHM_FILE_FOR_DB_LOCK, &shm_fd_for_db_lock, &mapped_for_db_lock);
 
@@ -1599,7 +1659,7 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code)
        sqlite3 *_db_handle = emstorage_get_db_handle();
 #endif
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int ret = false;
 
        DELETE_CRITICAL_SECTION(_transactionBeginLock);
@@ -1611,7 +1671,7 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code)
                
                if (ret != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION(" db_util_close fail - %d", ret);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                        ret = false;
                        goto FINISH_OFF;
                }
@@ -1637,7 +1697,7 @@ INTERNAL_FUNC int emstorage_open(int *err_code)
        EM_DEBUG_FUNC_BEGIN();
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
 
        int retValue;
 
@@ -1670,7 +1730,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
 {
        EM_DEBUG_FUNC_BEGIN();
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc = -1, ret = false;
        char sql_query_string[QUERY_SIZE] = {0, };
        char *create_table_query[] =
@@ -1678,54 +1738,58 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        /*  1. create mail_account_tbl */
        "CREATE TABLE mail_account_tbl \n"
        "(\n"
-       "  account_bind_type            INTEGER \n"
-       ", account_name                 VARCHAR(51) \n"
-       ", receiving_server_type        INTEGER \n"
-       ", receiving_server_addr        VARCHAR(51) \n"
-       ", email_addr                   VARCHAR(129) \n"
-       ", user_name                    VARCHAR(51) \n"
-       ", password                     VARCHAR(51) \n"
-       ", retrieval_mode               INTEGER \n"
-       ", port_num                     INTEGER \n"
-       ", use_security                 INTEGER \n"
-       ", sending_server_type          INTEGER \n"
-       ", sending_server_addr          VARCHAR(51) \n"
-       ", sending_port_num             INTEGER \n"
-       ", sending_auth                 INTEGER \n"
-       ", sending_security             INTEGER \n"
-       ", sending_user                 VARCHAR(51) \n"
-       ", sending_password             VARCHAR(51) \n"
-       ", display_name                 VARCHAR(31) \n"
-       ", reply_to_addr                VARCHAR(129) \n"
-       ", return_addr                  VARCHAR(129) \n"
-       ", account_id                   INTEGER PRIMARY KEY \n"
-       ", keep_on_server               INTEGER \n"
-       ", flag1                        INTEGER \n"
-       ", flag2                        INTEGER \n"
-       ", pop_before_smtp              INTEGER \n"            /*  POP before SMTP authentication  */
-       ", apop                         INTEGER \n"            /*  APOP authentication */
-       ", logo_icon_path               VARCHAR(256) \n"       /*  Receiving Option : Account logo icon  */
-       ", preset_account               INTEGER \n"            /*  Receiving Option : Preset account or not  */
-       ", target_storage               INTEGER \n"            /*  Receiving Option : Specifies the targetStorage. 0 is phone, 1 is MMC  */
-       ", check_interval               INTEGER \n"            /*  Receiving Option : Specifies the check interval. Unit is minute  */
-       ", priority                     INTEGER \n"            /*  Sending Option : Specifies the prority. 1=high 3=normal 5=low  */
-       ", keep_local_copy              INTEGER \n"            /*  Sending Option :   */
-       ", req_delivery_receipt         INTEGER \n"            /*  Sending Option :   */
-       ", req_read_receipt             INTEGER \n"            /*  Sending Option :   */
-       ", download_limit               INTEGER \n"            /*  Sending Option :   */
-       ", block_address                INTEGER \n"            /*  Sending Option :   */
-       ", block_subject                INTEGER \n"            /*  Sending Option :   */
-       ", display_name_from            VARCHAR(256) \n"       /*  Sending Option :   */
-       ", reply_with_body              INTEGER \n"            /*  Sending Option :   */
-       ", forward_with_files           INTEGER \n"            /*  Sending Option :   */
-       ", add_myname_card              INTEGER \n"            /*  Sending Option :   */
-       ", add_signature                INTEGER \n"            /*  Sending Option :   */
-       ", signature                    VARCHAR(256) \n"       /*  Sending Option :   */
-       ", add_my_address_to_bcc        INTEGER \n"            /*  Sending Option :   */
-       ", my_account_id                INTEGER \n"            /*  My Account Id  */
-       ", index_color                  INTEGER \n"            /*  Index color  */
-       ", sync_status                  INTEGER \n"            /*  Sync Status */
-       ");",
+       "account_id                               INTEGER PRIMARY KEY,\n"
+       "account_name                             VARCHAR(51),\n"
+       "logo_icon_path                           VARCHAR(256),\n"
+       "user_data                                BLOB,\n"
+       "user_data_length                         INTEGER,\n"
+       "account_svc_id                           INTEGER,\n"
+       "sync_status                              INTEGER,\n"
+       "sync_disabled                            INTEGER,\n"
+       "default_mail_slot_size                   INTEGER,\n"
+       "user_display_name                        VARCHAR(31),\n"
+       "user_email_address                       VARCHAR(129),\n"
+       "reply_to_address                         VARCHAR(129),\n"
+       "return_address                           VARCHAR(129),\n"
+       "incoming_server_type                     INTEGER,\n"
+       "incoming_server_address                  VARCHAR(51),\n"
+       "incoming_server_port_number              INTEGER,\n"
+       "incoming_server_user_name                VARCHAR(51),\n"
+       "incoming_server_password                 VARCHAR(51),\n"
+       "incoming_server_secure_connection        INTEGER,\n"
+       "retrieval_mode                           INTEGER,\n"
+       "keep_mails_on_pop_server_after_download  INTEGER,\n"
+       "check_interval                           INTEGER,\n"
+       "auto_download_size                       INTEGER,\n"
+       "outgoing_server_type                     INTEGER,\n"
+       "outgoing_server_address                  VARCHAR(51),\n"
+       "outgoing_server_port_number              INTEGER,\n"
+       "outgoing_server_user_name                VARCHAR(51),\n"
+       "outgoing_server_password                 VARCHAR(51),\n"
+       "outgoing_server_secure_connection        INTEGER,\n"
+       "outgoing_server_need_authentication      INTEGER,\n"
+       "outgoing_server_use_same_authenticator   INTEGER,\n"
+       "priority                                 INTEGER,\n"
+       "keep_local_copy                          INTEGER,\n"
+       "req_delivery_receipt                     INTEGER,\n"
+       "req_read_receipt                         INTEGER,\n"
+       "download_limit                           INTEGER,\n"
+       "block_address                            INTEGER,\n"
+       "block_subject                            INTEGER,\n"
+       "display_name_from                        VARCHAR(256),\n"
+       "reply_with_body                          INTEGER,\n"
+       "forward_with_files                       INTEGER,\n"
+       "add_myname_card                          INTEGER,\n"
+       "add_signature                            INTEGER,\n"
+       "signature                                VARCHAR(256),\n"
+       "add_my_address_to_bcc                    INTEGER,\n"
+       "pop_before_smtp                          INTEGER,\n"
+       "incoming_server_requires_apop            INTEGER,\n"
+       "smime_type                               INTEGER,\n"
+       "certificate_path                         VARCHAR(256),\n"
+       "cipher_type                              INTEGER,\n"
+       "digest_type                              INTEGER\n"
+       "); \n ",
        /*  2. create mail_box_tbl */
        "CREATE TABLE mail_box_tbl \n"
        "(\n"
@@ -1740,13 +1804,14 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", total_mail_count_on_server   INTEGER \n"
        ", has_archived_mails           INTEGER \n"
        ", mail_slot_size               INTEGER \n"
+       ", last_sync_time               DATETIME \n"
        "); \n ",
 
        /*  3. create mail_read_mail_uid_tbl */
        "CREATE TABLE mail_read_mail_uid_tbl \n"
        "(\n"
        "  account_id                   INTEGER \n"
-       ", local_mbox                   VARCHAR(129) \n"
+       ", mailbox_id                   VARCHAR(129) \n"
        ", local_uid                    INTEGER \n"
        ", mailbox_name                 VARCHAR(256) \n"
        ", s_uid                        VARCHAR(129) \n"
@@ -1763,7 +1828,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", type                         INTEGER \n"
        ", value                        VARCHAR(257) \n"
        ", action_type                  INTEGER \n"
-       ", dest_mailbox                 VARCHAR(129) \n"
+       ", target_mailbox_id            INTEGER \n"
        ", flag1                        INTEGER \n"
        ", flag2                        INTEGER \n"
        "); \n ",
@@ -1794,6 +1859,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", body_download_status         INTEGER \n"
        ", file_path_plain              VARCHAR(257) \n"
        ", file_path_html               VARCHAR(257) \n"
+       ", file_path_mime_entity        VARCHAR(257) \n"
        ", mail_size                    INTEGER \n"
        ", flags_seen_field             BOOLEAN \n"
        ", flags_deleted_field          BOOLEAN \n"
@@ -1813,6 +1879,9 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", thread_item_count            INTEGER \n"
        ", preview_text                 TEXT \n"
        ", meeting_request_status       INTEGER \n"
+       ", message_class                INTEGER \n"
+       ", digest_type                  INTEGER \n"
+       ", smime_type                   INTEGER \n"
        ", FOREIGN KEY(account_id)      REFERENCES mail_account_tbl(account_id) \n"
        "); \n ",
        
@@ -1825,7 +1894,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", attachment_size                  INTEGER \n"
        ", mail_id                          INTEGER \n"
        ", account_id                       INTEGER \n"
-       ", mailbox_name                     VARCHAR(129) \n"
+       ", mailbox_id                       INTEGER \n"
        ", attachment_save_status           INTEGER \n"
        ", attachment_drm_type              INTEGER \n"
        ", attachment_drm_method            INTEGER \n"
@@ -1846,6 +1915,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", server_mail_id               INTEGER \n"
        ", activity_id                  INTEGER PRIMARY KEY \n"
        ", activity_type                INTEGER \n"
+       ", mailbox_id                   INTEGER \n"
        ", mailbox_name                 VARCHAR(4000) \n"
        "); \n ",
 #endif
@@ -1854,7 +1924,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        "(\n"
        "  mail_id                     INTEGER PRIMARY KEY \n"
        ", account_id                  INTEGER \n"
-       ", mailbox_name                TEXT \n"
+       ", mailbox_id                  INTEGER \n"
        ", meeting_response            INTEGER \n"
        ", start_time                  INTEGER \n"
        ", end_time                    INTEGER \n"
@@ -1881,6 +1951,21 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
        ", dest_mbox                   VARCHAR(129) \n"
        "); \n ",
 #endif
+       "CREATE TABLE mail_certificate_tbl \n"
+       "( \n"
+       "  certificate_id              INTEGER \n"
+       ", issue_year                  INTEGER \n"
+       ", issue_month                 INTEGER \n"
+       ", issue_day                   INTEGER \n"
+       ", expiration_year             INTEGER \n"
+       ", expiration_month            INTEGER \n"
+       ", expiration_day              INTEGER \n"
+       ", issue_organization_name     VARCHAR(256) \n"
+       ", email_address               VARCHAR(129) \n"
+       ", subject_str                 VARCHAR(256) \n"
+       ", filepath                    VARCHAR(256) \n"
+       ", password                    VARCHAR(51) \n"
+       "); \n ",
        NULL,
 };
        
@@ -1908,20 +1993,20 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], sizeof(sql_query_string));
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                /*  create mail_account_tbl unique index */
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_bind_type, account_id)");
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_id)");
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
 
        } /*  mail_account_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], rc, sqlite3_errmsg(local_db_handle)));
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
 
        sqlite3_free_table(result); 
@@ -1944,22 +2029,22 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_BOX_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
                /*  create mail_local_mailbox_tbl unique index */
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (account_id, local_yn, mailbox_name)");
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                
        } /*  mail_box_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_BOX_TBL], NULL, NULL, NULL);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_BOX_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result); 
@@ -1981,21 +2066,21 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
                /*  create mail_read_mail_uid_tbl unique index */
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, local_mbox, local_uid, mailbox_name, s_uid)");
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, mailbox_id, local_uid, mailbox_name, s_uid)");
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                
        } /*  mail_read_mail_uid_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result);
@@ -2018,14 +2103,14 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_RULE_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                
        } /*  mail_rule_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_RULE_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_RULE_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result);
@@ -2046,25 +2131,25 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
                /*  create mail_tbl unique index */
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_idx1 ON mail_tbl (mail_id, account_id)");
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                /*  create mail_tbl index for date_time */
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE INDEX mail_idx_date_time ON mail_tbl (date_time)");
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                /*  create mail_tbl index for thread_item_count */
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE INDEX mail_idx_thread_mail_count ON mail_tbl (thread_item_count)");
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
@@ -2072,9 +2157,9 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                /*  just one time call */
 /*             EFTSInitFTSIndex(FTS_EMAIL_IDX); */
        } /*  mail_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result);
@@ -2095,21 +2180,21 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
                /*  create mail_attachment_tbl unique index */
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_attachment_idx1 ON mail_attachment_tbl (mail_id, attachment_id) ");
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                
        } /*  mail_attachment_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result);
@@ -2132,14 +2217,14 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                
        } /*  mail_rule_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result);
@@ -2162,19 +2247,19 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_MEETING_TBL], sizeof(sql_query_string));
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_meeting_idx1 ON mail_meeting_tbl (mail_id)");
                
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                
        } /*  mail_contact_sync_tbl */
-       else if (type == EMF_CREATE_DB_CHECK)  {                
+       else if (type == EMAIL_CREATE_DB_CHECK)  {              
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], rc, sqlite3_errmsg(local_db_handle)));
        }
        sqlite3_free_table(result);
@@ -2197,20 +2282,47 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
                        SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL]);
                        
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
                        
                } /*  mail_rule_tbl */
-               else if (type == EMF_CREATE_DB_CHECK)  {        
+               else if (type == EMAIL_CREATE_DB_CHECK)  {      
                        rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL);
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL), rc);
-                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle)));
                }
                sqlite3_free_table(result);
                
 #endif /*  __FEATURE_LOCAL_ACTIVITY__ */
+       /*  create mail_certificate_tbl */
+       sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_certificate_tbl';";
+       /*  rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL);   */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+       if (atoi(result[1]) < 1) {
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+               EM_DEBUG_LOG("CREATE TABLE mail_certificate_tbl");
+
+               EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], sizeof(sql_query_string));
+
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_certificate_idx1 ON mail_certificate_tbl (certificate_id)");
+
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+       } /*  mail_contact_sync_tbl */
+       else if (type == EMAIL_CREATE_DB_CHECK)  {                
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], NULL, NULL, NULL), rc);
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], rc, sqlite3_errmsg(local_db_handle)));
+       }
+       sqlite3_free_table(result);
 
        ret = true;
        
@@ -2233,7 +2345,144 @@ FINISH_OFF:
 
 /* Query series --------------------------------------------------------------*/
 
-INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, emf_mail_list_item_t** result_mail_list,  int *result_count,  int *err_code)
+INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count)
+{
+       EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_transaction[%d], output_total_mail_count[%p], output_unseen_mail_count[%p]", input_conditional_clause, input_transaction, output_total_mail_count, output_unseen_mail_count);
+       int rc = -1;
+       int error = EMAIL_ERROR_NONE;
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+       char err_msg[1024];
+       char **result;
+       sqlite3 *local_db_handle = NULL;
+
+       if (!input_conditional_clause || (!output_total_mail_count && !output_unseen_mail_count)) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       memset(&sql_query_string, 0x00, sizeof(sql_query_string));
+       local_db_handle = emstorage_get_db_connection();
+
+       EMSTORAGE_START_READ_TRANSACTION(input_transaction);
+
+       SNPRINTF(sql_query_string, QUERY_SIZE, "SELECT COUNT(*) FROM mail_tbl");
+       EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause);
+
+       if (output_total_mail_count)  {
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       ("sqlite3_step fail:%d", rc));
+               _get_stmt_field_data_int(hStmt, output_total_mail_count, 0);
+       }
+
+       if (output_unseen_mail_count)  {
+               EM_SAFE_STRCAT(sql_query_string, " AND flags_seen_field = 0 ");
+
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+                       ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+               *output_unseen_mail_count = atoi(result[1]);
+               sqlite3_free_table(result);
+       }
+
+FINISH_OFF:
+
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_LOG("sqlite3_finalize failed [%d] : %s", rc, err_msg);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
+       _DISCONNECT_DB;
+
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
+
+INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count)
+{
+       EM_DEBUG_FUNC_BEGIN("input_conditional_clause [%p], input_transaction [%d], output_mail_id_list [%p], output_mail_id_count [%p]", input_conditional_clause, input_transaction, output_mail_id_list, output_mail_id_count);
+
+       int      i = 0;
+       int      count = 0;
+       int      rc = -1;
+       int      cur_query = 0;
+       int      col_index;
+       int      error = EMAIL_ERROR_NONE;
+       int     *result_mail_id_list = NULL;
+       char   **result = NULL;
+       char     sql_query_string[QUERY_SIZE] = {0, };
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+       EM_IF_NULL_RETURN_VALUE(input_conditional_clause, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_mail_id_list, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(output_mail_id_count, EMAIL_ERROR_INVALID_PARAM);
+
+       EMSTORAGE_START_READ_TRANSACTION(input_transaction);
+
+       /* Composing query */
+       SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT mail_id FROM mail_tbl ");
+       EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause);
+
+       EM_DEBUG_LOG("query[%s].", sql_query_string);
+
+       /* Performing query */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+       col_index = 1;
+
+       /*  to get mail list */
+       if (count == 0) {
+               EM_DEBUG_EXCEPTION("No mail found...");
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+
+       EM_DEBUG_LOG("There are [%d] mails.", count);
+
+       if (!(result_mail_id_list = (int*)em_malloc(sizeof(int) * count))) {
+               EM_DEBUG_EXCEPTION("malloc for result_mail_id_list failed...");
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       EM_DEBUG_LOG(">>>> DATA ASSIGN START >> ");
+
+       for (i = 0; i < count; i++)
+               _get_table_field_data_int(result, result_mail_id_list + i, col_index++);
+
+       EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d] >> ", count);
+
+       *output_mail_id_list  = result_mail_id_list;
+       *output_mail_id_count = count;
+
+FINISH_OFF:
+
+       if(result)
+               sqlite3_free_table(result);
+
+       EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
+       _DISCONNECT_DB;
+
+       if(error != EMAIL_ERROR_NONE)
+               EM_SAFE_FREE(result_mail_id_list);
+
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
+
+INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list,  int *result_count,  int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        EM_PROFILE_BEGIN(emstorage_query_mail_list_func);
@@ -2241,11 +2490,11 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
        int i = 0, count = 0, rc = -1, to_get_count = (result_mail_list)?0:1;
        int local_inline_content_count = 0, local_attachment_count = 0;
        int cur_query = 0, base_count = 0, col_index;
-       int ret = false, error = EMF_ERROR_NONE;
+       int ret = false, error = EMAIL_ERROR_NONE;
        char *date_time_string = NULL;
        char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
-       char *field_list = "mail_id, account_id, mailbox_name, full_address_from, email_address_sender, full_address_to, subject, body_download_status, 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, lock_status, attachment_count, inline_content_count, date_time, preview_text, thread_id, thread_item_count, meeting_request_status ";
-       emf_mail_list_item_t *mail_list_item_from_tbl = NULL;
+       char *field_list = "mail_id, account_id, mailbox_id, full_address_from, email_address_sender, full_address_to, subject, body_download_status, 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, lock_status, attachment_count, inline_content_count, date_time, preview_text, thread_id, thread_item_count, meeting_request_status, message_class, smime_type ";
+       email_mail_list_item_t *mail_list_item_from_tbl = NULL;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
        EM_IF_NULL_RETURN_VALUE(conditional_clause, false);
@@ -2255,18 +2504,19 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
        
        /*  select clause */
        if (to_get_count) /*  count only */
-               cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT count(*) FROM mail_tbl");
+               cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT mail_id FROM mail_tbl");
        else /*  mail list in plain form */
                cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT %s FROM mail_tbl ", field_list);
 
-       cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, conditional_clause, 0);
+       /* cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, conditional_clause); This code caused some crashes.*/
+       strncat(sql_query_string, conditional_clause, QUERY_SIZE - cur_query);
        
        EM_DEBUG_LOG("emstorage_query_mail_list : query[%s].", sql_query_string);
 
        /*  performing query            */      
        EM_PROFILE_BEGIN(emstorage_query_mail_list_performing_query);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        EM_PROFILE_END(emstorage_query_mail_list_performing_query);
        
@@ -2278,8 +2528,13 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
        EM_DEBUG_LOG("base_count [%d]", base_count);
 
        if (to_get_count) {     
-               /*  to get mail count */
-               count = atoi(result[1]);
+               /*  to get count */
+               if (!count) {
+                       EM_DEBUG_EXCEPTION("No mail found...");
+                       ret = false;
+                       error= EMAIL_ERROR_MAIL_NOT_FOUND;
+                       goto FINISH_OFF;
+               }
                EM_DEBUG_LOG("There are [%d] mails.", count);
        }
        else {
@@ -2287,14 +2542,14 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
                if (!count) {
                        EM_DEBUG_EXCEPTION("No mail found...");                 
                        ret = false;
-                       error= EMF_ERROR_MAIL_NOT_FOUND;
+                       error= EMAIL_ERROR_MAIL_NOT_FOUND;
                        goto FINISH_OFF;
                }
                
                EM_DEBUG_LOG("There are [%d] mails.", count);
-               if (!(mail_list_item_from_tbl = (emf_mail_list_item_t*)em_malloc(sizeof(emf_mail_list_item_t) * count))) {
+               if (!(mail_list_item_from_tbl = (email_mail_list_item_t*)em_malloc(sizeof(email_mail_list_item_t) * count))) {
                        EM_DEBUG_EXCEPTION("malloc for mail_list_item_from_tbl failed...");
-                       error = EMF_ERROR_OUT_OF_MEMORY;
+                       error = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
@@ -2303,7 +2558,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
                for (i = 0; i < count; i++) {
                        _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_string_without_allocation(result, mail_list_item_from_tbl[i].mailbox_name, STRING_LENGTH_FOR_DISPLAY, 1, 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++);
@@ -2327,6 +2582,8 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
                        _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++);
 
                        mail_list_item_from_tbl[i].has_attachment = ((local_attachment_count - local_inline_content_count)>0)?1:0;
                }
@@ -2372,15 +2629,15 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
        EM_DEBUG_FUNC_BEGIN("conditional_clause[%s], result_mail_tbl[%p], result_count [%p], transaction[%d], err_code[%p]", conditional_clause, result_mail_tbl, result_count, transaction, err_code);
 
        if (!conditional_clause) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
-       int i, col_index = FIELD_COUNT_OF_EMF_MAIL_TBL, rc, ret = false, count;
-       int error = EMF_ERROR_NONE;
+       int i, col_index = FIELD_COUNT_OF_MAIL_TBL, rc, ret = false, count;
+       int error = EMAIL_ERROR_NONE;
        char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
        emstorage_mail_tbl_t* p_data_tbl = NULL;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -2392,20 +2649,20 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        if (!count) {
                EM_DEBUG_EXCEPTION("No mail found...");                 
                ret = false;
-               error= EMF_ERROR_MAIL_NOT_FOUND;
+               error= EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        
        EM_DEBUG_LOG("There are [%d] mails.", count);
        if (!(p_data_tbl = (emstorage_mail_tbl_t*)em_malloc(sizeof(emstorage_mail_tbl_t) * count))) {
                EM_DEBUG_EXCEPTION("malloc for emstorage_mail_tbl_t failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -2435,6 +2692,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
                _get_table_field_data_int   (result, &(p_data_tbl[i].body_download_status), col_index++);
                _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_string(result, &(p_data_tbl[i].file_path_mime_entity), 0, col_index++);
                _get_table_field_data_int   (result, &(p_data_tbl[i].mail_size), col_index++);
                _get_table_field_data_char  (result, &(p_data_tbl[i].flags_seen_field), col_index++);
                _get_table_field_data_char  (result, &(p_data_tbl[i].flags_deleted_field), col_index++);
@@ -2454,6 +2712,9 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
                _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++);
                /*  check real body file... */
                if (p_data_tbl[i].body_download_status) {
                        struct stat buf;
@@ -2499,21 +2760,120 @@ 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)
+{
+       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);
+
+       int i = 0;
+       int rc;
+       int count = 0;
+       int col_index = 0;
+       int error = EMAIL_ERROR_NONE;
+       int read_count = 0;
+       int total_count = 0;
+       char **result;
+       char sql_query_string[QUERY_SIZE] = {0, };
+       char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, last_sync_time ";
+       emstorage_mailbox_tbl_t* p_data_tbl = NULL;
+       DB_STMT hStmt = NULL;
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+       EMSTORAGE_START_READ_TRANSACTION(input_transaction);
+
+       if (input_get_mail_count == 0) {        /*  without mail count  */
+               col_index = 12;
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl AS MBT %s", fields, input_conditional_clause);
+       }
+       else {  /*  with read count and total count */
+               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);
+       }
+
+       EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
+
+       EM_DEBUG_LOG("result count [%d]", count);
+
+       if(count == 0) {
+               EM_DEBUG_EXCEPTION("Can't find mailbox");
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+
+       if ((p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t) * count)) == NULL) {
+               EM_DEBUG_EXCEPTION("malloc failed...");
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       for (i = 0; i < count; i++)  {
+               _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
+               _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+               _get_table_field_data_int(result, (int*)&(p_data_tbl[i].mailbox_type), col_index++);
+               _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
+               _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
+               _get_table_field_data_int(result, (int*)&(p_data_tbl[i].last_sync_time), col_index++);
+
+               if (input_get_mail_count == 1) {
+                       _get_table_field_data_int(result, &(total_count), col_index++);
+                       p_data_tbl[i].total_mail_count_on_local = total_count;
+                       _get_table_field_data_int(result, &(read_count), col_index++);
+                       p_data_tbl[i].unread_count = total_count - read_count;                  /*  return unread count, NOT  */
+               }
+       }
+
+
+FINISH_OFF:
+       if (result)
+               sqlite3_free_table(result);
+
+       if (error == EMAIL_ERROR_NONE)  {
+               *output_mailbox_list = p_data_tbl;
+               *output_mailbox_count = count;
+               EM_DEBUG_LOG("Mailbox Count [ %d]", count);
+       }
+       else if (p_data_tbl != NULL)
+               emstorage_free_mailbox(&p_data_tbl, count, NULL);
+
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK) {
+                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
+       _DISCONNECT_DB;
+
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
 
 /* Query series --------------------------------------------------------------*/
 
-INTERNAL_FUNC int emstorage_check_duplicated_account(emf_account_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        
        if (!account)  {
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char **result;
        int count;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -2524,20 +2884,20 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(emf_account_t* account, int
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
                "SELECT COUNT(*) FROM mail_account_tbl "
                " WHERE "
-               " email_addr = '%s' AND "
-               " user_name = '%s' AND "
-               " receiving_server_type = %d AND "
-               " receiving_server_addr = '%s' AND "
-               " sending_user = '%s' AND "
-               " sending_server_type = %d AND "
-               " sending_server_addr = '%s'; ",
-               account->email_addr,
-               account->user_name, account->receiving_server_type, account->receiving_server_addr,
-               account->sending_user, account->sending_server_type, account->sending_server_addr
+               " user_email_address = '%s' AND "
+               " incoming_server_user_name = '%s' AND "
+               " incoming_server_type = %d AND "
+               " incoming_server_address = '%s' AND "
+               " outgoing_server_user_name = '%s' AND "
+               " outgoing_server_type = %d AND "
+               " outgoing_server_address = '%s'; ",
+               account->user_email_address,
+               account->incoming_server_user_name, account->incoming_server_type, account->incoming_server_address,
+               account->outgoing_server_user_name, account->outgoing_server_type, account->outgoing_server_address
        );
        EM_DEBUG_LOG("Query[%s]", sql_query_string);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        count = atoi(result[1]);
@@ -2547,12 +2907,12 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(emf_account_t* account, int
 
        if (count == 0) {       /*  not duplicated account */
                ret = true;
-               EM_DEBUG_LOG("NOT duplicated account: email_addr[%s]", account->email_addr);
+               EM_DEBUG_LOG("NOT duplicated account: user_email_address[%s]", account->user_email_address);
        }
        else {  /*  duplicated account */
                ret = false;
-               EM_DEBUG_LOG("The same account already exists. Duplicated account: email_addr[%s]", account->email_addr);
-               error = EMF_ERROR_ALREADY_EXISTS;
+               EM_DEBUG_LOG("The same account already exists. Duplicated account: user_email_address[%s]", account->user_email_address);
+               error = EMAIL_ERROR_ALREADY_EXISTS;
        }
        
 FINISH_OFF:
@@ -2574,12 +2934,12 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *
        
        if (!count)  {
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
  
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -2591,11 +2951,11 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *
        EM_DEBUG_LOG("SQL STMT [ %s ]", sql_query_string);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        *count = sqlite3_column_int(hStmt, 0);
@@ -2611,7 +2971,7 @@ FINISH_OFF:
                hStmt=NULL;
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d: %s", rc, err_msg);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
                EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
        }
@@ -2632,54 +2992,55 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_
        EM_DEBUG_FUNC_BEGIN();
        
        int i = 0, count = 0, rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int field_index = 0;
+       int error = EMAIL_ERROR_NONE;
        emstorage_account_tbl_t *p_data_tbl = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+       char *sql = "SELECT count(*) FROM mail_account_tbl;";
+       char **result;
+       sqlite3 *local_db_handle = NULL;
        DB_STMT hStmt = NULL;
 
        if (!select_num || !account_list)  {
                EM_DEBUG_EXCEPTION("select_num[%p], account_list[%p]", select_num, account_list);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_READ_TRANSACTION(transaction);
-
-       char sql_query_string[QUERY_SIZE] = {0, };
-       char *sql = "SELECT count(*) FROM mail_account_tbl;";
-       char **result;
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        count = atoi(result[1]);
        sqlite3_free_table(result);
 
-       if (!count) {
+       EM_DEBUG_LOG("count = %d", rc);
+
+       if (count == 0) {
                EM_DEBUG_EXCEPTION("no account found...");
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                ret = true;
                goto FINISH_OFF;
        }
-       EM_DEBUG_LOG("count = %d", rc);
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_account_tbl ORDER BY account_id");
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
 
        EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no account found...");
                
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                count = 0;
                ret = true;
                goto FINISH_OFF;
@@ -2687,89 +3048,99 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_
 
        if (!(p_data_tbl = (emstorage_account_tbl_t*)malloc(sizeof(emstorage_account_tbl_t) * count)))  {
                EM_DEBUG_EXCEPTION("malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        memset(p_data_tbl, 0x00, sizeof(emstorage_account_tbl_t) * count);
        for (i = 0; i < count; i++)  {
                /*  get recordset */
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_bind_type), ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].account_name), 0, ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].receiving_server_type), RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].receiving_server_addr), 0, RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].email_addr), 0, EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_name), 0, USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].password), 0, PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].retrieval_mode), RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].port_num), PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].use_security), USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_server_type), SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].sending_server_addr), 0, SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_port_num), SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_auth), SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_security), SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].sending_user), 0, SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].sending_password), 0, SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].display_name), 0, DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].reply_to_addr), 0, REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].return_addr), 0, RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].keep_on_server), KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].pop_before_smtp), POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].apop), APOP_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].logo_icon_path), 0, LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].preset_account), PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].target_storage), TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].check_interval), CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.priority), PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.keep_local_copy), KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_delivery_receipt), REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_read_receipt), REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.download_limit), DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_address), BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_subject), BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.display_name_from), 0, DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.reply_with_body), REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.forward_with_files), FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_myname_card), ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_signature), ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.signature), 0, SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_my_address_to_bcc), ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].my_account_id), MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].index_color), INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL);
+               field_index = 0;
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].account_id), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].account_name), 0, field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].logo_icon_path), 0, field_index++);
+               _get_stmt_field_data_blob(hStmt, &(p_data_tbl[i].user_data), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].user_data_length), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].account_svc_id), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].sync_status), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].sync_disabled), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].default_mail_slot_size), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_display_name), 0, field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_email_address), 0, field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].reply_to_address), 0, field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].return_address), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].incoming_server_type), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].incoming_server_address), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_port_number), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].incoming_server_user_name), 0, field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].incoming_server_password), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_secure_connection), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].retrieval_mode), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].keep_mails_on_pop_server_after_download), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].check_interval), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].auto_download_size), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].outgoing_server_type), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].outgoing_server_address), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_port_number), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].outgoing_server_user_name), 0, field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].outgoing_server_password), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_secure_connection), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_need_authentication), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_use_same_authenticator), field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].options.priority), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.keep_local_copy), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_delivery_receipt), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_read_receipt), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.download_limit), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_address), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_subject), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.display_name_from), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.reply_with_body), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.forward_with_files), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_myname_card), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_signature), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.signature), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].options.add_my_address_to_bcc), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].pop_before_smtp), field_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_requires_apop), field_index++);
+               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].smime_type), field_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].certificate_path), 0, field_index++);
+               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].cipher_type), field_index++);
+               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].digest_type), field_index++);
+
                if (with_password == true) {
                        /*  get password from the secure storage */
-                       char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];/*  = p_data_tbl[i].password; */
-                       char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];;/*  = p_data_tbl[i].sending_password; */
+                       char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+                       char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
 
-                       EM_SAFE_FREE(p_data_tbl[i].password);
-                       EM_SAFE_FREE(p_data_tbl[i].sending_password);
+                       EM_SAFE_FREE(p_data_tbl[i].incoming_server_password);
+                       EM_SAFE_FREE(p_data_tbl[i].outgoing_server_password);
 
                        /*  get password file name */
-                       if ((error = _get_password_file_name(p_data_tbl[i].account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
-                               EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
+                       if ((error = _get_password_file_name(p_data_tbl[i].account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+                               EM_DEBUG_EXCEPTION("_get_password_file_name failed. [%d]", error);
+                               error = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
                                goto FINISH_OFF;
                        }
                                
                        /*  read password from secure storage */
-                       if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl[i].password))) < 0 ) {
-                               EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()  failed...");
+                       if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl[i].incoming_server_password))) < 0 ) {
+                               EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()  failed. [%d]", error);
+                               error = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
                                goto FINISH_OFF;
                        }
-                       EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name,  p_data_tbl[i].password);
+                       EM_DEBUG_LOG("recv_password_file_name[%s], incoming_server_password[%s]", recv_password_file_name,  p_data_tbl[i].incoming_server_password);
                        
-                       if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl[i].sending_password))) < 0) {
-                               EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()  failed...");
+                       if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl[i].outgoing_server_password))) < 0) {
+                               EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()  failed. [%d]", error);
+                               error = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
                                goto FINISH_OFF;
                        }
-                       EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name,  p_data_tbl[i].sending_password);
+                       EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name,  p_data_tbl[i].outgoing_server_password);
                }
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
                EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i,  rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
        } 
        
@@ -2783,6 +3154,7 @@ FINISH_OFF:
        }
        else if (p_data_tbl != NULL)
                emstorage_free_account(&p_data_tbl, count, NULL);
+
        if (hStmt != NULL)  {
                EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
        
@@ -2790,13 +3162,13 @@ FINISH_OFF:
                hStmt = NULL;
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
        EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
        _DISCONNECT_DB;
-       
+
        if (err_code != NULL)
                *err_code = error;
 
@@ -2809,13 +3181,13 @@ INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int account_id, char *s
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]", account_id, server_mail_id, mail, transaction, err_code);
        
-       int ret = false, error = EMF_ERROR_NONE, result_count;
+       int ret = false, error = EMAIL_ERROR_NONE, result_count;
        char conditional_clause[QUERY_SIZE] = {0, };
        emstorage_mail_tbl_t* p_data_tbl = NULL;
 
        if (!server_mail_id || !mail) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               error = EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -2845,13 +3217,13 @@ FINISH_OFF:
 }
 
 
-static int _write_conditional_clause_for_getting_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, char *conditional_clause_string, int buffer_size, int *err_code)
+static int _write_conditional_clause_for_getting_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, bool input_except_delete_flagged_mails, char *conditional_clause_string, int buffer_size, int *err_code)
 {
        int cur_clause = 0, conditional_clause_count = 0, i = 0;
 
        if (account_id < ALL_ACCOUNT) {
                EM_DEBUG_EXCEPTION("Invalid account_id [%d]", account_id);
-               EM_RETURN_ERR_CODE(err_code, EMF_ERROR_INVALID_PARAM, false);
+               EM_RETURN_ERR_CODE(err_code, EMAIL_ERROR_INVALID_PARAM, false);
        }
 
        /*  where clause */
@@ -2866,10 +3238,10 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, const
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND account_id = %d", account_id);
        }
        
-       if (mailbox_name) {
+       if (mailbox_id > 0) {
                cur_clause += (conditional_clause_count++ == 0)?
-                       SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name):
-                       SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+                       SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE mailbox_id = %d", mailbox_id):
+                       SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_id = %d", mailbox_id);
        }
        else if(account_id != ALL_ACCOUNT) {
                cur_clause += (conditional_clause_count++ == 0)?
@@ -2882,17 +3254,17 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, const
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE thread_id = %d ", thread_id):
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND thread_id = %d ", thread_id);
        }
-       else if (thread_id == EMF_LIST_TYPE_THREAD)     {
+       else if (thread_id == EMAIL_LIST_TYPE_THREAD)   {
                cur_clause += (conditional_clause_count++ == 0)?
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE thread_item_count > 0"):
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND thread_item_count > 0");
        }
-       else if (thread_id == EMF_LIST_TYPE_LOCAL) {
+       else if (thread_id == EMAIL_LIST_TYPE_LOCAL) {
                cur_clause += (conditional_clause_count++ == 0)?
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE server_mail_status = 0"):
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND server_mail_status = 0");
        }
-       else if (thread_id == EMF_LIST_TYPE_UNREAD) {
+       else if (thread_id == EMAIL_LIST_TYPE_UNREAD) {
                cur_clause += (conditional_clause_count++ == 0)?
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE flags_seen_field == 0"):
                        SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND flags_seen_field == 0");
@@ -2921,31 +3293,37 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, const
                }
        }
 
+       if (input_except_delete_flagged_mails) {
+               cur_clause += (conditional_clause_count++ == 0)?
+                       SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE flags_deleted_field = 0"):
+                       SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND flags_deleted_field = 0");
+       }
+
        if (search_value) {
                switch (search_type) {
-                       case EMF_SEARCH_FILTER_SUBJECT:
+                       case EMAIL_SEARCH_FILTER_SUBJECT:
                                cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
-                                       " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
+                                       " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
                                break;
-                       case EMF_SEARCH_FILTER_SENDER:
+                       case EMAIL_SEARCH_FILTER_SENDER:
                                cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
-                                       " %s  ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
+                                       " %s  ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
                                        ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
                                break;
-                       case EMF_SEARCH_FILTER_RECIPIENT:
+                       case EMAIL_SEARCH_FILTER_RECIPIENT:
                                cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
-                                       " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "     
-                                       "       OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
-                                       "       OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+                                       " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " 
+                                       "       OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+                                       "       OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
                                        ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value);
                                break;
-                       case EMF_SEARCH_FILTER_ALL:
+                       case EMAIL_SEARCH_FILTER_ALL:
                                cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
-                                       " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') "
-                                       "       OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
-                                       "                       OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
-                                       "                       OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
-                                       "                       OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+                                       " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\' "
+                                       "       OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+                                       "                       OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+                                       "                       OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+                                       "                       OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
                                        "               ) "
                                        "       )"
                                        ")", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value, search_value, search_value);
@@ -2955,25 +3333,25 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, const
        
        /*  EM_DEBUG_LOG("where clause [%s]", conditional_clause_string); */
        static char sorting_str[][50] = { 
-                        " ORDER BY date_time DESC",                                             /* case EMF_SORT_DATETIME_HIGH: */
-                        " ORDER BY date_time ASC",                                               /* case EMF_SORT_DATETIME_LOW: */
-                        " ORDER BY full_address_from DESC, date_time DESC", /* case EMF_SORT_SENDER_HIGH: */
-                        " ORDER BY full_address_from ASC, date_time DESC",  /* case EMF_SORT_SENDER_LOW: */
-                        " ORDER BY full_address_to DESC, date_time DESC",   /* case EMF_SORT_RCPT_HIGH: */
-                        " ORDER BY full_address_to ASC, date_time DESC",       /* case EMF_SORT_RCPT_LOW: */
-                        " ORDER BY subject DESC, date_time DESC",                 /* case EMF_SORT_SUBJECT_HIGH: */
-                        " ORDER BY subject ASC, date_time DESC",                       /* case EMF_SORT_SUBJECT_LOW: */
-                        " ORDER BY priority DESC, date_time DESC",               /* case EMF_SORT_PRIORITY_HIGH: */
-                        " ORDER BY priority ASC, date_time DESC",                 /* case EMF_SORT_PRIORITY_LOW: */
-                        " ORDER BY attachment_count DESC, date_time DESC",  /* case EMF_SORT_ATTACHMENT_HIGH: */
-                        " ORDER BY attachment_count ASC, date_time DESC",   /* case EMF_SORT_ATTACHMENT_LOW: */
-                        " ORDER BY lock_status DESC, date_time DESC",     /* case EMF_SORT_FAVORITE_HIGH: */
-                        " ORDER BY lock_status ASC, date_time DESC",           /* case EMF_SORT_FAVORITE_LOW: */
-                        " ORDER BY mailbox_name DESC, date_time DESC",   /* case EMF_SORT_MAILBOX_NAME_HIGH: */
-                        " ORDER BY mailbox_name ASC, date_time DESC"           /* case EMF_SORT_MAILBOX_NAME_LOW: */
+                        " ORDER BY date_time DESC",                                             /* case EMAIL_SORT_DATETIME_HIGH: */
+                        " ORDER BY date_time ASC",                                               /* case EMAIL_SORT_DATETIME_LOW: */
+                        " ORDER BY full_address_from DESC, date_time DESC", /* case EMAIL_SORT_SENDER_HIGH: */
+                        " ORDER BY full_address_from ASC, date_time DESC",  /* case EMAIL_SORT_SENDER_LOW: */
+                        " ORDER BY full_address_to DESC, date_time DESC",   /* case EMAIL_SORT_RCPT_HIGH: */
+                        " ORDER BY full_address_to ASC, date_time DESC",       /* case EMAIL_SORT_RCPT_LOW: */
+                        " ORDER BY subject DESC, date_time DESC",                 /* case EMAIL_SORT_SUBJECT_HIGH: */
+                        " ORDER BY subject ASC, date_time DESC",                       /* case EMAIL_SORT_SUBJECT_LOW: */
+                        " ORDER BY priority DESC, date_time DESC",               /* case EMAIL_SORT_PRIORITY_HIGH: */
+                        " ORDER BY priority ASC, date_time DESC",                 /* case EMAIL_SORT_PRIORITY_LOW: */
+                        " ORDER BY attachment_count DESC, date_time DESC",  /* case EMAIL_SORT_ATTACHMENT_HIGH: */
+                        " ORDER BY attachment_count ASC, date_time DESC",   /* case EMAIL_SORT_ATTACHMENT_LOW: */
+                        " ORDER BY lock_status DESC, date_time DESC",     /* case EMAIL_SORT_FAVORITE_HIGH: */
+                        " ORDER BY lock_status ASC, date_time DESC",           /* case EMAIL_SORT_FAVORITE_LOW: */
+                        " ORDER BY mailbox_name DESC, date_time DESC",   /* case EMAIL_SORT_MAILBOX_NAME_HIGH: */
+                        " ORDER BY mailbox_name ASC, date_time DESC"           /* case EMAIL_SORT_MAILBOX_NAME_LOW: */
                         };
 
-       if (sorting < EMF_SORT_END && sorting >= 0)
+       if (sorting < EMAIL_SORT_END && sorting >= 0)
                cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size, " %s", sorting_str[sorting]);
        else
                EM_DEBUG_LOG(" Invalid Sorting order ");
@@ -2991,21 +3369,21 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, const
   *    
   *
   */
-INTERNAL_FUNC int emstorage_get_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list,  int *result_count,  int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list,  int *result_count,  int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        EM_PROFILE_BEGIN(emstorage_get_mail_list_func);
 
-       int ret = false, error = EMF_ERROR_NONE;
+       int ret = false, error = EMAIL_ERROR_NONE;
        char conditional_clause_string[QUERY_SIZE] = { 0, };
 
        if (account_id < ALL_ACCOUNT) {
                EM_DEBUG_EXCEPTION("Invalid account_id [%d]", account_id);
-               EM_RETURN_ERR_CODE(err_code, EMF_ERROR_INVALID_PARAM, false);
+               EM_RETURN_ERR_CODE(err_code, EMAIL_ERROR_INVALID_PARAM, false);
        }
        EM_IF_NULL_RETURN_VALUE(result_count, false);
 
-       _write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, addr_list, thread_id, start_index, limit_count, search_type, search_value, sorting, conditional_clause_string, QUERY_SIZE, &error);
+       _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, addr_list, thread_id, start_index, limit_count, search_type, search_value, sorting, true, conditional_clause_string, QUERY_SIZE, &error);
        
        EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
 
@@ -3031,12 +3409,12 @@ FINISH_OFF:
   *    
   *
   */
-INTERNAL_FUNC int emstorage_get_mails(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting,  int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting,  int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        EM_PROFILE_BEGIN(emStorageGetMails);
        
-       int count = 0, ret = false, error = EMF_ERROR_NONE;
+       int count = 0, ret = false, error = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t *p_data_tbl = NULL;
        char conditional_clause_string[QUERY_SIZE] = {0, };
 
@@ -3044,13 +3422,13 @@ INTERNAL_FUNC int emstorage_get_mails(int account_id, const char *mailbox_name,
        EM_IF_NULL_RETURN_VALUE(result_count, false);
 
        if (!result_count || !mail_list || account_id < ALL_ACCOUNT) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
-       _write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, addr_list, thread_id, start_index, limit_count, 0, NULL, sorting, conditional_clause_string, QUERY_SIZE, &error);
+       _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, addr_list, thread_id, start_index, limit_count, 0, NULL, sorting, true, conditional_clause_string, QUERY_SIZE, &error);
 
        EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
 
@@ -3085,23 +3463,27 @@ FINISH_OFF:
   *    
   *
   */
-INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, const char *mailbox_name, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list,  int *result_count,  int *err_code)
+INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list,  int *result_count,  int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        
-       int ret = false, error = EMF_ERROR_NONE;
+       int ret = false, error = EMAIL_ERROR_NONE;
        char conditional_clause[QUERY_SIZE] = {0, };
-       
+       char *temp_search_value = (char *)search_value;
+
        EM_IF_NULL_RETURN_VALUE(mail_list, false);
        EM_IF_NULL_RETURN_VALUE(result_count, false);
 
        if (!result_count || !mail_list || account_id < ALL_ACCOUNT) {
                EM_DEBUG_EXCEPTION("select_num[%p], Mail_list[%p]", result_count, mail_list);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
-       _write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, NULL, thread_id, start_index, limit_count, search_type, search_value, sorting, conditional_clause, QUERY_SIZE, &error);
+       temp_search_value = em_replace_all_string(temp_search_value, "_", "\\_");
+       temp_search_value = em_replace_all_string(temp_search_value, "%", "\\%");
+
+       _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, search_type, temp_search_value, sorting, true, conditional_clause, QUERY_SIZE, &error);
        
        EM_DEBUG_LOG("conditional_clause[%s]", conditional_clause);
 
@@ -3129,13 +3511,13 @@ static int _get_password_file_name(int account_id, char *recv_password_file_name
 
        if (account_id <= 0 || !recv_password_file_name || !send_password_file_name)  {
                EM_DEBUG_EXCEPTION("Invalid parameter");
-               return EMF_ERROR_INVALID_PARAM;
+               return EMAIL_ERROR_INVALID_PARAM;
        }
 
        sprintf(recv_password_file_name, ".email_account_%d_recv", account_id);
        sprintf(send_password_file_name, ".email_account_%d_send", account_id);
        EM_DEBUG_FUNC_END();
-       return EMF_ERROR_NONE;
+       return EMAIL_ERROR_NONE;
 }
 
 static int _read_password_from_secure_storage(char *file_name, char **password)
@@ -3144,17 +3526,18 @@ static int _read_password_from_secure_storage(char *file_name, char **password)
 
        if (!file_name || !password) {
                EM_DEBUG_EXCEPTION("Invalid Parameter");
-               return EMF_ERROR_INVALID_PARAM;
+               return EMAIL_ERROR_INVALID_PARAM;
        }       
 
        size_t buf_len = 0, read_len = 0;
        ssm_file_info_t sfi;
        char *temp_password = NULL;
-       int ret = EMF_ERROR_NONE;
+       int error_code_from_ssm = 0;
+       int ret = EMAIL_ERROR_NONE;
 
-       if (ssm_getinfo(file_name, &sfi, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
-               EM_DEBUG_EXCEPTION("ssm_getinfo() failed.");
-               ret = EMF_ERROR_SYSTEM_FAILURE;
+       if ( (error_code_from_ssm = ssm_getinfo(file_name, &sfi, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+               EM_DEBUG_EXCEPTION("ssm_getinfo() failed. [%d]", error_code_from_ssm);
+               ret = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -3162,15 +3545,14 @@ static int _read_password_from_secure_storage(char *file_name, char **password)
        EM_DEBUG_LOG("password buf_len[%d]", buf_len);
        if ((temp_password = (char *)malloc(buf_len + 1)) == NULL) {
                EM_DEBUG_EXCEPTION("malloc failed...");
-               
-               ret = EMF_ERROR_OUT_OF_MEMORY;
+               ret = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        memset(temp_password, 0x00, buf_len + 1);
 
-       if (ssm_read(file_name, temp_password, buf_len, &read_len, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
-               EM_DEBUG_EXCEPTION("ssm_read() failed.");
-               ret = EMF_ERROR_SYSTEM_FAILURE;
+       if ( (error_code_from_ssm = ssm_read(file_name, temp_password, buf_len, &read_len, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+               EM_DEBUG_EXCEPTION("ssm_read() failed. [%d]", error_code_from_ssm);
+               ret = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -3194,12 +3576,12 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
        if (!account)  {
                EM_DEBUG_EXCEPTION("account_id[%d], account[%p]", account_id, account);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        emstorage_account_tbl_t* p_data_tbl = NULL;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -3215,24 +3597,71 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
        sql_len = strlen(sql_query_string);
                
-       if (pulloption & EMF_ACC_GET_OPT_DEFAULT) {
-               SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "account_bind_type, receiving_server_type, receiving_server_addr, email_addr, user_name, \
-                retrieval_mode, port_num, use_security, sending_server_type, sending_server_addr, sending_port_num, sending_auth, sending_security, sending_user, \
-                display_name, reply_to_addr, return_addr, account_id, keep_on_server, flag1, flag2, pop_before_smtp, apop, logo_icon_path, preset_account, target_storage, check_interval, index_color, sync_status, ");
+       if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) {
+               SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len,
+                       "incoming_server_type,"
+                       "incoming_server_address,"
+                       "user_email_address,"
+                       "incoming_server_user_name,"
+                       "retrieval_mode,"
+                       "incoming_server_port_number,"
+                       "incoming_server_secure_connection,"
+                       "outgoing_server_type,"
+                       "outgoing_server_address,"
+                       "outgoing_server_port_number,"
+                       "outgoing_server_need_authentication,"
+                       "outgoing_server_secure_connection,"
+                       "outgoing_server_user_name,"
+                       "user_display_name,"
+                       "reply_to_address,"
+                       "return_address,"
+                       "account_id,"
+                       "keep_mails_on_pop_server_after_download,"
+                       "auto_download_size,"
+                       "outgoing_server_use_same_authenticator,"
+                       "pop_before_smtp,"
+                       "incoming_server_requires_apop,"
+                       "logo_icon_path,"
+                       "user_data,"
+                       "user_data_length,"
+                       "check_interval,"
+                       "sync_status,");
                sql_len = strlen(sql_query_string); 
        }
 
-       if (pulloption & EMF_ACC_GET_OPT_ACCOUNT_NAME) {
+       if (pulloption & EMAIL_ACC_GET_OPT_ACCOUNT_NAME) {
                SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " account_name, ");
                sql_len = strlen(sql_query_string); 
        }
 
        /*  get from secure storage, not from db */
-       if (pulloption & EMF_ACC_GET_OPT_OPTIONS) {
-               SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " priority, keep_local_copy, req_delivery_receipt, req_read_receipt, download_limit, block_address, block_subject, display_name_from, \
-                       reply_with_body, forward_with_files, add_myname_card, add_signature, signature,  add_my_address_to_bcc, my_account_id, ");
+       if (pulloption & EMAIL_ACC_GET_OPT_OPTIONS) {
+               SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len,
+                       "priority,"
+                       "keep_local_copy,"
+                       "req_delivery_receipt,"
+                       "req_read_receipt,"
+                       "download_limit,"
+                       "block_address,"
+                       "block_subject,"
+                       "display_name_from,"
+                       "reply_with_body,"
+                       "forward_with_files,"
+                       "add_myname_card,"
+                       "add_signature,"
+                       "signature,"
+                       "add_my_address_to_bcc,"
+                       "account_svc_id,"
+                       "sync_disabled,"
+                       "default_mail_slot_size,"
+                       "smime_type,"
+                       "certificate_path,"
+                       "cipher_type,"
+                       "digest_type,");
+
                sql_len = strlen(sql_query_string); 
        }
+
        /*  dummy value, FROM WHERE clause */
        SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "0 FROM mail_account_tbl WHERE account_id = %d", account_id);
 
@@ -3241,87 +3670,86 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
 
        /*  execute a sql and count rows */
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no matched account found...");
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                goto FINISH_OFF;
        }
 
        /*  Assign query result to structure */
        if (!(p_data_tbl = (emstorage_account_tbl_t *)malloc(sizeof(emstorage_account_tbl_t) * 1)))  {
                EM_DEBUG_EXCEPTION("malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
        memset(p_data_tbl, 0x00, sizeof(emstorage_account_tbl_t) * 1);
        int col_index = 0;
 
-       if (pulloption & EMF_ACC_GET_OPT_DEFAULT) {
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_bind_type), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->receiving_server_type), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->receiving_server_addr),  0, col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_addr), 0, col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->user_name), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->retrieval_mode), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->port_num), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->use_security), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_server_type), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->sending_server_addr), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_port_num), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_auth), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_security), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->sending_user), 0, col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->display_name), 0, col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->reply_to_addr), 0, col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->return_addr), 0, col_index++);
+       if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) {
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->incoming_server_type), col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->incoming_server_address),  0, col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->user_email_address), 0, col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->incoming_server_user_name), 0, col_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->retrieval_mode), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_port_number), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_secure_connection), col_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->outgoing_server_type), col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->outgoing_server_address), 0, col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_port_number), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_need_authentication), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_secure_connection), col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->outgoing_server_user_name), 0, col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->user_display_name), 0, col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->reply_to_address), 0, col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->return_address), 0, col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->keep_on_server), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag1), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag2), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->keep_mails_on_pop_server_after_download), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->auto_download_size), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_use_same_authenticator), col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->pop_before_smtp), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->apop), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_requires_apop), col_index++);
                _get_stmt_field_data_string(hStmt, &(p_data_tbl->logo_icon_path), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->preset_account), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->target_storage), col_index++);
+               _get_stmt_field_data_blob(hStmt, &p_data_tbl->user_data, col_index++);
+               _get_stmt_field_data_int(hStmt, &p_data_tbl->user_data_length, col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->check_interval), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->index_color), col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->sync_status), col_index++);
        }
 
-       if (pulloption & EMF_ACC_GET_OPT_ACCOUNT_NAME)
+       if (pulloption & EMAIL_ACC_GET_OPT_ACCOUNT_NAME)
                _get_stmt_field_data_string(hStmt, &(p_data_tbl->account_name), 0, col_index++);
 
-       if (pulloption & EMF_ACC_GET_OPT_PASSWORD) {
+       if (pulloption & EMAIL_ACC_GET_OPT_PASSWORD) {
                /*  get password file name */
-               if ((error = _get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
-                       EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
+               if ((error = _get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION("_get_password_file_name failed. [%d]", error);
                        goto FINISH_OFF;
                }               
 
                /*  read password from secure storage */
-               if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl->password))) < 0) {
-                       EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage()  failed...");
+               if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl->incoming_server_password))) < 0) {
+                       EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage()  failed. [%d]", error);
                        goto FINISH_OFF;
                }
-               EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name,  p_data_tbl->password);
+
+               EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name,  p_data_tbl->incoming_server_password);
                
-               if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl->sending_password))) < 0) {
-                       EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage()  failed...");
+               if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl->outgoing_server_password))) < 0) {
+                       EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage()  failed. [%d]", error);
                        goto FINISH_OFF;
                }
-               EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name,  p_data_tbl->sending_password);
+               EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name,  p_data_tbl->outgoing_server_password);
        }
 
-       if (pulloption & EMF_ACC_GET_OPT_OPTIONS) {
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.priority), col_index++);
+       if (pulloption & EMAIL_ACC_GET_OPT_OPTIONS) {
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.priority), col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.keep_local_copy), col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.req_delivery_receipt), col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.req_read_receipt), col_index++);
@@ -3334,8 +3762,14 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_myname_card), col_index++);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_signature), col_index++);
                _get_stmt_field_data_string(hStmt, &(p_data_tbl->options.signature), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_my_address_to_bcc), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->my_account_id), col_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.add_my_address_to_bcc), col_index++);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_svc_id), col_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->sync_disabled), col_index++);
+               _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->default_mail_slot_size), col_index++);
+               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->smime_type), col_index++);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl->certificate_path), 0, col_index++);
+               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->cipher_type), col_index++);
+               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->digest_type), col_index++);
        }
 
        ret = true;
@@ -3351,7 +3785,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -3370,21 +3804,21 @@ INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int *
        EM_DEBUG_FUNC_BEGIN("account_id[%d], password_length[%p], err_code[%p]", account_id, password_length, err_code);
 
        if (account_id <= 0 || password_length == NULL)  {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
        char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
        char *temp_password = NULL;
        
 
        /*  get password file name */
-       if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+       if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
                goto FINISH_OFF;
        }               
@@ -3411,18 +3845,18 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t* account_tbl, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account_tbl, transaction, err_code);
        
-       if (account_id < FIRST_ACCOUNT_ID || !account)  {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+       if (account_id < FIRST_ACCOUNT_ID || !account_tbl)  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc, ret = false;
  
        DB_STMT hStmt = NULL;
@@ -3435,111 +3869,118 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
                
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
                "UPDATE mail_account_tbl SET"
-               " account_bind_type = ?"
-               ", account_name = ?"
-               ", receiving_server_type = ?"
-               ", receiving_server_addr = ?"
-               ", email_addr = ?"
-               ", user_name = ?"
+               "  account_name = ?"
+               ", logo_icon_path = ?"
+               ", user_data = ?"
+               ", user_data_length = ?"
+               ", account_svc_id = ?"
+               ", sync_status = ?"
+               ", sync_disabled = ?"
+               ", default_mail_slot_size = ?"
+               ", user_display_name = ?"
+               ", user_email_address = ?"
+               ", reply_to_address = ?"
+               ", return_address = ?"
+               ", incoming_server_type = ?"
+               ", incoming_server_address = ?"
+               ", incoming_server_port_number = ?"
+               ", incoming_server_user_name = ?"
+               ", incoming_server_secure_connection = ?"
                ", retrieval_mode = ?"
-               ", port_num = ?"
-               ", use_security = ?"
-               ", sending_server_type = ?"
-               ", sending_server_addr = ?"
-               ", sending_port_num = ?"
-               ", sending_auth = ?"
-               ", sending_security = ?"
-               ", sending_user = ?"
-               ", display_name = ?"
-               ", reply_to_addr = ?"
-               ", return_addr = ?"
-               ", keep_on_server = ?"
-               ", flag1 = ?"
-               ", flag2 = ?"
-               ", pop_before_smtp = ?"            /*  POP before SMTP authentication */
-               ", apop = ?"                       /*  APOP authentication */
-               ", logo_icon_path = ?"             /*  Receving Option : Account logo icon  */
-               ", preset_account = ?"             /*  Receving Option : Preset account or not  */
-               ", target_storage = ?"             /*  Receving Option : Specifies the targetStorage. 0 is phone, 1 is MMC  */
-               ", check_interval = ?"             /*  Receving Option : Specifies the check interval. Unit is minute  */
-               ", priority = ?"                   /*  Sending Option : Specifies the prority. 1=high 3=normal 5=low  */
-               ", keep_local_copy = ?"            /*  Sending Option :   */
-               ", req_delivery_receipt = ?"       /*  Sending Option :   */
-               ", req_read_receipt = ?"           /*  Sending Option :   */
-               ", download_limit = ?"             /*  Sending Option :   */
-               ", block_address = ?"              /*  Sending Option :   */
-               ", block_subject = ?"              /*  Sending Option :   */
-               ", display_name_from = ?"          /*  Sending Option :   */
-               ", reply_with_body = ?"            /*  Sending Option :   */
-               ", forward_with_files = ?"         /*  Sending Option :   */
-               ", add_myname_card = ?"            /*  Sending Option :   */
-               ", add_signature = ?"              /*  Sending Option :   */
-               ", signature = ?"                  /*  Sending Option :   */
-               ", add_my_address_to_bcc = ?"      /*  Sending Option :   */
-               ", my_account_id = ?"              /*  Support 'My Account' */
-               ", index_color = ?"                /*  Index color */
-               ", sync_status = ?"                /*  Sync Status */
+               ", keep_mails_on_pop_server_after_download = ?"
+               ", check_interval = ?"
+               ", auto_download_size = ?"
+               ", outgoing_server_type = ?"
+               ", outgoing_server_address = ?"
+               ", outgoing_server_port_number = ?"
+               ", outgoing_server_user_name = ?"
+               ", outgoing_server_secure_connection = ?"
+               ", outgoing_server_need_authentication = ?"
+               ", outgoing_server_use_same_authenticator = ?"
+               ", priority = ?"
+               ", keep_local_copy = ?"
+               ", req_delivery_receipt = ?"
+               ", req_read_receipt = ?"
+               ", download_limit = ?"
+               ", block_address = ?"
+               ", block_subject = ?"
+               ", display_name_from = ?"
+               ", reply_with_body = ?"
+               ", forward_with_files = ?"
+               ", add_myname_card = ?"
+               ", add_signature = ?"
+               ", signature = ?"
+               ", add_my_address_to_bcc = ?"
+               ", pop_before_smtp = ?"
+               ", incoming_server_requires_apop = ?"
+               ", smime_type = ?"
+               ", certificate_path = ?"
+               ", cipher_type = ?"
+               ", digest_type = ?"
                " WHERE account_id = ?");        
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       EM_DEBUG_LOG("SQL[%s]", sql_query_string);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("sqlite3_prepare fail:(%d) %s", rc, sqlite3_errmsg(local_db_handle)));
        
        int i = 0;
-       
-       _bind_stmt_field_data_int(hStmt, i++, account->account_bind_type);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, i++, account->receiving_server_type);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->receiving_server_addr, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->email_addr, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, i++, account->retrieval_mode);
-       _bind_stmt_field_data_int(hStmt, i++, account->port_num);
-       _bind_stmt_field_data_int(hStmt, i++, account->use_security);
-       _bind_stmt_field_data_int(hStmt, i++, account->sending_server_type);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->sending_server_addr, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, i++, account->sending_port_num);
-       _bind_stmt_field_data_int(hStmt, i++, account->sending_auth);
-       _bind_stmt_field_data_int(hStmt, i++, account->sending_security);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->sending_user, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->reply_to_addr, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)account->return_addr, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, i++, account->keep_on_server);
-       _bind_stmt_field_data_int(hStmt, i++, account->flag1);
-       _bind_stmt_field_data_int(hStmt, i++, account->flag2);
-       _bind_stmt_field_data_int(hStmt, i++, account->pop_before_smtp);
-       _bind_stmt_field_data_int(hStmt, i++, account->apop);
-       _bind_stmt_field_data_string(hStmt, i++, account->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, i++, account->preset_account);
-       _bind_stmt_field_data_int(hStmt, i++, account->target_storage);
-       _bind_stmt_field_data_int(hStmt, i++, account->check_interval);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.priority);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.keep_local_copy);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.req_delivery_receipt);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.req_read_receipt);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.download_limit);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.block_address);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.block_subject);
-       _bind_stmt_field_data_string(hStmt, i++, account->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.reply_with_body);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.forward_with_files);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.add_myname_card);
-       _bind_stmt_field_data_int(hStmt, i++, account->options.add_signature);
-       _bind_stmt_field_data_string(hStmt, i++, account->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
-       if (account->options.add_my_address_to_bcc != 0)
-               account->options.add_my_address_to_bcc = 1;
-       _bind_stmt_field_data_int(hStmt, i++, account->options.add_my_address_to_bcc);
-       _bind_stmt_field_data_int(hStmt, i++, account->my_account_id);
-       _bind_stmt_field_data_int(hStmt, i++, account->index_color);
-       _bind_stmt_field_data_int(hStmt, i++, account->sync_status);
+
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_blob(hStmt, i++, account_tbl->user_data, account_tbl->user_data_length);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->user_data_length);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_svc_id);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_status);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_disabled);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->default_mail_slot_size);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_email_address, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->reply_to_address, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->return_address, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_type);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_address, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_port_number);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_secure_connection);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->retrieval_mode);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->keep_mails_on_pop_server_after_download);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->check_interval);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->auto_download_size);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_type);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_address, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_port_number);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_user_name, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_secure_connection);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_need_authentication);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_use_same_authenticator);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.priority);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.keep_local_copy);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_delivery_receipt);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_read_receipt);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.download_limit);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_address);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_subject);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.reply_with_body);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.forward_with_files);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_myname_card);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_signature);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_my_address_to_bcc);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->pop_before_smtp);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_requires_apop);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->smime_type);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->certificate_path, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type);
        _bind_stmt_field_data_int(hStmt, i++, account_id);
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        /*  validate account existence */
@@ -3547,35 +3988,35 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
        if (rc == 0) {
                EM_DEBUG_EXCEPTION(" no matched account found...");
        
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                goto FINISH_OFF;
        }
        
        /*  get password file name */
-       if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+       if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
                goto FINISH_OFF;
        }
 
        /*  save passwords to the secure storage */
-       EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account->password, send_password_file_name, account->sending_password);
-       if (account->password && (strlen(account->password) > 0)) {
-               if (ssm_write_buffer(account->password, strlen(account->password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
-                       EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -recv password : file[%s]", recv_password_file_name);
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+       EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account_tbl->incoming_server_password, send_password_file_name, account_tbl->outgoing_server_password);
+       if (account_tbl->incoming_server_password && (strlen(account_tbl->incoming_server_password) > 0)) {
+               if (ssm_write_buffer(account_tbl->incoming_server_password, strlen(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+                       EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -recv incoming_server_password : file[%s]", recv_password_file_name);
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;                
                }
        }
 
-       if (account->sending_password && (strlen(account->sending_password) > 0)) {
-               if (ssm_write_buffer(account->sending_password, strlen(account->sending_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+       if (account_tbl->outgoing_server_password && (strlen(account_tbl->outgoing_server_password) > 0)) {
+               if (ssm_write_buffer(account_tbl->outgoing_server_password, strlen(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
                        EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -send password : file[%s]", send_password_file_name);
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;                
                }
        }
        
-       if (!emstorage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account->account_id, 0, NULL, 0))
+       if (!emstorage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account_tbl->account_id, 0, NULL, 0))
                EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event[ NOTI_ACCOUNT_UPDATE] : Notification Failed >>> ");
        ret = true;
        
@@ -3587,7 +4028,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -3602,18 +4043,60 @@ FINISH_OFF:
        return ret;
 }
 
+INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account_id, char *field_name, int value, int transaction)
+{
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], field_name[%s], value[%d], transaction[%d]", account_id, field_name, value, transaction);
+       int error = EMAIL_ERROR_NONE;
+       int rc = 0;
+       int result = 0;
+       char sql_query_string[QUERY_SIZE] = {0, };
+       sqlite3 *local_db_handle = NULL;
+
+       if (!account_id  || !field_name) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       local_db_handle = emstorage_get_db_connection();
+
+       /* Write query string */
+       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_account_tbl SET %s = %d WHERE account_id = %d", field_name, value, account_id);
+
+       EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+       /* Execute query */
+       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       if (sqlite3_changes(local_db_handle) == 0)
+               EM_DEBUG_LOG("no mail matched...");
+
+
+FINISH_OFF:
+       result = (error == EMAIL_ERROR_NONE) ? true : false;
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, error);
+       _DISCONNECT_DB;
+
+       if (!emstorage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account_id, 0, field_name, value))
+               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event failed : NOTI_ACCOUNT_UPDATE [%s,%d]", field_name, value);
+
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
+
 INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code) 
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], result_sync_status [%p], err_code[%p]", account_id, result_sync_status, err_code);
 
        if(!result_sync_status) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
-       int error = EMF_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index;
+       int error = EMAIL_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index;
        char sql_query_string[QUERY_SIZE] = {0, };
        char **result = NULL;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -3624,12 +4107,12 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl");       
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        if (!count) {
                EM_DEBUG_EXCEPTION("no matched account found...");
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                goto FINISH_OFF;
        }
 
@@ -3658,11 +4141,11 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, emstorage_set_type_t set_operator, int sync_status, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], set_operator[%d], sync_status [%d], transaction[%d], err_code[%p]", account_id, set_operator, sync_status, transaction, err_code);
        
-       int error = EMF_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status;
+       int error = EMAIL_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status;
        char sql_query_string[QUERY_SIZE] = {0, };
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
@@ -3679,8 +4162,8 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, emstor
                                set_value = result_sync_status & (~set_value);
                                break;
                        default:
-                               EM_DEBUG_EXCEPTION("EMF_ERROR_NOT_SUPPORTED [%d]", set_operator);
-                               error = EMF_ERROR_NOT_SUPPORTED;
+                               EM_DEBUG_EXCEPTION("EMAIL_ERROR_NOT_SUPPORTED [%d]", set_operator);
+                               error = EMAIL_ERROR_NOT_SUPPORTED;
                                break;
                }
                EM_DEBUG_LOG("set_value [%d]", set_value);
@@ -3691,19 +4174,19 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, emstor
        if(account_id)
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE account_id = %d", set_value, account_id);       
        else
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE receiving_server_type <> 5", set_value);        
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE incoming_server_type <> 5", set_value);         
 
        EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        rc = sqlite3_changes(local_db_handle);
 
        if (rc == 0) {
                EM_DEBUG_EXCEPTION("no matched account found...");
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                goto FINISH_OFF;
        }
        
@@ -3724,19 +4207,20 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code);
        
-       if (!account)  {
-               EM_DEBUG_EXCEPTION("account[%p], transaction[%d], err_code[%p]", account, transaction, err_code);
+       if (!account_tbl)  {
+               EM_DEBUG_EXCEPTION("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
+       int error_from_ssm = 0;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
@@ -3750,7 +4234,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account, int tr
        char **result = NULL;
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        if (NULL==result[1]) rc = 1;
@@ -3758,161 +4242,169 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account, int tr
        sqlite3_free_table(result);
        result = NULL;
 
-       account->account_id = rc;
+       account_tbl->account_id = rc;
 
-       if ((error = _get_password_file_name(account->account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+       if ((error = _get_password_file_name(account_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
                goto FINISH_OFF;
        }
 
-       EM_DEBUG_LOG(" >>>> ACCOUNT_ID [ %d ] ", account->account_id);
+       EM_DEBUG_LOG(" >>>> ACCOUNT_ID [ %d ] ", account_tbl->account_id);
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
                "INSERT INTO mail_account_tbl VALUES "
                "(        "
-               "   ?  "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "                /*  password - for receving */
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "                /*  sending_password */
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "         /*  POP before SMTP authentication */
-               "  , ? "         /*  APOP Authentication */
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "
-               "  , ? "                /*  add full_address_bcc */
-               "  , ? "                /*  my account id */
-               "  , ? "          /*  index_color */
-               "  , ? "          /*  Sync Status */
+               "    ? "  /*   account_id */
+               "  , ? "  /*   account_name */
+               "  , ? "  /*   logo_icon_path */
+               "  , ? "  /*   user_data */
+               "  , ? "  /*   user_data_length */
+               "  , ? "  /*   account_svc_id */
+               "  , ? "  /*   sync_status */
+               "  , ? "  /*   sync_disabled */
+               "  , ? "  /*   default_mail_slot_size */
+               "  , ? "  /*   user_display_name */
+               "  , ? "  /*   user_email_address */
+               "  , ? "  /*   reply_to_address */
+               "  , ? "  /*   return_address */
+               "  , ? "  /*   incoming_server_type */
+               "  , ? "  /*   incoming_server_address */
+               "  , ? "  /*   incoming_server_port_number */
+               "  , ? "  /*   incoming_server_user_name */
+               "  , ? "  /*   incoming_server_password */
+               "  , ? "  /*   incoming_server_secure_connection */
+               "  , ? "  /*   retrieval_mode */
+               "  , ? "  /*   keep_mails_on_pop_server_after_download */
+               "  , ? "  /*   check_interval */
+               "  , ? "  /*   auto_download_size */
+               "  , ? "  /*   outgoing_server_type */
+               "  , ? "  /*   outgoing_server_address */
+               "  , ? "  /*   outgoing_server_port_number */
+               "  , ? "  /*   outgoing_server_user_name */
+               "  , ? "  /*   outgoing_server_password */
+               "  , ? "  /*   outgoing_server_secure_connection */
+               "  , ? "  /*   outgoing_server_need_authentication */
+               "  , ? "  /*   outgoing_server_use_same_authenticator */
+               "  , ? "  /*   priority */
+               "  , ? "  /*   keep_local_copy */
+               "  , ? "  /*   req_delivery_receipt */
+               "  , ? "  /*   req_read_receipt */
+               "  , ? "  /*   download_limit */
+               "  , ? "  /*   block_address */
+               "  , ? "  /*   block_subject */
+               "  , ? "  /*   display_name_from */
+               "  , ? "  /*   reply_with_body */
+               "  , ? "  /*   forward_with_files */
+               "  , ? "  /*   add_myname_card */
+               "  , ? "  /*   add_signature */
+               "  , ? "  /*   signature */
+               "  , ? "  /*   add_my_address_to_bcc */
+               "  , ? "  /*   pop_before_smtp */
+               "  , ? "  /*   incoming_server_requires_apop */
+               "  , ? "  /*   smime_type */
+               "  , ? "  /*   certificate_path */
+               "  , ? "  /*   cipher_type */
+               "  , ? "  /*   digest_type */
                ") ");
        
-       
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
-       _bind_stmt_field_data_int(hStmt, ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->account_bind_type);
-       _bind_stmt_field_data_string(hStmt, ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->receiving_server_type);
-       _bind_stmt_field_data_string(hStmt, RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->receiving_server_addr, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->email_addr, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL, (char *)"", 0, PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL, account->retrieval_mode);
-       _bind_stmt_field_data_int(hStmt, PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL, account->port_num);
-       _bind_stmt_field_data_int(hStmt, USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL, account->use_security);
-       _bind_stmt_field_data_int(hStmt, SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_server_type);
-       _bind_stmt_field_data_string(hStmt, SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->sending_server_addr, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_port_num);
-       _bind_stmt_field_data_int(hStmt, SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_auth);
-       _bind_stmt_field_data_int(hStmt, SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_security);
-       _bind_stmt_field_data_string(hStmt, SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->sending_user, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL, (char *)"", 0, SENDING_PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->reply_to_addr, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_string(hStmt, RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->return_addr, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL, account->account_id);
-       _bind_stmt_field_data_int(hStmt, KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL, account->keep_on_server);
-       _bind_stmt_field_data_int(hStmt, FLAG1_IDX_IN_MAIL_ACCOUNT_TBL, account->flag1);
-       _bind_stmt_field_data_int(hStmt, FLAG2_IDX_IN_MAIL_ACCOUNT_TBL, account->flag2);
-       _bind_stmt_field_data_int(hStmt, POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL, account->pop_before_smtp); /* POP before SMTP authentication [deepam.p@siso.com] */
-       _bind_stmt_field_data_int(hStmt, APOP_IDX_IN_MAIL_ACCOUNT_TBL, account->apop); /* APOP Support [deepam.p@siso.com] */
-       _bind_stmt_field_data_string(hStmt, LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL, account->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL, account->preset_account);
-       _bind_stmt_field_data_int(hStmt, TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL, account->target_storage);
-       _bind_stmt_field_data_int(hStmt, CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL, account->check_interval);
-       _bind_stmt_field_data_int(hStmt, PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.priority);
-       _bind_stmt_field_data_int(hStmt, KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.keep_local_copy);
-       _bind_stmt_field_data_int(hStmt, REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.req_delivery_receipt);
-       _bind_stmt_field_data_int(hStmt, REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.req_read_receipt);
-       _bind_stmt_field_data_int(hStmt, DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.download_limit);
-       _bind_stmt_field_data_int(hStmt, BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL, account->options.block_address);
-       _bind_stmt_field_data_int(hStmt, BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.block_subject);
-       _bind_stmt_field_data_string(hStmt, DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL, account->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
-       _bind_stmt_field_data_int(hStmt, REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.reply_with_body);
-       _bind_stmt_field_data_int(hStmt, FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL, account->options.forward_with_files);
-       _bind_stmt_field_data_int(hStmt, ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_myname_card);
-       _bind_stmt_field_data_int(hStmt, ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_signature);
-       _bind_stmt_field_data_string(hStmt, SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL, account->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
-       if (account->options.add_my_address_to_bcc != 0)
-               account->options.add_my_address_to_bcc = 1;
-       _bind_stmt_field_data_int(hStmt, ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_my_address_to_bcc);
-       _bind_stmt_field_data_int(hStmt, MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL, account->my_account_id);
-       _bind_stmt_field_data_int(hStmt, INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL, account->index_color);
-       _bind_stmt_field_data_int(hStmt, SYNC_STATUS_IDX_IN_MAIL_ACCOUNT_TBL, account->sync_status);
+       int i = 0;
+
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_id);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_blob(hStmt, i++, account_tbl->user_data, account_tbl->user_data_length);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->user_data_length);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_svc_id);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_status);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_disabled);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->default_mail_slot_size);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_email_address, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->reply_to_address, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->return_address, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_type);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_address, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_port_number);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)"", 0, PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_secure_connection);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->retrieval_mode);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->keep_mails_on_pop_server_after_download);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->check_interval);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->auto_download_size);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_type);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_address, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_port_number);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_user_name, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char *)"", 0, SENDING_PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_secure_connection);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_need_authentication);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_use_same_authenticator);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.priority);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.keep_local_copy);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_delivery_receipt);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_read_receipt);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.download_limit);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_address);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_subject);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.reply_with_body);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.forward_with_files);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_myname_card);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_signature);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_my_address_to_bcc);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->pop_before_smtp);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_requires_apop);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->smime_type);
+       _bind_stmt_field_data_string(hStmt, i++, account_tbl->certificate_path, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type);
+       _bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
 
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
        
 
        /*  save passwords to the secure storage */
-       EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account->password, send_password_file_name, account->sending_password);
-       if (ssm_write_buffer(account->password, strlen(account->password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
-               EM_DEBUG_EXCEPTION("ssm_write_buffer failed - recv password : file[%s]", recv_password_file_name);
-               error = EMF_ERROR_SYSTEM_FAILURE;
+       EM_DEBUG_LOG("save to the secure storage : recv_file[%s], send_file[%s]", recv_password_file_name, send_password_file_name);
+       if ( (error_from_ssm = ssm_write_buffer(account_tbl->incoming_server_password, strlen(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+               EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d] - recv password : file[%s]", error_from_ssm, recv_password_file_name);
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;                
        }
-       if (ssm_write_buffer(account->sending_password, strlen(account->sending_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
-               EM_DEBUG_EXCEPTION("ssm_write_buffer failed - send password : file[%s]", send_password_file_name);
-               error = EMF_ERROR_SYSTEM_FAILURE;
+       if ( (error_from_ssm = ssm_write_buffer(account_tbl->outgoing_server_password, strlen(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+               EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d] - send password : file[%s]", error_from_ssm, send_password_file_name);
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;                
        }
 
-       if (!emstorage_notify_storage_event(NOTI_ACCOUNT_ADD, account->account_id, 0, NULL, 0))
-               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
        ret = true;
+
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+       if (!emstorage_notify_storage_event(NOTI_ACCOUNT_ADD, account_tbl->account_id, 0, NULL, 0))
+               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
        
 FINISH_OFF:
        
        if (hStmt != NULL)  {
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
-                       EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
                }               
        }
        else
                EM_DEBUG_LOG("hStmt is NULL!!!");
        
-       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
        
        if (err_code != NULL)
@@ -3931,12 +4423,12 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int
                EM_DEBUG_EXCEPTION(" account_id[%d]", account_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
 
@@ -3947,7 +4439,7 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int
        char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
 
        /*  get password file name */
-       if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+       if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
                goto FINISH_OFF;
        }
@@ -3957,28 +4449,28 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_account_tbl WHERE account_id = %d", account_id);
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        /*  validate account existence */
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no matched account found...");
-               error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
                goto FINISH_OFF;
        }
 
                /*  delete from secure storage */
        if (ssm_delete_file(recv_password_file_name,  SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
                EM_DEBUG_EXCEPTION(" ssm_delete_file failed -recv password : file[%s]", recv_password_file_name);
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;                
        }
        if (ssm_delete_file(send_password_file_name,  SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
                EM_DEBUG_EXCEPTION(" ssm_delete_file failed -send password : file[%s]", send_password_file_name);
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;                
        }
        ret = true;
@@ -3989,7 +4481,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -4009,12 +4501,12 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t** account_list,
        EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        if (count > 0)  {
                if (!account_list || !*account_list)  {
                        EM_DEBUG_EXCEPTION("account_list[%p], count[%d]", account_list, count);
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
                
@@ -4023,19 +4515,21 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t** account_list,
                
                for (; i < count; i++)  {
                        EM_SAFE_FREE(p[i].account_name);
-                       EM_SAFE_FREE(p[i].receiving_server_addr);
-                       EM_SAFE_FREE(p[i].email_addr);
-                       EM_SAFE_FREE(p[i].user_name);
-                       EM_SAFE_FREE(p[i].password);
-                       EM_SAFE_FREE(p[i].sending_server_addr);
-                       EM_SAFE_FREE(p[i].sending_user);
-                       EM_SAFE_FREE(p[i].sending_password);
-                       EM_SAFE_FREE(p[i].display_name);
-                       EM_SAFE_FREE(p[i].reply_to_addr);
-                       EM_SAFE_FREE(p[i].return_addr);
+                       EM_SAFE_FREE(p[i].incoming_server_address);
+                       EM_SAFE_FREE(p[i].user_email_address);
+                       EM_SAFE_FREE(p[i].user_data);
+                       EM_SAFE_FREE(p[i].incoming_server_user_name);
+                       EM_SAFE_FREE(p[i].incoming_server_password);
+                       EM_SAFE_FREE(p[i].outgoing_server_address);
+                       EM_SAFE_FREE(p[i].outgoing_server_user_name);
+                       EM_SAFE_FREE(p[i].outgoing_server_password);
+                       EM_SAFE_FREE(p[i].user_display_name);
+                       EM_SAFE_FREE(p[i].reply_to_address);
+                       EM_SAFE_FREE(p[i].return_address);
                        EM_SAFE_FREE(p[i].logo_icon_path);
                        EM_SAFE_FREE(p[i].options.display_name_from);
                        EM_SAFE_FREE(p[i].options.signature);
+                       EM_SAFE_FREE(p[i].certificate_path);
                }
                
                EM_SAFE_FREE(p); 
@@ -4060,12 +4554,12 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int
                EM_DEBUG_EXCEPTION(" account_list[%d], local_yn[%d], count[%p]", account_id, local_yn, count);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -4076,7 +4570,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -4097,7 +4591,7 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_mailbox(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
        
@@ -4105,107 +4599,53 @@ INTERNAL_FUNC int emstorage_get_mailbox(int account_id, int local_yn, email_mail
                EM_DEBUG_EXCEPTION("Invalid parameters");
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
 
                return false;
        }
 
-       int i = 0, rc, count = 0, ret = false, col_index;
-       int error = EMF_ERROR_NONE;
-       emstorage_mailbox_tbl_t* p_data_tbl = NULL;
-       char **result;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-       EMSTORAGE_START_READ_TRANSACTION(transaction);
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
                
        if (account_id == ALL_ACCOUNT) {
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl ", fields);
-               if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL)
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE local_yn = %d ", local_yn);
+               if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL)
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " WHERE local_yn = %d ", local_yn);
        }
        else {
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d  ", fields, account_id);
-       if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL)
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND local_yn = %d ", local_yn);
+               SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d  ", account_id);
+               if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL)
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND local_yn = %d ", local_yn);
        }
 
        switch (sort_type) {
                case EMAIL_MAILBOX_SORT_BY_NAME_ASC :
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_name ASC");
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_name ASC");
                        break;
 
                case EMAIL_MAILBOX_SORT_BY_NAME_DSC :
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_name DESC");
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_name DESC");
                        break;
 
                case EMAIL_MAILBOX_SORT_BY_TYPE_ASC :
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_type ASC");
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_type ASC");
                        break;
 
                case EMAIL_MAILBOX_SORT_BY_TYPE_DSC :
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_type DEC");
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_type DEC");
                        break;
        }
 
-       EM_DEBUG_LOG("emstorage_get_mailbox : query[%s]", sql_query_string);
+       EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
 
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
-       if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count))) {
-               EM_DEBUG_EXCEPTION(" malloc failed...");
-               
-               error = EMF_ERROR_OUT_OF_MEMORY;
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
-       
-       memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-       
-       col_index = 11;
-       
-       for (i = 0; i < count; i++)  {
-               _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
-               _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
-               _get_table_field_data_int(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
-               _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
-       }
-       
+
        ret = true;
        
 FINISH_OFF:
-       if (result)
-               sqlite3_free_table(result);
-
-       if (ret == true)  {
-               *mailbox_list = p_data_tbl;
-               *select_num = count;
-               EM_DEBUG_LOG("Mailbox Count [ %d]", count);
-       }
-       else if (p_data_tbl != NULL)
-               emstorage_free_mailbox(&p_data_tbl, count, NULL);
-       
-       if (hStmt != NULL)  {
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK) {
-                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
        
        if (err_code != NULL)
                *err_code = error;
@@ -4214,141 +4654,46 @@ FINISH_OFF:
        return ret;
 }
 
-
-INTERNAL_FUNC int emstorage_get_mailbox_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
-       
-       if (!select_num || !mailbox_list) {
-               EM_DEBUG_EXCEPTION("Invalid parameters");
-               
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-
-               return false;
-       }
 
-       int i = 0;
-       int rc;
-       int count = 0;
        int ret = false;
-       int col_index;
-       int error = EMF_ERROR_NONE;
-       emstorage_mailbox_tbl_t* p_data_tbl = NULL;
-       char **result;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-       int add = 0;
-       int read_count = 0;
-       int total_count = 0;
-
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-       EMSTORAGE_START_READ_TRANSACTION(transaction);
+       int error = EMAIL_ERROR_NONE;
+       int where_clause_count = 0;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
 
-       add = 0;
-       if (with_count == 0) {  /*  without count  */
-               col_index = 11;
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl AS MBT", fields);
-               if (account_id > ALL_ACCOUNT) {
-                       add = 1;
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d  ", account_id);
-               }
-       }
-       else {  /*  with read count and total count */
-               col_index = 13;
-               if (account_id > ALL_ACCOUNT) {
-                       add = 1;
-                       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 WHERE account_id = %d GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name WHERE account_id = %d ", fields, account_id, account_id);
-               }
-               else {
-                       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 ", fields);
-               }
+       if (!select_num || !mailbox_list) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               error = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
        }
 
-       if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL) {
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s local_yn = %d ", (add ? "WHERE" : "AND"), local_yn);
+       if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL) {
+               SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), "WHERE local_yn = %d ",  local_yn);
+               where_clause_count++;
        }
 
-       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY MBT.mailbox_name ");
-       EM_DEBUG_LOG("query[%s]", sql_query_string);
+       if (account_id > 0) {
+               if (where_clause_count == 0) {
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " WHERE ");
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " account_id = %d ", account_id);
+               }
+               else
+                       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND account_id = %d ", account_id);
+       }
 
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
-       EM_DEBUG_LOG("result count [%d]", count);
+       SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY MBT.mailbox_name ");
+       EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
 
-       if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count)))  {
-               EM_DEBUG_EXCEPTION("malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 1, 1, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
-       
-       memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-       
-       for (i = 0; i < count; i++)  {
-               _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
-               _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
-               _get_table_field_data_int(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
-               _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
 
-               if (with_count == 1) {
-                       _get_table_field_data_int(result, &(total_count), col_index++);
-                       p_data_tbl[i].total_mail_count_on_local = total_count;
-                       _get_table_field_data_int(result, &(read_count), col_index++);
-                       p_data_tbl[i].unread_count = total_count - read_count;                  /*  return unread count, NOT  */
-               }
-               /*
-               EM_DEBUG_LOG("[%d]", i);
-               EM_DEBUG_LOG("p_data_tbl[%d].mailbox_id[%d]", i, p_data_tbl[i].mailbox_id);
-               EM_DEBUG_LOG("p_data_tbl[%d].account_id[%d]", i, p_data_tbl[i].account_id);
-               EM_DEBUG_LOG("p_data_tbl[%d].local_yn[%d]", i, p_data_tbl[i].local_yn);
-               EM_DEBUG_LOG("p_data_tbl[%d].mailbox_name[%s]", i, p_data_tbl[i].mailbox_name);
-               EM_DEBUG_LOG("p_data_tbl[%d].mailbox_type[%d]", i, p_data_tbl[i].mailbox_type);
-               EM_DEBUG_LOG("p_data_tbl[%d].alias[%s]", i, p_data_tbl[i].alias);
-               EM_DEBUG_LOG("p_data_tbl[%d].sync_with_server_yn[%d]", i, p_data_tbl[i].sync_with_server_yn);
-               EM_DEBUG_LOG("p_data_tbl[%d].modifiable_yn[%d]", i, p_data_tbl[i].modifiable_yn);
-               EM_DEBUG_LOG("p_data_tbl[%d].has_archived_mails[%d]", i, p_data_tbl[i].has_archived_mails);
-               EM_DEBUG_LOG("p_data_tbl[%d].mail_slot_size[%d]", i, p_data_tbl[i].mail_slot_size);
-               EM_DEBUG_LOG("p_data_tbl[%d].unread_count[%d]", i, p_data_tbl[i].unread_count);
-               EM_DEBUG_LOG("p_data_tbl[%d].total_mail_count_on_local[%d]", i, p_data_tbl[i].total_mail_count_on_local);
-               EM_DEBUG_LOG("p_data_tbl[%d].total_mail_count_on_server[%d]", i, p_data_tbl[i].total_mail_count_on_server);
-               */
-       }
-       
        ret = true;
        
 FINISH_OFF:
-       if (result)
-               sqlite3_free_table(result);
-
-       if (ret == true)  {
-               *mailbox_list = p_data_tbl;
-               *select_num = count;
-               EM_DEBUG_LOG("Mailbox Count [ %d]", count);
-       }
-       else if (p_data_tbl != NULL)
-               emstorage_free_mailbox(&p_data_tbl, count, NULL);
-       
-       if (hStmt != NULL)  {
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK) {
-                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
        
        if (err_code != NULL)
                *err_code = error;
@@ -4364,71 +4709,29 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_
                EM_DEBUG_EXCEPTION("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p]", account_id, parent_mailbox_name, select_num, mailbox_list);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
-       int i = 0, rc, count = 0, ret = false, col_index;
-       int error = EMF_ERROR_NONE;
-       emstorage_mailbox_tbl_t* p_data_tbl = NULL;
-       char **result;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-       EMSTORAGE_START_READ_TRANSACTION(transaction);
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
 
        if (parent_mailbox_name)
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d  AND UPPER(mailbox_name) LIKE UPPER('%s/%%') ORDER BY mailbox_name", fields, account_id, 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);
        else
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d  AND (mailbox_name NOT LIKE '%%/%%') ORDER BY mailbox_name", fields, account_id);
-
-       EM_DEBUG_LOG("query : %s", sql_query_string);
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+               SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d  AND (mailbox_name NOT LIKE '%%/%%') ORDER BY mailbox_name", account_id);
 
+       EM_DEBUG_LOG("conditional_clause_string", conditional_clause_string);
 
-       if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count)))  {
-               EM_DEBUG_EXCEPTION(" malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
-       
-       memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-       col_index = 11;
-       
-       for (i = 0; i < count; i++)  {
-               _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
-               _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
-               _get_table_field_data_int(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
-               _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
-               _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
-       }
-
-       if (result)
-               sqlite3_free_table(result);
 
        ret = true;
        
 FINISH_OFF:
-       if (ret == true)  {
-               *mailbox_list = p_data_tbl;
-               *select_num = count;
-               EM_DEBUG_LOG(" Mailbox Count [ %d] ", count);
-       }
-       else if (p_data_tbl != NULL)
-               emstorage_free_mailbox(&p_data_tbl, count, NULL);
-       
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
        
        if (err_code != NULL)
                *err_code = error;
@@ -4441,100 +4744,29 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int loc
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
        if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list)  {
-               EM_DEBUG_EXCEPTION("\account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p]", account_id, local_yn, select_num, mailbox_list);
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+
                return false;
        }
 
-       int i = 0, rc, count = 0, ret = false;
-       int error = EMF_ERROR_NONE;
-       emstorage_mailbox_tbl_t* p_data_tbl = NULL;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-       
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-       EMSTORAGE_START_READ_TRANSACTION(transaction);
-       
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND modifiable_yn = 0 ORDER BY mailbox_name", fields, account_id);
-       EM_DEBUG_LOG("sql[%s]", sql_query_string);
-       
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
        
-       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("sqlite3_step fail:%d", rc));
-
-       char **result;
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-       sqlite3_free_table(result);
-       if (count == 0) {
-               EM_DEBUG_EXCEPTION(" no mailbox_name found...");
-               
-               ret = true;
-               goto FINISH_OFF;
-       }
+       SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND modifiable_yn = 0 ORDER BY mailbox_name", account_id);
+       EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
        
-       if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count)))  {
-               EM_DEBUG_EXCEPTION(" malloc failed...");
-               
-               error = EMF_ERROR_OUT_OF_MEMORY;
+       if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
                goto FINISH_OFF;
        }
        
-       memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-       
-       int col_index = 0;
-       for (i = 0; i < count; i++)  {
-               col_index = 0;
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].mailbox_id), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].local_yn), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].mailbox_name), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].alias), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sync_with_server_yn), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].modifiable_yn), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].has_archived_mails), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].mail_slot_size), col_index++);
-               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("sqlite3_step fail:%d", rc));
-       }
-       
        ret = true;
        
 FINISH_OFF:
-       if (ret == true) {
-               *mailbox_list = p_data_tbl;
-               *select_num = count;
-               EM_DEBUG_LOG("Mailbox Count[%d]", count);
-       }
-       else if (p_data_tbl != NULL)
-               emstorage_free_mailbox(&p_data_tbl, count, NULL);
-       
-       if (hStmt != NULL)  {
-               EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
-
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK)  {
-                       EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
        
        if (err_code != NULL)
                *err_code = error;
@@ -4543,7 +4775,52 @@ FINISH_OFF:
        return ret;
 }
 
+INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id, int input_transaction)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_transaction [%d]", input_mailbox_id, input_transaction);
+
+       int      result_code = false;
+       int      error = EMAIL_ERROR_NONE;
+       int      rc;
+       time_t   current_time = 0;
+       char     sql_query_string[QUERY_SIZE] = {0, };
+       sqlite3 *local_db_handle = NULL;
+
+       if (!input_mailbox_id )  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       time(&current_time);
+
+       local_db_handle = emstorage_get_db_connection();
+
+       EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error);
+
+       SNPRINTF(sql_query_string, sizeof(sql_query_string),
+               "UPDATE mail_box_tbl SET"
+               " last_sync_time = %d"
+               " WHERE mailbox_id = %d"
+               , (int)current_time
+               , input_mailbox_id);
+
+       EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+FINISH_OFF:
+
+       if(error == EMAIL_ERROR_NONE)
+               result_code = true;
+
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, result_code, error);
+       _DISCONNECT_DB;
 
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
+}
 
 INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t** result_mailbox, int transaction, int *err_code)
 {
@@ -4554,102 +4831,53 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch
                EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
-       int rc, ret = false;
-       int error = EMF_ERROR_NONE;
-       int col_index = 0;
-       emstorage_mailbox_tbl_t* p_data_tbl = NULL;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-       sqlite3 *local_db_handle = NULL;
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       int result_count = 0;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
 
-       if(strcmp(mailbox_name, EMF_SEARCH_RESULT_MAILBOX_NAME) == 0) {
-               if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t))))  {
+       if(strcmp(mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) == 0) {
+               if (!(*result_mailbox = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t))))  {
                        EM_DEBUG_EXCEPTION("malloc failed...");
-                       error = EMF_ERROR_OUT_OF_MEMORY;
+                       error = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
-               p_data_tbl->mailbox_id                 = 0;
-               p_data_tbl->account_id                 = account_id;
-               p_data_tbl->local_yn                   = 1;
-               p_data_tbl->mailbox_name               = EM_SAFE_STRDUP(mailbox_name);
-               p_data_tbl->mailbox_type               = EMF_MAILBOX_TYPE_SEARCH_RESULT;
-               p_data_tbl->alias                      = EM_SAFE_STRDUP(mailbox_name);
-               p_data_tbl->sync_with_server_yn        = 0;
-               p_data_tbl->modifiable_yn              = 1;
-               p_data_tbl->total_mail_count_on_server = 1;
-               p_data_tbl->has_archived_mails         = 0;
-               p_data_tbl->mail_slot_size             = 0x0FFFFFFF;
+               (*result_mailbox)->mailbox_id                 = 0;
+               (*result_mailbox)->account_id                 = account_id;
+               (*result_mailbox)->local_yn                   = 1;
+               (*result_mailbox)->mailbox_name               = EM_SAFE_STRDUP(mailbox_name);
+               (*result_mailbox)->mailbox_type               = EMAIL_MAILBOX_TYPE_SEARCH_RESULT;
+               (*result_mailbox)->alias                      = EM_SAFE_STRDUP(mailbox_name);
+               (*result_mailbox)->sync_with_server_yn        = 0;
+               (*result_mailbox)->modifiable_yn              = 1;
+               (*result_mailbox)->total_mail_count_on_server = 1;
+               (*result_mailbox)->has_archived_mails         = 0;
+               (*result_mailbox)->mail_slot_size             = 0x0FFFFFFF;
        }
        else {
-               local_db_handle = emstorage_get_db_connection();
-
-               EMSTORAGE_START_READ_TRANSACTION(transaction);
 
                if (local_yn == -1)
-                       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND mailbox_name = '%s'", fields, account_id, mailbox_name);
+                       SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox_name);
                else
-                       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d AND mailbox_name = '%s'", fields, account_id, local_yn, mailbox_name);
-       
-               EM_DEBUG_LOG("query = [%s]", sql_query_string);
+                       SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND local_yn = %d AND mailbox_name = '%s'", account_id, local_yn, mailbox_name);
        
+               EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("sqlite3_step fail:%d", rc));
-       
-               if (rc == SQLITE_DONE) {
-                       EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
-                       error = EMF_ERROR_MAILBOX_NOT_FOUND;
-                       goto FINISH_OFF;
-               }
-
-               if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t))))  {
-                       EM_DEBUG_EXCEPTION("malloc failed...");
-                       error = EMF_ERROR_OUT_OF_MEMORY;
+               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;
                }
-       
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->local_yn), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->mailbox_type), col_index++);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl->alias), 0, col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->sync_with_server_yn), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->modifiable_yn), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->total_mail_count_on_server), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->has_archived_mails), col_index++);
-               _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_slot_size), col_index++);
        }
 
        ret = true;
        
 FINISH_OFF:
-       if (ret == true)
-               *result_mailbox = p_data_tbl;
-       else if (p_data_tbl != NULL)
-               emstorage_free_mailbox(&p_data_tbl, 1, NULL);
-       
-       if (hStmt != NULL)  {
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK)  {
-                       EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-       
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
-       
+
        if (err_code != NULL)
                *err_code = error;
 
@@ -4658,21 +4886,21 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t** mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t** mailbox_name, int transaction, int *err_code)
 {
        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 < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
+       if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
 
                EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        emstorage_mailbox_tbl_t *p_data_tbl = NULL;
        emstorage_account_tbl_t *account = NULL;
        DB_STMT hStmt = NULL;
@@ -4684,7 +4912,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, emf_mail
        
        /* validate account */
        /*  Check whether the account exists. */
-       if (!emstorage_get_account_by_id(account_id, EMF_ACC_GET_OPT_ACCOUNT_NAME,  &account, true, &error) || !account) {
+       if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME,  &account, true, &error) || !account) {
                EM_DEBUG_EXCEPTION(" emstorage_get_account_by_id failed - %d", error);
                goto FINISH_OFF;
        }
@@ -4698,22 +4926,22 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, emf_mail
                
        
        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 = EMF_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE; 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 (rc == SQLITE_DONE) {
                EM_DEBUG_EXCEPTION(" no matched mailbox_name found...");
-               error = EMF_ERROR_MAILBOX_NOT_FOUND;
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
                goto FINISH_OFF;
        }
 
        
        if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t))))  {
                EM_DEBUG_EXCEPTION(" malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        
@@ -4745,7 +4973,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -4759,19 +4987,46 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_mailboxname_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox)
 {
-       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 < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name)  {
-               EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], output_mailbox[%p]", input_mailbox_id, output_mailbox);
+
+       if (input_mailbox_id <= 0 || !output_mailbox)  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return  EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       int  ret = EMAIL_ERROR_NONE;
+       int  result_count = 0;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
+
+       SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE mailbox_id = %d", input_mailbox_id);
+
+       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) {
+               EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", ret);
+               goto FINISH_OFF;
+       }
+
+FINISH_OFF:
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_id[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_id, transaction, err_code);
+       if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_id)  {
+               EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_id[%p]", account_id, mailbox_type, mailbox_id);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
-       char *p_mailbox = NULL;
+       int error = EMAIL_ERROR_NONE;
        emstorage_account_tbl_t* account = NULL;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -4780,7 +5035,7 @@ INTERNAL_FUNC int emstorage_get_mailboxname_by_mailbox_type(int account_id, emf_
        EMSTORAGE_START_READ_TRANSACTION(transaction);
 
        /*  Check whether the account exists. */
-       if (!emstorage_get_account_by_id(account_id, EMF_ACC_GET_OPT_ACCOUNT_NAME,  &account, true, &error) || !account) {
+       if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME,  &account, true, &error) || !account) {
                EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", error);
                goto FINISH_OFF;
        }
@@ -4788,6 +5043,78 @@ INTERNAL_FUNC int emstorage_get_mailboxname_by_mailbox_type(int account_id, emf_
        if (account )
                emstorage_free_account(&account, 1, NULL);
        
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_id  FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
+
+       EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("sqlite3_step fail:%d", rc));
+
+       if (rc == SQLITE_DONE) {
+               EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+
+       _get_stmt_field_data_int(hStmt, mailbox_id, 0);
+
+       ret = true;
+
+FINISH_OFF:
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+       _DISCONNECT_DB;
+
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
+{
+       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)  {
+               EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+
+       int rc, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       emstorage_account_tbl_t* account = NULL;
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+       /*  Check whether the account exists. */
+       if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME,  &account, true, &error) || !account) {
+               EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", error);
+               goto FINISH_OFF;
+       }
+
+       if (account )
+               emstorage_free_account(&account, 1, NULL);
+
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_name  FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
 
        EM_DEBUG_LOG("query = [%s]", sql_query_string);
@@ -4795,35 +5122,30 @@ INTERNAL_FUNC int emstorage_get_mailboxname_by_mailbox_type(int account_id, emf_
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        if (rc == SQLITE_DONE) {
                EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
-               error = EMF_ERROR_MAILBOX_NOT_FOUND;
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
                goto FINISH_OFF;
        }
  
-       _get_stmt_field_data_string(hStmt, &(p_mailbox), 0, 0);
+       _get_stmt_field_data_string(hStmt, mailbox_name, 0, 0);
 
        ret = true;
        
 FINISH_OFF:
-       if (ret == true)
-               *mailbox_name = p_mailbox;
-       else 
-               EM_SAFE_FREE(p_mailbox);
-       
        if (hStmt != NULL)  {
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -4841,7 +5163,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], local_yn [%d], mailbox_name [%p], modifiable_yn [%d], transaction [%d], err_code [%p]", account_id, local_yn, mailbox_name, modifiable_yn, transaction, err_code);
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -4859,7 +5181,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc
                , local_yn
                , mailbox_name);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
  
        ret = true;
@@ -4877,18 +5199,18 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, char *mailbox_name, int total_count_on_server, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, mailbox_name, total_count_on_server,  transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, input_mailbox_id, total_count_on_server,  transaction, err_code);
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
-       if (account_id <= 0 || !mailbox_name)  {
-               EM_DEBUG_EXCEPTION("account_id[%d], mailbox_name[%p]", account_id, mailbox_name);
+       if (account_id <= 0 || input_mailbox_id <= 0)  {
+               EM_DEBUG_EXCEPTION("account_id[%d], input_mailbox_id[%d]", account_id, input_mailbox_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }       
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -4899,13 +5221,13 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, char *mai
                "UPDATE mail_box_tbl SET"
                " total_mail_count_on_server = %d"
                " WHERE account_id = %d"
-               " AND mailbox_name = '%s'"
+               " AND mailbox_id = %d"
                , total_count_on_server
                , account_id
-               , mailbox_name);
+               , input_mailbox_id);
        EM_DEBUG_LOG("query[%s]", sql_query_string);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
  
        ret = true;
@@ -4923,20 +5245,20 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t* result_mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t* result_mailbox, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, result_mailbox, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, result_mailbox, transaction, err_code);
        
-       if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result_mailbox)  {       
-               EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox);
+       if (account_id < FIRST_ACCOUNT_ID || input_mailbox_id <= 0 || !result_mailbox)  {
+               EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p]", account_id, local_yn, input_mailbox_id, result_mailbox);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        DB_STMT hStmt = NULL;
        int i = 0;
@@ -4957,10 +5279,10 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, char *m
                        ", total_mail_count_on_server = ?"
                        " WHERE account_id = %d"
                        " AND local_yn = %d"
-                       " AND mailbox_name = '%s'"
+                       " AND mailbox_id = '%d'"
                        , account_id
                        , local_yn
-                       , mailbox_name);
+                       , input_mailbox_id);
        }
        else {
                SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -4974,15 +5296,15 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, char *m
                        ", mail_slot_size= ?"
                        ", total_mail_count_on_server = ?"
                        " WHERE account_id = %d"
-                       " AND mailbox_name = '%s'"
+                       " AND mailbox_id = '%d'"
                        , account_id
-                       , mailbox_name);
+                       , input_mailbox_id);
        }
 
                
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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++, result_mailbox->mailbox_id);
@@ -4996,9 +5318,9 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, char *m
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        ret = true;
@@ -5011,7 +5333,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -5023,20 +5345,20 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t* target_mailbox, int transaction, int *err_code)
+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)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], target_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, target_mailbox, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], new_mailbox_type[%d], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, new_mailbox_type, transaction, err_code);
        
-       if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !target_mailbox)  {       
-               EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], target_mailbox[%p]", account_id, local_yn, mailbox_name, target_mailbox);
+       if (account_id < FIRST_ACCOUNT_ID || !mailbox_name)  {
+               EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s]", account_id, local_yn, mailbox_name);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -5072,23 +5394,23 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch
        EM_DEBUG_LOG("SQL(%s)", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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++, target_mailbox->mailbox_type);
+       _bind_stmt_field_data_int(hStmt, i++, new_mailbox_type);
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
                hStmt = NULL;
        }
@@ -5097,7 +5419,6 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch
        i = 0;
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
                        "UPDATE mail_tbl SET"
-                       " mailbox_id = ?"
                        " mailbox_type = ?"
                        " WHERE account_id = %d"
                        " AND mailbox_name = '%s'"
@@ -5107,17 +5428,16 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch
        EM_DEBUG_LOG("SQL[%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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++, target_mailbox->mailbox_id);
-       _bind_stmt_field_data_int(hStmt, i++, target_mailbox->mailbox_type);
+       _bind_stmt_field_data_int(hStmt, i++, new_mailbox_type);
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        ret = true;
@@ -5130,7 +5450,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -5148,24 +5468,27 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in
        
        if (!mailbox_tbl)  {
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0,};
        char **result = NULL;
+       time_t current_time;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
        
        EM_SAFE_STRCPY(sql_query_string, "SELECT max(rowid) FROM mail_box_tbl;");
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
+       time(&current_time);
+
        if (NULL == result[1])
                rc = 1;
        else
@@ -5178,22 +5501,23 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in
 
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
                "INSERT INTO mail_box_tbl VALUES "
-               "( ?"  /*  mailbox_id */
-               ", ?"  /*  account_id */
-               ", ?"  /*  local_yn */
-               ", ?"  /*  mailbox_name */
-               ", ?"  /*  mailbox_type */
-               ", ?"  /*  alias */
-               ", ?"  /*  sync_with_server_yn */
-               ", ?"  /*  modifiable_yn */
-               ", ?"  /*  total_mail_count_on_server */
-               ", ?"  /*  has_archived_mails */
-               ", ? )");/*  mail_slot_size */
+               "( ?"    /* mailbox_id */
+               ", ?"    /* account_id */
+               ", ?"    /* local_yn */
+               ", ?"    /* mailbox_name */
+               ", ?"    /* mailbox_type */
+               ", ?"    /* alias */
+               ", ?"    /* sync_with_server_yn */
+               ", ?"    /* modifiable_yn */
+               ", ?"    /* total_mail_count_on_server */
+               ", ?"    /* has_archived_mails */
+               ", ?"    /* mail_slot_size */
+               ", ? )");/* last_sync_time */
        
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        int col_index = 0;
@@ -5209,14 +5533,13 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in
        _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->total_mail_count_on_server);
        _bind_stmt_field_data_int(hStmt, col_index++, 0);
        _bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->mail_slot_size);
+       _bind_stmt_field_data_int(hStmt, col_index++, current_time);
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%dn", rc));
-       if (!emstorage_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_tbl->account_id, 0, mailbox_tbl->mailbox_name, 0))
-               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+
        ret = true;
        
 FINISH_OFF:
@@ -5226,13 +5549,16 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
        EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
        
+       if (error == EMAIL_ERROR_NONE && !emstorage_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_tbl->account_id, mailbox_tbl->mailbox_id, mailbox_tbl->mailbox_name, 0))
+               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+
        if (err_code != NULL)
                *err_code = error;
 
@@ -5249,11 +5575,11 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo
                EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0,};
 
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -5263,7 +5589,7 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET modifiable_yn = %d WHERE account_id = %d", modifiable_yn, account_id);
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        rc = sqlite3_changes(local_db_handle);
@@ -5276,7 +5602,7 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo
 FINISH_OFF:
        EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
-       
+
        if (err_code != NULL)
                *err_code = error;
        EM_DEBUG_FUNC_END("ret [%d]", ret);
@@ -5285,20 +5611,20 @@ FINISH_OFF:
 
 }
 
-INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, char *mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, transaction, err_code);
        
        if (account_id < FIRST_ACCOUNT_ID)  {   
-               EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%p]", account_id, local_yn, mailbox_name);
+               EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], input_mailbox_id[%d]", account_id, local_yn, input_mailbox_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -5309,19 +5635,19 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, char *m
        else
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d ", account_id, local_yn);
        
-       if (mailbox_name)  {            /*  NULL means all mailbox_name */
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(1+ strlen(sql_query_string)), "AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+       if (input_mailbox_id > 0)  {            /*  0 means all mailbox_name */
+               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(1+ strlen(sql_query_string)), "AND mailbox_id = %d", input_mailbox_id);
        }
        
        EM_DEBUG_LOG("mailbox sql_query_string [%s]", sql_query_string);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found...");
-                       error = EMF_ERROR_MAILBOX_NOT_FOUND;
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
                ret = true;
        }
        ret = true;
@@ -5331,6 +5657,11 @@ FINISH_OFF:
        EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
        
+       if(error == EMAIL_ERROR_NONE) {
+               if (!emstorage_notify_storage_event(NOTI_MAILBOX_DELETE, account_id, input_mailbox_id, NULL, 0))
+                       EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+       }
+
        if (err_code != NULL)
                *err_code = error;
 
@@ -5343,13 +5674,13 @@ INTERNAL_FUNC int emstorage_free_mailbox(emstorage_mailbox_tbl_t** mailbox_list,
        EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d], err_code[%p]", mailbox_list, count, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
                
        if (count > 0)  {
                if (!mailbox_list || !*mailbox_list)  {
                        EM_DEBUG_EXCEPTION(" mailbox_list[%p], count[%d]", mailbox_list, count);
                        
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
                
@@ -5382,12 +5713,12 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo
                EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], count[%p], exist[%p]", account_id, mailbox_name, count);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -5398,7 +5729,7 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -5427,12 +5758,12 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na
                EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], uid[%p], exist[%p]", account_id, mailbox_name , uid, exist);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -5447,7 +5778,7 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *exist = atoi(result[1]);
@@ -5478,12 +5809,12 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_
        if (!mail)  {
                EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false, temp_rule;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
 
@@ -5495,25 +5826,26 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
 
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        *mail = (emstorage_mail_tbl_t*)malloc(sizeof(emstorage_mail_tbl_t));
        if (*mail == NULL) {
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                EM_DEBUG_EXCEPTION("Memory allocation for mail failed.");
                goto FINISH_OFF;
 
        }
        memset(*mail, 0x00, sizeof(emstorage_mail_tbl_t));
-       
+
        _get_stmt_field_data_int(hStmt, &((*mail)->account_id), ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
-       _get_stmt_field_data_string(hStmt, &((*mail)->mailbox_name), 0, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+       _get_stmt_field_data_int(hStmt, &((*mail)->mailbox_id), LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+       _get_stmt_field_data_string(hStmt, &((*mail)->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
        _get_stmt_field_data_int(hStmt, &((*mail)->mail_id), LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
        _get_stmt_field_data_string(hStmt, &((*mail)->server_mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
        _get_stmt_field_data_string(hStmt, &((*mail)->server_mail_id), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
@@ -5530,7 +5862,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -5544,20 +5876,20 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox, emstorage_read_mail_uid_tbl_t** read_mail_uid, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t** read_mail_uid, int *count, int transaction, int *err_code)
 {
        EM_PROFILE_BEGIN(emStorageGetDownloadList);
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%s], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, local_mbox, read_mail_uid, count, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, read_mail_uid, count, transaction, err_code);
        if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid || !count)  {
-               EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%s], read_mail_uid[%p], count[%p]", account_id, local_mbox, read_mail_uid, count);
+               EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%s], read_mail_uid[%p], count[%p]", account_id, mailbox_id, read_mail_uid, count);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
  
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -5568,8 +5900,8 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_READ_TRANSACTION(transaction);
 
-       if (local_mbox)
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d AND UPPER(local_mbox) = UPPER('%s')", account_id, local_mbox);
+       if (mailbox_id)
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_id = %d", account_id, mailbox_id);
        else
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d", account_id);
 
@@ -5579,18 +5911,18 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        char **result;
        /*  rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL); */
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        sqlite3_free_table(result);
@@ -5603,7 +5935,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox
 
        if (!(p_data_tbl = (emstorage_read_mail_uid_tbl_t*)malloc(sizeof(emstorage_read_mail_uid_tbl_t) * *count)))  {
                EM_DEBUG_EXCEPTION(" malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -5611,7 +5943,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox
 
        for (i = 0; i < *count; ++i)  {
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].local_mbox), 0, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].mailbox_id),LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].local_uid), LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
                _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
                _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].s_uid), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
@@ -5620,7 +5952,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag), FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL);
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
        }
        
@@ -5638,7 +5970,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -5653,20 +5985,20 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailbox_id, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, mail_size, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size, transaction, err_code);
        
        if (account_id < FIRST_ACCOUNT_ID || !mail_size)  {
-               EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, mail_size);
+               EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        
@@ -5678,35 +6010,35 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local
                SNPRINTF(sql_query_string, sizeof(sql_query_string),
                        "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl "
                        "WHERE account_id = %d "
-                       "AND local_mbox = '%s' "
+                       "AND mailbox_id = '%s' "
                        "AND local_uid = %d "
                        "AND mailbox_name = '%s' "
                        "AND s_uid = '%s'",
-                       account_id, local_mbox, local_uid, mailbox_name, uid);
+                       account_id, mailbox_id, local_uid, mailbox_name, uid);
        }
        else {
                SNPRINTF(sql_query_string, sizeof(sql_query_string),
                        "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl "
                        "WHERE account_id = %d "
-                       "AND local_mbox = '%s' "
+                       "AND mailbox_id = '%s' "
                        "AND local_uid = %d "
                        "AND s_uid = '%s'",
-                       account_id, local_mbox, local_uid, uid);
+                       account_id, mailbox_id, local_uid, uid);
        }
        
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE) {
                EM_DEBUG_EXCEPTION(" no matched mail found....");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;                
        }
  
@@ -5720,7 +6052,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -5741,12 +6073,12 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
        if (!read_mail_uid)  {
                EM_DEBUG_EXCEPTION("read_mail_uid[%p]", read_mail_uid);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, rc2,  ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        
@@ -5758,7 +6090,7 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        if (NULL==result[1]) rc = 1;
@@ -5783,12 +6115,12 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
                EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
                EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
                
-               error = EMF_ERROR_DB_FAILURE;
+               error = EMAIL_ERROR_DB_FAILURE;
                goto FINISH_OFF;
        }
 
        EM_DEBUG_LOG("account_id VALUE [%d] ", read_mail_uid->account_id);
-       EM_DEBUG_LOG("local_mbox VALUE [%s] ", read_mail_uid->local_mbox);
+       EM_DEBUG_LOG("mailbox_id VALUE [%d] ", read_mail_uid->mailbox_id);
        EM_DEBUG_LOG("local_uid VALUE [%d] ", read_mail_uid->local_uid);
        EM_DEBUG_LOG("mailbox_name VALUE [%s] ", read_mail_uid->mailbox_name);
        EM_DEBUG_LOG("s_uid VALUE [%s] ", read_mail_uid->s_uid);
@@ -5798,7 +6130,7 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
        EM_DEBUG_LOG("rc VALUE [%d] ", rc);
 
        _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->account_id);
-       _bind_stmt_field_data_string(hStmt, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_int(hStmt, LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->mailbox_id);
        _bind_stmt_field_data_int(hStmt, LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->local_uid);
        _bind_stmt_field_data_string(hStmt, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
        _bind_stmt_field_data_string(hStmt, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
@@ -5809,9 +6141,9 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle)));
 
        
@@ -5824,7 +6156,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
  
@@ -5838,20 +6170,20 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%p], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code);
        
        if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid)  {
-               EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%p], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, read_mail_uid);
+               EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        
@@ -5862,7 +6194,7 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, char *local_mbo
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
                "UPDATE mail_read_mail_uid_tbl SET"
                "  account_id = ?"
-               ", local_mbox = ?"
+               ", mailbox_id = ?"
                ", local_uid  = ?"
                ", mailbox_name = ?"
                ", s_uid = ?"
@@ -5870,7 +6202,7 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, char *local_mbo
                ", data2 = ?"
                ", flag  = ?"
                " WHERE account_id = ?"
-               " AND local_mbox  = ?"
+               " AND mailbox_id  = ?"
                " AND local_uid   = ?"
                " AND mailbox_name= ?"
                " AND s_uid = ?");
@@ -5878,29 +6210,29 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, char *local_mbo
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
  
        
        int i = 0;
        
        _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->account_id);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->mailbox_id);
        _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->local_uid);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char*)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char*)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
        _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->data1);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->data2, 0, DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char*)read_mail_uid->data2, 0, DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL);
        _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->flag);
        _bind_stmt_field_data_int(hStmt, i++, account_id);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, mailbox_id);
        _bind_stmt_field_data_int(hStmt, i++, local_uid);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char*)mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+       _bind_stmt_field_data_string(hStmt, i++, (char*)uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
  
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        ret = true;
@@ -5913,7 +6245,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
  
@@ -5935,12 +6267,12 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox
                EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%s], uid[%s]", account_id, mailbox_name, uid);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -5958,7 +6290,7 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox
        }
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
  
        
@@ -5981,13 +6313,13 @@ INTERNAL_FUNC int emstorage_free_read_mail_uid(emstorage_read_mail_uid_tbl_t** r
        EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], count[%d], err_code[%p]", read_mail_uid, count, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        if (count > 0)  {
                if (!read_mail_uid || !*read_mail_uid)  {       
                        EM_DEBUG_EXCEPTION(" read_mail_uid[%p], count[%d]", read_mail_uid, count);
                        
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
                
@@ -5995,7 +6327,6 @@ INTERNAL_FUNC int emstorage_free_read_mail_uid(emstorage_read_mail_uid_tbl_t** r
                int i;
                
                for (i = 0; i < count; i++)  {
-                       EM_SAFE_FREE(p[i].local_mbox);
                        EM_SAFE_FREE(p[i].mailbox_name);
                        EM_SAFE_FREE(p[i].s_uid);
                        EM_SAFE_FREE(p[i].data2);
@@ -6022,12 +6353,12 @@ INTERNAL_FUNC int emstorage_get_rule_count(int account_id, int *count, int trans
                EM_DEBUG_EXCEPTION(" account_id[%d], count[%p]", account_id, count);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error =  EMF_ERROR_NONE;
+       int error =  EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -6038,7 +6369,7 @@ INTERNAL_FUNC int emstorage_get_rule_count(int account_id, int *count, int trans
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -6065,12 +6396,12 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in
                EM_DEBUG_EXCEPTION(" account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p]", account_id, type, start_idx, select_num, is_completed, rule_list);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        emstorage_rule_tbl_t* p_data_tbl = NULL;
        int i = 0, count = 0;
@@ -6090,18 +6421,18 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        char **result;
        /*  rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        sqlite3_free_table(result);
@@ -6116,7 +6447,7 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in
        if (!(p_data_tbl = (emstorage_rule_tbl_t*)malloc(sizeof(emstorage_rule_tbl_t) * count))) {
                EM_DEBUG_EXCEPTION(" malloc failed...");
                
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        
@@ -6128,12 +6459,12 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].type), TYPE_IDX_IN_MAIL_RULE_TBL);
                _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].value), 0, VALUE_IDX_IN_MAIL_RULE_TBL);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].action_type), ACTION_TYPE_IDX_IN_MAIL_RULE_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].dest_mailbox), 0, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].target_mailbox_id), TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_RULE_TBL);
                _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_RULE_TBL);
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
        }
        
@@ -6156,7 +6487,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -6179,13 +6510,13 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag
                EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], rule[%p]", account_id, rule_id, rule);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        emstorage_rule_tbl_t* p_data_tbl = NULL;
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
  
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -6196,23 +6527,23 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag
        
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION(" no matched rule found...");
-               error = EMF_ERROR_FILTER_NOT_FOUND;
+               error = EMAIL_ERROR_FILTER_NOT_FOUND;
                goto FINISH_OFF;
        }
        
        if (!(p_data_tbl = (emstorage_rule_tbl_t*)malloc(sizeof(emstorage_rule_tbl_t))))  {
                EM_DEBUG_EXCEPTION(" malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        
@@ -6222,7 +6553,7 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->type), TYPE_IDX_IN_MAIL_RULE_TBL);
        _get_stmt_field_data_string(hStmt, &(p_data_tbl->value), 0, VALUE_IDX_IN_MAIL_RULE_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->action_type), ACTION_TYPE_IDX_IN_MAIL_RULE_TBL);
-       _get_stmt_field_data_string(hStmt, &(p_data_tbl->dest_mailbox), 0, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->target_mailbox_id), TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag1), FLAG1_IDX_IN_MAIL_RULE_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag2), FLAG2_IDX_IN_MAIL_RULE_TBL);
        
@@ -6241,7 +6572,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
  
@@ -6265,12 +6596,12 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r
                EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], new_rule[%p]", account_id, rule_id, new_rule);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
  
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -6282,7 +6613,7 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r
                "  type = ?"
                ", value = ?"
                ", action_type = ?"
-               ", dest_mailbox = ?"
+               ", target_mailbox_id = ?"
                ", flag1 = ?"
                ", flag2 = ?"
                " WHERE account_id = ?"
@@ -6291,7 +6622,7 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        int i = 0;
@@ -6299,7 +6630,7 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r
        _bind_stmt_field_data_int(hStmt, i++, new_rule->type);
        _bind_stmt_field_data_string(hStmt, i++, (char *)new_rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
        _bind_stmt_field_data_int(hStmt, i++, new_rule->action_type);
-       _bind_stmt_field_data_string(hStmt, i++, (char *)new_rule->dest_mailbox, 0, DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL);
+       _bind_stmt_field_data_int(hStmt, i++, new_rule->target_mailbox_id);
        _bind_stmt_field_data_int(hStmt, i++, new_rule->flag1);
        _bind_stmt_field_data_int(hStmt, i++, new_rule->flag2);
        _bind_stmt_field_data_int(hStmt, i++, account_id);
@@ -6307,7 +6638,7 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r
  
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        ret = true;
@@ -6320,7 +6651,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -6343,14 +6674,14 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio
                        EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc, ret = false;
 
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -6362,17 +6693,17 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio
  
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION(" no matched rule found...");
-               error = EMF_ERROR_FILTER_NOT_FOUND;
+               error = EMAIL_ERROR_FILTER_NOT_FOUND;
                goto FINISH_OFF;
        }
 
@@ -6386,7 +6717,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
  
@@ -6410,12 +6741,12 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction
                        EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, rc_2, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
 
@@ -6429,7 +6760,7 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction
        sql = "SELECT max(rowid) FROM mail_rule_tbl;";
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
        
        if (NULL==result[1])
@@ -6445,28 +6776,28 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction
                ", ?"           /*  type */
                ", ?"           /*  value */
                ", ?"           /*  action_type */
-               ", ?"           /*  dest_mailbox */
+               ", ?"           /*  target_mailbox_id */
                ", ?"           /*  flag1 */
                ", ?)");        /*  flag2 */
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc_2);
        if (rc_2 != SQLITE_OK)  {
                EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc_2, sqlite3_errmsg(local_db_handle));
-               error = EMF_ERROR_DB_FAILURE;
+               error = EMAIL_ERROR_DB_FAILURE;
                goto FINISH_OFF;
        }
  
        _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL, rule->account_id);
        _bind_stmt_field_data_int(hStmt, RULE_ID_IDX_IN_MAIL_RULE_TBL, rc);
        _bind_stmt_field_data_int(hStmt, TYPE_IDX_IN_MAIL_RULE_TBL, rule->type);
-       _bind_stmt_field_data_string(hStmt, VALUE_IDX_IN_MAIL_RULE_TBL, (char *)rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
+       _bind_stmt_field_data_string(hStmt, VALUE_IDX_IN_MAIL_RULE_TBL, (char*)rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
        _bind_stmt_field_data_int(hStmt, ACTION_TYPE_IDX_IN_MAIL_RULE_TBL, rule->action_type);
-       _bind_stmt_field_data_string(hStmt, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL, (char *)rule->dest_mailbox, 0, DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL);
+       _bind_stmt_field_data_int(hStmt, TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL, rule->target_mailbox_id);
        _bind_stmt_field_data_int(hStmt, FLAG1_IDX_IN_MAIL_RULE_TBL, rule->flag1);
        _bind_stmt_field_data_int(hStmt, FLAG2_IDX_IN_MAIL_RULE_TBL, rule->flag2);
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        ret = true;
@@ -6479,7 +6810,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK) {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -6501,12 +6832,12 @@ INTERNAL_FUNC int emstorage_delete_rule(int account_id, int rule_id, int transac
                EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d]", account_id, rule_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -6514,13 +6845,13 @@ INTERNAL_FUNC int emstorage_delete_rule(int account_id, int rule_id, int transac
        
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_rule_tbl WHERE account_id = %d AND rule_id = %d", account_id, rule_id);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0) {
                EM_DEBUG_EXCEPTION(" no matched rule found...");
                
-               error = EMF_ERROR_FILTER_NOT_FOUND;
+               error = EMAIL_ERROR_FILTER_NOT_FOUND;
                goto FINISH_OFF;
        }
        
@@ -6542,13 +6873,13 @@ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t** rule_list, int coun
        EM_DEBUG_FUNC_BEGIN("rule_list[%p], conut[%d], err_code[%p]", rule_list, count, err_code);
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        if (count > 0) {
                if (!rule_list || !*rule_list) {
                        EM_DEBUG_EXCEPTION(" rule_list[%p], conut[%d]", rule_list, count);
                        
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
                
@@ -6557,7 +6888,6 @@ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t** rule_list, int coun
                
                for (; i < count; i++) {
                        EM_SAFE_FREE(p[i].value);
-                       EM_SAFE_FREE(p[i].dest_mailbox);
                }
                
                EM_SAFE_FREE(p); *rule_list = NULL;
@@ -6578,12 +6908,12 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n
        if (!total && !unseen) {
                EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p], unseen[%p]", account_id, mailbox_name, total, unseen);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        char err_msg[1024];
@@ -6608,7 +6938,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n
                char **result;
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF2; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF2; },
                        ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                *total = atoi(result[1]);
@@ -6616,11 +6946,11 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n
 #else
                
                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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF2; },
+               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF2; },
                        ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF2; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF2; },
                        ("sqlite3_step fail:%d", rc));
                _get_stmt_field_data_int(hStmt, total, 0);
 #endif         /*  USE_GET_RECORD_COUNT_API */
@@ -6639,7 +6969,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n
                
                char **result;
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                        ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                *unseen = atoi(result[1]);
@@ -6656,7 +6986,7 @@ FINISH_OFF2:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" EDBStmtClearRow failed - %d: %s", rc, err_msg);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 #endif
@@ -6678,7 +7008,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
        if (mail_id <= 0 || !mail)  {   
                EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
@@ -6687,7 +7017,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
        if (p_data_tbl == NULL)  {
                EM_DEBUG_EXCEPTION("malloc failed...");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_OUT_OF_MEMORY;
+                       *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
                return false;
        }
        
@@ -6696,7 +7026,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
        char sql_query_string[QUERY_SIZE] = {0, };
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -6704,7 +7034,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
        switch (type)  {
                case RETRIEVE_SUMMARY:
                        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                               "SELECT account_id, mail_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id);
+                               "SELECT account_id, mail_id, mailbox_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id);
                        break;
                
                case RETRIEVE_FIELDS_FOR_DELETE:
@@ -6719,46 +7049,47 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
                
                case RETRIEVE_FLAG:
                        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                               "SELECT account_id, mailbox_name, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+                               "SELECT account_id, mailbox_name, flags_seen_field, thread_id, mailbox_id FROM mail_tbl WHERE mail_id = %d", mail_id);
                        break;
                
                default :
-                       EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM : type [%d]", type);
-                       error = EMF_ERROR_INVALID_PARAM;
+                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type);
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
        }
        
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no matched mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        switch (type)  {
                case RETRIEVE_SUMMARY:
                        _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), 0);
                        _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), 1);
-                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, 2);
-                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), 3);
-                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, 4);
-                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, 5);
-                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, 6);
-                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, 7);
-                       _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), 8);
-                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->save_status), 9);
-                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), 10);
-                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 11);
-                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), 12);
+                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), 2);
+                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, 3);
+                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), 4);
+                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, 5);
+                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, 6);
+                       _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, &(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);
                        break;
                        
                case RETRIEVE_FIELDS_FOR_DELETE:
@@ -6778,6 +7109,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->mailbox_name), 0, 1);
                        _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), 2);
                        _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 3);
+                       _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), 4);
                        break;
        }
        
@@ -6795,7 +7127,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -6815,9 +7147,9 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
        EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_ids, number_of_mails, type, mail, transaction, err_code);
        
        if (number_of_mails <= 0 || !mail_ids)  {       
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
@@ -6826,13 +7158,13 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
        if (p_data_tbl == NULL)  {
                EM_DEBUG_EXCEPTION("malloc failed...");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_OUT_OF_MEMORY;
+                       *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
                return false;
        }
        
        DB_STMT hStmt = NULL;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int i = 0, item_count = 0, rc = -1, field_count, col_index, cur_sql_query_string = 0;
        char **result = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -6861,13 +7193,13 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
                
                case RETRIEVE_FLAG:
                        cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                               "SELECT account_id, mailbox_name, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in (");
+                               "SELECT account_id, mailbox_id, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in (");
                        field_count = 4;
                        break;
                
                default :
-                       EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM : type [%d]", type);
-                       error = EMF_ERROR_INVALID_PARAM;
+                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type);
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
        }
 
@@ -6878,12 +7210,12 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
        EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, strlen(sql_query_string));
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no matched mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
 
@@ -6891,7 +7223,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
 
        if(number_of_mails != item_count) {
                EM_DEBUG_EXCEPTION("Can't find all emails");
-               /* error = EMF_ERROR_MAIL_NOT_FOUND;
+               /* error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF; */ /* removed temporarily */
        }
 
@@ -6929,7 +7261,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
                                
                        case RETRIEVE_FLAG:
                                _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
-                               _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+                               _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), 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].thread_id), col_index++);
                                break;
@@ -6952,7 +7284,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -6973,11 +7305,11 @@ INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t** m
        if (mail_id <= 0 || !mail) {    
                EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
-       int ret = false, error = EMF_ERROR_NONE, count;
+       int ret = false, error = EMAIL_ERROR_NONE, count;
        char conditional_clause[QUERY_SIZE] = {0, };
        emstorage_mail_tbl_t* p_data_tbl = NULL;
        
@@ -7010,14 +7342,14 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search,
 
        if (!search_handle || !searched)  {     
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                EM_DEBUG_FUNC_END("false");
                return false;
        }
        
        emstorage_search_filter_t* p = search;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        int rc, ret = false;
@@ -7068,18 +7400,18 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search,
 
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &mail_count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        sqlite3_free_table(result);
@@ -7097,7 +7429,7 @@ FINISH_OFF:
                        rc = sqlite3_finalize(hStmt);
                        if (rc != SQLITE_OK)  {
                                EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                               error = EMF_ERROR_DB_FAILURE;
+                               error = EMAIL_ERROR_DB_FAILURE;
                        }
                }
                
@@ -7120,14 +7452,14 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                EM_DEBUG_EXCEPTION(" search_handle[%d], type[%d], data[%p]", search_handle, type, data);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        emstorage_mail_tbl_t* p_data_tbl = NULL;
        DB_STMT hStmt = (DB_STMT)search_handle;
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
 
        switch (type)  {
                case RETRIEVE_ID:
@@ -7139,7 +7471,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                        if (!(p_data_tbl = em_malloc(sizeof(emstorage_mail_tbl_t)))) {
                                EM_DEBUG_EXCEPTION(" em_malloc failed...");
                                
-                               error = EMF_ERROR_OUT_OF_MEMORY;
+                               error = EMAIL_ERROR_OUT_OF_MEMORY;
                                goto FINISH_OFF;
                        }
                        
@@ -7154,6 +7486,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                        _get_stmt_field_data_int   (hStmt, &(p_data_tbl->body_download_status), BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL);
                        _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL);
                        _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL);
+                       _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL);
                        _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);
@@ -7163,6 +7496,9 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                        _get_stmt_field_data_int   (hStmt, &(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);
                                
                        if (type == RETRIEVE_ALL)  {
                                _get_stmt_field_data_int   (hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL);
@@ -7201,7 +7537,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                        if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t))))  {
                                EM_DEBUG_EXCEPTION(" malloc failed...");
                                
-                               error = EMF_ERROR_OUT_OF_MEMORY;
+                               error = EMAIL_ERROR_OUT_OF_MEMORY;
                                goto FINISH_OFF;
                        }
                        
@@ -7220,7 +7556,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
                case RETRIEVE_ADDRESS:
                        if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t))))  {
                                EM_DEBUG_EXCEPTION(" malloc failed...");
-                               error = EMF_ERROR_OUT_OF_MEMORY;
+                               error = EMAIL_ERROR_OUT_OF_MEMORY;
                                goto FINISH_OFF;
                        }
                        
@@ -7237,7 +7573,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        ret = true;
@@ -7255,12 +7591,12 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction,
 {
        EM_DEBUG_FUNC_BEGIN("search_handle[%d], transaction[%d], err_code[%p]", search_handle, transaction, err_code);
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc, ret = false;
        
        if (search_handle < 0)  {
                EM_DEBUG_EXCEPTION(" search_handle[%d]", search_handle);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -7271,7 +7607,7 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction,
        rc = sqlite3_finalize(hStmt);
        if (rc != SQLITE_OK)  {
                EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-               error = EMF_ERROR_DB_FAILURE;
+               error = EMAIL_ERROR_DB_FAILURE;
        }
  
        ret = true;
@@ -7295,7 +7631,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
                EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
@@ -7303,9 +7639,10 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
        char sql_query_string[QUERY_SIZE] = {0, };
        int rc = -1;                            
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int i = 0;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
+       char mailbox_id_param_string[10] = {0,};
 
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
        
@@ -7344,12 +7681,13 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
                ", message_id = ?"
                ", report_status = ?"
                ", preview_text = ?"
+               ", smime_type = ?"
                " WHERE mail_id = %d AND account_id != 0 "
                , mail_id);
 
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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++, mail->mail_id);
@@ -7385,19 +7723,20 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->message_id, 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_int   (hStmt, i++, mail->report_status);
        _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->smime_type);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no matched mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
-
-       if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail->mail_id, mail->mailbox_name, 0))
+       SNPRINTF(mailbox_id_param_string, 10, "%d", mail->mailbox_id);
+       if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail->mail_id, mailbox_id_param_string, 0))
                EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
        
        ret = true;
@@ -7408,7 +7747,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -7430,13 +7769,13 @@ INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char
                EM_DEBUG_EXCEPTION(" old_mailbox_name[%p], new_mailbox_name[%p]", old_mailbox_name, new_mailbox_name);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -7448,14 +7787,14 @@ INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name);
  
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0) {
                EM_DEBUG_EXCEPTION(" no matched mail found...");
                
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
  
@@ -7464,13 +7803,13 @@ INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no matched mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        
@@ -7503,23 +7842,23 @@ INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int  *err_code)
        EM_IF_NULL_RETURN_VALUE(err_code, false);
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc = 0;
        char sql_query_string[QUERY_SIZE] = {0, };
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
        memset(sql_query_string, 0x00, sizeof(sql_query_string));
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMF_MAIL_STATUS_SENDING);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMAIL_MAIL_STATUS_SENDING);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0) {
                EM_DEBUG_LOG(" No Matched Mail Exists ");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
        }
        
        ret = true;
@@ -7536,14 +7875,29 @@ FINISH_OFF:
 INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], mail_ids_count[%d], field_name[%s], value[%d], transaction[%d], err_code[%p]", account_id, mail_ids, mail_ids_count, field_name, value, transaction, err_code);
-       int i, error, rc, ret = false, cur_mail_id_string = 0, mail_id_string_buffer_length = 0;
-       char sql_query_string[QUERY_SIZE] = {0, }, *mail_id_string_buffer = NULL, *parameter_string = NULL;
+       int i = 0;
+       int error = EMAIL_ERROR_NONE;
+       int rc = 0;
+       int ret = false;
+       int cur_mail_id_string = 0;
+       int mail_id_string_buffer_length = 0;
+       char  sql_query_string[QUERY_SIZE] = {0, };
+       char *mail_id_string_buffer = NULL;
+       char *parameter_string = NULL;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
+       email_mail_attribute_type target_mail_attribute_type = 0;
        
        if (!mail_ids  || !field_name || account_id == 0) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+
+       if( (error = _get_attribute_type_by_mail_field_name(field_name, &target_mail_attribute_type)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_get_attribute_type_by_mail_field_name failed [%d]", error);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = error;
                return false;
        }
 
@@ -7554,7 +7908,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
 
        if(!mail_id_string_buffer) {
                EM_DEBUG_EXCEPTION("em_malloc failed");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        
@@ -7569,7 +7923,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
 
        if(!parameter_string) {
                EM_DEBUG_EXCEPTION("em_malloc failed");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -7578,10 +7932,12 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
        /* Write query string */
        SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET %s = %d WHERE mail_id in (%s) AND account_id = %d", field_name, value, mail_id_string_buffer, account_id);
 
+       EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
        /* Execute query */
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        if (sqlite3_changes(local_db_handle) == 0) 
                EM_DEBUG_LOG("no mail matched...");
@@ -7592,8 +7948,8 @@ FINISH_OFF:
        EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
        
-       if (ret && parameter_string && !emstorage_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, 0, parameter_string, value))
-                       EM_DEBUG_EXCEPTION("emstorage_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", field_name, value);
+       if (ret && parameter_string && !emstorage_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, target_mail_attribute_type, parameter_string, value))
+               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", field_name, value);
        
        EM_SAFE_FREE(mail_id_string_buffer);
        EM_SAFE_FREE(parameter_string);
@@ -7601,23 +7957,23 @@ FINISH_OFF:
        if (err_code != NULL)
                *err_code = error;
 
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       EM_DEBUG_FUNC_END("error [%d]", error);
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_t type, emstorage_mail_tbl_t* mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t* mail, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code);
        
        if (mail_id <= 0 || !mail)  {
                EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], mail[%p]", mail_id, type, mail);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int move_flag = 0;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -7625,7 +7981,8 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
        int rc = 0;
        int i = 0;
 
-       char *mailbox_name = NULL;      
+       char *mailbox_name = NULL;
+       char mailbox_id_param_string[10] = {0,};
 
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
@@ -7648,12 +8005,15 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                                ", attachment_count = ?"
                                ", preview_text= ?"
                                ", meeting_request_status = ? "
+                               ", message_class = ? "
+                               ", digest_type = ? "
+                               ", smime_type = ? "
                                " WHERE mail_id = %d AND account_id != 0"
                                , mail_id);
 
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                         i = 0;
                        
@@ -7671,6 +8031,9 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                        _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count);
                        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL);
                        _bind_stmt_field_data_int(hStmt, i++, mail->meeting_request_status);
+                       _bind_stmt_field_data_int(hStmt, i++, mail->message_class);
+                       _bind_stmt_field_data_int(hStmt, i++, mail->digest_type);
+                       _bind_stmt_field_data_int(hStmt, i++, mail->smime_type);
                        break;
                        
                case UPDATE_MAILBOX: {
@@ -7699,7 +8062,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                                EM_DEBUG_LOG("Query [%s]", sql_query_string);
                                
                                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-                               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                        ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        }
                        break;
@@ -7727,7 +8090,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
  
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
                        break;
@@ -7751,7 +8114,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
  
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        break;
 
@@ -7766,7 +8129,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
  
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        break;
                        
@@ -7801,13 +8164,16 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                                ", attachment_count = ?"
                                ", inline_content_count = ?"
                                ", meeting_request_status = ?"
+                               ", message_class = ?"
+                               ", digest_type = ?"
+                               ", smime_type = ?"
                                " WHERE mail_id = %d AND account_id != 0"
                                , mail_id);
  
                        
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
                        EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
-                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        i = 0;  
                        _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
@@ -7838,6 +8204,9 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                        _bind_stmt_field_data_int   (hStmt, i++, mail->attachment_count);
                        _bind_stmt_field_data_int   (hStmt, i++, mail->inline_content_count);
                        _bind_stmt_field_data_int   (hStmt, i++, mail->meeting_request_status);
+                       _bind_stmt_field_data_int   (hStmt, i++, mail->message_class);
+                       _bind_stmt_field_data_int   (hStmt, i++, mail->digest_type);
+                       _bind_stmt_field_data_int   (hStmt, i++, mail->smime_type);
                        break;
                        
                case UPDATE_DATETIME:  {
@@ -7851,7 +8220,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                                , mail_id);
 
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        break;
                }
@@ -7867,7 +8236,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                        hStmt = NULL;
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        i = 0;
                        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
@@ -7884,7 +8253,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                        hStmt = NULL;
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                        i = 0;
                        _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
@@ -7902,7 +8271,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                                hStmt = NULL;
                                
                                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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                        ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                                i = 0;
                                _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
@@ -7926,7 +8295,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
 
                        
                        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                         i = 0;
                        
@@ -7944,36 +8313,36 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_
                default:
                        EM_DEBUG_LOG(" type[%d]", type);
                        
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
        }
  
        if (hStmt != NULL)  {
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+               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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
                rc = sqlite3_changes(local_db_handle);
                if (rc == 0)  {
                        EM_DEBUG_EXCEPTION(" no matched mail found...");
        
-                       error = EMF_ERROR_MAIL_NOT_FOUND;
+                       error = EMAIL_ERROR_MAIL_NOT_FOUND;
                        goto FINISH_OFF;
                }
        }       
 
        if (mail->account_id == 0) {
-               emstorage_mail_tbl_t* mail_for_account = NULL;
-               if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_ACCOUNT, &mail_for_account, true, &error) || !mail_for_account) {
+               emstorage_mail_tbl_t* mail_for_account_tbl = NULL;
+               if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_ACCOUNT, &mail_for_account_tbl, true, &error) || !mail_for_account_tbl) {
                        EM_DEBUG_EXCEPTION(" emstorage_get_mail_field_by_id failed - %d", error);
 /*              */
                        goto FINISH_OFF;
                }
-               mail->account_id = mail_for_account->account_id;
-               if (mail_for_account
-                       emstorage_free_mail(&mail_for_account, 1, NULL);
+               mail->account_id = mail_for_account_tbl->account_id;
+               if (mail_for_account_tbl)
+                       emstorage_free_mail(&mail_for_account_tbl, 1, NULL);
        }
 
        ret = true;
@@ -7984,7 +8353,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
                hStmt = NULL;
        }
@@ -7995,12 +8364,13 @@ FINISH_OFF:
        /*h.gahlaut@samsung.com: Moving publication of notification after commiting transaction to DB */
        
        if (ret == true &&  move_flag != 1) {
-               if (!emstorage_get_mailboxname_by_mailbox_type(mail->account_id, EMF_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &error))
-                       EM_DEBUG_EXCEPTION(" emstorage_get_mailboxname_by_mailbox_type failed - %d", error);
+               if (!emstorage_get_mailbox_name_by_mailbox_type(mail->account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &error))
+                       EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_name_by_mailbox_type failed - %d", error);
 
                if (mail->mailbox_name && mailbox_name) {
                        if (strcmp(mail->mailbox_name, mailbox_name) != 0) {
-                               if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, mail->mailbox_name, type))
+                               SNPRINTF(mailbox_id_param_string, 10, "%d", mail->mailbox_id);
+                               if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, mailbox_id_param_string, type))
                                        EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
                        }
                }
@@ -8019,171 +8389,16 @@ FINISH_OFF:
        EM_DEBUG_FUNC_END("ret [%d]", ret);
        return ret;
 }
-
-
-INTERNAL_FUNC int emstorage_get_mail_count_with_draft_flag(int account_id, const char *mailbox_name, int *total, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, transaction, err_code);
-       
-       if (!total)  {
-               EM_DEBUG_EXCEPTION("accoun_id[%d], mailbox_name[%s], total[%p]", account_id, mailbox_name, total);
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               return false;
-       }
+       EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
        
-       int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-
-       memset(&sql_query_string, 0x00, sizeof(sql_query_string));
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-       EMSTORAGE_START_READ_TRANSACTION(transaction);
-       
-       if (total)  {
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_draft_field = 1");
-               
-               if (account_id != ALL_ACCOUNT)
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
-               
-               if (mailbox_name)
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
-               
-#ifdef USE_GET_RECORD_COUNT_API
-               EM_DEBUG_LOG("Query : [%s]", sql_query_string);
-               char **result;
-
-               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-                       ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-               *total = atoi(result[1]);
-               sqlite3_free_table(result);
-#else
-               
-               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("sqlite3_step fail:%d", rc));
-
-               _get_stmt_field_data_int(hStmt, total, 0);
-#endif         /*  USE_GET_RECORD_COUNT_API */
-       }
-       ret = true;             
-
-FINISH_OFF:
-#ifndef USE_GET_RECORD_COUNT_API
-       if (hStmt != NULL)  {
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK)  {
-                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-#endif
-
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
-       
-       if (err_code != NULL)
-               *err_code = error;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-}
-
-INTERNAL_FUNC int emstorage_get_mail_count_on_sending(int account_id, const char *mailbox_name, int *total, int transaction, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, transaction, err_code);
-       
-       if (!total)  {          
-               EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p]", account_id, mailbox_name, total);
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               return false;
-       }
-       
-       int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-
-       memset(&sql_query_string, 0x00, sizeof(sql_query_string));
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-       EMSTORAGE_START_READ_TRANSACTION(transaction);
-       
-       if (total)  {
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE save_status = %d ", EMF_MAIL_STATUS_SENDING);
-               
-               if (account_id != ALL_ACCOUNT)
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
-               
-               if (mailbox_name)
-                       SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
-               
-#ifdef USE_GET_RECORD_COUNT_API
-               char **result;
-
-               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-                       ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-               *total = atoi(result[1]);
-               sqlite3_free_table(result);
-#else
-               
-               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-               EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("sqlite3_step fail:%d", rc));
-
-               _get_stmt_field_data_int(hStmt, total, 0);
-#endif         /*  USE_GET_RECORD_COUNT_API */
-       }
-       ret = true;             
-
-FINISH_OFF:
-#ifndef USE_GET_RECORD_COUNT_API
-       if (hStmt != NULL)  {
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK) {
-                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-#endif
-
-       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-       _DISCONNECT_DB;
-       
-       if (err_code != NULL)
-               *err_code = error;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-
-}
-
-INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
-       
-       int rc, ret = false;
-       int error = EMF_ERROR_NONE;
-       int latest_mail_id = 0;
-       sqlite3 *local_db_handle = NULL;
-       char *sql = "SELECT MAX(mail_id) FROM mail_tbl;";
-       char **result = NULL;
+       int rc, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       int latest_mail_id = 0;
+       sqlite3 *local_db_handle = NULL;
+       char *sql = "SELECT MAX(mail_id) FROM mail_tbl;";
+       char **result = NULL;
 
 #ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
        _timedlock_shm_mutex(&mapped_for_generating_mail_id, 2);
@@ -8196,7 +8411,7 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int
                local_db_handle = emstorage_get_db_connection();
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                        ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
                if (NULL == result[1])
                        rc = 1;
@@ -8239,12 +8454,12 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
        if (!mail_tbl_data)  {
                EM_DEBUG_EXCEPTION("mail_tbl_data[%p], get_id[%d]", mail_tbl_data, get_id);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        DB_STMT hStmt = NULL;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -8257,7 +8472,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
                char **result;
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                        ("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle)));
 
                if (NULL == result[1])
@@ -8300,6 +8515,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
                ", ?" /*  body_download_status */
                ", ?" /*  file_path_plain */
                ", ?" /*  file_path_html */
+               ", ?" /*  file_path_mime_entity */
                ", ?" /*  mail_size */
                ", ?" /*  flags_seen_field */
                ", ?" /*  flags_deleted_field */
@@ -8319,10 +8535,13 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
                ", ?" /*  thread_item_count */
                ", ?" /*  preview_text */
                ", ?" /*  meeting_request_status */
+               ", ?" /*  message_class */
+               ", ?" /*  digest_type */
+               ", ?" /*  smime_type */
                ")");
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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, MAIL_ID_IDX_IN_MAIL_TBL, mail_tbl_data->mail_id);
@@ -8349,6 +8568,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
        _bind_stmt_field_data_int   (hStmt, BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->body_download_status);
        _bind_stmt_field_data_string(hStmt, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, FILE_PATH_HTML_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+       _bind_stmt_field_data_string(hStmt, FILE_PATH_MIME_ENTITY_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_int   (hStmt, MAIL_SIZE_IDX_IN_MAIL_TBL, mail_tbl_data->mail_size);
        _bind_stmt_field_data_int   (hStmt, FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_seen_field);
        _bind_stmt_field_data_int   (hStmt, FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_deleted_field);
@@ -8368,10 +8588,13 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
        _bind_stmt_field_data_int   (hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->thread_item_count);
        _bind_stmt_field_data_string(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_int   (hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->meeting_request_status);
+       _bind_stmt_field_data_int   (hStmt, MESSAGE_CLASS_IDX_IN_MAIL_TBL, mail_tbl_data->message_class);
+       _bind_stmt_field_data_int   (hStmt, DIGEST_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->digest_type);
+       _bind_stmt_field_data_int   (hStmt, SMIME_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->smime_type);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", 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));
        ret = true;
        
 FINISH_OFF:
@@ -8380,7 +8603,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -8396,34 +8619,34 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, char *target_mailbox_name, int mail_ids[], int number_of_mails, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id [%d], target_mailbox_name [%s], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", account_id, target_mailbox_name, mail_ids, number_of_mails, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id [%d], input_mailbox_id [%d], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", account_id, input_mailbox_id, mail_ids, number_of_mails, transaction, err_code);
 
        int rc, ret = false, i, cur_conditional_clause = 0;
-       int error = EMF_ERROR_NONE;
-       int target_mailbox_id = 0;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, }, conditional_clause[QUERY_SIZE] = {0, };
        emstorage_mailbox_tbl_t *result_mailbox = NULL;
-       emf_mailbox_type_e target_mailbox_type = EMF_MAILBOX_TYPE_USER_DEFINED;
+       email_mailbox_type_e target_mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED;
+       char* target_mailbox_name = NULL;
 
-       if (!mail_ids || !target_mailbox_name) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+       if (!mail_ids || input_mailbox_id <= 0) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }               
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
-       if(!emstorage_get_mailbox_by_name(account_id, -1, target_mailbox_name, &result_mailbox, true, &error)) {
-               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d]", error);
+       if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &result_mailbox)) != EMAIL_ERROR_NONE || !result_mailbox) {
+               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", error);
                goto FINISH_OFF;
        }
 
        if(result_mailbox) {
+               target_mailbox_name = EM_SAFE_STRDUP(result_mailbox->mailbox_name);
                target_mailbox_type = result_mailbox->mailbox_type;
-               target_mailbox_id   = result_mailbox->mailbox_id;
                emstorage_free_mailbox(&result_mailbox, 1, NULL);
        }
        
@@ -8439,7 +8662,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, char *target_mai
        /* Updating a mail_tbl */
 
        memset(sql_query_string, 0x00, QUERY_SIZE);
-       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_name = '%s', mailbox_type = %d, mailbox_id = %d %s", target_mailbox_name, target_mailbox_type, target_mailbox_id, conditional_clause);
+       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_name = '%s', mailbox_type = %d, mailbox_id = %d %s", target_mailbox_name, target_mailbox_type, input_mailbox_id, conditional_clause);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
@@ -8449,7 +8672,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, char *target_mai
        /* Updating a mail_attachment_tbl */
 
        memset(sql_query_string, 0x00, QUERY_SIZE);
-       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_name = '%s' %s", target_mailbox_name, conditional_clause);
+       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_id = '%d' %s", input_mailbox_id, conditional_clause);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
@@ -8458,7 +8681,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, char *target_mai
 
        /* Updating a mail_meeting_tbl */
        memset(sql_query_string, 0x00, QUERY_SIZE);
-       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_name = '%s' %s", target_mailbox_name, conditional_clause);
+       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_id = %d %s", input_mailbox_id, conditional_clause);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
@@ -8475,7 +8698,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, char *target_mai
        conditional_clause[strlen(conditional_clause) - 1] = ')';
 
        memset(sql_query_string, 0x00, QUERY_SIZE);
-       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', local_mbox = '%s' %s", target_mailbox_name, target_mailbox_name, conditional_clause);
+       SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', mailbox_id = %d %s", target_mailbox_name, input_mailbox_id, conditional_clause);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
@@ -8488,6 +8711,8 @@ FINISH_OFF:
        EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
        
+       EM_SAFE_FREE(target_mailbox_name);
+
        if (err_code != NULL)
                *err_code = error;
 
@@ -8502,12 +8727,12 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa
        if (!mail_id)  {
                EM_DEBUG_EXCEPTION("mail_id[%d]", mail_id);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }               
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -8541,13 +8766,13 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_
        EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", mail_ids, number_of_mails, transaction, err_code);
 
        int rc, ret = false, i, cur_sql_query_string = 0;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        if (!mail_ids) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }               
        
@@ -8588,12 +8813,12 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti
                EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -8603,13 +8828,13 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
        }
  
        /* Delete all mails  mail_read_mail_uid_tbl table based on account id */
@@ -8617,13 +8842,13 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION("no mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
        }
 
        if (!emstorage_notify_storage_event(NOTI_MAIL_DELETE_WITH_ACCOUNT, account_id, 0 , NULL, 0))
@@ -8643,42 +8868,42 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mailbox, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mbox[%p], transaction[%d], err_code[%p]", account_id, mbox, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code);
        
-       if (account_id < FIRST_ACCOUNT_ID || !mbox)  {
-               EM_DEBUG_EXCEPTION(" account_id[%d], mbox[%p]", account_id, mbox);
+       if (account_id < FIRST_ACCOUNT_ID || !mailbox)  {
+               EM_DEBUG_EXCEPTION(" account_id[%d], mailbox[%p]", account_id, mailbox);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
        
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mbox);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                
 
        /* Delete Mails from mail_read_mail_uid_tbl */
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mbox);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox);
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
-       if (!emstorage_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, 0 , mbox, 0))
+       if (!emstorage_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, 0 , mailbox, 0))
                EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ] >>>> ");
        
        ret = true;
@@ -8703,7 +8928,7 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun
                        EM_DEBUG_EXCEPTION("mail_ilst[%p], count[%d]", mail_list, count);
                        
                        if (err_code)
-                               *err_code = EMF_ERROR_INVALID_PARAM;
+                               *err_code = EMAIL_ERROR_INVALID_PARAM;
                        return false;
                }
 
@@ -8723,6 +8948,7 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun
                        EM_SAFE_FREE(p->subject);
                        EM_SAFE_FREE(p->file_path_plain);
                        EM_SAFE_FREE(p->file_path_html);
+                       EM_SAFE_FREE(p->file_path_mime_entity);
                        EM_SAFE_FREE(p->message_id);
                        EM_SAFE_FREE(p->email_address_sender);
                        EM_SAFE_FREE(p->email_address_recipient);
@@ -8734,7 +8960,7 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun
        }
        
        if (err_code != NULL)
-               *err_code = EMF_ERROR_NONE;
+               *err_code = EMAIL_ERROR_NONE;
 
        EM_DEBUG_FUNC_END();
        return true;
@@ -8747,12 +8973,12 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr
        if (mail_id <= 0 || !count)  {
                EM_DEBUG_EXCEPTION("mail_id[%d], count[%p]", mail_id, count);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -8763,7 +8989,7 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -8788,11 +9014,11 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
        EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_transaction[%d], output_attachment_list[%p], output_attachment_count[%p]", input_mail_id, output_attachment_list, input_transaction, output_attachment_count);
        
        if (input_mail_id <= 0 || !output_attachment_list || !output_attachment_count)  {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
-               return EMF_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
        }
        
-       int                         error = EMF_ERROR_NONE;
+       int                         error = EMAIL_ERROR_NONE;
        int                         i = 0;
        int                         rc = -1;
        char                      **result = NULL;
@@ -8804,14 +9030,14 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
        EMSTORAGE_START_READ_TRANSACTION(input_transaction);
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", input_mail_id);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *output_attachment_count = atoi(result[1]);
        sqlite3_free_table(result);
        
        if(*output_attachment_count == 0) {
-               error = EMF_ERROR_NONE;
+               error = EMAIL_ERROR_NONE;
                goto FINISH_OFF;
        }
        
@@ -8819,7 +9045,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
        
        if (!p_data_tbl)  {
                EM_DEBUG_EXCEPTION("em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        
@@ -8827,14 +9053,14 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
        EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;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 (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no matched attachment found...");
-               error = EMF_ERROR_ATTACHMENT_NOT_FOUND;
+               error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND;
                goto FINISH_OFF;
        }
        for (i = 0; i < *output_attachment_count; i++)  {
@@ -8844,7 +9070,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
                _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
                _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
                _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
-               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL);
+               _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].mailbox_id), MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
                _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].attachment_save_status), ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL);
                _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].attachment_drm_type), ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL);
                _get_stmt_field_data_int   (hStmt, &(p_data_tbl[i].attachment_drm_method), ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL);
@@ -8853,12 +9079,12 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
                
                EM_DEBUG_LOG("attachment[%d].attachment_id : %d", i, p_data_tbl[i].attachment_id);
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;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));
        }
        
 FINISH_OFF:
 
-       if (error == EMF_ERROR_NONE)
+       if (error == EMAIL_ERROR_NONE)
                *output_attachment_list = p_data_tbl;
        else if (p_data_tbl != NULL)
                emstorage_free_attachment(&p_data_tbl, *output_attachment_count, NULL);
@@ -8867,7 +9093,7 @@ FINISH_OFF:
        
        if (rc != SQLITE_OK)  {
                EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc);
-               error = EMF_ERROR_DB_FAILURE;
+               error = EMAIL_ERROR_DB_FAILURE;
        }
        
        EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
@@ -8878,49 +9104,49 @@ FINISH_OFF:
        return error;
 }
 
-INTERNAL_FUNC int emstorage_get_attachment(int mail_id, int attachment_id, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, attachment_id, attachment, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", attachment_id, attachment, transaction, err_code);
        
-       if (mail_id <= 0 || attachment_id <= 0 || !attachment)  {
-               EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d], attachment[%p]", mail_id, attachment_id, attachment);
+       if (attachment_id <= 0 || !attachment)  {
+               EM_DEBUG_EXCEPTION("attachment_id[%d], attachment[%p]", attachment_id, attachment);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        emstorage_attachment_tbl_t* p_data_tbl = NULL;
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
        EMSTORAGE_START_READ_TRANSACTION(transaction);
        
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d AND attachment_id = %d", mail_id, attachment_id);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE attachment_id = %d",  attachment_id);
 
        sqlite3_stmt* hStmt = NULL;
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
        
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no matched attachment found...");
-               error = EMF_ERROR_ATTACHMENT_NOT_FOUND;
+               error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND;
                goto FINISH_OFF;
        }
 
        if (!(p_data_tbl = (emstorage_attachment_tbl_t*)em_malloc(sizeof(emstorage_attachment_tbl_t) * 1)))  {
                EM_DEBUG_EXCEPTION("malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -8930,7 +9156,7 @@ INTERNAL_FUNC int emstorage_get_attachment(int mail_id, int attachment_id, emsto
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
-       _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_save_status), ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_drm_type), ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL);
        _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_drm_method), ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL);
@@ -8954,7 +9180,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -8976,14 +9202,14 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a
                EM_DEBUG_EXCEPTION(" mail_id[%d], nth[%d], attachment[%p]", mail_id, nth, attachment_tbl);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        emstorage_attachment_tbl_t* p_data_tbl = NULL;
        char *p = NULL;
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -8995,23 +9221,23 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a
        DB_STMT hStmt = NULL;
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION(" no matched attachment found...");
-               error = EMF_ERROR_ATTACHMENT_NOT_FOUND;
+               error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND;
                goto FINISH_OFF;
        }
        
        if (!(p_data_tbl = (emstorage_attachment_tbl_t*)em_malloc(sizeof(emstorage_attachment_tbl_t) * 1)))  {
                EM_DEBUG_EXCEPTION(" malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -9023,8 +9249,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a
        p_data_tbl->attachment_size = sqlite3_column_int(hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
        p_data_tbl->mail_id = sqlite3_column_int(hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
        p_data_tbl->account_id = sqlite3_column_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
-       if ((p = (char *)sqlite3_column_text(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
-               p_data_tbl->mailbox_name = cpy_str(p);
+       p_data_tbl->mailbox_id = sqlite3_column_int(hStmt, MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
        p_data_tbl->attachment_save_status = sqlite3_column_int(hStmt, ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL);
        p_data_tbl->attachment_drm_type = sqlite3_column_int(hStmt, ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL);
        p_data_tbl->attachment_drm_method = sqlite3_column_int(hStmt, ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL);
@@ -9050,7 +9275,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        
@@ -9064,19 +9289,19 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, emf_mail_change_type_t type, emstorage_attachment_tbl_t* attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t* attachment, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, type, attachment, transaction, err_code);
        
        if (mail_id <= 0 || !attachment)  {
                EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], attachment[%p]", mail_id, type, attachment);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        
@@ -9089,28 +9314,27 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, emf_mail_change
        switch (type)  {
                case UPDATE_MAILBOX:
                                EM_DEBUG_LOG("UPDATE_MAILBOX");
-                       if (!attachment->mailbox_name)  {
-                               EM_DEBUG_EXCEPTION(" attachment->mailbox_name[%p]", attachment->mailbox_name);
-                               error = EMF_ERROR_INVALID_PARAM;
+                       if (!attachment->mailbox_id)  {
+                               EM_DEBUG_EXCEPTION(" attachment->mailbox_id[%d]", attachment->mailbox_id);
+                               error = EMAIL_ERROR_INVALID_PARAM;
                                goto FINISH_OFF;
                        }
                        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                               "UPDATE mail_attachment_tbl SET mailbox_name = ? WHERE mail_id = %d", mail_id);
-                       
+                               "UPDATE mail_attachment_tbl SET mailbox_id = ? WHERE mail_id = %d", mail_id);
+
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
                        EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
-                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
-                       _bind_stmt_field_data_string(hStmt, i++, (char *)attachment->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+                       _bind_stmt_field_data_int(hStmt, i++, attachment->mailbox_id);
                        break;
                        
                case UPDATE_SAVENAME:
                        EM_DEBUG_LOG("UPDATE_SAVENAME");
                        if (!attachment->attachment_path)  {
                                EM_DEBUG_EXCEPTION(" attachment->attachment_path[%p]", attachment->attachment_path);
-                               error = EMF_ERROR_INVALID_PARAM;
+                               error = EMAIL_ERROR_INVALID_PARAM;
                                goto FINISH_OFF;
                        }
 
@@ -9127,7 +9351,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, emf_mail_change
                        
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
                        EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
-                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       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++, attachment->attachment_size);
@@ -9136,13 +9360,13 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, emf_mail_change
                        
                default:
                        EM_DEBUG_LOG("type[%d]", type);
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
        }
        EM_DEBUG_LOG("query = [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        ret = true;
        
@@ -9152,7 +9376,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -9166,158 +9390,101 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_rename_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, int input_transaction)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_new_mailbox_name[%p], input_new_mailbox_alias [%p], input_transaction[%d]", input_mailbox_id, input_new_mailbox_name, input_new_mailbox_alias, input_transaction);
 
-       if (account_id < FIRST_ACCOUNT_ID ||!old_mailbox_name || !new_mailbox_name)  {
-               EM_DEBUG_EXCEPTION("Invalid Parameters");
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               return false;
-       }
-       
-       int rc, ret = true;
-       int error = EMF_ERROR_NONE;
+       int rc = 0;
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
-       
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-
-       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+       sqlite3 *local_db_handle = NULL;
+       int account_id = 0;
+       emstorage_mailbox_tbl_t *old_mailbox_data = NULL;
 
-       SNPRINTF(sql_query_string, sizeof(sql_query_string),
-               "UPDATE mail_tbl SET"
-               " mailbox_name = '%s'"
-               " WHERE account_id = %d"
-               " AND mailbox_name = '%s'"
-               , new_mailbox_name
-               , account_id
-               , old_mailbox_name);
+       if (input_mailbox_id <= 0 || !input_new_mailbox_name || !input_new_mailbox_alias)  {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
 
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+       local_db_handle = emstorage_get_db_connection();
 
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &old_mailbox_data)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", error);
+               goto FINISH_OFF;
+       }
+       account_id = old_mailbox_data->account_id;
 
-       if (sqlite3_changes(local_db_handle) == 0) 
-               EM_DEBUG_LOG("no mail matched...");
+       EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error);
 
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-               "UPDATE mail_attachment_tbl SET"
+               "UPDATE mail_box_tbl SET"
                " mailbox_name = '%s'"
-               " WHERE account_id = %d"
-               " AND mailbox_name = '%s'"
-               , new_mailbox_name
-               , account_id
-               , old_mailbox_name);
+               ",alias = '%s'"
+               " WHERE mailbox_id = %d"
+               , input_new_mailbox_name
+               , input_new_mailbox_alias
+               , input_mailbox_id);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
-       if (sqlite3_changes(local_db_handle) == 0) 
-               EM_DEBUG_LOG("no attachment matched...");
+       if (sqlite3_changes(local_db_handle) == 0)
+               EM_DEBUG_LOG("no mail_meeting_tbl matched...");
 
+       /* Update mail_tbl */
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-               "UPDATE mail_meeting_tbl SET"
+               "UPDATE mail_tbl SET"
                " mailbox_name = '%s'"
-               " WHERE account_id = %d"
-               " AND mailbox_name = '%s'"
-               , new_mailbox_name
-               , account_id
-               , old_mailbox_name);
+               " WHERE mailbox_id = %d"
+               , input_new_mailbox_name
+               , input_mailbox_id);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        if (sqlite3_changes(local_db_handle) == 0) 
-               EM_DEBUG_LOG("no mail_meeting_tbl matched...");
+               EM_DEBUG_LOG("no mail matched...");
 
        ret = true;
        
 FINISH_OFF:
 
-       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
-       _DISCONNECT_DB;
-       
-       if (err_code != NULL)
-               *err_code = error;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-}
-       
-
-INTERNAL_FUNC int emstorage_change_attachment_mbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, error);
 
-       if (account_id < FIRST_ACCOUNT_ID || !old_mailbox_name || !new_mailbox_name)  {
-               EM_DEBUG_EXCEPTION(" account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p]", account_id, old_mailbox_name, new_mailbox_name);
-               
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               return false;
+       if (ret) {
+               if (!emstorage_notify_storage_event(NOTI_MAILBOX_RENAME, account_id, input_mailbox_id, input_new_mailbox_name, 0))
+                       EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAILBOX_RENAME ] >>>> ");
        }
-       
-       int rc, ret = true;
-       int error = EMF_ERROR_NONE;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-
-       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
-       SNPRINTF(sql_query_string, sizeof(sql_query_string),
-               "UPDATE mail_attachment_tbl SET"
-               " mailbox_name = '%s'"
-               " WHERE account_id = %d"
-               " AND mailbox_name = '%s'"
-               , new_mailbox_name
-               , account_id
-               , old_mailbox_name);
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
-               ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-       rc = sqlite3_changes(local_db_handle);
-       if (rc == 0)  {
-               EM_DEBUG_EXCEPTION(" no attachment found...");
+       else {
+               if (!emstorage_notify_storage_event(NOTI_MAILBOX_RENAME_FAIL, account_id, input_mailbox_id, input_new_mailbox_name, 0))
+                       EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAILBOX_RENAME_FAIL ] >>>> ");
        }
 
-       ret = true;
-       
-FINISH_OFF:
+       if (old_mailbox_data)
+               emstorage_free_mailbox(&old_mailbox_data, 1, NULL);
 
-       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
        _DISCONNECT_DB;
-       
-       if (err_code != NULL)
-               *err_code = error;
 
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
+       EM_DEBUG_FUNC_END("error [%d]", error);
+       return error;
 }
-
        
 INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("attachment_no [%p], err_code[%p]", attachment_no, err_code);
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char *sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
        char **result;
        
        if (!attachment_no)  {
                EM_DEBUG_EXCEPTION("Invalid attachment");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -9327,7 +9494,7 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        if (NULL == result[1])
@@ -9358,7 +9525,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        char *sql = NULL;
        char **result;
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -9366,7 +9533,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        if (!attachment_tbl)  {
                EM_DEBUG_EXCEPTION("attachment_tbl[%p], iscopy[%d]", attachment_tbl, iscopy);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
@@ -9375,7 +9542,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        if (NULL==result[1]) rc = 1;
@@ -9392,7 +9559,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
                ", ?"   /* attachment_size */
                ", ?"   /* mail_id */
                ", ?"   /* account_id */
-               ", ?"   /* mailbox_name */
+               ", ?"   /* mailbox_id */
                ", ?"   /* attachment_save_status */
                ", ?"   /* attachment_drm_type */
                ", ?"   /* attachment_drm_method */
@@ -9406,7 +9573,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_id);
@@ -9415,7 +9582,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        _bind_stmt_field_data_int   (hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_size);
        _bind_stmt_field_data_int   (hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->mail_id);
        _bind_stmt_field_data_int   (hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->account_id);
-       _bind_stmt_field_data_string(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+       _bind_stmt_field_data_int   (hStmt, MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->mailbox_id);
        _bind_stmt_field_data_int   (hStmt, ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_save_status);
        _bind_stmt_field_data_int   (hStmt, ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_drm_type);
        _bind_stmt_field_data_int   (hStmt, ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_drm_method);
@@ -9428,9 +9595,9 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 /*
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -9438,15 +9605,15 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 */
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no matched mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        
@@ -9457,7 +9624,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -9476,13 +9643,13 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
        EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], transaction[%d], err_code[%p]", attachment_tbl, transaction, err_code);
        
        int rc, ret = false, field_idx = 0;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        if (!attachment_tbl)  {
                EM_DEBUG_EXCEPTION(" attachment_tbl[%p] ", attachment_tbl);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -9497,7 +9664,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
                ", attachment_size = ?"
                ", mail_id = ?"
                ", account_id = ?"
-               ", mailbox_name = ?"
+               ", mailbox_id = ?"
                ", attachment_save_status = ?"
                ", attachment_drm_type = ?"
                ", attachment_drm_method = ?"
@@ -9508,7 +9675,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
@@ -9516,7 +9683,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
        _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->attachment_size);
        _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->mail_id);
        _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->account_id);
-       _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+       _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->mailbox_id);
        _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->attachment_save_status);
        _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->attachment_drm_type);
        _bind_stmt_field_data_int   (hStmt, field_idx++ , attachment_tbl->attachment_drm_method);
@@ -9526,9 +9693,9 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 /* 
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -9536,15 +9703,15 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 */
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no matched mail found...");
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        
@@ -9555,7 +9722,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -9569,34 +9736,67 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_delete_attachment_on_db(int mail_id, int attachment_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id[%d], transaction[%d], err_code[%p]", mail_id, attachment_id, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("attachment_id[%d], transaction[%d], err_code[%p]", attachment_id, transaction, err_code);
        
-       if (mail_id < 0 || attachment_id < 0)  {
-               EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d]", mail_id, attachment_id);
+       if (attachment_id < 0)  {
+               EM_DEBUG_EXCEPTION("attachment_id[%d]", attachment_id);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
        EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
        
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl");
-       
-       if (mail_id)    /*  '0' means all mail */
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE mail_id = %d", mail_id);
-       if (attachment_id) /*  '0' means all attachment */
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND attachment_id = %d", attachment_id);
-               
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE attachment_id = %d", attachment_id);
+
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+       ret = true;
+
+FINISH_OFF:
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+       _DISCONNECT_DB;
+
+       if (err_code)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
+
+       if (mail_id < 0)  {
+               EM_DEBUG_EXCEPTION("mail_id[%d]", mail_id);
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+
+       int rc, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       char sql_query_string[QUERY_SIZE] = {0, };
+
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE mail_id = %d", mail_id);
+
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        ret = true;
@@ -9612,11 +9812,11 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mbox[%p], transaction[%d], err_code[%p]", account_id, mbox, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code);
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc, ret = false;
        char sql_query_string[QUERY_SIZE] = {0, };
        
@@ -9629,11 +9829,11 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mb
        if (account_id != ALL_ACCOUNT) /*  '0' means all account */
                SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id);
 
-       if (mbox)       /*  NULL means all mailbox_name */
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mbox);
+       if (mailbox)    /*  NULL means all mailbox_name */
+               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mailbox);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        ret = true;
@@ -9657,7 +9857,7 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm
                if ((attachment_tbl_list == NULL) || (*attachment_tbl_list == NULL))  {
                        EM_DEBUG_EXCEPTION(" attachment_tbl_list[%p], count[%d]", attachment_tbl_list, count);
                        if (err_code != NULL)
-                               *err_code = EMF_ERROR_INVALID_PARAM;
+                               *err_code = EMAIL_ERROR_INVALID_PARAM;
                        return false;
                }
                
@@ -9665,7 +9865,6 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm
                int i;
                
                for (i = 0; i < count; i++)  {
-                       EM_SAFE_FREE(p[i].mailbox_name);
                        EM_SAFE_FREE(p[i].attachment_name);
                        EM_SAFE_FREE(p[i].attachment_path);
 #ifdef __ATTACHMENT_OPTI__
@@ -9678,7 +9877,7 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm
        }
        
        if (err_code != NULL)
-               *err_code = EMF_ERROR_NONE;
+               *err_code = EMAIL_ERROR_NONE;
        EM_DEBUG_FUNC_END();
        return true;
 }
@@ -9709,7 +9908,7 @@ INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code)
        EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; },
                ("SQL(BEGIN) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
        if (ret == false && err_code != NULL)
-               *err_code = EMF_ERROR_DB_FAILURE;
+               *err_code = EMAIL_ERROR_DB_FAILURE;
 
        EM_PROFILE_END(emStorageBeginTransaction);
        EM_DEBUG_FUNC_END("ret [%d]", ret);
@@ -9732,7 +9931,7 @@ INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code
 
        LEAVE_CRITICAL_SECTION(_transactionEndLock);
        if (ret == false && err_code != NULL)
-               *err_code = EMF_ERROR_DB_FAILURE;
+               *err_code = EMAIL_ERROR_DB_FAILURE;
 
        EM_DEBUG_FUNC_END("ret [%d]", ret);
        return ret;
@@ -9757,38 +9956,38 @@ INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_co
        LEAVE_CRITICAL_SECTION(_transactionEndLock);
 
        if (ret == false && err_code != NULL)
-               *err_code = EMF_ERROR_DB_FAILURE;
+               *err_code = EMAIL_ERROR_DB_FAILURE;
 
        EM_DEBUG_FUNC_END("ret [%d]", ret);
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, emf_mailbox_t* mailbox_name, int *result, int *err_code)
+INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mailbox, int *result, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], result[%p], err_code[%p]", account_id, mailbox_name, result, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], result[%p], err_code[%p]", account_id, mailbox, result, err_code);
        
-       if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result)  {
-               if (mailbox_name)
-                       EM_DEBUG_EXCEPTION("Invalid Parameter. accoun_id[%d], mailbox_name[%p]", account_id, mailbox_name);
+       if (account_id < FIRST_ACCOUNT_ID || !mailbox || !result)  {
+               if (mailbox)
+                       EM_DEBUG_EXCEPTION("Invalid Parameter. accoun_id[%d], mailbox[%p]", account_id, mailbox);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
 
                return false;
        }
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int mail_count = 0;
 
-       if (!emstorage_get_mail_count(account_id, mailbox_name->name, &mail_count, NULL, true, &error)) {
+       if (!emstorage_get_mail_count(account_id, mailbox->mailbox_name, &mail_count, NULL, true, &error)) {
                EM_DEBUG_EXCEPTION("emstorage_get_mail_count failed [%d]", error);
                goto FINISH_OFF;
        }
        
-       if (mailbox_name) {
-               EM_DEBUG_LOG("mail_count[%d] mail_slot_size[%d]", mail_count, mailbox_name->mail_slot_size);
-               if (mail_count >= mailbox_name->mail_slot_size)
+       if (mailbox) {
+               EM_DEBUG_LOG("mail_count[%d] mail_slot_size[%d]", mail_count, mailbox->mail_slot_size);
+               if (mail_count >= mailbox->mail_slot_size)
                        *result = true;
                else
                        *result = false;
@@ -9811,11 +10010,11 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
        EM_DEBUG_FUNC_BEGIN("transaction[%d], err_code[%p]", transaction, err_code);
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
-       const emf_db_object_t* tables = _g_db_tables;
-       const emf_db_object_t* indexes = _g_db_indexes;
+       const email_db_object_t* tables = _g_db_tables;
+       const email_db_object_t* indexes = _g_db_indexes;
        char data_path[256];
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -9837,7 +10036,7 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
                if (indexes->data_flag)  {
                        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP index %s", indexes->object_name);
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                }
                indexes++;
@@ -9847,7 +10046,7 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
                if (tables->data_flag)  {
                        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP table %s", tables->object_name);
                        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                }
                
@@ -9892,14 +10091,14 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
        EM_PROFILE_BEGIN(profile_emstorage_get_save_name);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char *dir_name = NULL;
        char create_dir[1024]={0};
        char *temp_file = NULL;
        
        if (!name_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0)  {        
                EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -9955,7 +10154,7 @@ INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_
        if (!name_buf || account_id < FIRST_ACCOUNT_ID)  {
                EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
@@ -9983,7 +10182,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
        EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], err_code[%p]", account_id, mail_id, atch_id, err_code);
        EM_PROFILE_BEGIN(profile_emcore_save_create_dir);
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        char buf[512];
        struct stat sbuf;
@@ -9993,7 +10192,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
                if (stat(buf, &sbuf) == 0) {
                        if ((sbuf.st_mode & S_IFMT) != S_IFDIR)  {
                                EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
-                               error = EMF_ERROR_SYSTEM_FAILURE;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                goto FINISH_OFF;
                        }
                }
@@ -10001,7 +10200,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
                        if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
                                EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
                                EM_DEBUG_EXCEPTION("mkdir failed l(Errno=%d)][ErrStr=%s]", errno, strerror(errno));
-                               error = EMF_ERROR_SYSTEM_FAILURE;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                goto FINISH_OFF;
                        }
                }
@@ -10010,7 +10209,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
        if (mail_id > 0)  {
                if (account_id < FIRST_ACCOUNT_ID)  {
                        EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
 
@@ -10020,7 +10219,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
                        if ((sbuf.st_mode & S_IFMT) != S_IFDIR)  {
                                EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
                                
-                               error = EMF_ERROR_SYSTEM_FAILURE;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                goto FINISH_OFF;
                        }
                }
@@ -10028,7 +10227,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
                        if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
                                EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
                                EM_DEBUG_EXCEPTION("mkdir failed l (Errno=%d)][ErrStr=%s]", errno, strerror(errno));
-                               error = EMF_ERROR_SYSTEM_FAILURE;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                goto FINISH_OFF;
                        }
                }
@@ -10038,7 +10237,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
                if (account_id < FIRST_ACCOUNT_ID || mail_id <= 0)  {
                        EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
                        
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
 
@@ -10048,14 +10247,14 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
                        if ((sbuf.st_mode & S_IFMT) != S_IFDIR)  {
                                EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
                                
-                               error = EMF_ERROR_SYSTEM_FAILURE;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                goto FINISH_OFF;
                        }
                }
                else  {
                        if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
                                EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
-                               error = EMF_ERROR_SYSTEM_FAILURE;
+                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                goto FINISH_OFF;
                        }
                }
@@ -10077,7 +10276,7 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s
        EM_DEBUG_FUNC_BEGIN("src_file[%s], dst_file[%s], err_code[%p]", src_file, dst_file, err_code);
        EM_DEBUG_LOG("Using the fsync function");
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        struct stat st_buf;
 
        int fp_src = 0;
@@ -10090,14 +10289,14 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s
        if (!src_file || !dst_file)  {
                EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file);
                
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
        if (stat(src_file, &st_buf) < 0) {
                EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", src_file);
                
-               error = EMF_ERROR_SYSTEM_FAILURE;               /* EMF_ERROR_INVALID_PATH; */
+               error = EMAIL_ERROR_SYSTEM_FAILURE;             /* EMAIL_ERROR_INVALID_PATH; */
                goto FINISH_OFF;
        }
        
@@ -10107,20 +10306,20 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s
 
        if (!buf) {
                EM_DEBUG_EXCEPTION(">>> Memory cannot be allocated");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
        if (buf) {
                if (!(fp_src = open(src_file, O_RDONLY))) {
                        EM_DEBUG_EXCEPTION(">>>> Source Fail open %s Failed [ %d ] - Error [ %s ]", src_file, errno, strerror(errno));
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;                                
                }
 
                if (!(fp_dst = open(dst_file, O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) {
                        EM_DEBUG_EXCEPTION(">>>> Destination Fail open %s Failed [ %d ] - Error [ %s ]", dst_file, errno, strerror(errno));
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;                                
                }
 
@@ -10129,7 +10328,7 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s
                                EM_DEBUG_LOG("Nread Value [%d]", nread);
                                if ((nwritten = write(fp_dst, buf, nread)) != nread) {
                                        EM_DEBUG_EXCEPTION("fwrite failed...");
-                                       error = EMF_ERROR_UNKNOWN;
+                                       error = EMAIL_ERROR_UNKNOWN;
                                        goto FINISH_OFF;
                                }
                                EM_DEBUG_LOG("NWRITTEN [%d]", nwritten);
@@ -10151,7 +10350,7 @@ FINISH_OFF:
                close(fp_dst);                  
        }
        EM_SAFE_FREE(buf);
-       if (nread < 0 || error == EMF_ERROR_UNKNOWN)
+       if (nread < 0 || error == EMAIL_ERROR_UNKNOWN)
                remove(dst_file);
        
        if (err_code != NULL)
@@ -10180,11 +10379,11 @@ static int _get_temp_file_name(char **filename, int *err_code)
        EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        if (filename == NULL) {
                EM_DEBUG_EXCEPTION(" filename[%p]", filename);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -10199,7 +10398,7 @@ static int _get_temp_file_name(char **filename, int *err_code)
        char *p = EM_SAFE_STRDUP(tempname);
        if (p == NULL)  {
                EM_DEBUG_EXCEPTION(" strdup failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        
@@ -10231,7 +10430,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in
        char *match_str = NULL;
        int nwritten = 0;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int data_count_to_written = 0;
        char *temp_file_name = NULL;
        int err = 0;
@@ -10244,7 +10443,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in
        if (stat(file_path, &st_buf) < 0) {
                EM_DEBUG_EXCEPTION(" stat(\"%s\") failed...", file_path);
                
-               error = EMF_ERROR_SYSTEM_FAILURE;               /* EMF_ERROR_INVALID_PATH; */
+               error = EMAIL_ERROR_SYSTEM_FAILURE;             /* EMAIL_ERROR_INVALID_PATH; */
                goto FINISH_OFF;
        }
 
@@ -10262,7 +10461,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in
        if (!(fp_src = fopen(file_path, "rb"))) {
                EM_DEBUG_EXCEPTION(" file_path fopen failed - %s", file_path);
                        
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;
                }
                                
@@ -10323,7 +10522,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in
                                        /* Open the Temp file in Append mode */
                                        if (!(fp_dest = fopen(temp_file_name, "ab"))) {
                                                EM_DEBUG_EXCEPTION(" fopen failed - %s", temp_file_name);
-                                               error = EMF_ERROR_SYSTEM_FAILURE;
+                                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                                goto FINISH_OFF;
                                        }
 
@@ -10338,7 +10537,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in
 
                                                if (nwritten <= 0) {
                                                        EM_DEBUG_EXCEPTION(" Error Occured while writing Old data : [%d ] bytes written ", nwritten);
-                                                       error = EMF_ERROR_SYSTEM_FAILURE;
+                                                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                                                        goto FINISH_OFF;
                                                }
                                                else {
@@ -10353,7 +10552,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in
                                        }
                                        else {
                                                EM_DEBUG_EXCEPTION(" Error Occured while writing New data : [%d ] bytes written ", nwritten);
-                                               error = EMF_ERROR_SYSTEM_FAILURE;
+                                               error = EMAIL_ERROR_SYSTEM_FAILURE;
                                                goto FINISH_OFF;
                                        }
                                                        
@@ -10392,11 +10591,11 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s
        EM_DEBUG_FUNC_BEGIN("src_file[%p], dst_file[%p], err_code[%p]", src_file, dst_file, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        if (src_file == NULL || dst_file == NULL)  {
                EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -10424,13 +10623,13 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s
                                                EM_DEBUG_EXCEPTION("no dst file found [%s]", src_file);
 
                                        EM_DEBUG_EXCEPTION("no file found [%d]", errno);
-                                       error = EMF_ERROR_FILE_NOT_FOUND;
+                                       error = EMAIL_ERROR_FILE_NOT_FOUND;
                                        goto FINISH_OFF;
                                        
                                }
                                else  {
                                        EM_DEBUG_EXCEPTION("rename failed [%d]", errno);
-                                       error = EMF_ERROR_SYSTEM_FAILURE;
+                                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                                        goto FINISH_OFF;
                                }
                        }
@@ -10455,12 +10654,12 @@ INTERNAL_FUNC int emstorage_delete_file(char *src_file, int *err_code)
        EM_DEBUG_FUNC_BEGIN("src_file[%p], err_code[%p]", src_file, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        if (src_file == NULL) {
                EM_DEBUG_EXCEPTION(" src_file[%p]", src_file);
                
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -10468,13 +10667,13 @@ INTERNAL_FUNC int emstorage_delete_file(char *src_file, int *err_code)
                if (errno != ENOENT) {
                        EM_DEBUG_EXCEPTION(" remove failed - %d", errno);
                        
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                        goto FINISH_OFF;
                }
                else {
                        EM_DEBUG_EXCEPTION(" no file found...");
                        
-                       error = EMF_ERROR_FILE_NOT_FOUND;
+                       error = EMAIL_ERROR_FILE_NOT_FOUND;
                }
        }
        
@@ -10497,11 +10696,11 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code)
                EM_DEBUG_EXCEPTION(" src_dir[%p]", src_dir);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        DIR *dirp;
        struct dirent *dp;
@@ -10514,13 +10713,13 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code)
                if (errno == ENOENT)  {
                        EM_DEBUG_EXCEPTION("directory[%s] does not exist...", src_dir);
                        if (err_code != NULL)
-                               *err_code = EMF_ERROR_SYSTEM_FAILURE;
+                               *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
                        return true;
                }
                else  {
                        EM_DEBUG_EXCEPTION("opendir failed - %d", errno);
                        if (err_code != NULL)
-                               *err_code = EMF_ERROR_SYSTEM_FAILURE;
+                               *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
                        return false;
                }
        }
@@ -10547,7 +10746,7 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code)
                                        EM_DEBUG_EXCEPTION("remove failed - %s", buf);
                                        closedir(dirp);
                                        if (err_code != NULL)
-                                               *err_code = EMF_ERROR_SYSTEM_FAILURE;
+                                               *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
                                        return false;
                                }
                        }
@@ -10565,7 +10764,7 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code)
        if (remove(src_dir) < 0)  {
                EM_DEBUG_EXCEPTION("remove failed [%s]", src_dir);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_SYSTEM_FAILURE;
+                       *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
                return false;
        }
        
@@ -10580,14 +10779,14 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se
 {
        EM_DEBUG_FUNC_BEGIN("new_server_uid[%s], old_server_uid[%s]", new_server_uid, old_server_uid);
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        int transaction = true;
        
        if (!old_server_uid || !new_server_uid) {       
                EM_DEBUG_EXCEPTION("Invalid parameters");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -10598,9 +10797,9 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se
                 "UPDATE mail_tbl SET server_mail_id=\'%s\' WHERE server_mail_id=%s ", new_server_uid, old_server_uid);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        ret = true;
@@ -10622,14 +10821,14 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], new_server_uid[%s], mbox_name[%s]", mail_id, new_server_uid, mbox_name);
 
        int rc, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        int transaction = true;
        
        if (!mail_id || !new_server_uid || !mbox_name)  {               
                EM_DEBUG_EXCEPTION("Invalid parameters");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -10637,9 +10836,9 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u
 
        
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\', local_mbox=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id);
+                "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\', mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id);
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        ret     = true;
          
@@ -10664,13 +10863,13 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co
        if ((!mail_id) ||(account_id <= 0 &&  account_id != -1)) {
                EM_DEBUG_EXCEPTION(" mail_id[%p], account_id[%d] ", mail_id, account_id);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }       
 
        int ret = false;
        int rc = -1;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        int count = 0;
        int mailid = 0;
@@ -10689,24 +10888,24 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co
                
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("  sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        char **result;
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        sqlite3_free_table(result);
        if (count == 0)  {
                EM_DEBUG_EXCEPTION("no Mails found...");
                ret = false;
-               error= EMF_ERROR_MAIL_NOT_FOUND;
+               error= EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        
@@ -10722,7 +10921,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
        EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
@@ -10782,12 +10981,12 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
                EM_DEBUG_EXCEPTION("total_usage[%p]", total_usage);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int   ret = false;
-       int   error = EMF_ERROR_NONE;
+       int   error = EMAIL_ERROR_NONE;
        char  syscmd[256] = {0, };
        char  line[256] = {0, };
        char *line_from_file = NULL;
@@ -10798,7 +10997,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
        if (setting_system_command(syscmd) == -1) {
                EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd);
 
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;                
        }
 
@@ -10807,7 +11006,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
        if (setting_system_command(syscmd) == -1) {
                EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : Setting > Memory] System Command [%s] is failed", syscmd);
                
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;        
        }
 
@@ -10815,7 +11014,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
        if (fp == NULL) {
                perror(SETTING_MEMORY_TEMP_FILE_PATH);
                
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;        
        }
  
@@ -10823,7 +11022,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
 
        if(line_from_file == NULL) {
                EM_DEBUG_EXCEPTION("fgets failed");
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
        total_diskusage = strtoul(line, NULL, 10);
@@ -10834,7 +11033,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
        SNPRINTF(syscmd, sizeof(syscmd), "rm -f %s", SETTING_MEMORY_TEMP_FILE_PATH);
        if (setting_system_command(syscmd) == -1) {
                EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage :  [Setting > Memory] System Command [%s] is failed", syscmd);
-               error = EMF_ERROR_SYSTEM_FAILURE;
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;        
        }
 
@@ -10860,7 +11059,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
 {
        DB_STMT hStmt = NULL;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc = 0;
        char sql_query_string[QUERY_SIZE] = {0, };
 
@@ -10907,7 +11106,10 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
                ", ?" /*  alias_sender */
                ", ?" /*  alias_recipient */
                ", ?" /*  thread_item_count */
-               ", ?"   /*  meeting_request_status */
+               ", ?" /*  meeting_request_status */
+               ", ?" /*  message_class */
+               ", ?" /*  digest_type */
+               ", ?" /*  smime_type */
                ")");
 
        int transaction = true;
@@ -10917,13 +11119,13 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
  
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       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, MAIL_ID_IDX_IN_MAIL_TBL, mail_id);
        _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_TBL, account_id);
        _bind_stmt_field_data_string(hStmt, MAILBOX_NAME_IDX_IN_MAIL_TBL, "OUTBOX", 0, MAILBOX_LEN_IN_MAIL_TBL);
-       _bind_stmt_field_data_int(hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, EMF_MAILBOX_TYPE_OUTBOX);
+       _bind_stmt_field_data_int(hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, EMAIL_MAILBOX_TYPE_OUTBOX);
        _bind_stmt_field_data_string(hStmt, SUBJECT_IDX_IN_MAIL_TBL, "save test - long", 1, SUBJECT_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_string(hStmt, DATETIME_IDX_IN_MAIL_TBL, "20100316052908", 0, DATETIME_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_int(hStmt, SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL, 0);
@@ -10963,11 +11165,14 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
        _bind_stmt_field_data_int(hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, 0);
        _bind_stmt_field_data_string(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, "preview body", 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
        _bind_stmt_field_data_int(hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, 0);
+       _bind_stmt_field_data_int(hStmt, MESSAGE_CLASS_IDX_IN_MAIL_TBL, 0);
+       _bind_stmt_field_data_int(hStmt, DIGEST_TYPE_IDX_IN_MAIL_TBL, 0);
+       _bind_stmt_field_data_int(hStmt, SMIME_TYPE_IDX_IN_MAIL_TBL, 0);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        ret = true;
 
@@ -10976,7 +11181,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
  
@@ -11002,7 +11207,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
        EM_PROFILE_BEGIN(profile_emstorage_get_thread_id_of_thread_mails);
        int      rc = 0, query_size = 0, query_size_account = 0;
        int      account_id = 0;
-       int      err_code = EMF_ERROR_NONE;
+       int      err_code = EMAIL_ERROR_NONE;
        int      count = 0, result_thread_id = -1, latest_mail_id_in_thread = -1;
        time_t   latest_date_time = 0;
        time_t   date_time = 0;
@@ -11015,14 +11220,14 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
        char     stripped_subject[1025];
        sqlite3 *local_db_handle = emstorage_get_db_connection();
 
-       EM_IF_NULL_RETURN_VALUE(mail_tbl, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(thread_id, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(result_latest_mail_id_in_thread, EMF_ERROR_INVALID_PARAM);
-       EM_IF_NULL_RETURN_VALUE(thread_item_count, EMF_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(mail_tbl, EMAIL_ERROR_INVALID_PARAM);
+       EM_IF_NULL_RETURN_VALUE(thread_id, EMAIL_ERROR_INVALID_PARAM);
+       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 == EMF_MAILBOX_TYPE_TRASH ||
-           mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_SPAMBOX ||
-           mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_ALL_EMAILS) {
+       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;
        }
@@ -11034,9 +11239,9 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
        
        EM_DEBUG_LOG("subject : %s", subject);
 
-       if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject) != EMF_ERROR_NONE)  {
+       if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject) != EMAIL_ERROR_NONE)        {
                EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view  is failed");
-               err_code =  EMF_ERROR_UNKNOWN;
+               err_code =  EMAIL_ERROR_UNKNOWN;
                result_thread_id = -1;
                goto FINISH_OFF;
        }
@@ -11053,7 +11258,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
                sql_account = malloc(query_size_account);
                if (sql_account == NULL) {
                        EM_DEBUG_EXCEPTION("malloc for sql_account  is failed %d", query_size_account);
-                       err_code =  EMF_ERROR_OUT_OF_MEMORY;
+                       err_code =  EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
                snprintf(sql_account, query_size_account, sql_format_account, account_id);
@@ -11065,7 +11270,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
        
        if (sql_query_string == NULL) {
                EM_DEBUG_EXCEPTION("malloc for sql  is failed %d", query_size);
-               err_code =  EMF_ERROR_OUT_OF_MEMORY;
+               err_code =  EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -11081,7 +11286,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG("Result rows count : %d", count);
@@ -11124,7 +11329,7 @@ INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail
        EM_DEBUG_FUNC_BEGIN();
        
        int count = 0, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        emstorage_mail_tbl_t *p_data_tbl = NULL;
        char conditional_clause[QUERY_SIZE] = {0, };
 
@@ -11157,24 +11362,24 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count,  int *err_code)
+INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count,  int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], search_type [%d], search_value [%p], sorting [%d], sender_list[%p], sender_count[%p] err_code[%p]"
                , account_id , mailbox_name , search_type , search_value , sorting , sender_list, sender_count, err_code);
        
        if ((!sender_list) ||(!sender_count)) {
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int count = 0;
        int i, col_index = 0;
        int read_count = 0;
-       emf_sender_list_t *p_sender_list = NULL;
+       email_sender_list_t *p_sender_list = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        char **result = NULL;
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -11196,23 +11401,23 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_
 
        if (search_value) {
                switch (search_type) {
-                       case EMF_SEARCH_FILTER_SUBJECT:
+                       case EMAIL_SEARCH_FILTER_SUBJECT:
                                SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
                                        " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", search_value);
                                break;
-                       case EMF_SEARCH_FILTER_SENDER:
+                       case EMAIL_SEARCH_FILTER_SENDER:
                                SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
                                        " AND  ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
                                        ") ", search_value);
                                break;
-                       case EMF_SEARCH_FILTER_RECIPIENT:
+                       case EMAIL_SEARCH_FILTER_RECIPIENT:
                                SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
                                        " AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "    
                                        "       OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
                                        "       OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
                                        ") ", search_value, search_value, search_value);
                                break;
-                       case EMF_SEARCH_FILTER_ALL:
+                       case EMAIL_SEARCH_FILTER_ALL:
                                SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
                                        " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') "
                                        "       OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
@@ -11235,14 +11440,14 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_
        EM_DEBUG_LOG("query[%s]", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG("Count of Sender [%d]", count);
        
-       if (!(p_sender_list = (emf_sender_list_t*)em_malloc(sizeof(emf_sender_list_t) * count))) {
+       if (!(p_sender_list = (email_sender_list_t*)em_malloc(sizeof(email_sender_list_t) * count))) {
                EM_DEBUG_EXCEPTION("em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -11281,20 +11486,20 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_free_sender_list(emf_sender_list_t **sender_list, int count)
+INTERNAL_FUNC int emstorage_free_sender_list(email_sender_list_t **sender_list, int count)
 {
        EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count);
 
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        
        if (count > 0)  {
                if (!sender_list || !*sender_list)  {
                        EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count);
-                       err = EMF_ERROR_INVALID_PARAM;
+                       err = EMAIL_ERROR_INVALID_PARAM;
                        return err;
                }
                
-               emf_sender_list_t* p = *sender_list;
+               email_sender_list_t* p = *sender_list;
                int i = 0;
                
                for (; i < count; i++)  {
@@ -11310,35 +11515,35 @@ INTERNAL_FUNC int emstorage_free_sender_list(emf_sender_list_t **sender_list, in
 }
 
 
-INTERNAL_FUNC int emstorage_free_address_info_list(emf_address_info_list_t **address_info_list)
+INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **address_info_list)
 {
        EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
 
-       int err = EMF_ERROR_NONE;
-       emf_address_info_t *p_address_info = NULL;
+       int err = EMAIL_ERROR_NONE;
+       email_address_info_t *p_address_info = NULL;
        GList *list = NULL;
        GList *node = NULL;
        int i = 0;
        
        if (!address_info_list || !*address_info_list)  {
                EM_DEBUG_EXCEPTION("address_info_list[%p]", address_info_list);
-               err = EMF_ERROR_INVALID_PARAM;
+               err = EMAIL_ERROR_INVALID_PARAM;
                return err;
        }
 
        /*  delete GLists */
-       for (i = EMF_ADDRESS_TYPE_FROM; i <= EMF_ADDRESS_TYPE_BCC; i++) {
+       for (i = EMAIL_ADDRESS_TYPE_FROM; i <= EMAIL_ADDRESS_TYPE_BCC; i++) {
                switch (i) {
-                       case EMF_ADDRESS_TYPE_FROM:
+                       case EMAIL_ADDRESS_TYPE_FROM:
                                list = (*address_info_list)->from;
                                break;
-                       case EMF_ADDRESS_TYPE_TO:
+                       case EMAIL_ADDRESS_TYPE_TO:
                                list = (*address_info_list)->to;
                                break;
-                       case EMF_ADDRESS_TYPE_CC:
+                       case EMAIL_ADDRESS_TYPE_CC:
                                list = (*address_info_list)->cc;
                                break;
-                       case EMF_ADDRESS_TYPE_BCC:
+                       case EMAIL_ADDRESS_TYPE_BCC:
                                list = (*address_info_list)->bcc;
                                break;
                }
@@ -11346,7 +11551,7 @@ INTERNAL_FUNC int emstorage_free_address_info_list(emf_address_info_list_t **add
                /*  delete dynamic-allocated memory for each item */
                node = g_list_first(list);
                while (node != NULL) {
-                       p_address_info = (emf_address_info_t*)node->data;
+                       p_address_info = (email_address_info_t*)node->data;
                        EM_SAFE_FREE(p_address_info->address);
                        EM_SAFE_FREE(p_address_info->display_name);
                        EM_SAFE_FREE(node->data);
@@ -11363,20 +11568,20 @@ INTERNAL_FUNC int emstorage_free_address_info_list(emf_address_info_list_t **add
 }
 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
 
-INTERNAL_FUNC int emstorage_add_pbd_activity(emf_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("local_activity[%p], activity_id[%p], transaction[%d], err_code[%p]", local_activity, activity_id, transaction, err_code);
 
        if (!local_activity || !activity_id) {
                EM_DEBUG_EXCEPTION("local_activity[%p], transaction[%d], activity_id[%p], err_code[%p]", local_activity, activity_id, transaction, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int i = 0;
 
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -11392,6 +11597,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(emf_event_partial_body_thd* local_a
                ",?"  /* Server mail ID */
                ",?"  /* Activity ID */
                ",?"  /* Activity type*/
+               ",?"  /* Mailbox ID*/
                ",?"  /* Mailbox name*/
                ") ");
 
@@ -11401,7 +11607,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(emf_event_partial_body_thd* local_a
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
 
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        if (NULL==result[1]) rc = 1;
@@ -11414,12 +11620,12 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(emf_event_partial_body_thd* local_a
        EM_DEBUG_LOG(">>>>> ACTIVITY ID [ %d ], MAIL ID [ %d ], ACTIVITY TYPE [ %d ], SERVER MAIL ID [ %lu ]", \
                local_activity->activity_id, local_activity->mail_id, local_activity->activity_type, local_activity->server_mail_id);
 
-       if (local_activity->mailbox_name)
-               EM_DEBUG_LOG(" MAILBOX NAME [ %s ]", local_activity->mailbox_name);
+       if (local_activity->mailbox_id)
+               EM_DEBUG_LOG(" MAILBOX ID [ %d ]", local_activity->mailbox_id);
        
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG(">>>> SQL STMT [ %s ]", sql_query_string);
@@ -11429,14 +11635,15 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(emf_event_partial_body_thd* local_a
        _bind_stmt_field_data_int(hStmt, i++, local_activity->server_mail_id);
        _bind_stmt_field_data_int(hStmt, i++, local_activity->activity_id);
        _bind_stmt_field_data_int(hStmt, i++, local_activity->activity_type);
+       _bind_stmt_field_data_int(hStmt, i++, local_activity->mailbox_id);
        _bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->mailbox_name, 0, 3999);
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
 
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
        
        ret = true;
@@ -11450,7 +11657,7 @@ FINISH_OFF:
                hStmt = NULL;
                if (rc != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -11464,22 +11671,22 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, char *** mailbox_list, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
 
        if (account_id < FIRST_ACCOUNT_ID || NULL == &mailbox_list || NULL == count) {
                EM_DEBUG_EXCEPTION("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char **result;
        int i = 0, rc = -1;
-       char **mbox_list = NULL;
+       int *mbox_list = NULL;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
 
@@ -11488,11 +11695,11 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, char *** mailbo
        EMSTORAGE_START_READ_TRANSACTION(transaction);
 
        memset(sql_query_string, 0x00, sizeof(sql_query_string));
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(distinct mailbox_name) FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_name", account_id);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(distinct mailbox_id) FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_id", account_id);
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -11500,7 +11707,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, char *** mailbo
 
        if (!*count) {
                EM_DEBUG_EXCEPTION(" no mailbox_name found...");
-               error = EMF_ERROR_MAILBOX_NOT_FOUND;
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
                ret = true;
                goto FINISH_OFF;
        }
@@ -11509,7 +11716,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, char *** mailbo
        memset(sql_query_string, 0x00, sizeof(sql_query_string));
 
        /* SNPRINTF(g_sql_query, sizeof(g_sql_query), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by activity_id", account_id); */
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_name", account_id);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_id FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_id", account_id);
 
        EM_DEBUG_LOG(" Query [%s]", sql_query_string);
        
@@ -11517,30 +11724,29 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, char *** mailbo
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
 
        EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
-       if (NULL == (mbox_list = (char **)em_malloc(sizeof(char *) * (*count)))) {
+       if (NULL == (mbox_list = (int *)em_malloc(sizeof(int *) * (*count)))) {
                EM_DEBUG_EXCEPTION(" em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
-       memset(mbox_list, 0x00, sizeof(char *) * (*count));
+       memset(mbox_list, 0x00, sizeof(int) * (*count));
        
        for (i = 0; i < (*count); i++) {
-               _get_stmt_field_data_string(hStmt, &mbox_list[i], 0, ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
-
+               _get_stmt_field_data_int(hStmt, mbox_list + i, 0);
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
                /* EM_DEBUG_LOG("In emstorage_get_pdb_mailbox_list() loop, After sqlite3_step(), , i = %d, rc = %d.", i,  rc); */
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
-               EM_DEBUG_LOG("mbox_list %s", mbox_list[i]);
+               EM_DEBUG_LOG("mbox_list %d", mbox_list + i);
        }
 
        ret = true;
@@ -11556,7 +11762,7 @@ FINISH_OFF:
                hStmt = NULL;
                if (rc != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -11576,12 +11782,12 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count,
        if (NULL == &account_list || NULL == count) {
                EM_DEBUG_EXCEPTION("mailbox_list[%p], count[%p] err_code[%p]", account_list, count, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char *sql;
        char **result;
        int i = 0, rc = -1;
@@ -11598,7 +11804,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count,
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -11606,7 +11812,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count,
 
        if (!*count) {
                EM_DEBUG_EXCEPTION("no account found...");
-               error = EMF_ERROR_MAILBOX_NOT_FOUND;
+               error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
                ret = true;
                goto FINISH_OFF;
        }
@@ -11623,17 +11829,17 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count,
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
 
        EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        if (NULL == (result_account_list = (int *)em_malloc(sizeof(int) * (*count)))) {
                EM_DEBUG_EXCEPTION(" em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -11643,7 +11849,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count,
                _get_stmt_field_data_int(hStmt, result_account_list + i, 0);
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
                EM_DEBUG_LOG("account id -> %d", result_account_list[i]);
        }
@@ -11661,7 +11867,7 @@ FINISH_OFF:
                hStmt = NULL;
                if (rc != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -11675,25 +11881,25 @@ FINISH_OFF:
 
 
 
-INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, char *mailbox_name, emf_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], event_start[%p], err_code[%p]", account_id, event_start, err_code);
 
-       if (account_id < FIRST_ACCOUNT_ID || NULL == event_start || NULL == mailbox_name || NULL == count) {
-               EM_DEBUG_EXCEPTION("account_id[%d], emf_event_partial_body_thd[%p], mailbox_name[%p], count[%p], err_code[%p]", account_id, event_start, mailbox_name, count, err_code);
+       if (account_id < FIRST_ACCOUNT_ID || NULL == event_start || 0 == input_mailbox_id || NULL == count) {
+               EM_DEBUG_EXCEPTION("account_id[%d], email_event_partial_body_thd[%p], input_mailbox_id[%d], count[%p], err_code[%p]", account_id, event_start, input_mailbox_id, count, err_code);
 
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc = -1;
        int ret = false;
        char **result;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int i = 0;
        DB_STMT hStmt = NULL;
-       emf_event_partial_body_thd* event_list = NULL;
+       email_event_partial_body_thd* event_list = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -11701,11 +11907,11 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, char *mailbox_
        EMSTORAGE_START_READ_TRANSACTION(transaction);
 
        memset(sql_query_string, 0x00, sizeof(sql_query_string));
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_name = '%s' order by activity_id", account_id, mailbox_name);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id);
        
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        *count = atoi(result[1]);
@@ -11716,14 +11922,14 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, char *mailbox_
        if (!*count) {
                EM_DEBUG_EXCEPTION("No matched activity found in mail_partial_body_activity_tbl");
 
-               error = EMF_ERROR_MAIL_NOT_FOUND;
+               error = EMAIL_ERROR_MAIL_NOT_FOUND;
                ret = true;
                goto FINISH_OFF;
        }
        EM_DEBUG_LOG("Activity Count = %d", *count);
        
        memset(sql_query_string, 0x00, sizeof(sql_query_string));
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_name = '%s' order by activity_id", account_id, mailbox_name);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id);
 
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
@@ -11731,21 +11937,21 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, char *mailbox_
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
 
        EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
-       if (!(event_list = (emf_event_partial_body_thd*)em_malloc(sizeof(emf_event_partial_body_thd) * (*count)))) {
+       if (!(event_list = (email_event_partial_body_thd*)em_malloc(sizeof(email_event_partial_body_thd) * (*count)))) {
                EM_DEBUG_EXCEPTION("Malloc failed");
 
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
-       memset(event_list, 0x00, sizeof(emf_event_partial_body_thd) * (*count));
+       memset(event_list, 0x00, sizeof(email_event_partial_body_thd) * (*count));
        
        for (i=0; i < (*count); i++) {
                _get_stmt_field_data_int(hStmt, &(event_list[i].account_id), ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
@@ -11753,12 +11959,12 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, char *mailbox_
                _get_stmt_field_data_int(hStmt, (int *)&(event_list[i].server_mail_id), SERVER_MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
                _get_stmt_field_data_int(hStmt, &(event_list[i].activity_id), ACTIVITY_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
                _get_stmt_field_data_int(hStmt, &(event_list[i].activity_type), ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+               _get_stmt_field_data_int(hStmt, &(event_list[i].mailbox_id), MAILBOX_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
                _get_stmt_field_data_string(hStmt, &(event_list[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
-               
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
                /* EM_DEBUG_LOG("In emstorage_get_pbd_activity_data() loop, After sqlite3_step(), , i = %d, rc = %d.", i,  rc); */
-               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("sqlite3_step fail:%d", rc));
 
                event_list[i].event_type = 0;
@@ -11770,11 +11976,7 @@ FINISH_OFF:
        if (true == ret)
          *event_start = event_list;
        else {
-               if (event_list) {
-                       for (i=0; i < (*count); i++)
-                               EM_SAFE_FREE(event_list[i].mailbox_name);
-                       EM_SAFE_FREE(event_list);
-               }
+               EM_SAFE_FREE(event_list);
        }
 
        if (hStmt != NULL) {
@@ -11784,7 +11986,7 @@ FINISH_OFF:
                hStmt = NULL;
                if (rc != SQLITE_OK) {
                        EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -11808,13 +12010,13 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int
                EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], activity_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, activity_id, transaction, err_code);
 
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -11830,16 +12032,16 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        /*  validate activity existence */
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION("No matching activity found");
-               error = EMF_ERROR_DATA_NOT_FOUND;
+               error = EMAIL_ERROR_DATA_NOT_FOUND;
                ret = true;
                goto FINISH_OFF;
        }
@@ -11858,19 +12060,19 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, char *mailbox_name, int *activity_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
 
        if (account_id < FIRST_ACCOUNT_ID || NULL == activity_count || NULL == err_code) {
                EM_DEBUG_EXCEPTION("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        DB_STMT hStmt = NULL;
@@ -11880,19 +12082,19 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, char
        EMSTORAGE_START_READ_TRANSACTION(transaction);
        memset(sql_query_string, 0x00, sizeof(sql_query_string));
        
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d and mailbox_name = '%s'", account_id, mailbox_name);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d and mailbox_id = '%d'", account_id, input_mailbox_id);
 
        EM_DEBUG_LOG(" Query [%s]", sql_query_string);
 
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        _get_stmt_field_data_int(hStmt, activity_count, 0);
@@ -11909,7 +12111,7 @@ FINISH_OFF:
                hStmt=NULL;
                if (rc != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
                EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
        }
@@ -11932,12 +12134,12 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int tran
        if (NULL == activity_count || NULL == err_code) {
                EM_DEBUG_EXCEPTION("activity_count[%p], err_code[%p]", activity_count, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
 
@@ -11953,12 +12155,12 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int tran
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
        EM_DEBUG_LOG("  before sqlite3_prepare hStmt = %p", hStmt);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
 
        _get_stmt_field_data_int(hStmt, activity_count, 0);
@@ -11977,7 +12179,7 @@ FINISH_OFF:
                hStmt=NULL;
                if (rc != SQLITE_OK) {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
                EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
        }
@@ -11997,13 +12199,13 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr
        if (account_id < FIRST_ACCOUNT_ID) {
                EM_DEBUG_EXCEPTION("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -12014,16 +12216,16 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0) {
                EM_DEBUG_EXCEPTION("No matching activities found in mail_partial_body_activity_tbl");
-               error = EMF_ERROR_DATA_NOT_FOUND;
+               error = EMAIL_ERROR_DATA_NOT_FOUND;
                ret = true;
                goto FINISH_OFF;
        }
@@ -12049,14 +12251,14 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_
        EM_DEBUG_FUNC_BEGIN("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name);
 
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        int transaction = true;
 
        if (!old_server_uid || !new_server_uid || !mbox_name)  {
                EM_DEBUG_EXCEPTION("Invalid parameters");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
@@ -12069,15 +12271,15 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_
        EM_DEBUG_LOG("Query [%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0) {
                EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl");
-               error = EMF_ERROR_DATA_NOT_FOUND;
+               error = EMAIL_ERROR_DATA_NOT_FOUND;
                goto FINISH_OFF;
        }
 
@@ -12100,13 +12302,13 @@ INTERNAL_FUNC int emstorage_create_file(char *data_string, size_t file_size, cha
        EM_DEBUG_FUNC_BEGIN("file_size[%d] , dst_file_name[%s], err_code[%p]", file_size, dst_file_name, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        
        FILE* fp_dst = NULL;
        
        if (!data_string || !dst_file_name)  {                          
                EM_DEBUG_EXCEPTION("data_string[%p], dst_file_name[%p]", data_string, dst_file_name);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -12115,15 +12317,15 @@ INTERNAL_FUNC int emstorage_create_file(char *data_string, size_t file_size, cha
        if (!fp_dst)  {
                EM_DEBUG_EXCEPTION("fopen failed - %s", dst_file_name);
                if (errno == 28)
-                       error = EMF_ERROR_MAIL_MEMORY_FULL;
+                       error = EMAIL_ERROR_MAIL_MEMORY_FULL;
                else
-                       error = EMF_ERROR_SYSTEM_FAILURE;
+                       error = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;                        
        }
        
        if (fwrite(data_string, 1, file_size, fp_dst) < 0) {
                EM_DEBUG_EXCEPTION("fwrite failed...");
-               error = EMF_ERROR_UNKNOWN;
+               error = EMAIL_ERROR_UNKNOWN;
                goto FINISH_OFF;
        }
        
@@ -12152,14 +12354,14 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_
        EM_DEBUG_FUNC_BEGIN();
        int rc = -1;                               
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
 
        int transaction = true;
                
        if (!old_server_uid || !new_server_uid || !mbox_name)  {                
                EM_DEBUG_EXCEPTION("Invalid parameters");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
@@ -12170,14 +12372,14 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_
 
        
        SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\' , local_mbox=\'%s\', mailbox_name=\'%s\' WHERE s_uid=%s ", new_server_uid, mbox_name, mbox_name, old_server_uid);
+                "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\' , mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE s_uid=%s ", new_server_uid, mbox_name, mbox_name, old_server_uid);
 
         EM_DEBUG_LOG(" Query [%s]", sql_query_string);
         
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-        EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+        EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
                 ("sqlite3_exec fail:%d", rc));
-        EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+        EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                 ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
         
         
@@ -12185,7 +12387,7 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_
         if (rc == 0)
         {
                 EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl");
-                error = EMF_ERROR_DATA_NOT_FOUND;
+                error = EMAIL_ERROR_DATA_NOT_FOUND;
                 goto FINISH_OFF;
         }
 
@@ -12207,7 +12409,7 @@ FINISH_OFF:
 
 
 /**
- * @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, emf_id_set_t** server_uids, int *id_set_count, int *err_code);
+ * @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, email_id_set_t** server_uids, int *id_set_count, int *err_code);
  * Prepare an array of mail_id and corresponding server mail id.
  *
  *@author                                      h.gahlaut@samsung.com
@@ -12221,14 +12423,14 @@ FINISH_OFF:
  * @return This function returns true on success or false on failure.
  */
  
-INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, emf_id_set_t** idset, int *id_set_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_set_t** idset, int *id_set_count, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds);
 
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int ret = false;
-       emf_id_set_t* p_id_set = NULL;
+       email_id_set_t* p_id_set = NULL;
        int count = 0;
        const int buf_size = QUERY_SIZE;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -12242,7 +12444,7 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, emf_id_set_
        
        if (NULL == mail_ids || NULL == idset || NULL == id_set_count) {
                EM_DEBUG_EXCEPTION("Invalid Parameters mail_ids[%p] idset[%p]  id_set_count [%p]", mail_ids, idset, id_set_count);
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -12254,21 +12456,21 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, emf_id_set_
        
        /*  rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG(" Count of mails [%d ]", count);
 
        if (count <= 0) {
                EM_DEBUG_EXCEPTION("Can't find proper mail");
-               error = EMF_ERROR_DATA_NOT_FOUND;
+               error = EMAIL_ERROR_DATA_NOT_FOUND;
                goto FINISH_OFF;
        }
 
 
-       if (NULL == (p_id_set = (emf_id_set_t*)em_malloc(sizeof(emf_id_set_t) * count)))  {
+       if (NULL == (p_id_set = (email_id_set_t*)em_malloc(sizeof(email_id_set_t) * count)))  {
                EM_DEBUG_EXCEPTION(" em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -12319,7 +12521,7 @@ INTERNAL_FUNC int emstorage_delete_triggers_from_lucene()
 {
        EM_DEBUG_FUNC_BEGIN();
        int rc, ret = true, transaction = true;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        
        sqlite3 *local_db_handle = emstorage_get_db_connection();
@@ -12328,20 +12530,20 @@ INTERNAL_FUNC int emstorage_delete_triggers_from_lucene()
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerDelete;");
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerInsert;");
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
 
        SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerUpdate;");
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        ret = true;
@@ -12356,19 +12558,19 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mailbox_name, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
+INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_name[%p] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_name, rule, filtered_mail_id_list, count_of_mails, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_id[%d] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_id, rule, filtered_mail_id_list, count_of_mails, err_code);
        
-       if ((account_id <= 0) || (!dest_mailbox_name) || (!rule) || (!rule->value)|| (!filtered_mail_id_list) || (!count_of_mails)) {
+       if ((account_id <= 0) || (dest_mailbox_id <= 0) || (!rule) || (!rule->value)|| (!filtered_mail_id_list) || (!count_of_mails)) {
                EM_DEBUG_EXCEPTION("Invalid Parameter");
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
-       int rc = -1, ret = false, error = EMF_ERROR_NONE;
+       int rc = -1, ret = false, error = EMAIL_ERROR_NONE;
        int count = 0, col_index = 0, i = 0, where_pararaph_length = 0, *mail_list = NULL;
        char **result = NULL, *where_pararaph = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -12384,7 +12586,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mail
 
        if (where_pararaph == NULL) {
                EM_DEBUG_EXCEPTION("malloc failed for where_pararaph.");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -12392,20 +12594,20 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mail
        
        EM_DEBUG_LOG("rule->type [%d], rule->flag2[%d]", rule->type, rule->flag2);
 
-       if (rule->type == EMF_FILTER_FROM) {
+       if (rule->type == EMAIL_FILTER_FROM) {
                if (rule->flag2 == RULE_TYPE_INCLUDES)
                        SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND full_address_from like \'%%%s%%\'", account_id, rule->value);
                else /*  RULE_TYPE_EXACTLY */
                        SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND full_address_from = \'%s\'", account_id, rule->value);
        }
-       else if (rule->type == EMF_FILTER_SUBJECT) {
+       else if (rule->type == EMAIL_FILTER_SUBJECT) {
                if (rule->flag2 == RULE_TYPE_INCLUDES)
                        SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND subject like \'%%%s%%\'", account_id, rule->value);
                else /*  RULE_TYPE_EXACTLY */
                        SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND subject = \'%s\'", account_id, rule->value);
        }
        else {
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                EM_DEBUG_EXCEPTION("rule->type is invald");
                goto FINISH_OFF;
        }
@@ -12417,7 +12619,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mail
        
        /*  rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG("Count of mails [%d]", count);
@@ -12426,7 +12628,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mail
                mail_list = malloc(sizeof(int) * count);
                if (mail_list == NULL) {
                        EM_DEBUG_EXCEPTION("malloc failed for mail_list.");
-                       error = EMF_ERROR_OUT_OF_MEMORY;
+                       error = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
                
@@ -12435,13 +12637,13 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mail
                for (i = 0; i < count; i++) 
                        _get_table_field_data_int(result, &(mail_list[i]), col_index++);
 
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = \'%s\', mailbox_type = 5 ", dest_mailbox_name);
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_id = %d, mailbox_type = 5 ", dest_mailbox_id);
 
                if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE)
                strcat(sql_query_string, where_pararaph);
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        }       
        
@@ -12468,12 +12670,12 @@ FINISH_OFF:
        return ret;
 }
 
-#define EMF_SLOT_UNIT 25
+#define EMAIL_SLOT_UNIT 25
 
-INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, char *mailbox_name, int new_slot_size, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_name, new_slot_size, err_code);
-       int rc = -1, ret = false, err = EMF_ERROR_NONE;
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_id, new_slot_size, err_code);
+       int rc = -1, ret = false, err = EMAIL_ERROR_NONE;
        int where_pararaph_length = 0;
        char *where_pararaph = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -12485,13 +12687,13 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, char *mailbox_nam
        if (new_slot_size > 0)
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = %d ", new_slot_size);
        else if (new_slot_size == 0)
-               SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", EMF_SLOT_UNIT);
+               SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", EMAIL_SLOT_UNIT);
        else
                SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", new_slot_size * -1);
 
 
-       if (mailbox_name)
-               where_pararaph_length = strlen(mailbox_name) + 80;
+       if (mailbox_id)
+               where_pararaph_length = 80;
        else
                where_pararaph_length = 50;
 
@@ -12501,15 +12703,15 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, char *mailbox_nam
        where_pararaph = malloc(sizeof(char) * where_pararaph_length);
        if (where_pararaph == NULL) {
                EM_DEBUG_EXCEPTION("Memory allocation failed for where_pararaph");
-               err = EMF_ERROR_OUT_OF_MEMORY;
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
        memset(where_pararaph, 0x00, where_pararaph_length);
 
        if (account_id > ALL_ACCOUNT) {
                and = 1;
-               if (mailbox_name)
-                       SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_name = '%s' ", account_id, mailbox_name);
+               if (mailbox_id)
+                       SNPRINTF(where_pararaph, where_pararaph_length, "WHERE mailbox_id = %d ", mailbox_id);
                else
                        SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d ", account_id);
        }
@@ -12521,14 +12723,14 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, char *mailbox_nam
                strcat(sql_query_string, where_pararaph);
        else {
                EM_DEBUG_EXCEPTION("Query buffer overflowed !!!");
-               err = EMF_ERROR_OUT_OF_MEMORY;
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;                        
        }
 
        EM_DEBUG_LOG("query[%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        ret = true;
@@ -12548,23 +12750,23 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t* meeting_req, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], meeting_req[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, meeting_req, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, input_mailbox_id, meeting_req, transaction, err_code);
        
        if (!meeting_req || meeting_req->mail_id <= 0) {
                if (meeting_req)
                EM_DEBUG_EXCEPTION("mail_id[%]d", meeting_req->mail_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
 
                return false;
        }
        
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
        int col_index = 0;
@@ -12577,7 +12779,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, char *mailbox_na
                "INSERT INTO mail_meeting_tbl VALUES "
                "( ?"           /*  mail_id */
                ", ?"           /*  account_id */
-               ", ?"           /*  mailbox_name */
+               ", ?"           /*  mailbox_id */
                ", ?"           /*  meeting_response */
                ", ?"           /*  start_time */
                ", ?"           /*  end_time */
@@ -12597,7 +12799,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, char *mailbox_na
                EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
                EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
                
-               error = EMF_ERROR_DB_FAILURE;
+               error = EMAIL_ERROR_DB_FAILURE;
                goto FINISH_OFF;
        }
 
@@ -12621,7 +12823,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, char *mailbox_na
        */
        _bind_stmt_field_data_int(hStmt, col_index++, meeting_req->mail_id);
        _bind_stmt_field_data_int(hStmt, col_index++, account_id);
-       _bind_stmt_field_data_string(hStmt, col_index++, (char *)mailbox_name, 0, MAILBOX_LEN_IN_MAIL_MEETING_TBL);
+       _bind_stmt_field_data_int(hStmt, col_index++, input_mailbox_id);
        _bind_stmt_field_data_int(hStmt, col_index++, meeting_req->meeting_response);
 
        temp_unix_time = timegm(&(meeting_req->start_time));
@@ -12645,9 +12847,9 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, char *mailbox_na
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        ret = true;
@@ -12659,7 +12861,7 @@ FINISH_OFF:
                rc = sqlite3_finalize(hStmt);
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
  
@@ -12673,15 +12875,15 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, emf_meeting_request_t ** meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_request_t ** meeting_req, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
        
        int count = 0;
        int rc = -1;
        int ret = false;
-       int error = EMF_ERROR_NONE;
-       emf_meeting_request_t *p_temp_meeting_req = NULL;
+       int error = EMAIL_ERROR_NONE;
+       email_meeting_request_t *p_temp_meeting_req = NULL;
        int col_index = 0;
        time_t temp_unix_time;
 
@@ -12702,29 +12904,29 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, emf_meeting_request
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION(" no Meeting request found...");
                count = 0;
                ret = false;
-               error= EMF_ERROR_DATA_NOT_FOUND;
+               error= EMAIL_ERROR_DATA_NOT_FOUND;
                goto FINISH_OFF;
        }
        
-       if (!(p_temp_meeting_req = (emf_meeting_request_t*)malloc(sizeof(emf_meeting_request_t)))) {
+       if (!(p_temp_meeting_req = (email_meeting_request_t*)malloc(sizeof(email_meeting_request_t)))) {
                EM_DEBUG_EXCEPTION(" malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
-       memset(p_temp_meeting_req, 0x00, sizeof(emf_meeting_request_t));
+       memset(p_temp_meeting_req, 0x00, sizeof(email_meeting_request_t));
                
        col_index = 0;
 
@@ -12779,7 +12981,7 @@ FINISH_OFF:
                hStmt = NULL;
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -12794,12 +12996,12 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC int emstorage_update_meeting_request(emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meeting_req, int transaction, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("meeting_req[%p], transaction[%d], err_code[%p]", meeting_req, transaction, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int rc;
        DB_STMT hStmt = NULL;
        char sql_query_string[QUERY_SIZE] = {0, };
@@ -12807,7 +13009,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(emf_meeting_request_t* meetin
 
        if (!meeting_req) {
                EM_DEBUG_EXCEPTION("Invalid Parameter!");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -12838,7 +13040,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(emf_meeting_request_t* meetin
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 /*
        EM_DEBUG_LOG(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id);
@@ -12876,7 +13078,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(emf_meeting_request_t* meetin
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d", rc));
        ret = true;
 
@@ -12891,7 +13093,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
 
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }
        }
 
@@ -12904,158 +13106,21 @@ FINISH_OFF:
        return ret;     
 }
 
-
-INTERNAL_FUNC int emstorage_change_meeting_request_field(int account_id, char *mailbox_name, emf_mail_change_type_t type, emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], type[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, mailbox_name,  type, meeting_req, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, input_mailbox_id, transaction, err_code);
        
-       if (account_id <= 0 || !meeting_req || meeting_req->mail_id <= 0) {
-               if (meeting_req)
-                       EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id);
+       if (account_id < ALL_ACCOUNT || mail_id < 0) {
+               EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d]", account_id, mail_id);
                
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               return false;;
-       }
-
-       int rc;
-       int ret = false;
-       int error = EMF_ERROR_NONE;
-       DB_STMT hStmt = NULL;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       
-       int col_index = 0;
-       
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-
-       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
-       
-       switch (type)  {
-               case UPDATE_MAILBOX:
-                       EM_DEBUG_LOG(">>>>> UPDATE_MAILBOX : Move");
-                       if (!mailbox_name)  {
-                               EM_DEBUG_EXCEPTION(" mailbox_name[%p]", mailbox_name);
-                               error = EMF_ERROR_INVALID_PARAM;
-                               goto FINISH_OFF;
-                       }
-                       SNPRINTF(sql_query_string, sizeof(sql_query_string),
-                               "UPDATE mail_meeting_tbl SET mailbox_name = ? WHERE mail_id = %d", meeting_req->mail_id);
-                       
-                       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
-                       EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
-                       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-                       ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-                       _bind_stmt_field_data_string(hStmt, col_index++, (char *)mailbox_name, 0, MAILBOX_LEN_IN_MAIL_MEETING_TBL);
-                       break;
-
-               default:
-                       EM_DEBUG_LOG("type[%d]", type);
-                       
-                       error = EMF_ERROR_INVALID_PARAM;
-                       goto FINISH_OFF;
-       }
-       EM_DEBUG_LOG("Query = [%s]", sql_query_string);
-
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("sqlite3_step fail:%d", rc));
-
-       ret = true;
-       
-FINISH_OFF:
-       if (hStmt != NULL)  {
-               EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK)  {
-                       EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
-                       error = EMF_ERROR_DB_FAILURE;
-               }
-       }
-
-       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
-       _DISCONNECT_DB;
-       
-       if (err_code != NULL)
-               *err_code = error;
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-}
-
-
-INTERNAL_FUNC int emstorage_change_meeting_request_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
-
-       if (account_id < FIRST_ACCOUNT_ID || !old_mailbox_name || !new_mailbox_name)  {
-               EM_DEBUG_EXCEPTION("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p]", account_id, old_mailbox_name, new_mailbox_name);
-               
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
-               return false;
-       }
-       
-       int rc;
-       int ret = true;
-       int error = EMF_ERROR_NONE;
-       char sql_query_string[QUERY_SIZE] = {0, };
-       
-       sqlite3 *local_db_handle = emstorage_get_db_connection();
-
-       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
-
-       EM_DEBUG_LOG("Update mailbox_name - searching by mailbox_name name"); 
-       SNPRINTF(sql_query_string, sizeof(sql_query_string),
-               "UPDATE mail_meeting_tbl SET"
-               " mailbox_name = '%s'"
-               " WHERE account_id = %d"
-               " AND mailbox_name = '%s'"
-               , new_mailbox_name
-               , account_id
-               , old_mailbox_name);
-
-       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
-               ("sqlite3_exec fail:%d", rc));
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
-               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-       rc = sqlite3_changes(local_db_handle);
-       if (rc == 0) 
-               EM_DEBUG_EXCEPTION("NO meetring request found...");
-
-       ret = true;
-       
-FINISH_OFF:
-
-       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
-       _DISCONNECT_DB;
-       
-       if (err_code != NULL)
-               *err_code = error;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
-}
-
-
-INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, char *mailbox_name, int transaction, int *err_code)
-{
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], mailbox_name[%s], transaction[%d], err_code[%p]", account_id, mail_id, mailbox_name, transaction, err_code);
-       
-       if (account_id < ALL_ACCOUNT || mail_id < 0) {
-               EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d]", account_id, mail_id);
-               
-               if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int rc;
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int and = false;
        char sql_query_string[QUERY_SIZE] = {0, };
        
@@ -13072,12 +13137,12 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id,
                SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mail_id = %d", (and ? "AND" : "WHERE"), mail_id);
                and = true;
        }
-       if (mailbox_name) {             /*  NULL means all mailbox_name */
-               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'",  (and ? "AND" : "WHERE"), mailbox_name);
+       if (input_mailbox_id > 0) {             /*  0 means all mailbox_id */
+               SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_id = '%d'",  (and ? "AND" : "WHERE"), input_mailbox_id);
        }
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        ret = true;     
@@ -13093,61 +13158,42 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emstorage_free_meeting_request(emf_meeting_request_t **meeting_req, int count, int *err_code)
+
+INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeting_req)
 {
-       EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d], err_code[%p]", meeting_req, count, err_code);
+       EM_DEBUG_FUNC_BEGIN();
        
-       int ret = false;
-       int error = EMF_ERROR_NONE;
-       int i = 0;
-       emf_meeting_request_t *cursor;
-
-       if (count > 0) {
-               if (!meeting_req || !*meeting_req) {
-                       EM_DEBUG_EXCEPTION("meeting_req[%p], count[%d]", meeting_req, count);
-                       error = EMF_ERROR_INVALID_PARAM;
-                       goto FINISH_OFF;
+       if (!meeting_req ) {
+               EM_DEBUG_EXCEPTION("NULL PARAM");
+               return;
                }
                
-               for (i = 0; i < count; i++) {
-                       cursor = (*meeting_req) + i;
-                       EM_SAFE_FREE(cursor->location);
-                       EM_SAFE_FREE(cursor->global_object_id);
-               }
-               EM_SAFE_FREE(*meeting_req);
-       }
-       
-       ret = true;
-       
-FINISH_OFF:
-       if (err_code != NULL)
-               *err_code = error;
-
-       EM_DEBUG_FUNC_END("ret [%d]", ret);
-       return ret;
+       EM_SAFE_FREE(meeting_req->location);
+       EM_SAFE_FREE(meeting_req->global_object_id);
 
+       EM_DEBUG_FUNC_END();
 }
 
 
-INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, char *mailbox_name, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, mailbox_name, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code);
+       EM_DEBUG_FUNC_BEGIN("account_id [%d], input_mailbox_id [%d], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, input_mailbox_id, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code);
        EM_PROFILE_BEGIN(profile_emstorage_get_overflowed_mail_id_list);
        char sql_query_string[QUERY_SIZE] = {0, };
        char **result = NULL;
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int counter = 0, col_index = 0;
        int result_mail_id_count = 0;
        int *result_mail_id_list = NULL;
 
-       if (!mailbox_name || !mail_id_list || !mail_id_count || account_id < 1) {
+       if (input_mailbox_id <= 0 || !mail_id_list || !mail_id_count || account_id < 1) {
                EM_DEBUG_EXCEPTION("Invalid Parameter");
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
-       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s' ORDER BY date_time DESC LIMIT %d, 10000", account_id, mailbox_name, mail_slot_size);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, mail_slot_size);
        
        EM_DEBUG_LOG("query[%s].", sql_query_string);
 
@@ -13155,21 +13201,21 @@ INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, char *ma
        EMSTORAGE_START_READ_TRANSACTION(transaction);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        if (!result_mail_id_count) {
                EM_DEBUG_LOG("No mail found...");                       
                ret = false;
-               error= EMF_ERROR_MAIL_NOT_FOUND;
+               error= EMAIL_ERROR_MAIL_NOT_FOUND;
                goto FINISH_OFF;
        }
        
-       EM_DEBUG_LOG("There are [%d] overflowed mails in mailbox_name [%s]", result_mail_id_count, mailbox_name);
+       EM_DEBUG_LOG("There are [%d] overflowed mails in mailbox_id [%d]", result_mail_id_count, input_mailbox_id);
        
        if (!(result_mail_id_list = (int *)malloc(sizeof(int) * result_mail_id_count))) {
                EM_DEBUG_EXCEPTION("malloc for result_mail_id_list failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                sqlite3_free_table(result);
                goto FINISH_OFF;
        }
@@ -13213,7 +13259,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], thread_id[%p], err_code[%p]", mail_id, thread_id, err_code);
        
        int rc = -1, ret = false;
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        char **result;
        int result_count = 0;
@@ -13221,7 +13267,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id
        if (mail_id == 0 || thread_id == NULL) {
                EM_DEBUG_EXCEPTION("Invalid Parameter");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -13232,13 +13278,13 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id
 
        /*  rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        if (!result_count) {
                EM_DEBUG_EXCEPTION("No mail found...");                 
                ret = false;
-               err= EMF_ERROR_MAIL_NOT_FOUND;
+               err= EMAIL_ERROR_MAIL_NOT_FOUND;
                /* sqlite3_free_table(result); */
                goto FINISH_OFF;
        }
@@ -13266,7 +13312,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread
        EM_DEBUG_FUNC_BEGIN("account_id [%d], thread_id[%d], latest_mail_id [%d], thread_item_count[%d], err_code[%p]", account_id, thread_id, latest_mail_id, thread_item_count, err_code);
        
        int rc = -1, ret = false;
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
        char **result;
        int result_count = 0;
@@ -13274,7 +13320,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread
        if (thread_id == 0) {
                EM_DEBUG_EXCEPTION("Invalid Parameter");
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        
@@ -13286,13 +13332,13 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread
 
                /*  rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc);
-               EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                        ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
                EM_DEBUG_LOG("result_count[%d]", result_count);
                if (result_count == 0) {
                        EM_DEBUG_EXCEPTION("No mail found...");                 
                        ret = false;
-                       err= EMF_ERROR_MAIL_NOT_FOUND;
+                       err= EMAIL_ERROR_MAIL_NOT_FOUND;
                        sqlite3_free_table(result);
                        goto FINISH_OFF;
                }
@@ -13315,7 +13361,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread
                EM_DEBUG_LOG("query[%s]", sql_query_string);
 
                EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                        ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        /* } */
 
@@ -13324,7 +13370,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread
        EM_DEBUG_LOG("query[%s]", sql_query_string);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        ret = true;
@@ -13343,8 +13389,7 @@ FINISH_OFF:
 }
 
 
-INTERNAL_FUNC void
-emstorage_flush_db_cache()
+INTERNAL_FUNC void emstorage_flush_db_cache()
 {
        sqlite3_release_memory(-1);
 }
@@ -13361,7 +13406,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit
        EM_DEBUG_LOG(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code);
 
        int rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        DB_STMT hStmt = NULL;
        char sql_query_string[8192] = { 0x00, };
        int i = 0;
@@ -13369,7 +13414,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit
        if (!local_activity) {
                EM_DEBUG_EXCEPTION(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
 
@@ -13391,7 +13436,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit
        
        
        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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
@@ -13410,9 +13455,9 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
 
-       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+       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 = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
 
        ret = true;
@@ -13424,7 +13469,7 @@ FINISH_OFF:
                if (rc != SQLITE_OK)  {
                        EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
                        
-                       error = EMF_ERROR_DB_FAILURE;
+                       error = EMAIL_ERROR_DB_FAILURE;
                }               
        }
        else {
@@ -13452,7 +13497,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora
        EM_DEBUG_FUNC_BEGIN();
        
        int i = 0, count = 0, rc = -1, ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        emstorage_activity_tbl_t *p_activity_tbl = NULL;
        char sql_query_string[1024] = {0x00, };
        char **result = NULL;
@@ -13465,7 +13510,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora
        if (!select_num || !activity_list || account_id <= 0 || activityid < 0) {
                EM_DEBUG_LOG(" select_num[%p], activity_list[%p] account_id [%d] activityid [%d] ", select_num, activity_list, account_id, activityid);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
@@ -13485,7 +13530,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora
                
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
 
@@ -13494,7 +13539,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora
        
        if (!(p_activity_tbl = (emstorage_activity_tbl_t*)em_malloc(sizeof(emstorage_activity_tbl_t) * count))) {
                EM_DEBUG_EXCEPTION(" em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -13569,7 +13614,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code
        EM_DEBUG_FUNC_BEGIN();
        
        int ret = false;
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        int rc = -1;
        char *sql = NULL;
        char **result = NULL;   
@@ -13578,7 +13623,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code
        {
                EM_DEBUG_EXCEPTION(" activity_id[%p]", activity_id);
                
-               err = EMF_ERROR_INVALID_PARAM;
+               err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
 
@@ -13587,7 +13632,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code
        sql = "SELECT max(rowid) FROM mail_local_activity_tbl;";
        
        /*  rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); n EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); */
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
 
        if (NULL==result[1])
@@ -13622,12 +13667,12 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity
        
        if (account_id <= 0|| NULL == activity_id_list || NULL == activity_id_count ||lowest_activity_type <=0 || highest_activity_type <= 0)  {
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }
        
        int ret = false;
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int i = 0, rc = -1, count = 0;
        char sql_query_string[1024] = {0x00, };
        int *activity_ids = NULL;
@@ -13644,7 +13689,7 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity
 
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
                ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
 
        col_index = 1;
@@ -13653,7 +13698,7 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity
 
        if (NULL == (activity_ids = (int *)em_malloc(sizeof(int) * count))) {
                EM_DEBUG_EXCEPTION(" em_malloc failed...");
-               error = EMF_ERROR_OUT_OF_MEMORY;
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
        }
 
@@ -13690,13 +13735,13 @@ INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *er
 {
        EM_DEBUG_FUNC_BEGIN();
 
-       int error = EMF_ERROR_NONE;
+       int error = EMAIL_ERROR_NONE;
        int ret = false;
 
        EM_DEBUG_LOG(" activity_id_list [%p]", activity_id_list);
 
        if (NULL == activity_id_list) {
-               error = EMF_ERROR_INVALID_PARAM;
+               error = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
        else {
@@ -13732,12 +13777,12 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca
        if (!local_activity)  {
                EM_DEBUG_EXCEPTION(" local_activity[%p] ", local_activity);
                if (err_code != NULL)
-                       *err_code = EMF_ERROR_INVALID_PARAM;
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
        }               
        
        int rc = -1, ret = false;                       /* Prevent_FIX  */
-       int err = EMF_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        int query_and = 0;
        int query_where = 0;
        char sql_query_string[8192] = { 0x00, };
@@ -13789,13 +13834,13 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca
        EM_DEBUG_LOG(">>>>> Query [ %s ] ", sql_query_string);
        
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
-       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
                ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
        
        rc = sqlite3_changes(local_db_handle);
        if (rc == 0)  {
                EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found...");
-               err = EMF_ERROR_MAILBOX_NOT_FOUND;
+               err = EMAIL_ERROR_MAILBOX_NOT_FOUND;
        }
 
        ret = true;
@@ -13818,13 +13863,13 @@ INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local
        EM_DEBUG_LOG(" local_activity_list[%p], count[%d], err_code[%p]", local_activity_list, count, err_code);
        
        int ret = false;
-       int error = EMF_ERROR_INVALID_PARAM;
+       int error = EMAIL_ERROR_INVALID_PARAM;
        
        if (count > 0) {
                if (!local_activity_list || !*local_activity_list) {
                        EM_DEBUG_EXCEPTION(" local_activity_list[%p], count[%d]", local_activity_list, count);
                        
-                       error = EMF_ERROR_INVALID_PARAM;
+                       error = EMAIL_ERROR_INVALID_PARAM;
                        goto FINISH_OFF;
                }
                
@@ -13853,5 +13898,1179 @@ FINISH_OFF:
 }
 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
 
+static char *_mail_field_name_list[] = {
+               "mail_id",
+               "account_id",
+               "mailbox_id",
+               "mailbox_name",
+               "mailbox_type",
+               "subject",
+               "date_time",
+               "server_mail_status",
+               "server_mailbox_name",
+               "server_mail_id",
+               "message_id",
+               "full_address_from",
+               "full_address_to",
+               "full_address_cc",
+               "full_address_bcc",
+               "body_download_status",
+               "file_path_plain",
+               "file_path_html",
+               "file_size",
+               "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",
+               "lock_status",
+               "report_status",
+               "attachment_count",
+               "inline_content_count",
+               "thread_id",
+               "thread_item_count",
+               "preview_text",
+               "meeting_request_status",
+               "message_class",
+               "digest_type",
+               "smime_type"
+};
+
+static char*_get_mail_field_name_by_attribute_type(email_mail_attribute_type input_attribute_type)
+{
+       EM_DEBUG_FUNC_BEGIN("input_attribute_type [%d]", input_attribute_type);
+
+       if(input_attribute_type > EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS || input_attribute_type < 0) {
+               EM_DEBUG_EXCEPTION("Invalid input_attribute_type [%d]", input_attribute_type);
+               return NULL;
+       }
+
+       EM_DEBUG_FUNC_END("return [%s]", _mail_field_name_list[input_attribute_type]);
+       return _mail_field_name_list[input_attribute_type];
+}
+
+static int _get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type)
+{
+       EM_DEBUG_FUNC_BEGIN("input_mail_field_name [%p], output_mail_attribute_type [%p]", input_mail_field_name, output_mail_attribute_type);
+       int i = 0;
+       int err = EMAIL_ERROR_DATA_NOT_FOUND;
+
+       if(!input_mail_field_name || !output_mail_attribute_type) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       for (i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
+               if (EM_SAFE_STRCMP(input_mail_field_name, _mail_field_name_list[i]) == 0) {
+                       *output_mail_attribute_type = i;
+                       err = EMAIL_ERROR_NONE;
+                       break;
+               }
+       }
+
+       EM_DEBUG_FUNC_END("found mail attribute type [%d]", (int)*output_mail_attribute_type);
+       return err;
+}
+
+static int _get_key_value_string_for_list_filter_rule(email_list_filter_rule_t *input_list_filter_rule,char **output_key_value_string)
+{
+       EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_key_value_string [%p]", input_list_filter_rule, output_key_value_string);
+
+       int  ret = EMAIL_ERROR_NONE;
+       char key_value_string[QUERY_SIZE] = { 0, };
+       char *temp_key_value_1 = NULL;
+       char *temp_key_value_2 = NULL;
+
+       if(input_list_filter_rule == NULL || output_key_value_string == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       switch(input_list_filter_rule->target_attribute) {
+       case EMAIL_MAIL_ATTRIBUTE_MAIL_ID                 :
+       case EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID              :
+       case EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID              :
+       case EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE            :
+       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS      :
+       case EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS    :
+       case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN         :
+       case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML          :
+       case EMAIL_MAIL_ATTRIBUTE_FILE_SIZE               :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD        :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD     :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD     :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD    :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD      :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD       :
+       case EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD   :
+       case EMAIL_MAIL_ATTRIBUTE_DRM_STATUS              :
+       case EMAIL_MAIL_ATTRIBUTE_PRIORITY                :
+       case EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS             :
+       case EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS             :
+       case EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS           :
+       case EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT        :
+       case EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT    :
+       case EMAIL_MAIL_ATTRIBUTE_THREAD_ID               :
+       case EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT       :
+       case EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS  :
+       case EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS           :
+       case EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE             :
+       case EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE              :
+               SNPRINTF(key_value_string, QUERY_SIZE, "%d", input_list_filter_rule->key_value.integer_type_value);
+               break;
+
+       case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME            :
+       case EMAIL_MAIL_ATTRIBUTE_SUBJECT                 :
+       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME     :
+       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID          :
+       case EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID              :
+       case EMAIL_MAIL_ATTRIBUTE_FROM                    :
+       case EMAIL_MAIL_ATTRIBUTE_TO                      :
+       case EMAIL_MAIL_ATTRIBUTE_CC                      :
+       case EMAIL_MAIL_ATTRIBUTE_BCC                     :
+       case EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT            :
+               if(input_list_filter_rule->key_value.string_type_value == NULL) {
+                       EM_DEBUG_EXCEPTION("Invalid string_type_value [%p]", input_list_filter_rule->key_value.string_type_value);
+                       ret = EMAIL_ERROR_INVALID_PARAM;
+                       goto FINISH_OFF;
+               }
+
+               temp_key_value_1 = input_list_filter_rule->key_value.string_type_value;
+
+               temp_key_value_2 = em_replace_all_string(temp_key_value_1, "_", "\\_");
+               temp_key_value_1 = em_replace_all_string(temp_key_value_2, "%", "\\%");
+
+               if(input_list_filter_rule->rule_type == EMAIL_LIST_FILTER_RULE_INCLUDE)
+                       SNPRINTF(key_value_string, QUERY_SIZE, "\'%%%s%%\'", temp_key_value_1);
+               else
+                       SNPRINTF(key_value_string, QUERY_SIZE, "\'%s\'", temp_key_value_1);
+               break;
+
+       case EMAIL_MAIL_ATTRIBUTE_DATE_TIME               :
+               SNPRINTF(key_value_string, QUERY_SIZE, "%d", (int)input_list_filter_rule->key_value.datetime_type_value);
+               break;
+
+       default :
+               ret = EMAIL_ERROR_INVALID_PARAM;
+               EM_DEBUG_EXCEPTION("Invalid target_attribute [%d]", input_list_filter_rule->target_attribute);
+               break;
+       }
+
+       if(ret == EMAIL_ERROR_NONE && strlen(key_value_string) > 0) {
+               *output_key_value_string = strdup(key_value_string);
+       }
+
+FINISH_OFF:
+
+       EM_SAFE_FREE(temp_key_value_1);
+       EM_SAFE_FREE(temp_key_value_2);
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+static int _get_cert_password_file_name(int index, char *cert_password_file_name)
+{
+       EM_DEBUG_FUNC_BEGIN("index : [%d]", index);
+
+       if (index <= 0 || !cert_password_file_name) {
+               EM_DEBUG_EXCEPTION("Invalid parameter");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       sprintf(cert_password_file_name, ".email_cert_%d", index);
+
+       EM_DEBUG_FUNC_END();
+       return EMAIL_ERROR_NONE;
+}
+#endif
+
+static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_rule, char **output_string)
+{
+       EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_string [%p]", input_list_filter_rule, output_string);
+
+       int   ret = EMAIL_ERROR_NONE;
+       int   is_alpha = 0;
+       int   length_field_name = 0;
+       int   length_value = 0;
+       char  result_rule_string[QUERY_SIZE] = { 0 , };
+       char *mod_field_name_string = NULL;
+       char *mod_value_string = NULL;
+       char *temp_field_name_string = NULL;
+       char *temp_key_value_string = NULL;
+
+       if(input_list_filter_rule == NULL || output_string == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return  EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       temp_field_name_string = _get_mail_field_name_by_attribute_type(input_list_filter_rule->target_attribute);
+
+       if(temp_field_name_string == NULL) {
+               EM_DEBUG_EXCEPTION("Invalid target_attribute [%d]", input_list_filter_rule->target_attribute);
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       if( _get_key_value_string_for_list_filter_rule(input_list_filter_rule, &temp_key_value_string) != EMAIL_ERROR_NONE || temp_key_value_string == NULL) {
+               EM_DEBUG_EXCEPTION("_get_key_value_string_for_list_filter_rule failed");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       length_field_name = strlen(temp_field_name_string);
+       length_value      = strlen(temp_key_value_string);
+
+       switch(input_list_filter_rule->target_attribute) {
+       case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME            :
+       case EMAIL_MAIL_ATTRIBUTE_SUBJECT                 :
+       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME     :
+       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID          :
+       case EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID              :
+       case EMAIL_MAIL_ATTRIBUTE_FROM                    :
+       case EMAIL_MAIL_ATTRIBUTE_TO                      :
+       case EMAIL_MAIL_ATTRIBUTE_CC                      :
+       case EMAIL_MAIL_ATTRIBUTE_BCC                     :
+       case EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT            :
+               is_alpha = 1;
+               break;
+       default :
+               is_alpha = 0;
+               break;
+       }
+
+       if(is_alpha == 1 && input_list_filter_rule->case_sensitivity == false) {
+               length_field_name += strlen("UPPER() ");
+               length_value      += strlen("UPPER() ");
+               mod_field_name_string = em_malloc(sizeof(char) * length_field_name);
+               mod_value_string      = em_malloc(sizeof(char) * length_value);
+               SNPRINTF(mod_field_name_string, length_field_name, "UPPER(%s)", temp_field_name_string);
+               SNPRINTF(mod_value_string,      length_value, "UPPER(%s)", temp_key_value_string);
+               EM_SAFE_FREE(temp_key_value_string);
+       }
+       else {
+               mod_field_name_string = strdup(temp_field_name_string);
+               mod_value_string      = temp_key_value_string;
+       }
+
+       switch (input_list_filter_rule->rule_type) {
+       case EMAIL_LIST_FILTER_RULE_EQUAL     :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s = %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_NOT_EQUAL :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s = %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_LESS_THAN :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s < %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_GREATER_THAN :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s > %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_LESS_THAN_OR_EQUAL :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s <= %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_GREATER_THAN_OR_EQUAL :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s >= %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_INCLUDE   :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s LIKE %s ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_IN        :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s IN (%s) ", mod_field_name_string, mod_value_string);
+               break;
+       case EMAIL_LIST_FILTER_RULE_NOT_IN    :
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s NOT IN (%s) ", mod_field_name_string, mod_value_string);
+               break;
+       default :
+               EM_DEBUG_EXCEPTION("Invalid rule_type [%d]", input_list_filter_rule->rule_type);
+               ret = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       *output_string = strdup(result_rule_string);
+
+FINISH_OFF:
+       EM_SAFE_FREE(mod_field_name_string);
+       EM_SAFE_FREE(mod_value_string);
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule, char **output_string) {
+       EM_DEBUG_FUNC_BEGIN("input_sorting_rule [%p], output_string [%p]", input_sorting_rule, output_string);
+
+       char  result_rule_string[QUERY_SIZE] = { 0 , };
+       int   ret = EMAIL_ERROR_NONE;
+
+       if(input_sorting_rule->force_boolean_check) {
+               SNPRINTF(result_rule_string, QUERY_SIZE, "%s = 0 ", _get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
+       }
+       else
+               EM_SAFE_STRCPY(result_rule_string, _get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
+
+       switch (input_sorting_rule->sort_order) {
+               case EMAIL_SORT_ORDER_ASCEND     :
+                       EM_SAFE_STRCAT(result_rule_string, " ASC ");
+                       break;
+
+               case EMAIL_SORT_ORDER_DESCEND    :
+                       EM_SAFE_STRCAT(result_rule_string, " DESC ");
+                       break;
+
+               default :
+                       EM_DEBUG_EXCEPTION("Invalid sort_order [%d]", input_sorting_rule->sort_order);
+                       ret = EMAIL_ERROR_INVALID_PARAM;
+                       goto FINISH_OFF;
+       }
+
+       *output_string = strdup(result_rule_string);
+
+FINISH_OFF:
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause)
+{
+       EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d], input_sorting_rule_list[%p], input_sorting_rule_count [%d], input_start_index [%d], input_limit_count [%d], output_conditional_clause [%p]", input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, output_conditional_clause);
+       int ret = EMAIL_ERROR_NONE;
+       int i = 0;
+       char conditional_clause_string[QUERY_SIZE] = {0, };
+       char *result_string_for_a_item = NULL;
+
+       if ( (input_filter_count > 0 && !input_filter_list) || (input_sorting_rule_count > 0 && !input_sorting_rule_list) || output_conditional_clause == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+
+       if(input_filter_count > 0) {
+               strcpy(conditional_clause_string,  " WHERE ");
+
+               for ( i = 0; i < input_filter_count; i++) {
+                       switch (input_filter_list[i].list_filter_item_type) {
+                       case EMAIL_LIST_FILTER_ITEM_RULE :
+                               EM_DEBUG_LOG("[%d]list_filter_item_type is EMAIL_LIST_FILTER_ITEM_RULE", i);
+                               _make_filter_rule_string(&(input_filter_list[i].list_filter_item.rule), &result_string_for_a_item);
+                               break;
+
+                       case EMAIL_LIST_FILTER_ITEM_OPERATOR :
+                               EM_DEBUG_LOG("[%d]list_filter_item_type is EMAIL_LIST_FILTER_ITEM_OPERATOR", i);
+                               switch(input_filter_list[i].list_filter_item.operator_type) {
+                               case EMAIL_LIST_FILTER_OPERATOR_AND :
+                                       result_string_for_a_item = strdup("AND ");
+                                       break;
+                               case EMAIL_LIST_FILTER_OPERATOR_OR :
+                                       result_string_for_a_item = strdup("OR ");
+                                       break;
+                               case EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS :
+                                       result_string_for_a_item = strdup(" (");
+                                       break;
+                               case EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS :
+                                       result_string_for_a_item = strdup(") ");
+                                       break;
+                               }
+                               break;
+
+                       default :
+                               EM_DEBUG_EXCEPTION("Invalid list_filter_item_type [%d]", input_filter_list[i].list_filter_item_type);
+                               ret = EMAIL_ERROR_INVALID_PARAM;
+                               goto FINISH_OFF;
+                       }
+
+                       if(result_string_for_a_item == NULL) {
+                               EM_DEBUG_EXCEPTION("result_string_for_a_item is null");
+                               ret = EMAIL_ERROR_INVALID_PARAM;
+                               goto FINISH_OFF;
+                       }
+
+                       if(strlen(conditional_clause_string) + strlen(result_string_for_a_item) >= QUERY_SIZE) {
+                               EM_DEBUG_EXCEPTION("Query is too long");
+                               ret = EMAIL_ERROR_DATA_TOO_LONG;
+                               goto FINISH_OFF;
+                       }
+                       strcat(conditional_clause_string, result_string_for_a_item);
+                       EM_SAFE_FREE(result_string_for_a_item);
+               }
+       }
+
+       if(input_sorting_rule_count > 0) {
+               strcat(conditional_clause_string, "ORDER BY ");
+
+               for ( i = 0; i < input_sorting_rule_count; i++) {
+                       if( (ret = _make_order_rule_string(&input_sorting_rule_list[i], &result_string_for_a_item)) != EMAIL_ERROR_NONE) {
+                               EM_DEBUG_EXCEPTION("_make_order_rule_string failed. [%d]", ret);
+                               goto FINISH_OFF;
+                       }
+                       if(i > 0)
+                               strcat(conditional_clause_string, ", ");
+                       strcat(conditional_clause_string, result_string_for_a_item);
+                       EM_SAFE_FREE(result_string_for_a_item);
+               }
+       }
+
+       *output_conditional_clause = strdup(conditional_clause_string);
+
+FINISH_OFF:
+       EM_SAFE_FREE(result_string_for_a_item);
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count)
+{
+       EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d]", input_filter_list, input_filter_count);
+       int err = EMAIL_ERROR_NONE;
+       int i = 0;
+       email_list_filter_t *temp_filter_list = NULL;
+
+       EM_IF_NULL_RETURN_VALUE(input_filter_list, EMAIL_ERROR_INVALID_PARAM);
+
+       for ( i = 0; i < input_filter_count; i++) {
+               temp_filter_list = (*input_filter_list) + i;
+               if(temp_filter_list && temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE) {
+                       switch(temp_filter_list->list_filter_item.rule.target_attribute) {
+                       case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME :
+                       case EMAIL_MAIL_ATTRIBUTE_SUBJECT :
+                       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME :
+                       case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID :
+                       case EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID :
+                       case EMAIL_MAIL_ATTRIBUTE_FROM :
+                       case EMAIL_MAIL_ATTRIBUTE_TO :
+                       case EMAIL_MAIL_ATTRIBUTE_CC :
+                       case EMAIL_MAIL_ATTRIBUTE_BCC :
+                       case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN :
+                       case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML :
+                       case EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT :
+                               EM_SAFE_FREE(temp_filter_list->list_filter_item.rule.key_value.string_type_value);
+                               break;
+                       default :
+                               break;
+                       }
+               }
+       }
+
+       free(*input_filter_list);
+       *input_filter_list = NULL;
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
+
+       if (!certificate) {
+               EM_DEBUG_EXCEPTION("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+
+               return false;
+       }
+
+       int rc = -1, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+       char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+       char *sql = "SELECT max(rowid) FROM mail_certificate_tbl;";
+       char **result = NULL;
+
+       /*  rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+       if (NULL==result[1]) rc = 1;
+       else rc = atoi(result[1])+1;
+       sqlite3_free_table(result);
+
+       certificate->certificate_id = rc;
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+       if ((error = _get_cert_password_file_name(certificate->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+               goto FINISH_OFF;
+       }
+#endif
+       SNPRINTF(sql_query_string, sizeof(sql_query_string),
+               "INSERT INTO mail_certificate_tbl VALUES "
+               "(        "
+               "   ?  "                /* Index of certificate */
+               "  , ? "                /* Select the account */
+               "  , ? "                /* Year of issue */
+               "  , ? "                /* Month of issue */
+               "  , ? "                /* Day of issue */
+               "  , ? "                /* Year of expiration */
+               "  , ? "                /* Month of expiration */
+               "  , ? "                /* Day of expiration */
+               "  , ? "                /* Organization of issue */
+               "  , ? "                /* Email address */
+               "  , ? "                /* Subject of certificate */
+               "  , ? "                /* Name of saved certificate */
+               ") ");
+
+
+       /*  rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+       EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
+       _bind_stmt_field_data_int(hStmt, CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->certificate_id);
+       _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year);
+       _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month);
+       _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day);
+       _bind_stmt_field_data_int(hStmt, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_year);
+       _bind_stmt_field_data_int(hStmt, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_month);
+       _bind_stmt_field_data_int(hStmt, EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_day);
+       _bind_stmt_field_data_string(hStmt, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_organization_name, 0, ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
+       /*  rc = sqlite3_step(hStmt); */
+       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, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+       if (ssm_write_buffer(certificate->password, strlen(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+               EM_DEBUG_EXCEPTION("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name);
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
+               goto FINISH_OFF;
+       }
+#endif
+       ret = true;
+
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+       if (!emstorage_notify_storage_event(NOTI_CERTIFICATE_ADD, certificate->certificate_id, 0, NULL, 0))
+               EM_DEBUG_EXCEPTION("emstorage_notify_storage_event(NOTI_CERTIFICATE_ADD] : Notification failed");
+
+FINISH_OFF:
+
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+       else
+               EM_DEBUG_LOG("hStmt is NULL!!!");
+
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+       _DISCONNECT_DB;
+
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("certificate_list[%p], count[%d], err_code[%p]", certificate_list, count, err_code);
+       
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       
+       if (count > 0)  {
+               if (!certificate_list || !*certificate_list)  {
+                       EM_DEBUG_EXCEPTION("certificate_list[%p], count[%d]", certificate_list, count);
+                       error = EMAIL_ERROR_INVALID_PARAM;
+                       goto FINISH_OFF;
+               }
+               
+               emstorage_certificate_tbl_t *p = *certificate_list;
+               int i = 0;
+               
+               for (; i < count; i++)  {
+                       EM_SAFE_FREE(p[i].issue_organization_name);
+                       EM_SAFE_FREE(p[i].email_address);
+                       EM_SAFE_FREE(p[i].subject_str);
+                       EM_SAFE_FREE(p[i].filepath);
+                       EM_SAFE_FREE(p[i].password);
+               }
+               
+               EM_SAFE_FREE(p); 
+               *certificate_list = NULL;
+       }
+       
+       ret = true;
+       
+FINISH_OFF:
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN();
+
+       int i = 0, count = 0, rc = -1, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       emstorage_certificate_tbl_t *p_data_tbl = NULL;
+
+       DB_STMT hStmt = NULL;
+
+       if (!select_num || !certificate_list)  {
+               EM_DEBUG_EXCEPTION("select_num[%p], account_list[%p]", select_num, certificate_list);
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+       char sql_query_string[QUERY_SIZE] = {0, };
+       char *sql = "SELECT count(*) FROM mail_certificate_tbl;";
+       char **result;
+
+       /*  rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+       count = atoi(result[1]);
+       sqlite3_free_table(result);
+
+       if (!count) {
+               EM_DEBUG_EXCEPTION("no account found...");
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+               ret = true;
+               goto FINISH_OFF;
+       }
+       EM_DEBUG_LOG("count = %d", rc);
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_certificate_tbl ORDER BY account_id");
+
+       /*  rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL);   */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+       EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+       /*  rc = sqlite3_step(hStmt); */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), 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 (rc == SQLITE_DONE)  {
+               EM_DEBUG_EXCEPTION("no account found...");
+
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+               count = 0;
+               ret = true;
+               goto FINISH_OFF;
+       }
+
+       if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t) * count)))  {
+               EM_DEBUG_EXCEPTION("malloc failed...");
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+       memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t) * count);
+       for (i = 0; i < count; i++)  {
+               /*  get recordset */
+               _get_stmt_field_data_int(hStmt,  &(p_data_tbl[i].certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
+               _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
+               if (with_password == true) {
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+                       /*  get password from the secure storage */
+                       char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+
+                       EM_SAFE_FREE(p_data_tbl[i].password);
+
+                       /*  get password file name */
+                       if ((error = _get_cert_password_file_name(p_data_tbl[i].certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+                               EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+                               goto FINISH_OFF;
+                       }
+
+                       /*  read password from secure storage */
+                       if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl[i].password))) < 0) {
+                               EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed...");
+                               goto FINISH_OFF;
+                       }
+                       EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", cert_password_file_name,  p_data_tbl[i].password);
+#endif
+               }
+
+               /*  rc = sqlite3_step(hStmt); */
+               EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+               EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i,  rc);
+               EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+                       ("sqlite3_step fail:%d", rc));
+       }
+
+       ret = true;
+
+FINISH_OFF:
+       if (ret == true)  {
+               *certificate_list = p_data_tbl;
+               *select_num = count;
+               EM_DEBUG_LOG("COUNT : %d", count);
+       }
+       else if (p_data_tbl != NULL)
+               emstorage_free_certificate(&p_data_tbl, count, NULL);
+       if (hStmt != NULL)  {
+               EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+               rc = sqlite3_finalize(hStmt);
+               hStmt = NULL;
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+       _DISCONNECT_DB;
+
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("email_address[%s], certificate[%p], transaction[%d], err_code[%p]", email_address, certificate, transaction, err_code);
+
+       if (!certificate)  {
+               EM_DEBUG_EXCEPTION("email_address[%s], certificate[%p]", email_address, certificate);
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       emstorage_certificate_tbl_t *p_data_tbl = NULL;
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+       int rc = -1;
+       int sql_len = 0;
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+       char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif         
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+       /*  Make query string */
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
+       sql_len = strlen(sql_query_string);
+               
+       /*  dummy value, FROM WHERE clause */
+       SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE email_address = '%s'", email_address);
+
+       /*  FROM clause */
+       EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+       /*  execute a sql and count rows */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("sqlite3_step fail:%d", rc));
+
+       if (rc == SQLITE_DONE)  {
+               EM_DEBUG_EXCEPTION("no matched certificate found...");
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+
+       /*  Assign query result to structure */
+       if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t))))  {
+               EM_DEBUG_EXCEPTION("malloc failed...");
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t));
+       _get_stmt_field_data_int(hStmt,  &(p_data_tbl->certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
+
+       if (with_password) {
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+               /*  get password file name */
+               if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+                       goto FINISH_OFF;
+               }               
+
+               /*  read password from secure storage */
+               if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage()  failed...");
+                       goto FINISH_OFF;
+               }
+               EM_DEBUG_LOG("cert_password_file_name[%s], password[%s]", cert_password_file_name,  p_data_tbl->password);
+#endif
+       }
+       ret = true;
+
+FINISH_OFF:
+       if (ret == true)
+               *certificate = p_data_tbl;
+       else {
+               if (p_data_tbl)
+                       emstorage_free_certificate((emstorage_certificate_tbl_t **)&p_data_tbl, 1, NULL);
+       }
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+       
+       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+       _DISCONNECT_DB;
+
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("index[%d], certificate[%p], transaction[%d], err_code[%p]", index, certificate, transaction, err_code);
+
+       if (!certificate)  {
+               EM_DEBUG_EXCEPTION("index[%d], account[%p]", index, certificate);
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       emstorage_certificate_tbl_t *p_data_tbl = NULL;
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+       int rc = -1;
+       int sql_len = 0;
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+       char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif         
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+       /*  Make query string */
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
+       sql_len = strlen(sql_query_string);
+               
+       /*  dummy value, FROM WHERE clause */
+       SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE certificate_id = %d", index);
+
+       /*  FROM clause */
+       EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+       /*  execute a sql and count rows */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+       EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("sqlite3_step fail:%d", rc));
+
+       if (rc == SQLITE_DONE)  {
+               EM_DEBUG_EXCEPTION("no matched certificate found...");
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+
+       /*  Assign query result to structure */
+       if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t))))  {
+               EM_DEBUG_EXCEPTION("malloc failed...");
+               error = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t));
+
+       _get_stmt_field_data_int(hStmt,  &(p_data_tbl->certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
+       _get_stmt_field_data_string(hStmt, &(p_data_tbl->filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
+
+       if (with_password) {
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+               /*  get password file name */
+               if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+                       goto FINISH_OFF;
+               }               
+
+               /*  read password from secure storage */
+               if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage()  failed...");
+                       goto FINISH_OFF;
+               }
+               EM_DEBUG_LOG("cert_password_file_name[%s], password[%s]", cert_password_file_name,  p_data_tbl->password);
+#endif
+       }
+       ret = true;
+
+FINISH_OFF:
+       if (ret == true)
+               *certificate = p_data_tbl;
+       else {
+               if (p_data_tbl)
+                       emstorage_free_certificate((emstorage_certificate_tbl_t **)&p_data_tbl, 1, NULL);
+       }
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+       
+       EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+       _DISCONNECT_DB;
+
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transaction, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("certificate_id[%d], transaction[%d], err_code[%p]", certificate_id, transaction, err_code);
+       
+       if (certificate_id < 1)  {      
+               EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id);
+               
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+       
+       int rc = -1, ret = false;
+       int error = EMAIL_ERROR_NONE;
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+       /*  TODO : delete password files - file names can be obtained from db or a rule that makes a name */
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ 
+       char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+       /*  get password file name */
+       if ((error = _get_cert_password_file_name(certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+               goto FINISH_OFF;
+       }
+#endif
+       /*  delete from db */
+       memset(sql_query_string, 0x00, sizeof(sql_query_string));
+       SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_certificate_tbl WHERE certificate_id = %d", certificate_id);
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+       EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+               ("sqlite3_exec fail:%d", rc));
+       EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+       /*  validate account existence */
+       rc = sqlite3_changes(local_db_handle);
+       if (rc == 0)  {
+               EM_DEBUG_EXCEPTION(" no matched certificate found...");
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ 
+       /*  delete from secure storage */
+       if (ssm_delete_file(cert_password_file_name,  SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+               EM_DEBUG_EXCEPTION(" ssm_delete_file failed -cert password : file[%s]", cert_password_file_name);
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
+               goto FINISH_OFF;                
+       }
+#endif 
+       ret = true;
+
+FINISH_OFF:
+       if (hStmt != NULL)  {
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+       _DISCONNECT_DB;
+
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
+
+INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
+{
+       EM_DEBUG_FUNC_BEGIN("certificate_id[%d], certificate[%p], transaction[%d], err_code[%p]", certificate_id, certificate, transaction, err_code);
+       
+       if (certificate_id < 1)  {      
+               EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id);
+               
+               if (err_code != NULL)
+                       *err_code = EMAIL_ERROR_INVALID_PARAM;
+               return false;
+       }
+       
+       int error = EMAIL_ERROR_NONE;
+       int rc, ret = false;
+       DB_STMT hStmt = NULL;
+       char sql_query_string[QUERY_SIZE] = {0, };
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ 
+       char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif
+       sqlite3 *local_db_handle = emstorage_get_db_connection();
+       EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+       SNPRINTF(sql_query_string, sizeof(sql_query_string),
+               "UPDATE mail_certificate_tbl SET"
+               " issue_year = ?"
+               ", issue_month = ?"             /* Index of certificate */
+               ", issue_day = ?"               /* Select the account */
+               ", expiration_year = ?"         /* Year of issue */
+               ", expiration_month = ?"                /* Month of issue */
+               ", expiration_day = ?"          /* Day of issue */
+               ", issue_organization_name = ?"         /* Year of expiration */
+               ", email_address = ?"           /* Month of expiration */
+               ", subject_str = ?"             /* Day of expiration */
+               ", filepath = ?"                /* Organization of issue */
+               ", password = ?"
+               " WHERE certificate_id = ?");
+        
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+       EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
+       EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+               ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       
+       _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year);
+       _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month);
+       _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day);
+       _bind_stmt_field_data_int(hStmt, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_year);
+       _bind_stmt_field_data_int(hStmt, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_month);
+       _bind_stmt_field_data_int(hStmt, EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_day);
+       _bind_stmt_field_data_string(hStmt, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_organization_name, 0, ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL);
+       _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
+       /*  rc = sqlite3_step(hStmt); */
+       EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+       EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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));
+       
+       /*  validate account existence */
+       rc = sqlite3_changes(local_db_handle);
+       if (rc == 0) {
+               EM_DEBUG_EXCEPTION(" no matched account found...");
+       
+               error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+               goto FINISH_OFF;
+       }
+       
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ 
+       /*  get password file name */
+       if ((error = _get_cert_password_file_name(certificate->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+               goto FINISH_OFF;
+       }               
+
+       /*  save passwords to the secure storage */
+       if (ssm_write_buffer(certificate->password, strlen(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+               EM_DEBUG_EXCEPTION("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name);
+               error = EMAIL_ERROR_SYSTEM_FAILURE;
+               goto FINISH_OFF;
+       }
+#endif 
+       if (!emstorage_notify_storage_event(NOTI_CERTIFICATE_UPDATE, certificate->certificate_id, 0, NULL, 0))
+               EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event[ NOTI_CERTIFICATE_UPDATE] : Notification Failed >>> ");
+       
+       ret = true;
+       
+FINISH_OFF:
+       if (hStmt != NULL)  {
+               EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+
+               rc = sqlite3_finalize(hStmt);
+               if (rc != SQLITE_OK)  {
+                       EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+                       error = EMAIL_ERROR_DB_FAILURE;
+               }
+       }
+
+       EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+       
+       _DISCONNECT_DB;
+       
+       if (err_code != NULL)
+               *err_code = error;
+
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
+}
 
 /*EOF*/