diff options
author | Yeongil Jang <yg0577.jang@samsung.com> | 2012-09-21 00:18:57 +0900 |
---|---|---|
committer | Yeongil Jang <yg0577.jang@samsung.com> | 2012-09-21 00:18:57 +0900 |
commit | b163391a122d812058dc9ab211b81e60204fffc7 (patch) | |
tree | 0fdf86bf4dc67b14c8913f8fa01d4e6270b1ea39 /email-core/email-core-event.c | |
parent | 4a95e692f2a57a0c273b2ce1f255be9a7ba1d2e3 (diff) | |
download | email-service-b163391a122d812058dc9ab211b81e60204fffc7.tar.gz email-service-b163391a122d812058dc9ab211b81e60204fffc7.tar.bz2 email-service-b163391a122d812058dc9ab211b81e60204fffc7.zip |
2.0_alpha release commitHEADsubmit/master/20120920.1528362.0_alphamaster2.0alpha
Diffstat (limited to 'email-core/email-core-event.c')
-rwxr-xr-x | email-core/email-core-event.c | 1415 |
1 files changed, 823 insertions, 592 deletions
diff --git a/email-core/email-core-event.c b/email-core/email-core-event.c index 90edd95..e3b13f4 100755 --- a/email-core/email-core-event.c +++ b/email-core/email-core-event.c @@ -64,7 +64,7 @@ #define TOTAL_PARTIAL_BODY_EVENTS 100 -static emf_event_partial_body_thd g_partial_body_thd_event_que[TOTAL_PARTIAL_BODY_EVENTS]; +static email_event_partial_body_thd g_partial_body_thd_event_que[TOTAL_PARTIAL_BODY_EVENTS]; static int g_partial_body_thd_next_event_idx = 0; /* Index of Next Event to be processed in the queue*/ static int g_partial_body_thd_loop = 1; /* Variable to make a continuos while loop */ @@ -77,7 +77,7 @@ static pthread_mutex_t _partial_body_thd_event_queue_lock = PTHREAD_MUTEX_INITIA static pthread_cond_t _partial_body_thd_cond = PTHREAD_COND_INITIALIZER; /* Condition variable on which partial body thread is waiting */ thread_t g_partial_body_thd ; /* Determines if thread is created or not. Non Null means thread is created */ -emf_event_partial_body_thd g_partial_body_bulk_dwd_que[BULK_PARTIAL_BODY_DOWNLOAD_COUNT]; +email_event_partial_body_thd g_partial_body_bulk_dwd_que[BULK_PARTIAL_BODY_DOWNLOAD_COUNT]; static int g_partial_body_bulk_dwd_next_event_idx = 0; /* Index of Next Event to be processed in the queue*/ static int g_partial_body_bulk_dwd_queue_empty = true; @@ -85,12 +85,12 @@ static pthread_mutex_t _state_variables_lock; /*[h.gahlaut] - All static function declaration for partial body download thread are done here */ -static int emcore_retrieve_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code); -static int emcore_copy_partial_body_thd_event(emf_event_partial_body_thd *src, emf_event_partial_body_thd *dest, int *error_code); +static int emcore_retrieve_partial_body_thread_event(email_event_partial_body_thd *partial_body_thd_event, int *error_code); +static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src, email_event_partial_body_thd *dest, int *error_code); static void emcore_pb_thd_set_local_activity_continue(int flag); static int emcore_set_pbd_thd_state(int flag); static int emcore_clear_bulk_pbd_que(int *err_code); -int emcore_mail_partial_body_download(emf_event_partial_body_thd *pbd_event, int *error_code); +int emcore_mail_partial_body_download(email_event_partial_body_thd *pbd_event, int *error_code); #endif @@ -111,7 +111,7 @@ INTERNAL_FUNC int g_save_local_activity_run = 0; typedef struct EVENT_CALLBACK_ELEM { - emf_event_callback callback; + email_event_callback callback; void *event_data; struct EVENT_CALLBACK_ELEM *next; } EVENT_CALLBACK_LIST; @@ -120,11 +120,11 @@ static pthread_mutex_t _event_available_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t _event_available_signal = PTHREAD_COND_INITIALIZER; static pthread_mutex_t *_event_queue_lock = NULL; static pthread_mutex_t *_event_callback_table_lock = NULL; -static EVENT_CALLBACK_LIST *_event_callback_table[EMF_ACTION_NUM]; /* array of singly-linked list for event callbacks */ +static EVENT_CALLBACK_LIST *_event_callback_table[EMAIL_ACTION_NUM]; /* array of singly-linked list for event callbacks */ void *thread_func_branch_command(void *arg); -static emf_event_t g_event_que[EVENT_QUEUE_MAX]; +static email_event_t g_event_que[EVENT_QUEUE_MAX]; int send_thread_run = 0; int recv_thread_run = 0; @@ -135,7 +135,7 @@ static pthread_cond_t _send_event_available_signal = PTHREAD_COND_INITIALIZER; static thread_t g_send_srv_thread; static thread_t g_srv_thread; -static emf_event_t g_send_event_que[EVENT_QUEUE_MAX]; +static email_event_t g_send_event_que[EVENT_QUEUE_MAX]; static int g_send_event_que_idx = 1; static int g_send_event_loop = 1; static int g_send_active_que = 0; @@ -172,7 +172,7 @@ static int is_gdk_lock_needed() return false; } -INTERNAL_FUNC int emcore_get_pending_event(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t *status) +INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id, int mail_id, email_event_status_type_t *status) { EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d]", action, account_id, mail_id); @@ -183,116 +183,137 @@ INTERNAL_FUNC int emcore_get_pending_event(emf_action_t action, int account_id, for (i = 1; i < EVENT_QUEUE_MAX; i++) { switch (g_event_que[i].type) { - case EMF_EVENT_SEND_MAIL: - case EMF_EVENT_SEND_MAIL_SAVED: - if (action == EMF_ACTION_SEND_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: + if (action == EMAIL_ACTION_SEND_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMF_EVENT_SYNC_HEADER: - if (action == EMF_ACTION_SYNC_HEADER && account_id == g_event_que[i].account_id) { + case EMAIL_EVENT_SYNC_HEADER: + if (action == EMAIL_ACTION_SYNC_HEADER && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMF_EVENT_SYNC_HEADER_OMA: - if (action == EMF_ACTION_SYNC_HEADER_OMA && account_id == g_event_que[i].account_id) { + case EMAIL_EVENT_SYNC_HEADER_OMA: + if (action == EMAIL_ACTION_SYNC_HEADER_OMA && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMF_EVENT_DOWNLOAD_BODY: - if (action == EMF_ACTION_DOWNLOAD_BODY && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { + case EMAIL_EVENT_DOWNLOAD_BODY: + if (action == EMAIL_ACTION_DOWNLOAD_BODY && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - if (action == EMF_ACTION_SYNC_MAIL_FLAG_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { + case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: + if (action == EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: - if (action == EMF_ACTION_SYNC_FLAGS_FIELD_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { + case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: + if (action == EMAIL_ACTION_SYNC_FLAGS_FIELD_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMF_EVENT_DOWNLOAD_ATTACHMENT: - if (action == EMF_ACTION_DOWNLOAD_ATTACHMENT && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + if (action == EMAIL_ACTION_DOWNLOAD_ATTACHMENT && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMF_EVENT_DELETE_MAIL: - case EMF_EVENT_DELETE_MAIL_ALL: - if (action == EMF_ACTION_DELETE_MAIL && account_id == g_event_que[i].account_id) { + case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL_ALL: + if (action == EMAIL_ACTION_DELETE_MAIL && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMF_EVENT_CREATE_MAILBOX: - if (action == EMF_ACTION_CREATE_MAILBOX && account_id == g_event_que[i].account_id) { + case EMAIL_EVENT_CREATE_MAILBOX: + if (action == EMAIL_ACTION_CREATE_MAILBOX && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMF_EVENT_DELETE_MAILBOX: - if (action == EMF_ACTION_DELETE_MAILBOX && account_id == g_event_que[i].account_id) { + case EMAIL_EVENT_DELETE_MAILBOX: + if (action == EMAIL_ACTION_DELETE_MAILBOX && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMF_EVENT_MOVE_MAIL: - if (action == EMF_ACTION_MOVE_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { + case EMAIL_EVENT_MOVE_MAIL: + if (action == EMAIL_ACTION_MOVE_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMF_EVENT_VALIDATE_ACCOUNT: - if (action == EMF_ACTION_VALIDATE_ACCOUNT && account_id == g_event_que[i].account_id) { + case EMAIL_EVENT_VALIDATE_ACCOUNT: + if (action == EMAIL_ACTION_VALIDATE_ACCOUNT && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: - if (action == EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT && account_id == 0) { + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + if (action == EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT && account_id == 0) { found = true; goto EXIT; } break; - case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT: - if (action == EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT && account_id == 0) { + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + if (action == EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT && account_id == 0) { found = true; goto EXIT; } break; - case EMF_EVENT_UPDATE_MAIL: - if (action == EMF_ACTION_UPDATE_MAIL) { + case EMAIL_EVENT_UPDATE_MAIL: + if (action == EMAIL_ACTION_UPDATE_MAIL) { found = true; goto EXIT; } break; - case EMF_EVENT_SET_MAIL_SLOT_SIZE: - if (action == EMF_ACTION_SET_MAIL_SLOT_SIZE) { + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + if (action == EMAIL_ACTION_SET_MAIL_SLOT_SIZE) { + found = true; + goto EXIT; + } + break; + + case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: + if (action == EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED) { found = true; goto EXIT; } break; + case EMAIL_EVENT_SEARCH_ON_SERVER: + if (action == EMAIL_ACTION_SEARCH_ON_SERVER && account_id == g_event_que[i].account_id) { + found = true; + goto EXIT; + } + break; + + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: + if (action == EMAIL_ACTION_MOVE_MAILBOX && account_id == g_event_que[i].account_id) { + found = true; + goto EXIT; + } + break; + default: break; } @@ -340,7 +361,7 @@ static void _receiving_busy_unref(void) g_receiving_busy_cnt--; } -static void waiting_status_notify(emf_event_t *event_data, int queue_idx) +static void waiting_status_notify(email_event_t *event_data, int queue_idx) { EM_DEBUG_FUNC_BEGIN("event_data[%p], queue_idx[%d]", event_data, queue_idx); @@ -348,76 +369,89 @@ static void waiting_status_notify(emf_event_t *event_data, int queue_idx) int mail_id = event_data->event_param_data_4; /* NOT ALWAYS */ switch (event_data->type) { - case EMF_EVENT_SEND_MAIL: - emcore_execute_event_callback(EMF_ACTION_SEND_MAIL, 0, 0, EMF_SEND_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_SEND_MAIL: + emcore_execute_event_callback(EMAIL_ACTION_SEND_MAIL, 0, 0, EMAIL_SEND_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_SYNC_HEADER: - emcore_execute_event_callback(EMF_ACTION_SYNC_HEADER, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_SYNC_HEADER: + emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_SYNC_HEADER_OMA: - emcore_execute_event_callback(EMF_ACTION_SYNC_HEADER_OMA, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); - break; + case EMAIL_EVENT_SYNC_HEADER_OMA: + emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER_OMA, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); + break; - case EMF_EVENT_DOWNLOAD_BODY: - emcore_execute_event_callback(EMF_ACTION_DOWNLOAD_BODY, 0, 0, EMF_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_DOWNLOAD_BODY: + emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_BODY, 0, 0, EMAIL_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); break; #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ - case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - emcore_execute_event_callback(EMF_ACTION_SYNC_MAIL_FLAG_TO_SERVER, 0, 0, EMF_SYNC_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: + emcore_execute_event_callback(EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER, 0, 0, EMAIL_SYNC_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); break; #endif - case EMF_EVENT_DOWNLOAD_ATTACHMENT: - emcore_execute_event_callback(EMF_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMF_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMAIL_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); + break; + + case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL_ALL: + emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAIL, 0, 0, EMAIL_DELETE_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); + break; + + case EMAIL_EVENT_VALIDATE_ACCOUNT: + emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); + break; + + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_DELETE_MAIL: - case EMF_EVENT_DELETE_MAIL_ALL: - emcore_execute_event_callback(EMF_ACTION_DELETE_MAIL, 0, 0, EMF_DELETE_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_MOVE_MAIL: + emcore_execute_event_callback(EMAIL_ACTION_MOVE_MAIL, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_VALIDATE_ACCOUNT: - emcore_execute_event_callback(EMF_ACTION_VALIDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_CREATE_MAILBOX: + emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT: - emcore_execute_event_callback(EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_MOVE_MAIL: - emcore_execute_event_callback(EMF_ACTION_MOVE_MAIL, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_UPDATE_MAIL: break; - case EMF_EVENT_CREATE_MAILBOX: - emcore_execute_event_callback(EMF_ACTION_CREATE_MAILBOX, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + emcore_execute_event_callback(EMAIL_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMAIL_SET_SLOT_SIZE_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: - emcore_execute_event_callback(EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: + emcore_execute_event_callback(EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED, 0, 0, EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_WAITING, account_id, event_data->event_param_data_4, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_UPDATE_MAIL: + case EMAIL_EVENT_SEARCH_ON_SERVER: + emcore_execute_event_callback(EMAIL_ACTION_SEARCH_ON_SERVER, 0, 0, EMAIL_SYNC_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMF_EVENT_SET_MAIL_SLOT_SIZE: - emcore_execute_event_callback(EMF_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMF_SET_SLOT_SIZE_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE); + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: + /* emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); */ break; + default: break; } EM_DEBUG_FUNC_END(); } -static void fail_status_notify(emf_event_t *event_data, int error) +static void fail_status_notify(email_event_t *event_data, int error) { EM_DEBUG_FUNC_BEGIN(); int account_id, mail_id; if(!event_data) { - EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM"); + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return; } account_id = event_data->account_id; @@ -426,62 +460,78 @@ static void fail_status_notify(emf_event_t *event_data, int error) EM_DEBUG_LOG("account_id[%d], mail_id[%d], error[%d]", account_id, mail_id, error); switch (event_data->type) { - case EMF_EVENT_SEND_MAIL: - /* case EMF_EVENT_SEND_MAIL_SAVED: */ - /* emcore_execute_event_callback(EMF_ACTION_SEND_MAIL, 0, 0, EMF_SEND_FAIL, account_id, mail_id, -1, error); */ - emcore_show_popup(mail_id, EMF_ACTION_SEND_MAIL, error); + case EMAIL_EVENT_SEND_MAIL: + /* case EMAIL_EVENT_SEND_MAIL_SAVED: */ + /* emcore_execute_event_callback(EMAIL_ACTION_SEND_MAIL, 0, 0, EMAIL_SEND_FAIL, account_id, mail_id, -1, error); */ + emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, error); break; - case EMF_EVENT_SYNC_HEADER: - emcore_execute_event_callback(EMF_ACTION_SYNC_HEADER, 0, 0, EMF_LIST_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_SYNC_HEADER, error); + case EMAIL_EVENT_SYNC_HEADER: + emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_SYNC_HEADER, error); break; - case EMF_EVENT_DOWNLOAD_BODY: - emcore_execute_event_callback(EMF_ACTION_DOWNLOAD_BODY, 0, 0, EMF_DOWNLOAD_FAIL, account_id, mail_id, -1, error); - emcore_show_popup(account_id, EMF_ACTION_DOWNLOAD_BODY, error); + case EMAIL_EVENT_DOWNLOAD_BODY: + emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_BODY, 0, 0, EMAIL_DOWNLOAD_FAIL, account_id, mail_id, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_DOWNLOAD_BODY, error); break; - case EMF_EVENT_DOWNLOAD_ATTACHMENT: - emcore_execute_event_callback(EMF_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMF_DOWNLOAD_FAIL, account_id, mail_id, -1, error); - emcore_show_popup(account_id, EMF_ACTION_DOWNLOAD_ATTACHMENT, error); + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMAIL_DOWNLOAD_FAIL, account_id, mail_id, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_DOWNLOAD_ATTACHMENT, error); break; - case EMF_EVENT_DELETE_MAIL: - case EMF_EVENT_DELETE_MAIL_ALL: - emcore_execute_event_callback(EMF_ACTION_DELETE_MAIL, 0, 0, EMF_DELETE_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_DELETE_MAIL, error); + case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL_ALL: + emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAIL, 0, 0, EMAIL_DELETE_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAIL, error); break; - case EMF_EVENT_VALIDATE_ACCOUNT: - emcore_execute_event_callback(EMF_ACTION_VALIDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_VALIDATE_ACCOUNT, error); + case EMAIL_EVENT_VALIDATE_ACCOUNT: + emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_ACCOUNT, error); break; - case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT: - emcore_execute_event_callback(EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT, error); + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, error); break; - case EMF_EVENT_CREATE_MAILBOX: - emcore_execute_event_callback(EMF_ACTION_CREATE_MAILBOX, 0, 0, EMF_LIST_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_CREATE_MAILBOX, error); + case EMAIL_EVENT_CREATE_MAILBOX: + emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_CREATE_MAILBOX, error); break; - case EMF_EVENT_DELETE_MAILBOX: - emcore_execute_event_callback(EMF_ACTION_DELETE_MAILBOX, 0, 0, EMF_LIST_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_DELETE_MAILBOX, error); + + case EMAIL_EVENT_DELETE_MAILBOX: + emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAILBOX, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAILBOX, error); break; - case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: - emcore_execute_event_callback(EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); - emcore_show_popup(account_id, EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, error); + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); + emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, error); break; - case EMF_EVENT_SET_MAIL_SLOT_SIZE: - emcore_execute_event_callback(EMF_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMF_SET_SLOT_SIZE_FAIL, account_id, 0, -1, EMF_ERROR_NONE); + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + emcore_execute_event_callback(EMAIL_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMAIL_SET_SLOT_SIZE_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); break; - - case EMF_EVENT_UPDATE_MAIL: + + case EMAIL_EVENT_SEARCH_ON_SERVER: + emcore_execute_event_callback(EMAIL_ACTION_SEARCH_ON_SERVER, 0, 0, EMAIL_SEARCH_ON_SERVER_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); + emcore_show_user_message(account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error); + break; + + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: + emcore_execute_event_callback(EMAIL_ACTION_MOVE_MAILBOX, 0, 0, EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); + emcore_show_user_message(account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error); + break; + + case EMAIL_EVENT_UPDATE_MAIL: + emcore_execute_event_callback(EMAIL_ACTION_UPDATE_MAIL, 0, 0, EMAIL_UPDATE_MAIL_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); + break; + + case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: + emcore_execute_event_callback(EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED, 0, 0, EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FAIL, account_id, event_data->event_param_data_4, -1, EMAIL_ERROR_NONE); break; default: @@ -497,13 +547,13 @@ static void emcore_initialize_event_callback_table() int i; - for (i = 0; i < EMF_ACTION_NUM; i++) + for (i = 0; i < EMAIL_ACTION_NUM; i++) _event_callback_table[i] = NULL; LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); } -int emcore_register_event_callback(emf_action_t action, emf_event_callback callback, void *event_data) +int emcore_register_event_callback(email_action_t action, email_event_callback callback, void *event_data) { EM_DEBUG_FUNC_BEGIN("action[%d], callback[%p], event_data[%p]", action, callback, event_data); @@ -525,7 +575,7 @@ int emcore_register_event_callback(emf_action_t action, emf_event_callback callb /* not found, so keep going */ - node = malloc(sizeof(EVENT_CALLBACK_LIST)); + node = em_malloc(sizeof(EVENT_CALLBACK_LIST)); if (node == NULL) /* not enough memory */ goto EXIT; @@ -544,7 +594,7 @@ EXIT : return ret; } -int emcore_unregister_event_callback(emf_action_t action, emf_event_callback callback) +int emcore_unregister_event_callback(email_action_t action, email_event_callback callback) { EM_DEBUG_FUNC_BEGIN("action[%d], callback[%p]", action, callback); @@ -580,7 +630,7 @@ int emcore_unregister_event_callback(emf_action_t action, emf_event_callback cal return ret; } -void emcore_execute_event_callback(emf_action_t action, int total, int done, int status, int account_id, int mail_id, int handle, int error) +void emcore_execute_event_callback(email_action_t action, int total, int done, int status, int account_id, int mail_id, int handle, int error) { EM_DEBUG_FUNC_BEGIN("action[%d], total[%d], done[%d], status[%d], account_id[%d], mail_id[%d], handle[%d], error[%d]", action, total, done, status, account_id, mail_id, handle, error); @@ -609,33 +659,33 @@ void emcore_execute_event_callback(emf_action_t action, int total, int done, int } /* insert a event to event queue */ -INTERNAL_FUNC int emcore_insert_event(emf_event_t *event_data, int *handle, int *err_code) +INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("event_data[%p], handle[%p], err_code[%p]", event_data, handle, err_code); if (!event_data) { EM_DEBUG_EXCEPTION("Invalid Parameter"); if (err_code != NULL) - *err_code = EMF_ERROR_INVALID_PARAM; + *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } if (!g_srv_thread) { EM_DEBUG_EXCEPTION("email-service is not ready"); if (err_code != NULL) - *err_code = EMF_ERROR_LOAD_ENGINE_FAILURE; + *err_code = EMAIL_ERROR_LOAD_ENGINE_FAILURE; return false; } int ret = true; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); if (!g_event_que[g_event_que_idx].type) { /* if current buffer has not event, insert event data to current buffer */ EM_DEBUG_LOG("Current buffer has not a event. [%d]", g_event_que_idx); - memcpy(g_event_que+g_event_que_idx, event_data, sizeof(emf_event_t)); - g_event_que[g_event_que_idx].status = EMF_EVENT_STATUS_WAIT; + memcpy(g_event_que+g_event_que_idx, event_data, sizeof(email_event_t)); + g_event_que[g_event_que_idx].status = EMAIL_EVENT_STATUS_WAIT; waiting_status_notify(event_data, g_event_que_idx); if (handle) *handle = g_event_que_idx; @@ -654,8 +704,8 @@ INTERNAL_FUNC int emcore_insert_event(emf_event_t *event_data, int *handle, int if (i < EVENT_QUEUE_MAX) { EM_DEBUG_LOG("I found available buffer. [%d]", g_event_que + j); - memcpy(g_event_que+j, event_data, sizeof(emf_event_t)); - g_event_que[j].status = EMF_EVENT_STATUS_WAIT; + memcpy(g_event_que+j, event_data, sizeof(email_event_t)); + g_event_que[j].status = EMAIL_EVENT_STATUS_WAIT; waiting_status_notify(event_data, j); if (handle) @@ -663,7 +713,7 @@ INTERNAL_FUNC int emcore_insert_event(emf_event_t *event_data, int *handle, int } else { EM_DEBUG_EXCEPTION("event que is full..."); - error = EMF_ERROR_EVENT_QUEUE_FULL; + error = EMAIL_ERROR_EVENT_QUEUE_FULL; ret = false; } } @@ -674,29 +724,32 @@ INTERNAL_FUNC int emcore_insert_event(emf_event_t *event_data, int *handle, int event_data->event_param_data_1 = NULL; /* MUST BE - to prevent double-free */ switch (event_data->type) { - case EMF_EVENT_SEND_MAIL: - case EMF_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: _sending_busy_ref(); break; - case EMF_EVENT_SYNC_HEADER: - case EMF_EVENT_DOWNLOAD_BODY: - case EMF_EVENT_DOWNLOAD_ATTACHMENT: - case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: - case EMF_EVENT_ISSUE_IDLE: - case EMF_EVENT_SYNC_IMAP_MAILBOX: - case EMF_EVENT_VALIDATE_ACCOUNT: - case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT: - case EMF_EVENT_MOVE_MAIL: - case EMF_EVENT_DELETE_MAIL: - case EMF_EVENT_DELETE_MAIL_ALL: - case EMF_EVENT_SYNC_HEADER_OMA: - case EMF_EVENT_CREATE_MAILBOX: - case EMF_EVENT_DELETE_MAILBOX: - case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: - case EMF_EVENT_SET_MAIL_SLOT_SIZE: - case EMF_EVENT_UPDATE_MAIL: + case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: + case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: + case EMAIL_EVENT_ISSUE_IDLE: + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + case EMAIL_EVENT_MOVE_MAIL: + case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL_ALL: + case EMAIL_EVENT_SYNC_HEADER_OMA: + case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_UPDATE_MAIL: + case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: + case EMAIL_EVENT_SEARCH_ON_SERVER: + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: _receiving_busy_ref(); break; default: @@ -729,26 +782,26 @@ INTERNAL_FUNC int emcore_insert_event(emf_event_t *event_data, int *handle, int } /* get a event from event_data queue */ -static int emcore_retrieve_event(emf_event_t *event_data, int *err_code) +static int emcore_retrieve_event(email_event_t *event_data, int *err_code) { EM_DEBUG_FUNC_BEGIN("event_data[%p], err_code[%p]", event_data, err_code); int ret = false; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); /* get a event_data if this queue is not empty */ if (g_event_que[g_event_que_idx].type) { - memcpy(event_data, g_event_que+g_event_que_idx, sizeof(emf_event_t)); + memcpy(event_data, g_event_que+g_event_que_idx, sizeof(email_event_t)); - if (event_data->status != EMF_EVENT_STATUS_WAIT) { /* EMF_EVENT_STATUS_CANCELED */ - memset(g_event_que+g_event_que_idx, 0x00, sizeof(emf_event_t)); + if (event_data->status != EMAIL_EVENT_STATUS_WAIT) { /* EMAIL_EVENT_STATUS_CANCELED */ + memset(g_event_que+g_event_que_idx, 0x00, sizeof(email_event_t)); g_active_que = 0; } else { EM_DEBUG_LINE; - g_event_que[g_event_que_idx].status = EMF_EVENT_STATUS_STARTED; + g_event_que[g_event_que_idx].status = EMAIL_EVENT_STATUS_STARTED; g_active_que = g_event_que_idx; ret = true; } @@ -760,7 +813,7 @@ static int emcore_retrieve_event(emf_event_t *event_data, int *err_code) } else { g_active_que = 0; - error = EMF_ERROR_EVENT_QUEUE_EMPTY; + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; } LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); @@ -780,7 +833,7 @@ static int emcore_event_loop_continue() -INTERNAL_FUNC int emcore_insert_send_event(emf_event_t *event_data, int *handle, int *err_code) +INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_data, int *handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("event_data[%p], handle[%p], err_code[%p]", event_data, handle, err_code); @@ -788,21 +841,21 @@ INTERNAL_FUNC int emcore_insert_send_event(emf_event_t *event_data, int *handle, EM_DEBUG_EXCEPTION("\t event_data[%p], handle[%p]", event_data, handle); if (err_code != NULL) - *err_code = EMF_ERROR_INVALID_PARAM; + *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } int ret = true; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); if (!g_send_event_que[g_send_event_que_idx].type) { /* if current buffer has not event_data, insert event_data data to current buffer */ EM_DEBUG_LOG("Current buffer has not a event_data. [%d]", g_send_event_que_idx); - memcpy(g_send_event_que+g_send_event_que_idx, event_data, sizeof(emf_event_t)); + memcpy(g_send_event_que+g_send_event_que_idx, event_data, sizeof(email_event_t)); - g_send_event_que[g_send_event_que_idx].status = EMF_EVENT_STATUS_WAIT; + g_send_event_que[g_send_event_que_idx].status = EMAIL_EVENT_STATUS_WAIT; if (handle) *handle = g_send_event_que_idx; @@ -822,13 +875,13 @@ INTERNAL_FUNC int emcore_insert_send_event(emf_event_t *event_data, int *handle, if (i < EVENT_QUEUE_MAX) { EM_DEBUG_LOG("I found available buffer. [%d]", j); - memcpy(g_send_event_que+j, event_data, sizeof(emf_event_t)); - g_send_event_que[j].status = EMF_EVENT_STATUS_WAIT; + memcpy(g_send_event_que+j, event_data, sizeof(email_event_t)); + g_send_event_que[j].status = EMAIL_EVENT_STATUS_WAIT; if (handle) *handle = j; } else { EM_DEBUG_EXCEPTION("event_data queue is full..."); - error = EMF_ERROR_EVENT_QUEUE_FULL; + error = EMAIL_ERROR_EVENT_QUEUE_FULL; ret = false; } } @@ -842,7 +895,7 @@ INTERNAL_FUNC int emcore_insert_send_event(emf_event_t *event_data, int *handle, } if (handle) - EM_DEBUG_LOG("emcore_insert_send_event-handle[%d]", *handle); + EM_DEBUG_LOG("emcore_insert_event_for_sending_mails-handle[%d]", *handle); if (err_code != NULL) *err_code = error; @@ -852,24 +905,24 @@ INTERNAL_FUNC int emcore_insert_send_event(emf_event_t *event_data, int *handle, } -static int emcore_retrieve_send_event(emf_event_t *event_data, int *err_code) +static int emcore_retrieve_send_event(email_event_t *event_data, int *err_code) { EM_DEBUG_FUNC_BEGIN(); int ret = false; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); /* get a event_data if this queue is not empty */ if (g_send_event_que[g_send_event_que_idx].type) { - memcpy(event_data, g_send_event_que+g_send_event_que_idx, sizeof(emf_event_t)); + memcpy(event_data, g_send_event_que+g_send_event_que_idx, sizeof(email_event_t)); - if (event_data->status != EMF_EVENT_STATUS_WAIT) { - memset(g_send_event_que+g_send_event_que_idx, 0x00, sizeof(emf_event_t)); + if (event_data->status != EMAIL_EVENT_STATUS_WAIT) { + memset(g_send_event_que+g_send_event_que_idx, 0x00, sizeof(email_event_t)); g_send_active_que = 0; } else { - g_send_event_que[g_send_event_que_idx].status = EMF_EVENT_STATUS_STARTED; + g_send_event_que[g_send_event_que_idx].status = EMAIL_EVENT_STATUS_STARTED; EM_DEBUG_LOG("g_send_event_que_idx[%d]", g_send_event_que_idx); g_send_active_que = g_send_event_que_idx; @@ -884,7 +937,7 @@ static int emcore_retrieve_send_event(emf_event_t *event_data, int *err_code) else { EM_DEBUG_LOG("\t send event_data queue is empty..."); g_send_active_que = 0; - error = EMF_ERROR_EVENT_QUEUE_EMPTY; + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; } LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); @@ -896,12 +949,12 @@ static int emcore_retrieve_send_event(emf_event_t *event_data, int *err_code) } -void* send_event_handler(void *arg) +void* thread_func_branch_command_for_sending_mails(void *arg) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_event_t event_data; - emf_session_t *session = NULL; + int err = EMAIL_ERROR_NONE; + email_event_t event_data; + email_session_t *session = NULL; if (!emstorage_open(&err)) { EM_DEBUG_EXCEPTION("\t emstorage_open falied - %d", err); @@ -949,12 +1002,12 @@ void* send_event_handler(void *arg) EM_DEBUG_LOG(">>>>>>>>>>>>>>Got SEND event_data>>>>>>>>>>>>>>>>"); send_thread_run = 1; g_client_run = 1; - emf_option_t *option = NULL; + email_option_t *option = NULL; if (!emnetwork_check_network_status( &err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - emcore_show_popup(event_data.event_param_data_4, EMF_ACTION_SEND_MAIL, err); + emcore_show_user_message(event_data.event_param_data_4, EMAIL_ACTION_SEND_MAIL, err); if (!emstorage_notify_network_event(NOTI_SEND_FAIL, event_data.account_id, NULL , event_data.event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_SEND_FAIL] Failed >>>> "); goto FINISH_OFF; @@ -962,11 +1015,11 @@ void* send_event_handler(void *arg) switch (event_data.type) { - case EMF_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL: emdevice_set_dimming_on_off(false, NULL); - option = (emf_option_t *)event_data.event_param_data_1; + option = (email_option_t *)event_data.event_param_data_1; - if (!emcore_send_mail(event_data.account_id, event_data.event_param_data_3, event_data.event_param_data_4, option, &err)) + if (!emcore_send_mail(event_data.account_id, event_data.event_param_data_5, event_data.event_param_data_4, option, &err)) EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", err); if (option) @@ -974,10 +1027,10 @@ void* send_event_handler(void *arg) emdevice_set_dimming_on_off(true, NULL); break; - case EMF_EVENT_SEND_MAIL_SAVED: /* send mails to been saved in offline-mode */ + case EMAIL_EVENT_SEND_MAIL_SAVED: /* send mails to been saved in offline-mode */ emdevice_set_dimming_on_off(false, NULL); - emf_option_t *option = (emf_option_t *)event_data.event_param_data_1; + email_option_t *option = (email_option_t *)event_data.event_param_data_1; if (!emcore_send_saved_mail(event_data.account_id, event_data.event_param_data_3, option, &err)) EM_DEBUG_EXCEPTION("emcore_send_saved_mail failed - %d", err); @@ -989,7 +1042,7 @@ void* send_event_handler(void *arg) break; #ifdef __FEATURE_LOCAL_ACTIVITY__ - case EMF_EVENT_LOCAL_ACTIVITY: { + case EMAIL_EVENT_LOCAL_ACTIVITY: { emdevice_set_dimming_on_off(false, NULL); emstorage_activity_tbl_t *local_activity = NULL; int activity_id_count = 0; @@ -1018,9 +1071,9 @@ void* send_event_handler(void *arg) case ACTIVITY_DELETEMAIL_SEND: /* New Activity Type Added for Race Condition and Crash Fix */ { if (!emcore_delete_mail(local_activity[0].account_id, &local_activity[0].mail_id, - EMF_DELETE_FOR_SEND_THREAD, + EMAIL_DELETE_FOR_SEND_THREAD, true, - EMF_DELETED_BY_COMMAND, + EMAIL_DELETED_BY_COMMAND, false, &err)) { EM_DEBUG_LOG("\t emcore_delete_mail failed - %d", err); @@ -1060,7 +1113,7 @@ void* send_event_handler(void *arg) ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); - memset(g_send_event_que+g_send_active_que, 0x00, sizeof(emf_event_t)); + memset(g_send_event_que+g_send_active_que, 0x00, sizeof(email_event_t)); LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); @@ -1078,11 +1131,11 @@ FINISH_OFF: } -int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbox_name, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbox_id, int handle_to_be_published, int *error) { - EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_name [%p], handle_to_be_published [%d], error[%p]", input_account_id, input_mailbox_name, handle_to_be_published, error); + EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d], handle_to_be_published [%d], error[%p]", input_account_id, input_mailbox_id, handle_to_be_published, error); - int err = EMF_ERROR_NONE, sync_type = 0, ret = false; + int err = EMAIL_ERROR_NONE, sync_type = 0, ret = false; int mailbox_count = 0, account_count = 0; int counter, account_index; int unread = 0, total_unread = 0; @@ -1092,51 +1145,53 @@ int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbo #ifndef __FEATURE_KEEP_CONNECTION__ MAILSTREAM *stream = NULL; #endif + char mailbox_id_param_string[10] = {0,}; - if (input_mailbox_name == NULL) - sync_type = EMF_SYNC_ALL_MAILBOX; + if (input_mailbox_id == 0) + sync_type = EMAIL_SYNC_ALL_MAILBOX; else { - if (!emstorage_get_mailbox_by_name(input_account_id, -1, input_mailbox_name, &mailbox_tbl_target, true, &err) || !mailbox_tbl_target) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d]", err); + if (!emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl_target) || !mailbox_tbl_target) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); goto FINISH_OFF; } } + if(mailbox_tbl_target) + SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl_target->mailbox_id); - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, input_mailbox_name, handle_to_be_published, 0)) - EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_DOWNLOAD_START] Failed >>>> "); + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, 0)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [ NOTI_DOWNLOAD_START] Failed >>>> "); if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_name, handle_to_be_published, err)) + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); } else { - if (sync_type != EMF_SYNC_ALL_MAILBOX) { /* Sync only particular mailbox */ + if (sync_type != EMAIL_SYNC_ALL_MAILBOX) { /* Sync only particular mailbox */ - if (!emstorage_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); - - if (!emstorage_get_mailbox_by_mailbox_type(input_account_id, EMF_MAILBOX_TYPE_SPAMBOX, &mailbox_tbl_spam, false, &err)) { - + if ((err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + + if (!emstorage_get_mailbox_by_mailbox_type(input_account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_tbl_spam, false, &err)) { EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); } if (!emcore_sync_header(mailbox_tbl_target, mailbox_tbl_spam, NULL, &uid_list, &unread, &err)) { EM_DEBUG_EXCEPTION("emcore_sync_header failed [%d]", err); - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, mailbox_tbl_target->account_id, mailbox_tbl_target->mailbox_name, handle_to_be_published, err)) + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, mailbox_tbl_target->account_id, mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); } else { EM_DEBUG_LOG("emcore_sync_header succeeded [%d]", err); - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FINISH, mailbox_tbl_target->account_id, mailbox_tbl_target->mailbox_name, handle_to_be_published, 0)) + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FINISH, mailbox_tbl_target->account_id, mailbox_id_param_string, handle_to_be_published, 0)) EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_DOWNLOAD_FINISH] Failed >>>> "); } - total_unread = total_unread + unread; + total_unread += unread; - if (total_unread > 0 && !emstorage_update_sync_status_of_account(input_account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); + if (total_unread > 0 && (err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); if (!emcore_finalize_sync(input_account_id, &err)) EM_DEBUG_EXCEPTION("emcore_finalize_sync failed [%d]", err); @@ -1146,8 +1201,8 @@ int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbo /* Sync of all mailbox */ if (input_account_id == ALL_ACCOUNT) { - if (!emstorage_update_sync_status_of_account(ALL_ACCOUNT, SET_TYPE_SET, SYNC_STATUS_SYNCING, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); + if ((err = emcore_update_sync_status_of_account(ALL_ACCOUNT, SET_TYPE_SET, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); if (!emstorage_get_account_list(&account_count, &account_tbl_array , true, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [ %d ] ", err); @@ -1159,12 +1214,12 @@ int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbo else { EM_DEBUG_LOG("Sync all mailbox of an account[%d].", input_account_id); - if (!emstorage_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); + if ((err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); - if (!emstorage_get_account_by_id(input_account_id, EMF_ACC_GET_OPT_DEFAULT, &account_tbl_array, true, &err)) { + if (!emstorage_get_account_by_id(input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account_tbl_array, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [ %d ] ", err); - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_name, handle_to_be_published, err)) + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); goto FINISH_OFF; } @@ -1172,46 +1227,46 @@ int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbo } for (account_index = 0 ; account_index < account_count; account_index++) { - if (account_tbl_array[account_index].receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC) { + if (account_tbl_array[account_index].incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { EM_DEBUG_LOG("account[%d] is for ActiveSync. Skip ", account_index); continue; } - - if (!emstorage_get_mailbox(account_tbl_array[account_index].account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &mailbox_count, &mailbox_tbl_list, true, &err) || mailbox_count <= 0) { + if (!emstorage_get_mailbox_list(account_tbl_array[account_index].account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &mailbox_count, &mailbox_tbl_list, true, &err) || mailbox_count <= 0) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err); - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, input_mailbox_name, handle_to_be_published, err)) + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, (input_mailbox_id == 0 )? NULL : mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); - goto FINISH_OFF; + + continue; } - EM_DEBUG_LOG("emcore_get_list_to_be_sync returns [%d] mailboxes", mailbox_count); + EM_DEBUG_LOG("emcore_get_mailbox_list_to_be_sync returns [%d] mailboxes", mailbox_count); if(mailbox_tbl_spam) { if (!emstorage_free_mailbox(&mailbox_tbl_spam, 1, &err)) { - EM_DEBUG_EXCEPTION("emstorage_free_mailbox failed [%d]", err); } mailbox_tbl_spam = NULL; } - if (!emstorage_get_mailbox_by_mailbox_type(account_tbl_array[account_index].account_id, EMF_MAILBOX_TYPE_SPAMBOX, &mailbox_tbl_spam, false, &err)) { - + if (!emstorage_get_mailbox_by_mailbox_type(account_tbl_array[account_index].account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_tbl_spam, false, &err)) { EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); } if (mailbox_count > 0) { #ifndef __FEATURE_KEEP_CONNECTION__ - if (account_tbl_array[account_index].receiving_server_type == EMF_SERVER_TYPE_IMAP4) { - if (!emcore_connect_to_remote_mailbox(account_tbl_array[account_index].account_id, mailbox_tbl_list[0].mailbox_name, (void **)&stream, &err)) { + if (account_tbl_array[account_index].incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + memset(mailbox_id_param_string, 0, 10); + SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl_list[0].mailbox_id); + if (!emcore_connect_to_remote_mailbox(account_tbl_array[account_index].account_id, mailbox_tbl_list[0].mailbox_id, (void **)&stream, &err)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); - if (err == EMF_ERROR_LOGIN_FAILURE) - EM_DEBUG_EXCEPTION("EMF_ERROR_LOGIN_FAILURE "); + if (err == EMAIL_ERROR_LOGIN_FAILURE) + EM_DEBUG_EXCEPTION("EMAIL_ERROR_LOGIN_FAILURE "); /* continue; */ - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_tbl_list[0].mailbox_name, handle_to_be_published, err)) + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); - goto FINISH_OFF; + continue; } EM_DEBUG_LOG("emcore_connect_to_remote_mailbox returns [%d] : ", err); } @@ -1221,24 +1276,26 @@ int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbo } for (counter = 0; counter < mailbox_count; counter++) { - if ( mailbox_tbl_list[counter].mailbox_type == EMF_MAILBOX_TYPE_ALL_EMAILS - || mailbox_tbl_list[counter].mailbox_type == EMF_MAILBOX_TYPE_TRASH - /*|| mailbox_tbl_list[counter].mailbox_type == EMF_MAILBOX_TYPE_SPAMBOX */) + if ( mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_ALL_EMAILS + || mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_TRASH + /*|| mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX */) EM_DEBUG_LOG("Skipped for all emails or trash"); - else if ((mailbox_tbl_list[counter].sync_with_server_yn)) { - EM_DEBUG_LOG("..........syncing %s mailbox......", mailbox_tbl_list[counter].mailbox_name); + else if (!mailbox_tbl_list[counter].local_yn) { + EM_DEBUG_LOG("..........syncing %s mailbox( mailbox_id = %d)......", mailbox_tbl_list[counter].mailbox_name, mailbox_tbl_list[counter].mailbox_id); #ifdef __FEATURE_KEEP_CONNECTION__ if (!emcore_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, NULL, &uid_list, &unread, &err)) { #else /* __FEATURE_KEEP_CONNECTION__ */ if (!emcore_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, (void *)stream, &uid_list, &unread, &err)) { #endif /* __FEATURE_KEEP_CONNECTION__ */ - EM_DEBUG_EXCEPTION("emcore_sync_header for %s failed [%d]", mailbox_tbl_list[counter].mailbox_name, err); + EM_DEBUG_EXCEPTION("emcore_sync_header for %s(mailbox_id = %d) failed [%d]", mailbox_tbl_list[counter].mailbox_name, mailbox_tbl_list[counter].mailbox_id, err); #ifndef __FEATURE_KEEP_CONNECTION__ - if (err == EMF_ERROR_CONNECTION_BROKEN || err == EMF_ERROR_NO_SUCH_HOST || err == EMF_ERROR_SOCKET_FAILURE) + if (err == EMAIL_ERROR_CONNECTION_BROKEN || err == EMAIL_ERROR_NO_SUCH_HOST || err == EMAIL_ERROR_SOCKET_FAILURE) stream = NULL; /* Don't retry to connect for broken connection. It might cause crash. */ #endif /* __FEATURE_KEEP_CONNECTION__ */ - if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_tbl_list[counter].mailbox_name, handle_to_be_published, err)) + memset(mailbox_id_param_string, 0, 10); + SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl_list[counter].mailbox_id); + if (!emstorage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); break; @@ -1248,11 +1305,11 @@ int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbo } EM_DEBUG_LOG("Sync for account_id(%d) is completed....!", account_tbl_array[account_index].account_id); - if ((err == EMF_ERROR_NONE) && !emstorage_notify_network_event(NOTI_DOWNLOAD_FINISH, account_tbl_array[account_index].account_id, NULL, handle_to_be_published, 0)) + if ((err == EMAIL_ERROR_NONE) && !emstorage_notify_network_event(NOTI_DOWNLOAD_FINISH, account_tbl_array[account_index].account_id, NULL, handle_to_be_published, 0)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_DOWNLOAD_FINISH] Failed >>>> "); - if ((total_unread || unread) && !emstorage_update_sync_status_of_account(account_tbl_array[account_index].account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS, true, &err)) - EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); + if ((total_unread > 0) && (err = emcore_update_sync_status_of_account(account_tbl_array[account_index].account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); if (!emcore_finalize_sync(account_tbl_array[account_index].account_id, &err)) EM_DEBUG_EXCEPTION("emcore_finalize_sync failed [%d]", err); @@ -1292,18 +1349,18 @@ FINISH_OFF: return ret; } -int event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emf_account_t *account, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *account, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN("account [%p]", account); int err, ret = false; if(!account) { - EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM"); - err = EMF_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - EM_DEBUG_LOG("receiving_server_addr : %s", account->receiving_server_addr); + EM_DEBUG_LOG("incoming_server_address : %s", account->incoming_server_address); if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -1313,11 +1370,11 @@ int event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emf_account_t *account, goto FINISH_OFF; } else { - EM_DEBUG_LOG("receiving_server_addr : %s", account->receiving_server_addr); + EM_DEBUG_LOG("incoming_server_address : %s", account->incoming_server_address); if (!emcore_validate_account_with_account_info(account, &err)) { EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info failed err : %d", err); - if (err == EMF_ERROR_CANCELLED) { + if (err == EMAIL_ERROR_CANCELLED) { EM_DEBUG_EXCEPTION(" notify : NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL "); if (!emstorage_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL, account->account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL] Failed"); @@ -1334,11 +1391,11 @@ int event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emf_account_t *account, emcore_refresh_account_reference(); - if ((EMF_SERVER_TYPE_IMAP4 == account->receiving_server_type)) { + if ((EMAIL_SERVER_TYPE_IMAP4 == account->incoming_server_type)) { if (!emcore_sync_mailbox_list(account->account_id, "", &err)) { - EM_DEBUG_EXCEPTION("emcore_get_list_to_be_sync falied [%d]", err); + EM_DEBUG_EXCEPTION("emcore_get_mailbox_list_to_be_sync falied [%d]", err); /* delete account whose mailbox couldn't be obtained from server */ - emcore_delete_account_(account->account_id, NULL); + emcore_delete_account(account->account_id, NULL); goto FINISH_OFF; } @@ -1354,7 +1411,7 @@ int event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emf_account_t *account, FINISH_OFF: - if (ret == false && err != EMF_ERROR_CANCELLED) { + if (ret == false && err != EMAIL_ERROR_CANCELLED) { if (!emstorage_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, account->account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } @@ -1365,7 +1422,7 @@ FINISH_OFF: return ret; } -int event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, emf_account_t *new_account_info, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, email_account_t *new_account_info, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN("account_id [%d], new_account_info [%p]", account_id, new_account_info); int err, ret = false; @@ -1373,7 +1430,7 @@ int event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, emf_acco if (!new_account_info) { EM_DEBUG_EXCEPTION("Invalid Parameter"); - err = EMF_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -1385,14 +1442,14 @@ int event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, emf_acco goto FINISH_OFF; } else { - EM_DEBUG_LOG("receiving_server_addr : %s", new_account_info->receiving_server_addr); + EM_DEBUG_LOG("incoming_server_address: (%s)", new_account_info->incoming_server_address); if (!emcore_validate_account_with_account_info(new_account_info, &err)) { - EM_DEBUG_EXCEPTION("\t emcore_validate_account_with_account_info failed err : %d", err); - if (err == EMF_ERROR_CANCELLED) { + EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info() failed err : %d", err); + if (err == EMAIL_ERROR_CANCELLED) { EM_DEBUG_EXCEPTION(" notify : NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL "); if (!emstorage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL, new_account_info->account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL] Failed"); + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL] Failed"); goto FINISH_OFF; } else { @@ -1417,7 +1474,7 @@ int event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, emf_acco emcore_refresh_account_reference(); } - EM_DEBUG_EXCEPTION("validating and updating an account are succeeded for account id [%d], err [%d]", new_account_info->account_id, err); + EM_DEBUG_LOG("validating and updating an account are succeeded for account id [%d], err [%d]", new_account_info->account_id, err); if (!emstorage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH, new_account_info->account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH] Success"); } @@ -1431,7 +1488,7 @@ FINISH_OFF: if (new_account_tbl) emstorage_free_account(&new_account_tbl, 1, NULL); - if (ret == false && err != EMF_ERROR_CANCELLED) { + if (ret == false && err != EMAIL_ERROR_CANCELLED) { if (!emstorage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, new_account_info->account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } @@ -1443,24 +1500,44 @@ FINISH_OFF: return ret; } -int event_handler_EMF_EVENT_SET_MAIL_SLOT_SIZE(int account_id, char *mailbox_name, int new_slot_size, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_SET_MAIL_SLOT_SIZE(int account_id, int mailbox_id, int new_slot_size, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN(); - emcore_set_mail_slot_size(account_id, mailbox_name, new_slot_size, error); + emcore_set_mail_slot_size(account_id, mailbox_id, new_slot_size, error); EM_DEBUG_FUNC_END(); return true; } +static int event_handler_EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED(int input_account_id, int input_mailbox_id) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d]", input_account_id, input_mailbox_id); + int err = EMAIL_ERROR_NONE; + + if ( (err = emcore_expunge_mails_deleted_flagged_from_remote_server(input_account_id, input_mailbox_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_expunge_mails_deleted_flagged_from_remote_server failed [%d]", err); + goto FINISH_OFF; + } + + if ( (err = emcore_expunge_mails_deleted_flagged_from_local_storage(input_mailbox_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_expunge_mails_deleted_flagged_from_local_storage failed [%d]", err); + goto FINISH_OFF; + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} #ifdef __FEATURE_LOCAL_ACTIVITY__ -int event_handler_EMF_EVENT_LOCAL_ACTIVITY(int account_id, int *error) +int event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(int account_id, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_mailbox_t mailbox; + int err = EMAIL_ERROR_NONE; + email_mailbox_t mailbox; emstorage_activity_tbl_t *local_activity = NULL; int activity_id_count = 0; int activity_chunk_count = 0; @@ -1515,8 +1592,8 @@ int event_handler_EMF_EVENT_LOCAL_ACTIVITY(int account_id, int *error) if (!emcore_delete_mail(local_activity[k-1].account_id, mail_id_list, j, - EMF_DELETE_LOCAL_AND_SERVER, - EMF_DELETED_BY_COMMAND, + EMAIL_DELETE_LOCAL_AND_SERVER, + EMAIL_DELETED_BY_COMMAND, false, &err)) EM_DEBUG_LOG("\t emcore_delete_mail failed - %d", err); @@ -1577,16 +1654,15 @@ int event_handler_EMF_EVENT_LOCAL_ACTIVITY(int account_id, int *error) } #endif /* __FEATURE_LOCAL_ACTIVITY__ */ -int event_handler_EMF_EVENT_DOWNLOAD_BODY(int account_id, char *mailbox_name, int mail_id, int option, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_DOWNLOAD_BODY(int account_id, int mail_id, int option, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_mailbox_t mailbox; + int err = EMAIL_ERROR_NONE; + email_mailbox_t mailbox; memset(&mailbox, 0x00, sizeof(mailbox)); mailbox.account_id = account_id; - mailbox.name = mailbox_name; if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -1612,30 +1688,26 @@ int event_handler_EMF_EVENT_DOWNLOAD_BODY(int account_id, char *mailbox_name, in return true; } -int event_handler_EMF_EVENT_DOWNLOAD_ATTACHMENT(int account_id, char *mailbox_name, int mail_id, char *attachment_no, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_DOWNLOAD_ATTACHMENT(int account_id, int mail_id, int attachment_no, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_mailbox_t mailbox; + int err = EMAIL_ERROR_NONE; - EM_DEBUG_LOG("attachment_no is %d", atoi(attachment_no)); + EM_DEBUG_LOG("attachment_no is %d", attachment_no); if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - emstorage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, atoi(attachment_no), err); + emstorage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, attachment_no, err); } else { - memset(&mailbox, 0x00, sizeof(mailbox)); - mailbox.account_id = account_id; - mailbox.name = mailbox_name; - + #ifdef __ATTACHMENT_OPTI__ - if (!emcore_download_attachment_bulk(mailbox.account_id, mail_id, (char *)attachment_no, &err)) - EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed - %d", err); + if (!emcore_download_attachment_bulk(account_id, mail_id, attachment_no, &err)) + EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed [%d]", err); #else - if (!emcore_download_attachment(mailbox.account_id, mail_id, (char *)attachment_no, &err)) - EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed - %d", err); + if (!emcore_download_attachment(account_id, mail_id, attachment_no, &err)) + EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed [%d]", err); #endif } @@ -1646,11 +1718,11 @@ int event_handler_EMF_EVENT_DOWNLOAD_ATTACHMENT(int account_id, char *mailbox_na return true; } -int event_handler_EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER(int mail_ids[], int num, emf_flags_field_type field_type, int value, int *error) +int event_handler_EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER(int mail_ids[], int num, email_flags_field_type field_type, int value, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("dnet_init failed [%d]", err); @@ -1664,11 +1736,11 @@ int event_handler_EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER(int mail_ids[], int num, return true; } -int event_handler_EMF_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -1681,7 +1753,7 @@ int event_handler_EMF_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_pu if (!emcore_validate_account(account_id, &err)) { EM_DEBUG_EXCEPTION("emcore_validate_account failed account id : %d err : %d", account_id, err); - if (err == EMF_ERROR_CANCELLED) { + if (err == EMAIL_ERROR_CANCELLED) { EM_DEBUG_EXCEPTION("notify : NOTI_VALIDATE_ACCOUNT_CANCEL "); if (!emstorage_notify_network_event(NOTI_VALIDATE_ACCOUNT_CANCEL, account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_CANCEL] Failed >>>> "); @@ -1692,17 +1764,16 @@ int event_handler_EMF_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_pu } } else { - emf_account_t *account_ref; + email_account_t *account_ref; account_ref = emcore_get_account_reference(account_id); if (account_ref) { - EM_DEBUG_LOG("account_ref->receiving_server_type[%d]", account_ref->receiving_server_type); - EM_DEBUG_LOG("account_ref->preset_account[%d]", account_ref->preset_account); - if ((EMF_SERVER_TYPE_IMAP4 == account_ref->receiving_server_type) && (account_ref->preset_account)) { + EM_DEBUG_LOG("account_ref->incoming_server_type[%d]", account_ref->incoming_server_type); + if ( EMAIL_SERVER_TYPE_IMAP4 == account_ref->incoming_server_type ) { if (!emcore_check_thread_status()) - err = EMF_ERROR_CANCELLED; + err = EMAIL_ERROR_CANCELLED; else if (!emcore_sync_mailbox_list(account_id, "", &err)) - EM_DEBUG_EXCEPTION("\t emcore_get_list_to_be_sync falied - %d", err); + EM_DEBUG_EXCEPTION("\t emcore_get_mailbox_list_to_be_sync falied - %d", err); } if (err > 0) { @@ -1721,61 +1792,57 @@ int event_handler_EMF_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_pu return true; } -int event_handler_EMF_EVENT_UPDATE_MAIL(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_from_eas, int handle_to_be_published) +int event_handler_EMAIL_EVENT_UPDATE_MAIL(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas, int handle_to_be_published) { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], input_meeting_request[%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas); - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; - if ( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMF_ERROR_NONE) + if ( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_update_mail failed [%d]", err); if(input_mail_data) - emcore_free_mail_data(&input_mail_data, 1, NULL); + emcore_free_mail_data_list(&input_mail_data, 1); if(input_attachment_data_list) emcore_free_attachment_data(&input_attachment_data_list, input_attachment_count, NULL); if(input_meeting_request) - emstorage_free_meeting_request(&input_meeting_request, 1, NULL); + emstorage_free_meeting_request(input_meeting_request); EM_DEBUG_FUNC_END("err [%d", err); return err; } -int event_handler_EMF_EVENT_MOVE_MAIL(int account_id, char *srt_mailbox_name, int *mail_ids, int mail_id_count, char *dest_mailbox_name, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_MOVE_MAIL(int account_id, int *mail_ids, int mail_id_count, int dest_mailbox_id, int src_mailbox_id, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE, ret = false; - emf_mailbox_t dest_mailbox; - emf_account_t *account_ref = NULL; + int err = EMAIL_ERROR_NONE, ret = false; + email_account_t *account_ref = NULL; if (!(account_ref = emcore_get_account_reference(account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); - err = EMF_ERROR_INVALID_ACCOUNT; + err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - memset(&dest_mailbox, 0, sizeof(emf_mailbox_t)); - dest_mailbox.name = dest_mailbox_name; - - /* Remove mail local */ + /* Move mail local */ /* - if (!emcore_mail_move(mail_ids, mail_id_count, dest_mailbox.name, EMF_MOVED_BY_COMMAND, 0, &err)) { + if (!emcore_mail_move(mail_ids, mail_id_count, dest_mailbox.mailbox_name, EMAIL_MOVED_BY_COMMAND, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_mail_move failed [%d]", err); goto FINISH_OFF; } */ - if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4) { - /* Remove mail on server */ + if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + /* Move mail on server */ if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); else { #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ - if (!emcore_move_mail_on_server_ex(account_id , srt_mailbox_name, mail_ids, mail_id_count, dest_mailbox_name, &err)) + if (!emcore_move_mail_on_server_ex(account_id , src_mailbox_id, mail_ids, mail_id_count, dest_mailbox_id, &err)) EM_DEBUG_EXCEPTION("emcore_move_mail_on_server_ex failed - %d", err); #else - if (!emcore_move_mail_on_server(account_id , srt_mailbox_name, mail_ids, mail_id_count, dest_mailbox_name, &err)) + if (!emcore_move_mail_on_server(account_id , src_mailbox_id, mail_ids, mail_id_count, dest_mailbox_id, &err)) EM_DEBUG_EXCEPTION("\t emcore_move_mail_on_server failed - %d", err); #endif } @@ -1791,20 +1858,15 @@ FINISH_OFF: return ret; } -int event_handler_EMF_EVENT_DELETE_MAILBOX(int account_id, char *mailbox_name, int on_server, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_DELETE_MAILBOX(int mailbox_id, int on_server, int handle_to_be_published, int *error) { - EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_mailbox_t mailbox; - - memset(&mailbox, 0x00, sizeof(mailbox)); - mailbox.account_id = account_id; - mailbox.name = mailbox_name; + EM_DEBUG_FUNC_BEGIN("mailbox_id [%d], on_server [%d], handle_to_be_published [%d], error [%p]", mailbox_id, on_server, handle_to_be_published, error); + int err = EMAIL_ERROR_NONE; if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); else { - if (!emcore_delete_mailbox(&mailbox, on_server, &err)) + if (!emcore_delete_mailbox(mailbox_id, on_server, &err)) EM_DEBUG_LOG("emcore_delete failed - %d", err); } @@ -1815,16 +1877,16 @@ int event_handler_EMF_EVENT_DELETE_MAILBOX(int account_id, char *mailbox_name, i return true; } -int event_handler_EMF_EVENT_CREATE_MAILBOX(int account_id, char *mailbox_name, char *mailbox_alias, int mailbox_type, int on_server, int handle_to_be_published, int *error) +int event_handler_EMAIL_EVENT_CREATE_MAILBOX(int account_id, char *mailbox_name, char *mailbox_alias, int mailbox_type, int on_server, int handle_to_be_published, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_mailbox_t mailbox; + int err = EMAIL_ERROR_NONE; + email_mailbox_t mailbox; memset(&mailbox, 0x00, sizeof(mailbox)); mailbox.account_id = account_id; - mailbox.name = mailbox_name; + mailbox.mailbox_name = mailbox_name; mailbox.alias = mailbox_alias; mailbox.mailbox_type = mailbox_type; @@ -1844,11 +1906,11 @@ int event_handler_EMF_EVENT_CREATE_MAILBOX(int account_id, char *mailbox_name, c return true; } -int event_handler_EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) +int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) { EM_DEBUG_FUNC_BEGIN("mail_id [%d], error [%p]", mail_id, error); - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -1879,17 +1941,13 @@ int event_handler_EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) return true; } -int event_handler_EMF_EVENT_DELETE_MAIL_ALL(int account_id, char *mailbox_name, int with_server, int *error) +int event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(int input_mailbox_id, int input_from_server, int *error) { - EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], with_server [%d], error [%p]", account_id, mailbox_name, with_server, error); - int err = EMF_ERROR_NONE; - emf_mailbox_t temp_mailbox = { 0 }; + EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_from_server [%d], error [%p]", input_mailbox_id, input_from_server, error); + int err = EMAIL_ERROR_NONE; - temp_mailbox.account_id = account_id; - temp_mailbox.name = mailbox_name; - - if (!emcore_delete_mail_all(&temp_mailbox, with_server, &err)) - EM_DEBUG_EXCEPTION("emcore_delete_mail_all failed [%d]", err); + if (!emcore_delete_all_mails_of_mailbox(input_mailbox_id, input_from_server, &err)) + EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); if (error) *error = err; @@ -1898,32 +1956,22 @@ int event_handler_EMF_EVENT_DELETE_MAIL_ALL(int account_id, char *mailbox_name, return true; } -int event_handler_EMF_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, char *mailbox_name, int *error) +int event_handler_EMAIL_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, int *error) { EM_DEBUG_FUNC_BEGIN(); - int mail_id = 0, err = EMF_ERROR_NONE, ret = false; - emf_account_t *account_ref = NULL; + int err = EMAIL_ERROR_NONE; + int ret = false; + email_account_t *account_ref = NULL; if (!(account_ref = emcore_get_account_reference(account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); - err = EMF_ERROR_INVALID_ACCOUNT; + err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4) { - if (!emnetwork_check_network_status(&err)) { - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - - if (!emstorage_notify_network_event(NOTI_MAIL_DELETE_ON_SERVER_FAIL, account_id, mailbox_name, mail_id, err)) - EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [NOTI_MAIL_DELETE_ON_SERVER_FAIL] Failed"); - - } - else if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, EMF_DELETE_LOCAL_AND_SERVER, EMF_DELETED_BY_COMMAND, false, &err)) { - EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err); - - if (!emstorage_notify_network_event(NOTI_MAIL_DELETE_ON_SERVER_FAIL, account_id, mailbox_name, mail_id, err)) - EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_MAIL_DELETE_ON_SERVER_FAIL] Failed"); - } + if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, EMAIL_DELETE_FROM_SERVER, EMAIL_DELETED_BY_COMMAND, false, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err); + goto FINISH_OFF; } ret = true; @@ -1936,10 +1984,10 @@ FINISH_OFF: return ret; } -int event_hanlder_EMF_EVENT_SYNC_HEADER_OMA(int account_id, char *maibox_name, int *error) +int event_hanlder_EMAIL_EVENT_SYNC_HEADER_OMA(int account_id, char *maibox_name, int *error) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -1959,13 +2007,161 @@ int event_hanlder_EMF_EVENT_SYNC_HEADER_OMA(int account_id, char *maibox_name, i return true; } +int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, char *criteria, int handle_to_be_published, int *error) +{ + EM_DEBUG_FUNC_BEGIN("account_id : [%d], mailbox_id : [%d], criteria : [%s]", account_id, mailbox_id, criteria); + + int err = EMAIL_ERROR_NONE; + int i = 0; + int mail_id = 0; + int thread_id = 0; + char temp_uid_string[20] = {0,}; + + emcore_uid_list uid_elem; + emstorage_mailbox_tbl_t *search_mailbox = NULL; + emstorage_mail_tbl_t *new_mail_tbl_data = NULL; + + MAILSTREAM *stream = NULL; + MESSAGECACHE *mail_cache_element = NULL; + ENVELOPE *env = NULL; + emstorage_mailbox_tbl_t* local_mailbox = NULL; + char mailbox_id_param_string[10] = {0,}; + + if (account_id < 0 || mailbox_id == 0) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if ( (err = emstorage_get_mailbox_by_id(mailbox_id, &local_mailbox)) != EMAIL_ERROR_NONE || !local_mailbox) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); + goto FINISH_OFF; + } + + SNPRINTF(mailbox_id_param_string, 10, "%d", local_mailbox->mailbox_id); + + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_START, account_id, mailbox_id_param_string, handle_to_be_published, 0)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_START] failed >>>>"); + + if (!emnetwork_check_network_status(&err)) { + EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, 0, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed"); + goto FINISH_OFF; + } + + if (!emcore_connect_to_remote_mailbox(account_id, mailbox_id, (void **)&stream, &err)) { + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed"); + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); + goto FINISH_OFF; + } + + if (!mail_search_full(stream, NIL, mail_criteria(criteria), SE_FREE)) { + EM_DEBUG_EXCEPTION("mail_search failed"); + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); + goto FINISH_OFF; + } + + for (i = 1; i <= stream->nmsgs; ++i) { + mail_cache_element = mail_elt(stream, i); + if (mail_cache_element->searched) { + env = mail_fetchstructure_full(stream, i, NULL, FT_PEEK); + + memset(&uid_elem, 0x00, sizeof(uid_elem)); + + uid_elem.msgno = mail_cache_element->msgno; + SNPRINTF(temp_uid_string, 20, "%4lu", mail_cache_element->private.uid); + uid_elem.uid = temp_uid_string; + uid_elem.flag.seen = mail_cache_element->seen; + + if (!emcore_make_mail_tbl_data_from_envelope(stream, env, &uid_elem, &new_mail_tbl_data, &err) || !new_mail_tbl_data) { + EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err); + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); + goto FINISH_OFF; + } + + if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &search_mailbox, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); + goto FINISH_OFF; + } + + if ((err = emcore_add_mail_to_mailbox(search_mailbox, new_mail_tbl_data, &mail_id, &thread_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox failed [%d]", err); + if (!emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); + goto FINISH_OFF; + } + memset(mailbox_id_param_string, 0, 10); + SNPRINTF(mailbox_id_param_string, 10, "%d", search_mailbox->mailbox_id); + if (!emstorage_notify_storage_event(NOTI_MAIL_ADD, account_id, mail_id, mailbox_id_param_string, thread_id)) { + EM_DEBUG_EXCEPTION("emstorage_notify_storage_event [NOTI_MAIL_ADD] failed"); + } + + if (new_mail_tbl_data) { + emstorage_free_mail(&new_mail_tbl_data, 1, NULL); + new_mail_tbl_data = NULL; + } + } + } + + if (err == EMAIL_ERROR_NONE && !emstorage_notify_network_event(NOTI_SEARCH_ON_SERVER_FINISH, account_id, NULL, handle_to_be_published, 0)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event[NOTI_SEARCH_ON_SERVER_FINISH] Failed >>>>>"); + +FINISH_OFF: + + if (search_mailbox != NULL) + emstorage_free_mailbox(&search_mailbox, 1, NULL); + + if (new_mail_tbl_data) + emstorage_free_mail(&new_mail_tbl_data, 1, NULL); + + if (local_mailbox) + emstorage_free_mailbox(&local_mailbox, 1, NULL); + + if (error) + *error = err; + + EM_DEBUG_FUNC_END(); + return true; +} + +static int event_handler_EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER(int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, int handle_to_be_published) +{ + EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d], input_old_mailbox_path %s], input_new_mailbox_alias [%s], handle_to_be_published [%d]", input_account_id, input_mailbox_id, input_old_mailbox_path, input_new_mailbox_path, handle_to_be_published); + int err = EMAIL_ERROR_NONE; + + if ((err = emcore_move_mailbox_on_imap_server(input_account_id, input_old_mailbox_path, input_new_mailbox_path)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_move_mailbox_on_imap_server failed [%d]", err); + goto FINISH_OFF; + } + + if (err == EMAIL_ERROR_NONE) { + if(!emstorage_notify_network_event(NOTI_RENAME_MAILBOX_FINISH, input_mailbox_id, input_new_mailbox_path, handle_to_be_published, 0)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event[NOTI_RENAME_MAILBOX_FINISH] failed"); + } + else if (!emstorage_notify_network_event(NOTI_RENAME_MAILBOX_FAIL, input_mailbox_id, input_new_mailbox_path, handle_to_be_published, 0)) + EM_DEBUG_EXCEPTION("emstorage_notify_network_event[NOTI_RENAME_MAILBOX_FAIL] failed"); + +FINISH_OFF: + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + void* thread_func_branch_command(void *arg) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE, is_storage_full = false, noti_id = 0; - emf_event_t event_data; - emf_session_t *session = NULL; + int err = EMAIL_ERROR_NONE; + int is_storage_full = false; + int noti_id = 0; + email_event_t event_data; + email_session_t *session = NULL; + emstorage_account_tbl_t *account_tbl = NULL; int handle_to_be_published = 0; if (!emstorage_open(&err)) { @@ -2043,19 +2239,19 @@ void* thread_func_branch_command(void *arg) /* Handling storage full */ is_storage_full = false; - if (event_data.type == EMF_EVENT_SYNC_HEADER || event_data.type == EMF_EVENT_SYNC_HEADER_OMA || - event_data.type == EMF_EVENT_DOWNLOAD_BODY || event_data.type == EMF_EVENT_DOWNLOAD_ATTACHMENT) { + if (event_data.type == EMAIL_EVENT_SYNC_HEADER || event_data.type == EMAIL_EVENT_SYNC_HEADER_OMA || + event_data.type == EMAIL_EVENT_DOWNLOAD_BODY || event_data.type == EMAIL_EVENT_DOWNLOAD_ATTACHMENT) { if (emcore_is_storage_full(&err) == true) { EM_DEBUG_EXCEPTION("Storage is full"); switch (event_data.type) { - case EMF_EVENT_SYNC_HEADER: - case EMF_EVENT_SYNC_HEADER_OMA: + case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_SYNC_HEADER_OMA: noti_id = NOTI_DOWNLOAD_FAIL; break; - case EMF_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_BODY: noti_id = NOTI_DOWNLOAD_BODY_FAIL; break; - case EMF_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: noti_id = NOTI_DOWNLOAD_ATTACH_FAIL; break; default: @@ -2070,143 +2266,176 @@ void* thread_func_branch_command(void *arg) emdevice_set_dimming_on_off(false, NULL); - switch (event_data.type) { - case EMF_EVENT_SYNC_IMAP_MAILBOX: /* get imap mailbox list */ - if (!emnetwork_check_network_status(&err)) - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - else { - if (!emcore_sync_mailbox_list(event_data.account_id, event_data.event_param_data_3, &err)) - EM_DEBUG_EXCEPTION("emcore_sync_mailbox_list failed [%d]", err); - } - EM_SAFE_FREE(event_data.event_param_data_3); - break; - - case EMF_EVENT_SYNC_HEADER: /* synchronize mail header */ - if (is_storage_full == false) - event_handler_EMF_EVENT_SYNC_HEADER(event_data.account_id, event_data.event_param_data_1, handle_to_be_published, &err); - EM_SAFE_FREE(event_data.event_param_data_1); - break; + if (event_data.account_id > 0) { + if (!emstorage_get_account_by_id(event_data.account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account_tbl, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_by_id [%d]", err); + } + } - case EMF_EVENT_SYNC_HEADER_OMA: /* synchronize mail header for OMA */ - if (is_storage_full == false) - event_hanlder_EMF_EVENT_SYNC_HEADER_OMA(event_data.account_id, event_data.event_param_data_1, &err); - EM_SAFE_FREE(event_data.event_param_data_1); - break; - - case EMF_EVENT_DOWNLOAD_BODY: /* download mail body */ - if (is_storage_full == false) - event_handler_EMF_EVENT_DOWNLOAD_BODY(event_data.account_id, event_data.event_param_data_1, (int)event_data.event_param_data_4, (int)event_data.event_param_data_3, handle_to_be_published, &err); - event_data.event_param_data_3 = NULL; /* MUST BE */ - EM_SAFE_FREE(event_data.event_param_data_1); - break; - - case EMF_EVENT_DOWNLOAD_ATTACHMENT: /* download attachment */ - if (is_storage_full == false) - event_handler_EMF_EVENT_DOWNLOAD_ATTACHMENT(event_data.account_id, event_data.event_param_data_1, (int)event_data.event_param_data_4, event_data.event_param_data_3, handle_to_be_published, &err); - EM_SAFE_FREE(event_data.event_param_data_3); - break; + if (account_tbl) + EM_DEBUG_LOG("account_id : [%d], sync_disabled : [%d]", event_data.account_id, account_tbl->sync_disabled); + + if (!account_tbl || account_tbl->sync_disabled == 0) { + switch (event_data.type) { + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: /* get imap mailbox list */ + if (!emnetwork_check_network_status(&err)) + EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); + else { + if (!emcore_sync_mailbox_list(event_data.account_id, event_data.event_param_data_3, &err)) + EM_DEBUG_EXCEPTION("emcore_sync_mailbox_list failed [%d]", err); + } + EM_SAFE_FREE(event_data.event_param_data_3); + break; - case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: /* Sync flags field */ - event_handler_EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER((int*)event_data.event_param_data_3, event_data.event_param_data_4 , event_data.event_param_data_5, event_data.event_param_data_6, &err); - EM_SAFE_FREE(event_data.event_param_data_3); - break; - - case EMF_EVENT_DELETE_MAIL: /* delete mails */ - event_handler_EMF_EVENT_DELETE_MAIL(event_data.account_id, (int *)event_data.event_param_data_3, event_data.event_param_data_4, event_data.event_param_data_1, &err); - EM_SAFE_FREE(event_data.event_param_data_1); - EM_SAFE_FREE(event_data.event_param_data_3); - break; - - case EMF_EVENT_DELETE_MAIL_ALL: /* delete all mails */ - event_handler_EMF_EVENT_DELETE_MAIL_ALL((int)event_data.account_id, (char *)event_data.event_param_data_1, (int)event_data.event_param_data_4, &err); - EM_SAFE_FREE(event_data.event_param_data_1); - break; + case EMAIL_EVENT_SYNC_HEADER: /* synchronize mail header */ + if (is_storage_full == false) + event_handler_EMAIL_EVENT_SYNC_HEADER(event_data.account_id, event_data.event_param_data_5, handle_to_be_published, &err); + break; + + case EMAIL_EVENT_SYNC_HEADER_OMA: /* synchronize mail header for OMA */ + if (is_storage_full == false) + event_hanlder_EMAIL_EVENT_SYNC_HEADER_OMA(event_data.account_id, event_data.event_param_data_1, &err); + EM_SAFE_FREE(event_data.event_param_data_1); + break; + + case EMAIL_EVENT_DOWNLOAD_BODY: /* download mail body */ + if (is_storage_full == false) + event_handler_EMAIL_EVENT_DOWNLOAD_BODY(event_data.account_id, (int)event_data.event_param_data_4, (int)event_data.event_param_data_3, handle_to_be_published, &err); + event_data.event_param_data_3 = NULL; /* MUST BE */ + break; + + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: /* download attachment */ + if (is_storage_full == false) + event_handler_EMAIL_EVENT_DOWNLOAD_ATTACHMENT(event_data.account_id, (int)event_data.event_param_data_4, event_data.event_param_data_5, handle_to_be_published, &err); + break; + + case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: /* Sync flags field */ + event_handler_EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER((int*)event_data.event_param_data_3, event_data.event_param_data_4 , event_data.event_param_data_5, event_data.event_param_data_6, &err); + EM_SAFE_FREE(event_data.event_param_data_3); + break; + + case EMAIL_EVENT_DELETE_MAIL: /* delete mails */ + event_handler_EMAIL_EVENT_DELETE_MAIL(event_data.account_id, (int *)event_data.event_param_data_3, event_data.event_param_data_4, &err); + EM_SAFE_FREE(event_data.event_param_data_3); + break; + + case EMAIL_EVENT_DELETE_MAIL_ALL: /* delete all mails */ + event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(event_data.event_param_data_4, (int)event_data.event_param_data_5, &err); + break; #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ - case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - event_handler_EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER((int)event_data.event_param_data_4, &err); - break; + case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: + event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER((int)event_data.event_param_data_4, &err); + break; #endif - - case EMF_EVENT_CREATE_MAILBOX: - event_handler_EMF_EVENT_CREATE_MAILBOX(event_data.account_id, event_data.event_param_data_1, event_data.event_param_data_2, GPOINTER_TO_INT(event_data.event_param_data_3), event_data.event_param_data_4, handle_to_be_published, &err); - EM_SAFE_FREE(event_data.event_param_data_1); - EM_SAFE_FREE(event_data.event_param_data_2); - break; - case EMF_EVENT_DELETE_MAILBOX: - event_handler_EMF_EVENT_DELETE_MAILBOX(event_data.account_id, event_data.event_param_data_1, event_data.event_param_data_4, handle_to_be_published, &err); - EM_SAFE_FREE(event_data.event_param_data_1); - break; + case EMAIL_EVENT_CREATE_MAILBOX: + event_handler_EMAIL_EVENT_CREATE_MAILBOX(event_data.account_id, event_data.event_param_data_1, event_data.event_param_data_2, GPOINTER_TO_INT(event_data.event_param_data_3), event_data.event_param_data_4, handle_to_be_published, &err); + EM_SAFE_FREE(event_data.event_param_data_1); + EM_SAFE_FREE(event_data.event_param_data_2); + break; - case EMF_EVENT_MOVE_MAIL: - event_handler_EMF_EVENT_MOVE_MAIL(event_data.account_id, event_data.event_param_data_2, (int *)event_data.event_param_data_3, event_data.event_param_data_4, event_data.event_param_data_1, handle_to_be_published, &err); + case EMAIL_EVENT_DELETE_MAILBOX: + event_handler_EMAIL_EVENT_DELETE_MAILBOX(event_data.event_param_data_4, event_data.event_param_data_4, handle_to_be_published, &err); + break; - EM_SAFE_FREE(event_data.event_param_data_1); - EM_SAFE_FREE(event_data.event_param_data_2); - EM_SAFE_FREE(event_data.event_param_data_3); - break; + case EMAIL_EVENT_MOVE_MAIL: + event_handler_EMAIL_EVENT_MOVE_MAIL(event_data.account_id, (int *)event_data.event_param_data_3, event_data.event_param_data_4, event_data.event_param_data_5, event_data.event_param_data_8, handle_to_be_published, &err); - case EMF_EVENT_VALIDATE_ACCOUNT: - event_handler_EMF_EVENT_VALIDATE_ACCOUNT(event_data.account_id, handle_to_be_published, &err); - break; + EM_SAFE_FREE(event_data.event_param_data_3); + break; - case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT: - event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emcore_get_new_account_reference(), handle_to_be_published, &err); - break; + case EMAIL_EVENT_VALIDATE_ACCOUNT: + event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(event_data.account_id, handle_to_be_published, &err); + break; - case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: { - emf_account_t *pAccount = (emf_account_t *)event_data.event_param_data_1; - event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(event_data.account_id, pAccount, handle_to_be_published, &err); - emcore_free_account(&pAccount, 1, NULL); - } - break; + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: { +/* event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emcore_get_new_account_reference(), handle_to_be_published, &err);*/ + email_account_t *account = (email_account_t *)event_data.event_param_data_1; + event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(account, handle_to_be_published, &err); + emcore_free_account(account); + memset(account, 0, sizeof(email_account_t)); /*global account */ + } + break; - case EMF_EVENT_UPDATE_MAIL: - event_handler_EMF_EVENT_UPDATE_MAIL((emf_mail_data_t*)event_data.event_param_data_1, (emf_attachment_data_t*)event_data.event_param_data_2, event_data.event_param_data_4, (emf_meeting_request_t*)event_data.event_param_data_3, event_data.event_param_data_5, handle_to_be_published); - - event_data.event_param_data_1 = NULL; - event_data.event_param_data_2 = NULL; - event_data.event_param_data_3 = NULL; - break; + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: { + email_account_t *pAccount = (email_account_t *)event_data.event_param_data_1; + event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(event_data.account_id, pAccount, handle_to_be_published, &err); + emcore_free_account(pAccount); + EM_SAFE_FREE(pAccount); + } + break; - case EMF_EVENT_SET_MAIL_SLOT_SIZE: - event_handler_EMF_EVENT_SET_MAIL_SLOT_SIZE(event_data.account_id, event_data.event_param_data_3, event_data.event_param_data_4, handle_to_be_published, &err); - EM_SAFE_FREE(event_data.event_param_data_3); - break; - -#ifdef __FEATURE_LOCAL_ACTIVITY__ - case EMF_EVENT_LOCAL_ACTIVITY: - event_handler_EMF_EVENT_LOCAL_ACTIVITY(event_data.account_id, &err); - break; -#endif /* __FEATURE_LOCAL_ACTIVITY__*/ - - default: - break; + case EMAIL_EVENT_UPDATE_MAIL: + event_handler_EMAIL_EVENT_UPDATE_MAIL((email_mail_data_t*)event_data.event_param_data_1, (email_attachment_data_t*)event_data.event_param_data_2, event_data.event_param_data_4, (email_meeting_request_t*)event_data.event_param_data_3, event_data.event_param_data_5, handle_to_be_published); + + event_data.event_param_data_1 = NULL; + event_data.event_param_data_2 = NULL; + event_data.event_param_data_3 = NULL; + break; + + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + event_handler_EMAIL_EVENT_SET_MAIL_SLOT_SIZE(event_data.account_id, event_data.event_param_data_4, event_data.event_param_data_5, handle_to_be_published, &err); + break; + + case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: + err = event_handler_EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED(event_data.account_id, event_data.event_param_data_4); + break; + + #ifdef __FEATURE_LOCAL_ACTIVITY__ + case EMAIL_EVENT_LOCAL_ACTIVITY: + event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(event_data.account_id, &err); + break; + #endif /* __FEATURE_LOCAL_ACTIVITY__*/ + + case EMAIL_EVENT_SEARCH_ON_SERVER: + event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(event_data.account_id, event_data.event_param_data_4, (char *)event_data.event_param_data_1, handle_to_be_published, &err); + EM_SAFE_FREE(event_data.event_param_data_1); + break; + + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: + err = event_handler_EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER(event_data.account_id, event_data.event_param_data_4, (char*)event_data.event_param_data_1, (char*)event_data.event_param_data_2, handle_to_be_published); + EM_SAFE_FREE(event_data.event_param_data_1); + EM_SAFE_FREE(event_data.event_param_data_2); + break; + + default: + break; + } + } + + if (account_tbl) { + emstorage_free_account(&account_tbl, 1, NULL); + account_tbl = NULL; } + if (!emstorage_notify_response_to_api(event_data.type, handle_to_be_published, err)) + EM_DEBUG_EXCEPTION("emstorage_notify_response_to_api failed"); + emdevice_set_dimming_on_off(true, NULL); em_flush_memory(); switch (event_data.type) { - case EMF_EVENT_SEND_MAIL: - case EMF_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: _sending_busy_unref(); break; - case EMF_EVENT_SYNC_HEADER: - case EMF_EVENT_SYNC_HEADER_OMA: - case EMF_EVENT_DOWNLOAD_BODY: - case EMF_EVENT_DOWNLOAD_ATTACHMENT: - case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: - case EMF_EVENT_DELETE_MAIL: - case EMF_EVENT_DELETE_MAIL_ALL: - case EMF_EVENT_VALIDATE_ACCOUNT: - case EMF_EVENT_SYNC_IMAP_MAILBOX: - case EMF_EVENT_MOVE_MAIL: - case EMF_EVENT_CREATE_MAILBOX: - case EMF_EVENT_DELETE_MAILBOX: - case EMF_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_SYNC_HEADER_OMA: + case EMAIL_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: + case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: + case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL_ALL: + case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_MOVE_MAIL: + case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_SEARCH_ON_SERVER: + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: _receiving_busy_unref(); break; @@ -2217,7 +2446,7 @@ void* thread_func_branch_command(void *arg) event_data.type = 0; ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - memset(g_event_que+g_active_que, 0x00, sizeof(emf_event_t)); + memset(g_event_que+g_active_que, 0x00, sizeof(email_event_t)); LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); } @@ -2231,20 +2460,20 @@ void* thread_func_branch_command(void *arg) return SUCCESS; } /*Send event_data loop*/ -INTERNAL_FUNC int emcore_send_event_loop_start(int *err_code) +INTERNAL_FUNC int emcore_start_event_loop_for_sending_mails(int *err_code) { EM_DEBUG_FUNC_BEGIN(); int thread_error = -1; if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; memset(&g_send_event_que, 0x00, sizeof(g_send_event_que)); if (g_send_srv_thread) { EM_DEBUG_EXCEPTION("\t send service thread is already running..."); if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return true; } @@ -2258,17 +2487,17 @@ INTERNAL_FUNC int emcore_send_event_loop_start(int *err_code) INITIALIZE_CONDITION_VARIABLE(_send_event_available_signal); /* create thread */ - THREAD_CREATE_JOINABLE(g_send_srv_thread, send_event_handler, thread_error); + THREAD_CREATE_JOINABLE(g_send_srv_thread, thread_func_branch_command_for_sending_mails, thread_error); if (thread_error != 0) { EM_DEBUG_EXCEPTION("cannot make thread..."); if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return FAILURE; } if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END(); return SUCCESS; } @@ -2279,11 +2508,11 @@ INTERNAL_FUNC int emcore_send_event_loop_stop(int *err_code) EM_DEBUG_FUNC_BEGIN(); if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; if (!g_send_srv_thread) { if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return false; } @@ -2308,7 +2537,7 @@ INTERNAL_FUNC int emcore_send_event_loop_stop(int *err_code) g_send_active_que = 0; if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; return true; } @@ -2320,14 +2549,14 @@ INTERNAL_FUNC int emcore_start_event_loop(int *err_code) int thread_error; if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; memset(&g_event_que, 0x00, sizeof(g_event_que)); if (g_srv_thread) { EM_DEBUG_EXCEPTION("service thread is already running..."); if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return true; } @@ -2347,12 +2576,12 @@ INTERNAL_FUNC int emcore_start_event_loop(int *err_code) if (thread_error != 0) { EM_DEBUG_EXCEPTION("cannot create thread"); if (err_code != NULL) - *err_code = EMF_ERROR_SYSTEM_FAILURE; + *err_code = EMAIL_ERROR_SYSTEM_FAILURE; return FAILURE; } if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; return false; } @@ -2363,11 +2592,11 @@ INTERNAL_FUNC int emcore_stop_event_loop(int *err_code) EM_DEBUG_FUNC_BEGIN(); if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; if (!g_srv_thread) { if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return false; } @@ -2395,7 +2624,7 @@ INTERNAL_FUNC int emcore_stop_event_loop(int *err_code) g_active_que = 0; if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END(); return true; } @@ -2414,7 +2643,7 @@ INTERNAL_FUNC int emcore_check_thread_status() if (g_active_que <= 0) return true; - return (g_event_que[g_active_que].status == EMF_EVENT_STATUS_STARTED); + return (g_event_que[g_active_que].status == EMAIL_EVENT_STATUS_STARTED); } /* cancel a job */ @@ -2423,11 +2652,11 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) EM_DEBUG_FUNC_BEGIN("handle[%d], arg[%p], err_code[%p]", handle, arg, err_code); int ret = false; - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (handle <= 0 || handle > (EVENT_QUEUE_MAX - 1)) { EM_DEBUG_EXCEPTION("handle[%d], arg[%p]", handle, arg); - err = EMF_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -2435,48 +2664,50 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) EM_DEBUG_LOG("status[%d], type[%d], handle[%d]", g_event_que[handle].status, g_event_que[handle].type, handle); - if (g_event_que[handle].status == EMF_EVENT_STATUS_WAIT) { - fail_status_notify(&g_event_que[handle], EMF_ERROR_CANCELLED); + if (g_event_que[handle].status == EMAIL_EVENT_STATUS_WAIT) { + fail_status_notify(&g_event_que[handle], EMAIL_ERROR_CANCELLED); switch (g_event_que[handle].type) { - case EMF_EVENT_SEND_MAIL: - case EMF_EVENT_SEND_MAIL_SAVED: - EM_DEBUG_LOG("EMF_EVENT_SEND_MAIL or EMF_EVENT_SEND_MAIL_SAVED"); + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: + EM_DEBUG_LOG("EMAIL_EVENT_SEND_MAIL or EMAIL_EVENT_SEND_MAIL_SAVED"); _sending_busy_unref(); if (!emstorage_notify_network_event(NOTI_SEND_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> "); break; - case EMF_EVENT_DOWNLOAD_BODY: - EM_DEBUG_LOG("EMF_EVENT_DOWNLOAD_BODY"); + case EMAIL_EVENT_DOWNLOAD_BODY: + EM_DEBUG_LOG("EMAIL_EVENT_DOWNLOAD_BODY"); _receiving_busy_unref(); if (!emstorage_notify_network_event(NOTI_DOWNLOAD_BODY_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> "); break; - case EMF_EVENT_SYNC_HEADER: - case EMF_EVENT_SYNC_HEADER_OMA: - case EMF_EVENT_DOWNLOAD_ATTACHMENT: - case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: - EM_DEBUG_LOG("EMF_EVENT_SYNC_HEADER, EMF_EVENT_DOWNLOAD_ATTACHMENT"); + case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_SYNC_HEADER_OMA: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: + case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: + EM_DEBUG_LOG("EMAIL_EVENT_SYNC_HEADER, EMAIL_EVENT_DOWNLOAD_ATTACHMENT"); _receiving_busy_unref(); break; - case EMF_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_ACCOUNT: EM_DEBUG_LOG(" validate account waiting : cancel acc id : %d", g_event_que[handle].account_id); _receiving_busy_unref(); if (!emstorage_notify_network_event(NOTI_VALIDATE_ACCOUNT_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_CANCEL] Failed >>>> "); break; - case EMF_EVENT_DELETE_MAIL: - case EMF_EVENT_DELETE_MAIL_ALL: - case EMF_EVENT_SYNC_IMAP_MAILBOX: - case EMF_EVENT_MOVE_MAIL: - case EMF_EVENT_CREATE_MAILBOX: - case EMF_EVENT_DELETE_MAILBOX: - case EMF_EVENT_SET_MAIL_SLOT_SIZE: - EM_DEBUG_LOG("EMF_EVENT_DELETE_MAIL, EMF_EVENT_SYNC_IMAP_MAILBOX"); + case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL_ALL: + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_MOVE_MAIL: + case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_SEARCH_ON_SERVER: + case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: + EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX"); _receiving_busy_unref(); break; default: @@ -2484,8 +2715,8 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) } } - memset(g_event_que+handle, 0x00, sizeof(emf_event_t)); - g_event_que[handle].status = EMF_EVENT_STATUS_CANCELED; + memset(g_event_que+handle, 0x00, sizeof(email_event_t)); + g_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); @@ -2509,17 +2740,17 @@ int emcore_check_send_mail_thread_status() return true; EM_DEBUG_LOG("g_send_event_que[g_send_active_que[%d]].status[%d]", g_send_active_que, g_send_event_que[g_send_active_que].status); EM_DEBUG_FUNC_END(); - return (g_send_event_que[g_send_active_que].status == EMF_EVENT_STATUS_STARTED); + return (g_send_event_que[g_send_active_que].status == EMAIL_EVENT_STATUS_STARTED); } INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) { EM_DEBUG_FUNC_BEGIN(); - int error_code = EMF_ERROR_NONE; + int error_code = EMAIL_ERROR_NONE; int i, event_count = EVENT_QUEUE_MAX, exit_flag = 0, sleep_count = 0; for (i = 0 ; i < event_count; i++) { - if (g_event_que[i].type && g_event_que[i].status != EMF_EVENT_STATUS_UNUSED) { + if (g_event_que[i].type && g_event_que[i].status != EMAIL_EVENT_STATUS_UNUSED) { EM_DEBUG_LOG("There is a live thread. %d", i); if (g_event_que[i].account_id == account_id || g_event_que[i].account_id == ALL_ACCOUNT) { EM_DEBUG_LOG("And it is for account %d", g_event_que[i].account_id); @@ -2535,7 +2766,7 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) sleep_count++; exit_flag = 1; for (i = 0 ; i < event_count; i++) { - if (g_event_que[i].type && g_event_que[i].status != EMF_EVENT_STATUS_UNUSED) { + if (g_event_que[i].type && g_event_que[i].status != EMAIL_EVENT_STATUS_UNUSED) { EM_DEBUG_LOG("There is still a live thread. %d", i); if (g_event_que[i].account_id == account_id || g_event_que[i].account_id == ALL_ACCOUNT) { EM_DEBUG_LOG("And it is for account %d. So, I should sleep for a while.", g_event_que[i].account_id); @@ -2548,9 +2779,9 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) EM_DEBUG_LOG("Sleep count %d", sleep_count); if (sleep_count >= 30) - error_code = EMF_ERROR_CANNOT_STOP_THREAD; + error_code = EMAIL_ERROR_CANNOT_STOP_THREAD; else - error_code = EMF_ERROR_NONE; + error_code = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END(); return error_code; } @@ -2562,11 +2793,11 @@ INTERNAL_FUNC int emcore_cancel_send_mail_thread(int handle, void *arg, int *err EM_DEBUG_FUNC_BEGIN("handle[%d], arg[%p], err_code[%p]", handle, arg, err_code); int ret = false; - int err = EMF_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (handle <= 0 || handle > (EVENT_QUEUE_MAX - 1)) { EM_DEBUG_EXCEPTION("handle[%d], arg[%p]", handle, arg); - err = EMF_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -2574,14 +2805,14 @@ INTERNAL_FUNC int emcore_cancel_send_mail_thread(int handle, void *arg, int *err EM_DEBUG_LOG("event_data.status[%d], handle[%d]", g_send_event_que[handle].status, handle); - if (g_send_event_que[handle].status == EMF_EVENT_STATUS_WAIT) { - fail_status_notify(&g_send_event_que[handle], EMF_ERROR_CANCELLED); + if (g_send_event_que[handle].status == EMAIL_EVENT_STATUS_WAIT) { + fail_status_notify(&g_send_event_que[handle], EMAIL_ERROR_CANCELLED); switch (g_send_event_que[handle].type) { - case EMF_EVENT_SEND_MAIL: - case EMF_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: _sending_busy_unref(); - g_send_event_que[handle].status = EMF_EVENT_STATUS_CANCELED; + g_send_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; if (!emstorage_notify_network_event(NOTI_SEND_CANCEL, g_send_event_que[handle].account_id, NULL , g_send_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emstorage_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> "); break; @@ -2591,8 +2822,8 @@ INTERNAL_FUNC int emcore_cancel_send_mail_thread(int handle, void *arg, int *err } EM_DEBUG_LOG("send_mail_cancel"); - memset(g_send_event_que+handle, 0x00, sizeof(emf_event_t)); - g_send_event_que[handle].status = EMF_EVENT_STATUS_CANCELED; + memset(g_send_event_que+handle, 0x00, sizeof(email_event_t)); + g_send_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; EM_DEBUG_LOG("event_data.status[%d], handle[%d]", g_send_event_que[handle].status, handle); @@ -2609,13 +2840,13 @@ FINISH_OFF: } -INTERNAL_FUNC int emcore_get_receiving_event_queue(emf_event_t **event_queue, int *event_active_queue, int *err) +INTERNAL_FUNC int emcore_get_receiving_event_queue(email_event_t **event_queue, int *event_active_queue, int *err) { if (event_queue == NULL || event_active_queue == NULL) { - EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM event_queue[%p] event_active_queue[%p]", event_queue, event_active_queue); + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM event_queue[%p] event_active_queue[%p]", event_queue, event_active_queue); if (err) - *err = EMF_ERROR_INVALID_PARAM; + *err = EMAIL_ERROR_INVALID_PARAM; return false; } @@ -2626,7 +2857,7 @@ INTERNAL_FUNC int emcore_get_receiving_event_queue(emf_event_t **event_queue, in return true; } -INTERNAL_FUNC int emcore_free_event(emf_event_t *event_data) +INTERNAL_FUNC int emcore_free_event(email_event_t *event_data) { EM_DEBUG_FUNC_BEGIN("event_data [%p]", event_data); @@ -2679,7 +2910,7 @@ static int emcore_clear_bulk_pbd_que(int *err_code) EM_DEBUG_FUNC_BEGIN(); int ret = true; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int i = 0; for (i = 0; i < BULK_PARTIAL_BODY_DOWNLOAD_COUNT; ++i) { @@ -2736,7 +2967,7 @@ INTERNAL_FUNC int emcore_clear_partial_body_thd_event_que(int *err_code) EM_DEBUG_FUNC_BEGIN(); int ret = true; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int i = 0; ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); @@ -2809,15 +3040,15 @@ Also never call any function from this API which uses _partial_body_thd_event_qu */ -static int emcore_copy_partial_body_thd_event(emf_event_partial_body_thd *src, emf_event_partial_body_thd *dest, int *error_code) +static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src, email_event_partial_body_thd *dest, int *error_code) { EM_DEBUG_FUNC_BEGIN(); - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int ret = false; if (NULL == src || NULL == dest) { EM_DEBUG_LOG(" Invalid Parameter src [%p] dest [%p]", src, dest); - error = EMF_ERROR_INVALID_PARAM; + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -2825,6 +3056,7 @@ static int emcore_copy_partial_body_thd_event(emf_event_partial_body_thd *src, e dest->mail_id = src->mail_id; dest->server_mail_id = src->server_mail_id; dest->activity_id = src->activity_id; + dest->mailbox_id = src->mailbox_id; dest->mailbox_name = EM_SAFE_STRDUP(src->mailbox_name); dest->activity_type = src->activity_type; dest->event_type = src->event_type; @@ -2855,25 +3087,25 @@ Also never call any function from this API which uses _partial_body_thd_event_qu */ -INTERNAL_FUNC int emcore_free_partial_body_thd_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code) +INTERNAL_FUNC int emcore_free_partial_body_thd_event(email_event_partial_body_thd *partial_body_thd_event, int *error_code) { EM_DEBUG_FUNC_BEGIN(); if (NULL == partial_body_thd_event) { - *error_code = EMF_ERROR_INVALID_PARAM; + *error_code = EMAIL_ERROR_INVALID_PARAM; return false; } - emf_event_partial_body_thd *pbd_event = partial_body_thd_event; + email_event_partial_body_thd *pbd_event = partial_body_thd_event; /*Free character pointers in event_data cell */ EM_SAFE_FREE(pbd_event->mailbox_name); - memset(pbd_event, 0x00, sizeof(emf_event_partial_body_thd)); + memset(pbd_event, 0x00, sizeof(email_event_partial_body_thd)); EM_DEBUG_FUNC_END(); return true; } -INTERNAL_FUNC int emcore_insert_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code) +INTERNAL_FUNC int emcore_insert_partial_body_thread_event(email_event_partial_body_thd *partial_body_thd_event, int *error_code) { EM_DEBUG_FUNC_BEGIN(); @@ -2881,13 +3113,13 @@ INTERNAL_FUNC int emcore_insert_partial_body_thread_event(emf_event_partial_body EM_DEBUG_EXCEPTION("\t partial_body_thd_event [%p] ", partial_body_thd_event); if (error_code != NULL) { - *error_code = EMF_ERROR_INVALID_PARAM; + *error_code = EMAIL_ERROR_INVALID_PARAM; } return false; } int ret = false; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int empty_cell_index = -1; int index = 0; int count = 0; @@ -2933,7 +3165,7 @@ INTERNAL_FUNC int emcore_insert_partial_body_thread_event(emf_event_partial_body } else { EM_DEBUG_LOG(" partial body thread event_data queue is full "); - error = EMF_ERROR_EVENT_QUEUE_FULL; + error = EMAIL_ERROR_EVENT_QUEUE_FULL; g_partial_body_thd_queue_full = true; g_partial_body_thd_queue_empty = false; @@ -2952,12 +3184,12 @@ INTERNAL_FUNC int emcore_insert_partial_body_thread_event(emf_event_partial_body /* h.gahlaut : Return true only if event_data is retrieved successfully */ -static int emcore_retrieve_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code) +static int emcore_retrieve_partial_body_thread_event(email_event_partial_body_thd *partial_body_thd_event, int *error_code) { EM_DEBUG_FUNC_BEGIN(); int ret = false; - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int index = 0; /* Lock Mutex to protect event_data queue and associated global variables variables*/ @@ -2967,7 +3199,7 @@ static int emcore_retrieve_partial_body_thread_event(emf_event_partial_body_thd index = g_partial_body_thd_next_event_idx; if (0 == g_partial_body_thd_event_que[index].event_type) { - error = EMF_ERROR_EVENT_QUEUE_EMPTY; + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; g_partial_body_thd_queue_empty = true; g_partial_body_thd_queue_full = false; } @@ -3014,9 +3246,9 @@ gpointer partial_body_download_thread(gpointer data) { EM_DEBUG_FUNC_BEGIN(); - int err = EMF_ERROR_NONE; - emf_session_t *session = NULL; - emf_event_partial_body_thd partial_body_thd_event; + int err = EMAIL_ERROR_NONE; + email_session_t *session = NULL; + email_event_partial_body_thd partial_body_thd_event; EM_DEBUG_LOG(" ************ PB THREAD ID IS ALIVE. ID IS [%d] ********************" , THREAD_SELF()); @@ -3036,10 +3268,10 @@ gpointer partial_body_download_thread(gpointer data) if (false == emcore_get_empty_session(&session)) EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); else { /* Get and Event from the Partial Body thread Event Queue */ - memset(&partial_body_thd_event, 0x00, sizeof(emf_event_partial_body_thd)); + memset(&partial_body_thd_event, 0x00, sizeof(email_event_partial_body_thd)); if (false == emcore_retrieve_partial_body_thread_event(&partial_body_thd_event, &err)) { - if (EMF_ERROR_EVENT_QUEUE_EMPTY != err) + if (EMAIL_ERROR_EVENT_QUEUE_EMPTY != err) EM_DEBUG_EXCEPTION("emcore_retrieve_partial_body_thread_event failed [%d]", err); else { EM_DEBUG_LOG(" partial body thread event_data queue is empty."); @@ -3048,6 +3280,7 @@ gpointer partial_body_download_thread(gpointer data) if (!g_partial_body_bulk_dwd_queue_empty) { partial_body_thd_event.event_type = 0; partial_body_thd_event.account_id = g_partial_body_bulk_dwd_que[0].account_id; + partial_body_thd_event.mailbox_id = g_partial_body_bulk_dwd_que[0].mailbox_id; partial_body_thd_event.mailbox_name = EM_SAFE_STRDUP(g_partial_body_bulk_dwd_que[0].mailbox_name); if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) @@ -3103,13 +3336,13 @@ gpointer partial_body_download_thread(gpointer data) EM_DEBUG_LOG("partial_body_thd_event.account_id[%d]", partial_body_thd_event.account_id); switch (partial_body_thd_event.event_type) { - case EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD: { + case EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD: { if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) { EM_DEBUG_EXCEPTION("emcore_mail_partial_body_download from event_data queue failed [%d]", err); } break; } - case EMF_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD: { + case EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD: { partial_body_thd_event.event_type = 0; /* Both the checks below make sure that before starting local activity there is no new/pending event_data in @@ -3145,7 +3378,7 @@ gpointer partial_body_download_thread(gpointer data) return SUCCESS; } -INTERNAL_FUNC int emcore_partial_body_thread_loop_start(int *err_code) +INTERNAL_FUNC int emcore_start_thread_for_downloading_partial_body(int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -3154,13 +3387,15 @@ INTERNAL_FUNC int emcore_partial_body_thread_loop_start(int *err_code) /* Clear Partial Body Event Queue*/ memset(&g_partial_body_thd_event_que, 0x00, sizeof(g_partial_body_thd_event_que)); - for (i = 0; i < TOTAL_PARTIAL_BODY_EVENTS; ++i) - g_partial_body_thd_event_que[i].mailbox_name = NULL; + for (i = 0; i < TOTAL_PARTIAL_BODY_EVENTS; ++i) { + g_partial_body_thd_event_que[i].mailbox_name = NULL; + g_partial_body_thd_event_que[i].mailbox_id = 0; + } if (g_partial_body_thd) { EM_DEBUG_EXCEPTION("partial body thread is already running..."); if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return true; } @@ -3179,12 +3414,12 @@ INTERNAL_FUNC int emcore_partial_body_thread_loop_start(int *err_code) if (thread_error != 0) { EM_DEBUG_EXCEPTION("cannot make thread..."); if (err_code != NULL) - *err_code = EMF_ERROR_UNKNOWN; + *err_code = EMAIL_ERROR_UNKNOWN; return FAILURE; } if (err_code != NULL) - *err_code = EMF_ERROR_NONE; + *err_code = EMAIL_ERROR_NONE; return false; @@ -3194,12 +3429,12 @@ INTERNAL_FUNC int emcore_partial_body_thread_loop_start(int *err_code) static int emcore_partial_body_bulk_flush(int *error_code) { EM_DEBUG_FUNC_BEGIN(); - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int ret = false; MAILSTREAM *stream = NULL; void *tmp_stream = NULL; - if (!emcore_connect_to_remote_mailbox(g_partial_body_bulk_dwd_que[0].account_id, g_partial_body_bulk_dwd_que[0].mailbox_name, (void **)&tmp_stream, &error) || (NULL == tmp_stream)) { + if (!emcore_connect_to_remote_mailbox(g_partial_body_bulk_dwd_que[0].account_id, g_partial_body_bulk_dwd_que[0].mailbox_id, (void **)&tmp_stream, &error) || (NULL == tmp_stream)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", error); goto FINISH_OFF; } @@ -3232,33 +3467,33 @@ FINISH_OFF: /* Function to pass UID list and Data for bulk partial body download [santosh.br@samsung.com]/[h.gahlaut@samsung.com] */ -INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd *pbd_event, int *error_code) +INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd *pbd_event, int *error_code) { EM_DEBUG_FUNC_BEGIN(); - int error = EMF_ERROR_NONE; + int error = EMAIL_ERROR_NONE; int num_activity = 0; int ret = false; int count = 0; int i = 0, m = 0; MAILSTREAM *stream = NULL; void *tmp_stream = NULL; - emf_event_partial_body_thd *activity_data_list = NULL; - char **mailbox_list = NULL; + email_event_partial_body_thd *activity_data_list = NULL; + int *mailbox_list = NULL; if (NULL == pbd_event) { EM_DEBUG_EXCEPTION("Invalid Parameter pbd_event [%p] ", pbd_event); - error = EMF_ERROR_INVALID_PARAM; + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } /*Check if the event_data is to flush the event_data que array */ - if (EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD == pbd_event->event_type) { - EM_DEBUG_LOG("pbd_event->event_type is EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD"); + if (EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD == pbd_event->event_type) { + EM_DEBUG_LOG("pbd_event->event_type is EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD"); /*Check if the mailbox name and account id for this event_data is same as the mailbox name and account id for earlier events saved in download que array then append this event_data also to download que array */ - if ((NULL != g_partial_body_bulk_dwd_que[0].mailbox_name) && (0 == strncmp(g_partial_body_bulk_dwd_que[0].mailbox_name, pbd_event->mailbox_name, strlen(g_partial_body_bulk_dwd_que[0].mailbox_name))) && \ + if ((0 != g_partial_body_bulk_dwd_que[0].mailbox_id) && g_partial_body_bulk_dwd_que[0].mailbox_id == pbd_event->mailbox_id && \ (g_partial_body_bulk_dwd_que[0].account_id == pbd_event->account_id)) { EM_DEBUG_LOG("Event is for the same mailbox and same account as the already present events in download que"); EM_DEBUG_LOG("Check if the download que reached its limit. If yes then first flush the que."); @@ -3297,7 +3532,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * /* Get all the accounts for which local activities are pending */ if (false == emstorage_get_pbd_account_list(&account_list, &account_count, false, &error)) { EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_list failed.. [%d]", error); - error = EMF_ERROR_MAILBOX_NOT_FOUND; + error = EMAIL_ERROR_MAILBOX_NOT_FOUND; goto FINISH_OFF; } @@ -3305,7 +3540,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * /* Get the mailbox list for the account to start bulk partial body fetch for mails in each mailbox of accounts one by one*/ if (false == emstorage_get_pbd_mailbox_list(account_list[m], &mailbox_list, &count, false, &error)) { EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_list failed.. [%d]", error); - error = EMF_ERROR_MAILBOX_NOT_FOUND; + error = EMAIL_ERROR_MAILBOX_NOT_FOUND; goto FINISH_OFF; } @@ -3313,7 +3548,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * int k = 0; int activity_count = 0; - if (!emcore_connect_to_remote_mailbox(account_list[m], mailbox_list[i], (void **)&tmp_stream, &error)) { + if (!emcore_connect_to_remote_mailbox(account_list[m], mailbox_list[i], (void **)&tmp_stream, &error)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", error); stream = NULL; goto FINISH_OFF; @@ -3327,7 +3562,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * } if (activity_count > 0) { - int temp_error = EMF_ERROR_NONE; + int temp_error = EMAIL_ERROR_NONE; int j = 0; int iter = 0; int remainder = 0; @@ -3352,7 +3587,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * /*Call bulk download here */ if (false == emcore_download_bulk_partial_mail_body(stream, activity_data_list+index, num, &error)) { EM_DEBUG_EXCEPTION(" emcore_download_bulk_partial_mail_body failed.. [%d]", error); - temp_error = EMF_ERROR_NO_RESPONSE; + temp_error = EMAIL_ERROR_NO_RESPONSE; } for (k = 0; k < num; k++) { @@ -3367,8 +3602,8 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * ret = true; goto FINISH_OFF; /* Stop Local Activity Sync */ } - if (EMF_ERROR_NO_RESPONSE == temp_error) { - temp_error = EMF_ERROR_NONE; + if (EMAIL_ERROR_NO_RESPONSE == temp_error) { + temp_error = EMAIL_ERROR_NONE; break; } } @@ -3401,11 +3636,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(emf_event_partial_body_thd * FINISH_OFF: - if (mailbox_list) { - for (i = 0; i < count; i++) - EM_SAFE_FREE(mailbox_list[i]); - EM_SAFE_FREE(mailbox_list); - } + EM_SAFE_FREE(mailbox_list); if (activity_data_list) { for (i = 0; i < num_activity; i++) { |