Merged frm tizen 2.4 to tizen 3.0 48/52248/1 accepted/tizen/mobile/20151122.234022 accepted/tizen/tv/20151122.234033 accepted/tizen/wearable/20151122.234050 submit/tizen/20151120.071824
authorSunghyun Kwon <sh0701.kwon@samsung.com>
Fri, 20 Nov 2015 06:59:41 +0000 (15:59 +0900)
committerSunghyun Kwon <sh0701.kwon@samsung.com>
Fri, 20 Nov 2015 06:59:41 +0000 (15:59 +0900)
Change-Id: I65ed61258a3ac6179144e30e696a4f02b2cb7b71

email-common-use/include/email-types.h
email-core/email-core-alarm.c
email-core/email-core-auto-download.c
email-core/email-core-mailbox.c
email-core/email-core-smtp.c
email-core/include/email-core-alarm.h
email-daemon/email-daemon-account.c
email-daemon/email-daemon-init.c
email-daemon/email-daemon-mail.c
email-daemon/email-daemon-mailbox.c

index 6c20d4c..dde0b8e 100755 (executable)
@@ -835,7 +835,8 @@ typedef enum
  * @since_tizen 2.3 */
 typedef enum
 {
-    EMAIL_EVENT_STATUS_UNUSED        = 0,    /**< Initial status of event */
+    EMAIL_EVENT_STATUS_UNUSED        = 0,    /**< Initial status of event : DB data(priority low) */
+    EMAIL_EVENT_STATUS_DIRECT,               /**< Direct input status : event data(priority high) */
     EMAIL_EVENT_STATUS_WAIT,                 /**< Waiting status */
     EMAIL_EVENT_STATUS_STARTED,              /**< Event handling is started */
     EMAIL_EVENT_STATUS_CANCELED,             /**< Event handling is canceled */
@@ -1337,7 +1338,7 @@ typedef struct
     int                                vibrate_status;          /**< The repetition type */
     int                                display_content_status;  /**< The display_content status. 1 = ON, 0 = OFF */
     int                                default_ringtone_status; /**< The badge status.  1 = ON, 0 = OFF */
-    char                              *alert_ringtone_path;     /**< The ringtone path */
+    char                               *alert_ringtone_path;    /**< The ringtone path */
 } email_option_t;
 
 /**
index 0876dce..fffd7d6 100755 (executable)
@@ -154,7 +154,13 @@ INTERNAL_FUNC int emcore_check_alarm_by_class_id(email_alarm_class_t input_class
        return err;
 }
 
-static int emcore_add_alarm_data_to_alarm_data_list(char *multi_user_name, alarm_id_t input_alarm_id, email_alarm_class_t input_class_id, int input_reference_id, time_t input_trigger_at_time, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *user_data)
+static int emcore_add_alarm_data_to_alarm_data_list(char *multi_user_name,
+                                                                                                       alarm_id_t input_alarm_id,
+                                                                                                       email_alarm_class_t input_class_id,
+                                                                                                       int input_reference_id,
+                                                                                                       time_t input_trigger_at_time,
+                                                                                                       int (*input_alarm_callback)(email_alarm_data_t*, void *),
+                                                                                                       void *user_data)
 {
        EM_DEBUG_FUNC_BEGIN("input_alarm_id [%d] input_class_id[%d] input_reference_id[%d] input_trigger_at_time[%d] input_alarm_callback [%p] user_data[%p]", input_alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, user_data);
        int err = EMAIL_ERROR_NONE;
@@ -262,9 +268,17 @@ FINISH_OFF:
        return err;
 }
 
-INTERNAL_FUNC int emcore_add_alarm(char *multi_user_name, time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data)
+INTERNAL_FUNC int emcore_add_alarm(char *multi_user_name,
+                                                                       time_t input_trigger_at_time,
+                                                                       email_alarm_class_t input_class_id,
+                                                                       int input_reference_id,
+                                                                       int (*input_alarm_callback)(email_alarm_data_t*, void *),
+                                                                       void *input_user_data)
 {
-       EM_DEBUG_FUNC_BEGIN("input_trigger_at_time[%d] input_class_id[%d] input_reference_id[%d] input_alarm_callback[%p] input_user_data[%p]", input_trigger_at_time, input_class_id, input_reference_id, input_alarm_callback, input_user_data);
+       EM_DEBUG_FUNC_BEGIN("input_trigger_at_time[%d] input_class_id[%d] input_reference_id[%d] "
+                                               "input_alarm_callback[%p] input_user_data[%p]",
+                                               input_trigger_at_time, input_class_id, input_reference_id,
+                                               input_alarm_callback, input_user_data);
 
        int err = EMAIL_ERROR_NONE;
        int ret = 0;
@@ -278,13 +292,23 @@ INTERNAL_FUNC int emcore_add_alarm(char *multi_user_name, time_t input_trigger_a
 
        EM_DEBUG_ALARM_LOG("alarm_interval [%d]", (int)alarm_interval);
 
-       if ((ret = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, alarm_interval, ALARM_REPEAT_MODE_ONCE, EMAIL_ALARM_DESTINATION, &alarm_id)) != ALARMMGR_RESULT_SUCCESS) {
+       if ((ret = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE,
+                                                                       alarm_interval,
+                                                                       ALARM_REPEAT_MODE_ONCE,
+                                                                       EMAIL_ALARM_DESTINATION,
+                                                                       &alarm_id)) != ALARMMGR_RESULT_SUCCESS) {
                EM_DEBUG_EXCEPTION("alarmmgr_add_alarm failed [%d]",ret);
                err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
-       if ((err = emcore_add_alarm_data_to_alarm_data_list(multi_user_name, alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, input_user_data)) != EMAIL_ERROR_NONE) {
+       if ((err = emcore_add_alarm_data_to_alarm_data_list(multi_user_name,
+                                                                                                               alarm_id,
+                                                                                                               input_class_id,
+                                                                                                               input_reference_id,
+                                                                                                               input_trigger_at_time,
+                                                                                                               input_alarm_callback,
+                                                                                                               input_user_data)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emcore_add_alarm_data_to_alarm_data_list failed [%d]", err);
                goto FINISH_OFF;
        }
index bd8fc86..397f3b4 100755 (executable)
@@ -169,10 +169,17 @@ INTERNAL_FUNC int emcore_insert_auto_download_event(email_event_auto_download *e
                q_length = g_queue_get_length(g_auto_download_que);
        EM_DEBUG_LOG("Q Length : [%d]", q_length);
 
+       EM_DEBUG_LOG("event_data->status : [%d]", event_data->status);
+
        if (q_length > AUTO_DOWNLOAD_QUEUE_MAX) {
                EM_DEBUG_EXCEPTION("auto download que is full...");
                error = EMAIL_ERROR_EVENT_QUEUE_FULL;
                ret = false;
+       } else if (event_data->status == EMAIL_EVENT_STATUS_DIRECT) {
+               event_data->status = EMAIL_EVENT_STATUS_WAIT;
+               g_queue_push_head(g_auto_download_que, event_data);
+               //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal);
+               ret = true;
        } else {
                event_data->status = EMAIL_EVENT_STATUS_WAIT;
                g_queue_push_tail(g_auto_download_que, event_data);
@@ -620,12 +627,29 @@ CHECK_CONTINUE:
                                                        if (attachment_list[i].attachment_save_status)
                                                                continue;
 
-                                                       EM_DEBUG_LOG("#####AUTO DOWNLOAD ATTACHMENT[%d]: ACCOUNT_ID[%d] MAILBOX_ID[%d] MAIL_ID[%d] UID[%d] ACTIVITY[%d]#####",
-                                                                       j, event_data->account_id, event_data->mailbox_id,
-                                                                       event_data->mail_id, event_data->server_mail_id, event_data->activity_id);
-
-                                                       if (!emcore_gmime_download_attachment(event_data->multi_user_name, event_data->mail_id, j, 0, -1, 1, &err))
+                                                       EM_DEBUG_LOG("#####AUTO DOWNLOAD ATTACHMENT[%d]: ACCOUNT_ID[%d] "
+                                                                               "MAILBOX_ID[%d] MAIL_ID[%d] UID[%d] ACTIVITY[%d]#####",
+                                                                               j, event_data->account_id, event_data->mailbox_id,
+                                                                               event_data->mail_id, event_data->server_mail_id, event_data->activity_id);
+
+                                                       if (!emcore_gmime_download_attachment(event_data->multi_user_name,
+                                                                                                                                       event_data->mail_id,
+                                                                                                                                       j,
+                                                                                                                                       0,
+                                                                                                                                       -1,
+                                                                                                                                       1,
+                                                                                                                                       &err)) {
                                                                EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err);
+                                                               EM_DEBUG_LOG("Retry again");
+                                                               if (!emcore_gmime_download_attachment(event_data->multi_user_name,
+                                                                                                                                               event_data->mail_id,
+                                                                                                                                               j,
+                                                                                                                                               0,
+                                                                                                                                               -1,
+                                                                                                                                               1,
+                                                                                                                                               &err))
+                                                                       EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err);
+                                                       }
                                                }
 
                                                if (attachment_list)
@@ -638,7 +662,11 @@ CHECK_CONTINUE:
                        }
 
 DELETE_ACTIVITY:
-                       if (!emcore_delete_auto_download_activity(event_data->multi_user_name, event_data->account_id, event_data->mail_id, event_data->activity_id, &err)) {
+                       if (!emcore_delete_auto_download_activity(event_data->multi_user_name,
+                                                                                                               event_data->account_id,
+                                                                                                               event_data->mail_id,
+                                                                                                               event_data->activity_id,
+                                                                                                               &err)) {
                                EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err);
                        }
 
@@ -673,7 +701,13 @@ POP_HEAD:
 }
 
 
-INTERNAL_FUNC int emcore_insert_auto_download_job(char *multi_user_name, int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code)
+INTERNAL_FUNC int emcore_insert_auto_download_job(char *multi_user_name,
+                                                                                                       int account_id,
+                                                                                                       int mailbox_id,
+                                                                                                       int mail_id,
+                                                                                                       int auto_download_on,
+                                                                                                       char *uid,
+                                                                                                       int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id [%d], maibox_id[%d], mail_id[%d], uid[%p]", account_id, mailbox_id, mail_id, uid);
 
@@ -718,6 +752,8 @@ INTERNAL_FUNC int emcore_insert_auto_download_job(char *multi_user_name, int acc
                        EM_DEBUG_LOG("Activity inserted only in DB .. Queue is Full");
                }
                else {
+                       ad_event->status = EMAIL_EVENT_STATUS_DIRECT;
+
                        if (!emcore_insert_auto_download_event(ad_event, &err)) {
                                EM_DEBUG_EXCEPTION("emcore_insert_auto_download_event is failed [%d]", err);
                                goto FINISH_OFF;
index 546f53a..e4b9dab 100755 (executable)
@@ -257,11 +257,11 @@ INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (char *multi_user_name, int ac
                goto FINISH_OFF;
        }
 
-       if (!emcore_connect_to_remote_mailbox(multi_user_name, 
-                                                                                       account_id, 
-                                                                                       mailbox_id, 
+       if (!emcore_connect_to_remote_mailbox(multi_user_name,
+                                                                                       account_id,
+                                                                                       mailbox_id,
                                                                                        true,
-                                                                                       (void **)ret, 
+                                                                                       (void **)ret,
                                                                                        &err)) {
                EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
                EM_SAFE_FREE(ret);
@@ -301,14 +301,14 @@ FINISH_OFF:
 /* description
  *    get local mailbox list
  */
-INTERNAL_FUNC int emcore_get_mailbox_list(char *multi_user_name, int account_id, email_mailbox_t **mailbox_list,       
+INTERNAL_FUNC int emcore_get_mailbox_list(char *multi_user_name, int account_id, email_mailbox_t **mailbox_list,
                                                                                int *p_count, int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]", 
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]",
                                                        account_id, mailbox_list, p_count, err_code);
 
        if (account_id <= 0 || !mailbox_list || !p_count)  {
-               EM_DEBUG_EXCEPTION("PARAM Failed account_id[%d], mailbox_list[%p], p_count[%p]", 
+               EM_DEBUG_EXCEPTION("PARAM Failed account_id[%d], mailbox_list[%p], p_count[%p]",
                                                        account_id, mailbox_list, p_count);
                if (err_code != NULL)
                        *err_code = EMAIL_ERROR_INVALID_PARAM;
@@ -328,9 +328,9 @@ INTERNAL_FUNC int emcore_get_mailbox_list(char *multi_user_name, int account_id,
                goto FINISH_OFF;
        }
 
-       if (!emstorage_get_mailbox_list(multi_user_name, ref_account->account_id, 
-                                                                       EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, 
-                                                                       &count, &local_mailbox_list, true, &error))  {  
+       if (!emstorage_get_mailbox_list(multi_user_name, ref_account->account_id,
+                                                                       EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC,
+                                                                       &count, &local_mailbox_list, true, &error))  {
                EM_DEBUG_EXCEPTION(" emstorage_get_mailbox failed - %d", error);
                goto FINISH_OFF;
        }
@@ -399,9 +399,9 @@ int emcore_get_mailbox_list_to_be_sync(char *multi_user_name, int account_id, em
                goto FINISH_OFF;
        }
 
-       if (!emstorage_get_mailbox_list(multi_user_name, ref_account->account_id, 0, 
-                                                                       EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count, 
-                                                                       &mailbox_tbl_list, true, &error))  {    
+       if (!emstorage_get_mailbox_list(multi_user_name, ref_account->account_id, 0,
+                                                                       EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count,
+                                                                       &mailbox_tbl_list, true, &error))  {
                EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed - %d", error);
                goto FINISH_OFF;
        }
@@ -586,11 +586,11 @@ INTERNAL_FUNC int emcore_delete_mailbox(char *multi_user_name, int input_mailbox
 #ifdef __FEATURE_DELETE_MAILBOX_RECURSIVELY__
        if(input_recursive) {
                /* Getting children mailbox list */
-               if(!emstorage_get_child_mailbox_list(multi_user_name, 
-                                                                                       target_mailbox->account_id, 
-                                                                                       target_mailbox->mailbox_name, 
-                                                                                       &mailbox_count, 
-                                                                                       &target_mailbox_array, 
+               if(!emstorage_get_child_mailbox_list(multi_user_name,
+                                                                                       target_mailbox->account_id,
+                                                                                       target_mailbox->mailbox_name,
+                                                                                       &mailbox_count,
+                                                                                       &target_mailbox_array,
                                                                                        false,
                                                                                        &err)) {
                        EM_DEBUG_EXCEPTION("emstorage_get_child_mailbox_list failed. [%d]", err);
@@ -618,7 +618,7 @@ INTERNAL_FUNC int emcore_delete_mailbox(char *multi_user_name, int input_mailbox
                                continue;
                        }
                }
-               
+
                EM_DEBUG_LOG("Deleting mailbox_id [%d]", target_mailbox_array[i].mailbox_id);
                if (input_on_server) {
                        EM_DEBUG_LOG("Delete the mailbox in Sever >>> ");
@@ -630,11 +630,11 @@ INTERNAL_FUNC int emcore_delete_mailbox(char *multi_user_name, int input_mailbox
                                EM_DEBUG_LOG("Delete the mailbox in server : success");
                }
 
-               if (!emcore_delete_all_mails_of_mailbox(multi_user_name, 
-                                                                                               target_mailbox_array[i].account_id, 
+               if (!emcore_delete_all_mails_of_mailbox(multi_user_name,
+                                                                                               target_mailbox_array[i].account_id,
                                                                                                target_mailbox_array[i].mailbox_id,
                                                                                                0,
-                                                                                               false, 
+                                                                                               false,
                                                                                                &err))  {
                        if (err != EMAIL_ERROR_MAIL_NOT_FOUND) {
                                EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err);
@@ -649,7 +649,7 @@ INTERNAL_FUNC int emcore_delete_mailbox(char *multi_user_name, int input_mailbox
        }
 
 FINISH_OFF:
-       
+
        EM_SAFE_FREE(old_mailbox_name);
 
        if (target_mailbox)
@@ -704,12 +704,12 @@ INTERNAL_FUNC int emcore_delete_mailbox_all(char *multi_user_name, email_mailbox
                err = EMAIL_ERROR_INVALID_PARAM;
                goto FINISH_OFF;
        }
-       
-       if (!emcore_delete_all_mails_of_mailbox(multi_user_name, 
-                                                                                       mailbox->account_id, 
+
+       if (!emcore_delete_all_mails_of_mailbox(multi_user_name,
+                                                                                       mailbox->account_id,
                                                                                        mailbox->mailbox_id,
                                                                                        0,
-                                                                                       0, /*NULL, */ 
+                                                                                       0, /*NULL, */
                                                                                        &err)) {
                if (err != EMAIL_ERROR_MAIL_NOT_FOUND) {
                        EM_DEBUG_EXCEPTION(" emcore_delete_all_mails_of_mailbox failed - %d", err);
@@ -731,14 +731,14 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name, 
-                                                                               int input_mailbox_id, 
-                                                                               char *input_new_mailbox_name, 
-                                                                               char *input_new_mailbox_alias, 
-                                                                               void *input_eas_data, 
-                                                                               int input_eas_data_length, 
-                                                                               int input_on_server, 
-                                                                               int input_recursive, 
+INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
+                                                                               int input_mailbox_id,
+                                                                               char *input_new_mailbox_name,
+                                                                               char *input_new_mailbox_alias,
+                                                                               void *input_eas_data,
+                                                                               int input_eas_data_length,
+                                                                               int input_on_server,
+                                                                               int input_recursive,
                                                                                int handle_to_be_published)
 {
        EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_new_mailbox_name[%p] input_new_mailbox_alias[%p] input_eas_data[%p] input_eas_data_length[%d] input_on_server[%d] input_recursive[%d] handle_to_be_published[%d]", input_mailbox_id, input_new_mailbox_name, input_new_mailbox_alias, input_eas_data, input_eas_data_length, input_on_server, input_recursive, handle_to_be_published);
@@ -788,11 +788,11 @@ INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
        if (input_on_server) {
                EM_DEBUG_LOG("Rename the mailbox in Sever >>> ");
 
-               if ((err = emcore_rename_mailbox_on_imap_server(multi_user_name, 
-                                                                                                               target_mailbox->account_id, 
-                                                                                                               target_mailbox->mailbox_id, 
-                                                                                                               target_mailbox->mailbox_name, 
-                                                                                                               new_mailbox_name, 
+               if ((err = emcore_rename_mailbox_on_imap_server(multi_user_name,
+                                                                                                               target_mailbox->account_id,
+                                                                                                               target_mailbox->mailbox_id,
+                                                                                                               target_mailbox->mailbox_name,
+                                                                                                               new_mailbox_name,
                                                                                                                handle_to_be_published)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_rename_mailbox_on_imap_server failed [%d]", err);
                        goto FINISH_OFF;
@@ -804,11 +804,11 @@ INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
 #ifdef __FEATURE_RENAME_MAILBOX_RECURSIVELY__
        if(account_ref->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_recursive) {
                /* Getting children mailbox list */
-               if(!emstorage_get_child_mailbox_list(multi_user_name, 
-                                                                                       target_mailbox->account_id, 
-                                                                                       target_mailbox->mailbox_name, 
-                                                                                       &mailbox_count, 
-                                                                                       &target_mailbox_array, 
+               if(!emstorage_get_child_mailbox_list(multi_user_name,
+                                                                                       target_mailbox->account_id,
+                                                                                       target_mailbox->mailbox_name,
+                                                                                       &mailbox_count,
+                                                                                       &target_mailbox_array,
                                                                                        false,
                                                                                        &err)) {
                        EM_DEBUG_EXCEPTION("emstorage_get_child_mailbox_list failed. [%d]", err);
@@ -829,8 +829,8 @@ INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
 
        /* Rename mailboxes */
        for(i = 0; i < mailbox_count ; i++) {
-               EM_DEBUG_LOG_SEC("Rename mailbox_id [%d], mailbox_name [%s], old_mailbox_name [%s]", 
-                                                       target_mailbox_array[i].mailbox_id, 
+               EM_DEBUG_LOG_SEC("Rename mailbox_id [%d], mailbox_name [%s], old_mailbox_name [%s]",
+                                                       target_mailbox_array[i].mailbox_id,
                                                        target_mailbox_array[i].mailbox_name,
                                                        old_mailbox_name);
 
@@ -842,12 +842,12 @@ INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
                }
 
                if (input_mailbox_id == target_mailbox_array[i].mailbox_id) {
-                       if ((err = emstorage_rename_mailbox(multi_user_name, 
-                                                                                               target_mailbox_array[i].mailbox_id, 
-                                                                                               new_mailbox_name, 
-                                                                                               input_new_mailbox_alias, 
-                                                                                               input_eas_data, 
-                                                                                               input_eas_data_length, 
+                       if ((err = emstorage_rename_mailbox(multi_user_name,
+                                                                                               target_mailbox_array[i].mailbox_id,
+                                                                                               new_mailbox_name,
+                                                                                               input_new_mailbox_alias,
+                                                                                               input_eas_data,
+                                                                                               input_eas_data_length,
                                                                                                true)) != EMAIL_ERROR_NONE) {
                                EM_DEBUG_EXCEPTION("emstorage_rename_mailbox failed [%d]", err);
                                goto FINISH_OFF;
@@ -856,21 +856,21 @@ INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
                else {
                        EM_DEBUG_LOG_SEC("target_mailbox_array[i].mailbox_name[%s] "
                                                         "old_mailbox_name[%s] "
-                                                        "new_mailbox_name [%s]", 
-                                                        target_mailbox_array[i].mailbox_name, 
-                                                        old_mailbox_name, 
+                                                        "new_mailbox_name [%s]",
+                                                        target_mailbox_array[i].mailbox_name,
+                                                        old_mailbox_name,
                                                         new_mailbox_name);
-                       renamed_mailbox_name = em_replace_string(target_mailbox_array[i].mailbox_name, 
-                                                                                                       old_mailbox_name, 
+                       renamed_mailbox_name = em_replace_string(target_mailbox_array[i].mailbox_name,
+                                                                                                       old_mailbox_name,
                                                                                                        new_mailbox_name);
                        EM_DEBUG_LOG_SEC("renamed_mailbox_name[%s]", renamed_mailbox_name);
 
-                       if ((err = emstorage_rename_mailbox(multi_user_name, 
-                                                                                               target_mailbox_array[i].mailbox_id, 
-                                                                                               renamed_mailbox_name, 
-                                                                                               target_mailbox_array[i].alias, 
-                                                                                               NULL, 
-                                                                                               0, 
+                       if ((err = emstorage_rename_mailbox(multi_user_name,
+                                                                                               target_mailbox_array[i].mailbox_id,
+                                                                                               renamed_mailbox_name,
+                                                                                               target_mailbox_array[i].alias,
+                                                                                               NULL,
+                                                                                               0,
                                                                                                true)) != EMAIL_ERROR_NONE) {
                                EM_DEBUG_EXCEPTION("emstorage_rename_mailbox failed [%d]", err);
                                goto FINISH_OFF;
@@ -904,11 +904,11 @@ FINISH_OFF:
 extern long smtp_send(SENDSTREAM *stream, char *command, char *args);
 #endif /* __FEATURE_KEEP_CONNECTION__ */
 
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi_user_name, 
-                                                                                                                                               email_account_t *account, 
-                                                                                                                                               int input_mailbox_id, 
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi_user_name,
+                                                                                                                                               email_account_t *account,
+                                                                                                                                               int input_mailbox_id,
                                                                                                                                                int reusable,
-                                                                       /*either MAILSTREAM or SENDSTREAM*/ void **result_stream, 
+                                                                       /*either MAILSTREAM or SENDSTREAM*/ void **result_stream,
                                                                                                                                                int *err_code)
 {
        EM_PROFILE_BEGIN(emCoreMailboxOpen);
@@ -961,8 +961,8 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi
 
        /* set current network error as EMAIL_ERROR_NONE before network operation */
        session->error = EMAIL_ERROR_NONE;
-       emcore_set_network_error(EMAIL_ERROR_NONE);             
-       
+       emcore_set_network_error(EMAIL_ERROR_NONE);
+
        if (input_mailbox_id == EMAIL_CONNECT_FOR_SENDING) {
                mailbox_name = EM_SAFE_STRDUP(ENCODED_PATH_SMTP);
        } else if (input_mailbox_id == 0) {
@@ -977,11 +977,11 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi
 
        if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) {
                /*  open pop3/imap server */
-               if (!emcore_get_long_encoded_path_with_account_info(multi_user_name, 
-                                                                                                                       account, 
-                                                                                                                       mailbox_name, 
-                                                                                                                       '/', 
-                                                                                                                       &mbox_path, 
+               if (!emcore_get_long_encoded_path_with_account_info(multi_user_name,
+                                                                                                                       account,
+                                                                                                                       mailbox_name,
+                                                                                                                       '/',
+                                                                                                                       &mbox_path,
                                                                                                                        &error)) {
                        EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed - %d", error);
                        session->error = error;
@@ -993,11 +993,11 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi
                session->auth = 0; /*  ref_account->receiving_auth ? 1  :  0 */
 
                if (!(*result_stream = mail_open(*result_stream, mbox_path, IMAP_2004_LOG))) {
-                       EM_DEBUG_EXCEPTION("mail_open failed. session->error[%d], session->network[%d]", 
+                       EM_DEBUG_EXCEPTION("mail_open failed. session->error[%d], session->network[%d]",
                                                                session->error, session->network);
                        *result_stream = mail_close(*result_stream);
 
-                       if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST || 
+                       if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST ||
                                session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) {
                                error = emcore_refresh_xoauth2_access_token (multi_user_name, account->account_id);
 
@@ -1008,21 +1008,21 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi
 
                                                sleep(3); /* wait for updating access token */
                                                if (!(*result_stream = mail_open(*result_stream, mbox_path, IMAP_2004_LOG))) {
-                                                       EM_DEBUG_LOG("mail_open failed. session->error[%d], session->network[%d]", 
+                                                       EM_DEBUG_LOG("mail_open failed. session->error[%d], session->network[%d]",
                                                                                        session->error, session->network);
                                                }
                                                connection_retry_count++;
                                                EM_DEBUG_LOG ("connection_retry_count [%d]", connection_retry_count);
                                        }
                                }
-                       } else if ((session->error == EMAIL_ERROR_TLS_SSL_FAILURE || 
+                       } else if ((session->error == EMAIL_ERROR_TLS_SSL_FAILURE ||
                                                session->error == EMAIL_ERROR_CANNOT_NEGOTIATE_TLS)) {
                                char *replaced_mbox_path = NULL;
                                replaced_mbox_path = em_replace_string(mbox_path, "}", "/force_tls_v1_0}");
 
-                               if (replaced_mbox_path != NULL && 
+                               if (replaced_mbox_path != NULL &&
                                        !(*result_stream = mail_open(*result_stream, replaced_mbox_path, IMAP_2004_LOG))) {
-                                       EM_DEBUG_EXCEPTION("retry --> mail_open failed. session->error[%d], session->network[%d]", 
+                                       EM_DEBUG_EXCEPTION("retry --> mail_open failed. session->error[%d], session->network[%d]",
                                                                                session->error, session->network);
                                        *result_stream = mail_close(*result_stream);
                                }
@@ -1057,11 +1057,11 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi
                }
 #endif
                if (!*result_stream) {
-                       if (!emcore_get_long_encoded_path_with_account_info(multi_user_name, 
-                                                                                                                               account, 
-                                                                                                                               mailbox_name, 
-                                                                                                                               0, 
-                                                                                                                               &mbox_path, 
+                       if (!emcore_get_long_encoded_path_with_account_info(multi_user_name,
+                                                                                                                               account,
+                                                                                                                               mailbox_name,
+                                                                                                                               0,
+                                                                                                                               &mbox_path,
                                                                                                                                &error)) {
                                EM_DEBUG_EXCEPTION(" emcore_get_long_encoded_path failed - %d", error);
                                session->error = error;
@@ -1077,7 +1077,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi
                        if (!(*result_stream = smtp_open (host_list, 1))) {
                                EM_DEBUG_EXCEPTION_SEC("smtp_open error : outgoing_server_secure_connection[%d] "
                                                                           "session->error[%d] session->network[%d]",
-                                                                                 account->outgoing_server_secure_connection, 
+                                                                                 account->outgoing_server_secure_connection,
                                                                                  session->error, session->network);
 
                                if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST ||
@@ -1163,14 +1163,14 @@ emcore_close_mailbox uses mail_close inside it.
 
 mail_close is only used in emcore_connect_to_remote_mailbox and emcore_reset_streams as an exception to above rule*/
 
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name, 
-                                                                                                       int account_id, 
-                                                                                                       char *mailbox, 
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name,
+                                                                                                       int account_id,
+                                                                                                       char *mailbox,
                                                                                                        int reusable,
-                                                                                                       void **mail_stream, 
+                                                                                                       void **mail_stream,
                                                                                                        int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], reusable[%d], mail_stream[%p], err_code[%p]", 
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], reusable[%d], mail_stream[%p], err_code[%p]",
                                                account_id, mailbox, reusable, mail_stream, err_code);
 
        int ret = false;
@@ -1183,12 +1183,12 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name,
                error = EMAIL_ERROR_INVALID_ACCOUNT;
                goto FINISH_OFF;
        }
-       
-       ret = emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, 
-                                                                                                                               ref_account, 
-                                                                                                                               mailbox, 
+
+       ret = emcore_connect_to_remote_mailbox_with_account_info(multi_user_name,
+                                                                                                                               ref_account,
+                                                                                                                               mailbox,
                                                                                                                                reusable,
-                                                                                                                               mail_stream, 
+                                                                                                                               mail_stream,
                                                                                                                                &error);
 
 FINISH_OFF:
@@ -1245,14 +1245,14 @@ INTERNAL_FUNC void emcore_reset_streams()
 
 #else /*  __FEATURE_KEEP_CONNECTION__ */
 
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name, 
-                                                                                                       int account_id, 
-                                                                                                       int input_mailbox_id, 
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name,
+                                                                                                       int account_id,
+                                                                                                       int input_mailbox_id,
                                                                                                        int reusable,
-                                                                                                       void **mail_stream, 
+                                                                                                       void **mail_stream,
                                                                                                        int *err_code)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], reusable[%d], mail_stream[%p], err_code[%p]", 
+       EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], reusable[%d], mail_stream[%p], err_code[%p]",
                                                account_id, input_mailbox_id, reusable, mail_stream, err_code);
 
        int ret = false;
@@ -1284,13 +1284,13 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name,
                goto FINISH_OFF; */
        }
 
-       ret = emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, 
-                                                                                                                               ref_account, 
-                                                                                                                               input_mailbox_id, 
+       ret = emcore_connect_to_remote_mailbox_with_account_info(multi_user_name,
+                                                                                                                               ref_account,
+                                                                                                                               input_mailbox_id,
                                                                                                                                reusable,
-                                                                                                                               mail_stream, 
+                                                                                                                               mail_stream,
                                                                                                                                &error);
-       EM_DEBUG_LOG("ret[%d] incoming_server_type[%d] input_mailbox_id[%d]", 
+       EM_DEBUG_LOG("ret[%d] incoming_server_type[%d] input_mailbox_id[%d]",
                                        ret, ref_account->incoming_server_type, input_mailbox_id);
 
        if (ret == EMAIL_ERROR_NONE && input_mailbox_id == EMAIL_CONNECT_FOR_SENDING) {
@@ -1688,6 +1688,12 @@ INTERNAL_FUNC int emcore_save_local_activity_sync(int account_id, int *err_code)
 
        if (activity_count > 0) {
                event_data = em_malloc(sizeof(email_event_t));
+               if (!event_data) {
+                       EM_DEBUG_EXCEPTION("em_malloc failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
+
                event_data->type = EMAIL_EVENT_LOCAL_ACTIVITY;
                event_data->account_id  = account_id;
                if (!emcore_insert_event_for_sending_mails(event_data, &handle, &err)) {
index 2865855..d718c11 100755 (executable)
@@ -36,6 +36,7 @@
 
 #include "email-internal-types.h"
 #include "c-client.h"
+#include "email-daemon.h"
 #include "email-core-global.h"
 #include "email-core-utils.h"
 #include "email-storage.h"
@@ -4621,22 +4622,129 @@ static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_pa
 {
        EM_DEBUG_FUNC_BEGIN("alarm_data [%p] user_parameter [%p]", alarm_data, user_parameter);
        int err = EMAIL_ERROR_NONE;
-       int ret = 0;
-       char *multi_user_name = (char *)user_parameter;
 
        if (alarm_data == NULL) {
                EM_DEBUG_EXCEPTION("Invalid parameter");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               return err;
+       }
+
+       if (alarm_data->reference_id <= 0) {
+               EM_DEBUG_EXCEPTION("Invalid parameter");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               return err;
+       }
+
+       /* Insert the sending mail event */
+       int account_id = 0;
+       int input_mail_id = alarm_data->reference_id;
+       int dst_mailbox_id = 0;
+       int result_handle = 0;
+       char *multi_user_name = alarm_data->multi_user_name;
+
+       email_event_t *event_data = NULL;
+       emstorage_mail_tbl_t *mail_data = NULL;
+       emstorage_mailbox_tbl_t *outbox_tbl = NULL;
+
+       if (!emstorage_get_mail_by_id(multi_user_name, input_mail_id, &mail_data, false, &err)) {
+               EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err);
+               goto FINISH_OFF;
+       }
+
+       account_id = mail_data->account_id;
+
+       if (!emnetwork_check_network_status(&err)) {
+               EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed : [%d]", err);
                goto FINISH_OFF;
        }
 
-       /* send mail here */
-       if(!emcore_send_mail(multi_user_name, alarm_data->reference_id, &err)) {
-               EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", ret);
+#ifdef __FEATURE_MOVE_TO_OUTBOX_FIRST__
+       if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name,
+                                                                                               account_id,
+                                                                                               EMAIL_MAILBOX_TYPE_OUTBOX,
+                                                                                               &outbox_tbl,
+                                                                                               false,
+                                                                                               &err)) {
+               EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed : [%d]", err);
+               goto FINISH_OFF;
+       }
+
+       dst_mailbox_id = outbox_tbl->mailbox_id;
+       emstorage_free_mailbox(&outbox_tbl, 1, NULL);
+       outbox_tbl = NULL;
+
+       if (mail_data->mailbox_id != dst_mailbox_id) {
+               if (!emcore_move_mail(multi_user_name,
+                                                               &input_mail_id,
+                                                               1,
+                                                               dst_mailbox_id,
+                                                               EMAIL_MOVED_AFTER_SENDING,
+                                                               0,
+                                                               &err)) {
+                       EM_DEBUG_EXCEPTION("emcore_move_mail failed : [%d]", err);
+                       goto FINISH_OFF;
+               }
+       }
+#endif /* __FEATURE_MOVE_TO_OUTBOX_FIRST__ */
+
+       if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name,
+                                                                                                                       account_id,
+                                                                                                                       &input_mail_id,
+                                                                                                                       1,
+                                                                                                                       "save_status",
+                                                                                                                       EMAIL_MAIL_STATUS_SEND_WAIT,
+                                                                                                                       true,
+                                                                                                                       &err)) {
+               EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed : [%d]", err);
+               goto FINISH_OFF;
+       }
+
+       event_data = em_malloc(sizeof(email_event_t));
+       if (event_data == NULL) {
+               EM_DEBUG_EXCEPTION("em_malloc failed");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       event_data->type               = EMAIL_EVENT_SEND_MAIL;
+       event_data->account_id         = account_id;
+       event_data->event_param_data_4 = input_mail_id;
+       event_data->event_param_data_5 = mail_data->mailbox_id;
+       event_data->multi_user_name    = EM_SAFE_STRDUP(multi_user_name);
+
+       if (!emcore_insert_event_for_sending_mails(event_data, &result_handle, &err)) {
+               EM_DEBUG_EXCEPTION(" emcore_insert_event failed [%d]", err);
                goto FINISH_OFF;
        }
 
 FINISH_OFF:
 
+       emcore_add_transaction_info(input_mail_id, result_handle, NULL);
+
+       if (err != EMAIL_ERROR_NONE) {
+               if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name,
+                                                                                                                       account_id,
+                                                                                                                       &input_mail_id,
+                                                                                                                       1,
+                                                                                                                       "save_status",
+                                                                                                                       EMAIL_MAIL_STATUS_SAVED,
+                                                                                                                       true,
+                                                                                                                       &err))
+                       EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed : [%d]", err);
+
+               if (event_data) {
+                       emcore_free_event(event_data);
+                       EM_SAFE_FREE(event_data);
+               }
+       }
+
+       if (mail_data)
+               emstorage_free_mail(&mail_data, 1, NULL);
+
+       if (outbox_tbl)
+               emstorage_free_mailbox(&outbox_tbl, 1, NULL);
+
+
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
@@ -4654,20 +4762,25 @@ INTERNAL_FUNC int emcore_schedule_sending_mail(char *multi_user_name, int input_
                goto FINISH_OFF;
        }
 
-       /*
-       if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, mail_data->account_id, &(mail_data->mail_id), 1, "save_status", EMAIL_MAIL_STATUS_SEND_SCHEDULED, true, &err)) {
-               EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
-               goto FINISH_OFF;
-       }
-       */
-
-       if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, mail_data->account_id, &(mail_data->mail_id), 1, "scheduled_sending_time", input_time_to_send, true, &err)) {
+       if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name,
+                                                                                                                       mail_data->account_id,
+                                                                                                                       &(mail_data->mail_id),
+                                                                                                                       1,
+                                                                                                                       "scheduled_sending_time",
+                                                                                                                       input_time_to_send,
+                                                                                                                       true,
+                                                                                                                       &err)) {
                EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
                goto FINISH_OFF;
        }
 
        /* add alarm */
-       if ((err = emcore_add_alarm(multi_user_name, input_time_to_send, EMAIL_ALARM_CLASS_SCHEDULED_SENDING, input_mail_id, emcore_sending_alarm_cb, NULL)) != EMAIL_ERROR_NONE) {
+       if ((err = emcore_add_alarm(multi_user_name,
+                                                               input_time_to_send,
+                                                               EMAIL_ALARM_CLASS_SCHEDULED_SENDING,
+                                                               input_mail_id,
+                                                               emcore_sending_alarm_cb,
+                                                               NULL)) != EMAIL_ERROR_NONE) {
                EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]", err);
                goto FINISH_OFF;
        }
index d78f2bc..c368bb6 100755 (executable)
@@ -42,13 +42,13 @@ extern "C"
 #define EMAIL_ALARM_DESTINATION "email-service-0"\r
 \r
 typedef struct _email_alarm_data_t {\r
-       alarm_id_t                  alarm_id;\r
-       email_alarm_class_t           class_id;\r
-       int                         reference_id;\r
-       time_t                      trigger_at_time;\r
-       int                       (*alarm_callback)(struct _email_alarm_data_t*, void *);\r
-       char                       *multi_user_name;\r
-       void                       *user_data;\r
+       alarm_id_t                      alarm_id;\r
+       email_alarm_class_t     class_id;\r
+       int                                     reference_id;\r
+       time_t                          trigger_at_time;\r
+       int                                     (*alarm_callback)(struct _email_alarm_data_t*, void *);\r
+       char                            *multi_user_name;\r
+       void                            *user_data;\r
 } email_alarm_data_t;\r
 \r
 \r
index f1f0d42..8d803b2 100755 (executable)
@@ -178,6 +178,12 @@ INTERNAL_FUNC int emdaemon_validate_account(char *multi_user_name, int account_i
        }
 
        event_data = em_malloc(sizeof(email_event_t));
+       if (!event_data) {
+               EM_DEBUG_EXCEPTION("em_malloc failed");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
        event_data->type = EMAIL_EVENT_VALIDATE_ACCOUNT;
        event_data->event_param_data_1 = NULL;
        event_data->event_param_data_3 = NULL;
@@ -220,8 +226,7 @@ INTERNAL_FUNC int emdaemon_validate_account_ex(char *multi_user_name, email_acco
        email_event_t *event_data = NULL;
 
        event_data = em_malloc(sizeof(email_event_t));
-
-       if(!event_data) { /*prevent 53095*/
+       if (!event_data) { /*prevent 53095*/
                EM_DEBUG_EXCEPTION("em_malloc failed");
                err = EMAIL_ERROR_OUT_OF_MEMORY;
                goto FINISH_OFF;
@@ -261,7 +266,6 @@ INTERNAL_FUNC int emdaemon_validate_account_and_create(char *multi_user_name, em
        email_event_t *event_data = NULL;
 
        event_data = em_malloc(sizeof(email_event_t));
-
        if(!event_data) { /*prevent 53093*/
                EM_DEBUG_EXCEPTION("em_malloc failed");
                err = EMAIL_ERROR_OUT_OF_MEMORY;
index f433bd0..cea37c3 100755 (executable)
@@ -808,6 +808,7 @@ static int default_alarm_callback(int input_timer_id, void *user_parameter)
 FINISH_OFF:
 
        if (alarm_data) {
+               EM_SAFE_FREE(alarm_data->multi_user_name);
                EM_SAFE_FREE(alarm_data->user_data);
                EM_SAFE_FREE(alarm_data);
        }
index 32d8781..9087caa 100755 (executable)
@@ -299,7 +299,7 @@ INTERNAL_FUNC int emdaemon_add_mail(char *multi_user_name,
        }
 
 #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
-       if ( input_from_eas == 0 && ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
+       if (input_from_eas == 0 && ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
                event_data = em_malloc(sizeof(email_event_t));
                if (event_data == NULL) {
                        EM_DEBUG_EXCEPTION("em_malloc failed");
@@ -671,20 +671,20 @@ INTERNAL_FUNC int emdaemon_delete_mail(char *multi_user_name,
        }
 
        if (from_server == EMAIL_DELETE_LOCAL_AND_SERVER || from_server == EMAIL_DELETE_FROM_SERVER) {
-               if ((p = em_malloc(sizeof(int) * mail_ids_count)) == NULL) {
-                       EM_DEBUG_EXCEPTION("em_malloc for p failed...");
+               if ((event_data = em_malloc(sizeof(email_event_t)) ) == NULL) {
+                       EM_DEBUG_EXCEPTION("em_malloc for event_data failed...");
                        err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
-               memcpy(p, mail_ids, sizeof(int) * mail_ids_count);
-
-               if ((event_data = em_malloc(sizeof(email_event_t)) ) == NULL) {
-                       EM_DEBUG_EXCEPTION("em_malloc for event_data failed...");
+               if ((p = em_malloc(sizeof(int) * mail_ids_count)) == NULL) {
+                       EM_DEBUG_EXCEPTION("em_malloc for p failed...");
                        err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
                }
 
+               memcpy(p, mail_ids, sizeof(int) * mail_ids_count);
+
                event_data->type                   = EMAIL_EVENT_DELETE_MAIL;
                event_data->account_id             = account_id;
                event_data->event_param_data_3     = (char*)p;
@@ -705,7 +705,6 @@ FINISH_OFF:
                                emcore_free_event(event_data);
                                EM_SAFE_FREE(event_data);
                        }
-                       EM_SAFE_FREE(p);
                        goto FINISH_OFF2;
                }
        }
@@ -745,7 +744,6 @@ FINISH_OFF2:
                    emcore_free_event(thread_func_event_data);
                        EM_SAFE_FREE(thread_func_event_data);
                }
-               EM_SAFE_FREE(p2);
        }
 
        if (ref_account) {
@@ -849,7 +847,7 @@ int emdaemon_delete_mail_all(char *multi_user_name, int input_mailbox_id, int in
                        new_activity.dest_mbox          = NULL;
                        new_activity.account_id         = mailbox->account_id;
 
-                       if (! emcore_add_activity(&new_activity, &err))
+                       if (!emcore_add_activity(&new_activity, &err))
                                EM_DEBUG_EXCEPTION(" emcore_add_activity  Failed  - %d ", err);
 
                }
@@ -1045,7 +1043,6 @@ FINISH_OFF:
                        emcore_free_event(event_data);
                        EM_SAFE_FREE(event_data);
                }
-        EM_SAFE_FREE(p);
                goto FINISH_OFF2;
     }
 
@@ -1107,7 +1104,6 @@ FINISH_OFF2:
                        emcore_free_event(thread_func_event_data);
                        EM_SAFE_FREE(thread_func_event_data);
                }
-               EM_SAFE_FREE(p2);
        }
 
 #ifdef __FEATURE_LOCAL_ACTIVITY__
@@ -1224,7 +1220,6 @@ FINISH_OFF:
                        emcore_free_event(event_data);
                        EM_SAFE_FREE(event_data);
                }
-               EM_SAFE_FREE(p);
                goto FINISH_OFF2;
        }
 
@@ -1286,7 +1281,6 @@ FINISH_OFF2:
                        emcore_free_event(thread_func_event_data);
                        EM_SAFE_FREE(thread_func_event_data);
                }
-        EM_SAFE_FREE(p2);
     }
 
 #ifdef __FEATURE_LOCAL_ACTIVITY__
@@ -1344,6 +1338,13 @@ INTERNAL_FUNC int emdaemon_set_flags_field(char *multi_user_name, int account_id
        }
 
        if (onserver && account_tbl->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
+               event_data = em_malloc(sizeof(email_event_t));
+               if (event_data == NULL) {
+                       EM_DEBUG_EXCEPTION("em_malloc failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
+
                mail_id_array = em_malloc(sizeof(int) * num);
                if (mail_id_array == NULL)  {
                        EM_DEBUG_EXCEPTION("em_malloc failed...");
@@ -1353,13 +1354,6 @@ INTERNAL_FUNC int emdaemon_set_flags_field(char *multi_user_name, int account_id
 
                memcpy(mail_id_array, mail_ids, sizeof(int) * num);
 
-               event_data = em_malloc(sizeof(email_event_t));
-               if (event_data == NULL) {
-                       EM_DEBUG_EXCEPTION("em_malloc failed");
-                       err = EMAIL_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
-
                event_data->type               = EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER;
                event_data->account_id         = account_id;
                event_data->event_param_data_1 = NULL;
@@ -1830,7 +1824,6 @@ INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(char *multi_user_name,
 FINISH_OFF:
 
        if (event_insert == false && event_data) {
-               EM_SAFE_FREE(event_data->multi_user_name);
                emcore_free_event(event_data);
                EM_SAFE_FREE(event_data);
        }
index 350f0ad..78cb5dc 100755 (executable)
 extern int g_local_activity_run;
 #endif
 
-INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(char *multi_user_name, 
-                                                                                                       int account_id, 
-                                                                                                       char* mailbox, 
-                                                                                                       int *handle, 
+INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(char *multi_user_name,
+                                                                                                       int account_id,
+                                                                                                       char* mailbox,
+                                                                                                       int *handle,
                                                                                                        int* err_code)
 {
        EM_DEBUG_FUNC_BEGIN("account_id[%d] mailbox[%p] err_code[%p]", account_id, mailbox, err_code);
@@ -212,11 +212,16 @@ INTERNAL_FUNC int emdaemon_add_mailbox(char *multi_user_name, email_mailbox_t* n
        if ( ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC )
                on_server = 0;
 
-       if ( on_server ) {      /* async */
+       if (on_server) {        /* async */
+               event_data = em_malloc(sizeof(email_event_t));
+               if (event_data == NULL) {
+                       EM_DEBUG_EXCEPTION("em_malloc failed");
+                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                       goto FINISH_OFF;
+               }
 
                mailbox = em_malloc(sizeof(email_mailbox_t));
-
-               if(mailbox == NULL) {
+               if (mailbox == NULL) {
                        EM_DEBUG_EXCEPTION("em_malloc failed");
                        err = EMAIL_ERROR_OUT_OF_MEMORY;
                        goto FINISH_OFF;
@@ -236,18 +241,11 @@ INTERNAL_FUNC int emdaemon_add_mailbox(char *multi_user_name, email_mailbox_t* n
                        memcpy(mailbox->eas_data, new_mailbox->eas_data, new_mailbox->eas_data_length);
                }
 
-               event_data = em_malloc(sizeof(email_event_t));
-               if (event_data == NULL) {
-                       EM_DEBUG_EXCEPTION("em_malloc failed");
-                       err = EMAIL_ERROR_OUT_OF_MEMORY;
-                       goto FINISH_OFF;
-               }
-
                event_data->type               = EMAIL_EVENT_CREATE_MAILBOX;
                event_data->account_id         = new_mailbox->account_id;
                event_data->event_param_data_1 = (char*)mailbox;
                event_data->event_param_data_4 = on_server;
-               event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);                       
+               event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
 
                if(!emcore_insert_event(event_data, (int*)handle, &err)) {
                        EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
@@ -265,14 +263,10 @@ INTERNAL_FUNC int emdaemon_add_mailbox(char *multi_user_name, email_mailbox_t* n
 FINISH_OFF:
 
        if (ret == false) {
-               if(event_data) {
+               if (event_data) {
                        emcore_free_event(event_data);
                        EM_SAFE_FREE(event_data);
                }
-               if(mailbox) {
-                       emcore_free_mailbox(mailbox);
-                       EM_SAFE_FREE(mailbox);
-               }
        }
 
        if (ref_account) {
@@ -501,7 +495,7 @@ INTERNAL_FUNC int emdaemon_sync_header(char *multi_user_name, int input_account_
                event_data->type               = EMAIL_EVENT_SYNC_HEADER;
                event_data->account_id         = input_account_id;
                event_data->event_param_data_5 = input_mailbox_id;
-               event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);               
+               event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
 
                /* In case of Mailbox NULL, we need to set arg as EMAIL_SYNC_ALL_MAILBOX */
                if (input_mailbox_id == 0)
@@ -516,7 +510,7 @@ INTERNAL_FUNC int emdaemon_sync_header(char *multi_user_name, int input_account_
                event_data->type               = EMAIL_EVENT_SYNC_HEADER;
                event_data->account_id         = input_account_id;
                event_data->event_param_data_5 = input_mailbox_id;
-               event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);               
+               event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
 
                /* In case of Mailbox NULL, we need to set arg as EMAIL_SYNC_ALL_MAILBOX */
                if (input_mailbox_id == 0)