diff options
author | Sunghyun Kwon <sh0701.kwon@samsung.com> | 2014-02-20 14:58:45 +0900 |
---|---|---|
committer | Sunghyun Kwon <sh0701.kwon@samsung.com> | 2014-02-20 14:58:45 +0900 |
commit | cc2e0476a3397d0f8f76960a119f240b4ad01699 (patch) | |
tree | b75c921ec1f8ba2e8b3019df5b6c228d58b6befa /email-daemon | |
parent | 7e2c216892ac4d1ae8b4ec838f61f6213099b6e8 (diff) | |
download | email-service-cc2e0476a3397d0f8f76960a119f240b4ad01699.tar.gz email-service-cc2e0476a3397d0f8f76960a119f240b4ad01699.tar.bz2 email-service-cc2e0476a3397d0f8f76960a119f240b4ad01699.zip |
Merge the email-service to version 2.2
Change-Id: I26816a6b43c134a80e64c6051f8e1205df672ff7
Signed-off-by: Sunghyun Kwon <sh0701.kwon@samsung.com>
Diffstat (limited to 'email-daemon')
-rwxr-xr-x | email-daemon/CMakeLists.txt | 16 | ||||
-rwxr-xr-x | email-daemon/email-daemon-account.c | 248 | ||||
-rwxr-xr-x | email-daemon/email-daemon-auto-poll.c | 84 | ||||
-rwxr-xr-x | email-daemon/email-daemon-emn.c | 38 | ||||
-rwxr-xr-x | email-daemon/email-daemon-etc.c | 232 | ||||
-rwxr-xr-x | email-daemon/email-daemon-init.c | 299 | ||||
-rwxr-xr-x | email-daemon/email-daemon-mail.c | 302 | ||||
-rwxr-xr-x | email-daemon/email-daemon-mailbox.c | 237 | ||||
-rwxr-xr-x | email-daemon/include/email-daemon-auto-poll.h | 2 | ||||
-rwxr-xr-x | email-daemon/include/email-daemon-init.h | 8 | ||||
-rwxr-xr-x | email-daemon/include/email-daemon.h | 13 | ||||
-rwxr-xr-x | email-daemon/main.c | 541 |
12 files changed, 1577 insertions, 443 deletions
diff --git a/email-daemon/CMakeLists.txt b/email-daemon/CMakeLists.txt index 98f696f..06ec746 100755 --- a/email-daemon/CMakeLists.txt +++ b/email-daemon/CMakeLists.txt @@ -11,6 +11,9 @@ MESSAGE("") MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}") MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") +ADD_DEFINITIONS("-DSSL_CERT_DIRECTORY=\"/opt/etc/ssl/certs\"") +ADD_DEFINITIONS("-DSSL_KEY_DIRECTORY=\"/opt/etc/ssl/certs\"") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") ########################################################## @@ -19,6 +22,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") SET(MAIN-SRCS ${CMAKE_SOURCE_DIR}/email-daemon/main.c + ${CMAKE_SOURCE_DIR}/email-daemon/email-daemon-event.c ${CMAKE_SOURCE_DIR}/email-daemon/email-daemon-init.c ${CMAKE_SOURCE_DIR}/email-daemon/email-daemon-account.c ${CMAKE_SOURCE_DIR}/email-daemon/email-daemon-mail.c @@ -31,15 +35,21 @@ SET(MAIN-SRCS INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/email-common-use/include ${CMAKE_SOURCE_DIR}/email-ipc/include + ${CMAKE_SOURCE_DIR}/email-ipc/email-ipc-api/include + ${CMAKE_SOURCE_DIR}/email-ipc/email-activation/include ${CMAKE_SOURCE_DIR}/email-api/include ${CMAKE_SOURCE_DIR}/email-core/include ${CMAKE_SOURCE_DIR}/email-core/email-storage/include + ${CMAKE_SOURCE_DIR}/email-core/email-network/include + ${CMAKE_SOURCE_DIR}/email-core/email-device/include ${CMAKE_SOURCE_DIR}/email-daemon/include ) INCLUDE(FindPkgConfig) -pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 db-util openssl uw-imap-toolkit vconf contacts-service2 alarm-service mm-player drm-client feedback msg-service libwbxml2) - +pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 db-util + openssl uw-imap-toolkit vconf vconf-internal-keys contacts-service2 + alarm-service mm-player drm-client feedback msg-service + libwbxml2 libsmack notification) FOREACH(flag ${main_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -49,6 +59,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ADD_EXECUTABLE(${PROJECT_NAME} ${MAIN-SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${main_pkgs_LDFLAGS} dl ssl email-core email-storage email-network email-ipc email-common-use) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${main_pkgs_LDFLAGS} dl ssl email-core email-core-sound email-storage email-network email-ipc email-common-use email-device email-smime) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/email-daemon/email-daemon-account.c b/email-daemon/email-daemon-account.c index 6e7e517..11c1088 100755 --- a/email-daemon/email-daemon-account.c +++ b/email-daemon/email-daemon-account.c @@ -106,11 +106,12 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_delete_account(int account_id, int* err_code) { - EM_DEBUG_FUNC_BEGIN(); - int ret; + EM_DEBUG_FUNC_BEGIN("account_id[%d] err_code[%p]", account_id, err_code); + int ret = false; ret = emcore_delete_account(account_id, err_code); - EM_DEBUG_FUNC_END(); + + EM_DEBUG_FUNC_END("ret[%d]", ret); return ret; } @@ -162,10 +163,10 @@ INTERNAL_FUNC int emdaemon_validate_account(int account_id, int *handle, int* er int ret = false; int err = EMAIL_ERROR_NONE; - email_event_t event_data = {0}; - email_account_t* ref_account = NULL; + email_event_t *event_data = NULL; + email_account_t *ref_account = NULL; - if (account_id < 1) { + if (account_id < 1) { EM_DEBUG_EXCEPTION(" account_id[%d]", account_id); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -177,13 +178,15 @@ INTERNAL_FUNC int emdaemon_validate_account(int account_id, int *handle, int* er goto FINISH_OFF; } - event_data.type = EMAIL_EVENT_VALIDATE_ACCOUNT; - event_data.event_param_data_1 = NULL; - event_data.event_param_data_3 = NULL; - event_data.account_id = account_id; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_VALIDATE_ACCOUNT; + event_data->event_param_data_1 = NULL; + event_data->event_param_data_3 = NULL; + event_data->account_id = account_id; - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION(" emcore_insert_event falied [%d]", err); + goto FINISH_OFF; } ret = true; @@ -195,9 +198,16 @@ FINISH_OFF: EM_SAFE_FREE(ref_account); } + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -205,22 +215,39 @@ INTERNAL_FUNC int emdaemon_validate_account_ex(email_account_t* input_account, i { EM_DEBUG_FUNC_BEGIN("input_account[%p], output_handle[%p]", input_account, output_handle); + int ret = false; int err = EMAIL_ERROR_NONE; - email_event_t event_data = {0}; + email_event_t *event_data = NULL; + + event_data = em_malloc(sizeof(email_event_t)); + + if(!event_data) { /*prevent 53095*/ + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - event_data.type = EMAIL_EVENT_VALIDATE_ACCOUNT_EX; - event_data.event_param_data_1 = (void*)input_account; - event_data.event_param_data_3 = NULL; - event_data.account_id = NEW_ACCOUNT_ID; + event_data->type = EMAIL_EVENT_VALIDATE_ACCOUNT_EX; + event_data->event_param_data_1 = (void*)input_account; + event_data->event_param_data_3 = NULL; + event_data->account_id = NEW_ACCOUNT_ID; - if (!emcore_insert_event(&event_data, (int*)output_handle, &err)) { + if (!emcore_insert_event(event_data, (int*)output_handle, &err)) { EM_DEBUG_EXCEPTION(" emcore_insert_event falied [%d]", err); goto FINISH_OFF; } + ret = true; FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } @@ -230,14 +257,22 @@ INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_acco int ret = false; int err = EMAIL_ERROR_NONE; - email_event_t event_data = {0}; + email_event_t *event_data = NULL; + + event_data = em_malloc(sizeof(email_event_t)); + + if(!event_data) { /*prevent 53093*/ + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - event_data.type = EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT; - event_data.event_param_data_1 = (void*) new_account; - event_data.event_param_data_3 = NULL; - event_data.account_id = NEW_ACCOUNT_ID; + event_data->type = EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT; + event_data->event_param_data_1 = (void *)new_account; + event_data->event_param_data_3 = NULL; + event_data->account_id = NEW_ACCOUNT_ID; - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION(" emcore_insert_event falied [%d]", err); goto FINISH_OFF; } @@ -245,9 +280,17 @@ INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_acco ret = true; FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -273,11 +316,10 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a goto FINISH_OFF; } - EM_DEBUG_LOG("new_account->email_addr[%s]", new_account->user_email_address); + EM_DEBUG_LOG_SEC("new_account->email_addr[%s]", new_account->user_email_address); if(new_account->user_email_address) { - if (!em_verify_email_address(new_account->user_email_address, true, &err)) { - err = EMAIL_ERROR_INVALID_ADDRESS; - EM_DEBUG_EXCEPTION("Invalid Email Address"); + if ((err = em_verify_email_address (new_account->user_email_address, true)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_verify_email_address error [%d]", err); goto FINISH_OFF; } } @@ -298,23 +340,19 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a emcore_init_account_reference(); #ifdef __FEATURE_AUTO_POLLING__ - int old_check_interval = old_account_info.check_interval; - if( old_check_interval <= 0 && new_account->check_interval > 0) { - if(!emdaemon_add_polling_alarm(account_id, new_account->check_interval)) - EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> "); + int change_in_auto_polling_option = 0; - } - else if( (old_check_interval > 0) && (new_account->check_interval <= 0)) { + change_in_auto_polling_option = (old_account_info.check_interval != new_account->check_interval) || + (old_account_info.peak_interval != new_account->peak_interval) || + (old_account_info.peak_start_time != new_account->peak_start_time) || + (old_account_info.peak_end_time != new_account->peak_end_time); + + if(change_in_auto_polling_option) { if(!emdaemon_remove_polling_alarm(account_id)) - EM_DEBUG_EXCEPTION("emdaemon_remove_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> "); - } - else if(old_check_interval != new_account->check_interval && new_account->check_interval > 0) { - if(!emdaemon_remove_polling_alarm(account_id)) { - EM_DEBUG_EXCEPTION("emdaemon_remove_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> "); - goto FINISH_OFF; - } - if(!emdaemon_add_polling_alarm(account_id, new_account->check_interval)) - EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> "); + EM_DEBUG_LOG("emdaemon_remove_polling_alarm failed"); + + if(!emdaemon_add_polling_alarm(account_id)) + EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm failed"); } #endif @@ -340,12 +378,20 @@ INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email int ret = false; int err = EMAIL_ERROR_NONE; - email_event_t event_data = {0}; + email_event_t *event_data = NULL; + + event_data = em_malloc(sizeof(email_event_t)); + + if(!event_data) { /*prevent 53094*/ + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - event_data.type = EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT; - event_data.event_param_data_1 = (char *) duplicate_account(new_account_info); - event_data.event_param_data_3 = NULL; - event_data.account_id = old_account_id; + event_data->type = EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT; + event_data->event_param_data_1 = (char *) duplicate_account(new_account_info); + event_data->event_param_data_3 = NULL; + event_data->account_id = old_account_id; #if 0 email_account_t *pAccount = (email_account_t *)em_malloc(sizeof(email_account_t)); @@ -375,7 +421,7 @@ INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email memcpy(pAccount->user_data, new_account_info->user_data, new_account_info->user_data_length); #endif - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } @@ -383,9 +429,17 @@ INTERNAL_FUNC int emdaemon_validate_account_and_update(int old_account_id, email ret = true; FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -542,29 +596,35 @@ INTERNAL_FUNC int emdaemon_find_filter(email_rule_t* filter_info, int* err_code) int ret = false; int err = EMAIL_ERROR_NONE; - if (!filter_info) { + if (!filter_info) { EM_DEBUG_EXCEPTION(" filter_info[%p]", filter_info); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (filter_info->faction == EMAIL_FILTER_MOVE && !filter_info->target_mailbox_id) { - EM_DEBUG_EXCEPTION(" filter_info->faction[%d], filter_info->target_mailbox_id[%d]", filter_info->faction, filter_info->target_mailbox_id); + if (filter_info->faction == EMAIL_FILTER_MOVE && filter_info->target_mailbox_id <= 0) { + EM_DEBUG_EXCEPTION("filter_info->faction[%d], filter_info->target_mailbox_id[%d]", filter_info->faction, filter_info->target_mailbox_id); err = EMAIL_ERROR_INVALID_FILTER; goto FINISH_OFF; } filter_info->account_id = ALL_ACCOUNT; /* MUST BE */ - if (!emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { - EM_DEBUG_EXCEPTION(" emstorage_find_rule failed [%d]", err); - err = EMAIL_ERROR_FILTER_NOT_FOUND; + if (!emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_find_rule failed [%d]", err); goto FINISH_OFF; + } else { + if (err == EMAIL_ERROR_FILTER_NOT_FOUND) { + EM_DEBUG_LOG("EMAIL_ERROR_FILTER_NOT_FOUND"); + err = EMAIL_ERROR_FILTER_NOT_FOUND; + goto FINISH_OFF; + } } ret = true; FINISH_OFF: + if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); @@ -577,22 +637,27 @@ INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filter_info) /* default variable */ int err = EMAIL_ERROR_NONE; - if (!filter_info || !(filter_info->value)) { + if (!filter_info) { EM_DEBUG_EXCEPTION("filter_info[%p]", filter_info); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { + if (!emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_find_rule failed [%d]", err); - err = EMAIL_ERROR_ALREADY_EXISTS; goto FINISH_OFF; + } else { + if (err != EMAIL_ERROR_FILTER_NOT_FOUND) { + EM_DEBUG_LOG("filter already exist"); + err = EMAIL_ERROR_ALREADY_EXISTS; + goto FINISH_OFF; + } } switch (filter_info->faction) { case EMAIL_FILTER_MOVE : - if (!filter_info->target_mailbox_id && (filter_info->account_id <= 0)) { - EM_DEBUG_EXCEPTION("target_mailbox_id[%d], account_id[%d]", filter_info->target_mailbox_id, filter_info->account_id); + if (filter_info->account_id < 0) { + EM_DEBUG_EXCEPTION("Invalid Param : target_mailbox_id[%d], account_id[%d]", filter_info->target_mailbox_id, filter_info->account_id); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -606,7 +671,7 @@ INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filter_info) break; } - if (!emstorage_add_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { + if (!emstorage_add_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_rule failed [%d]", err); goto FINISH_OFF; } @@ -659,6 +724,7 @@ INTERNAL_FUNC int emdaemon_delete_filter(int filter_id, int* err_code) /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; + emstorage_rule_tbl_t *p_rule_tbl = NULL; if (filter_id <= 0) { EM_DEBUG_EXCEPTION(" fliter_id[%d]", filter_id); @@ -666,12 +732,17 @@ INTERNAL_FUNC int emdaemon_delete_filter(int filter_id, int* err_code) goto FINISH_OFF; } - if (!emdaemon_check_filter_id(filter_id, &err)) { - EM_DEBUG_EXCEPTION(" emdaemon_check_filter_id failed [%d]", err); + if (!emstorage_get_rule_by_id(filter_id, &p_rule_tbl, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed : [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_filter_mails_by_rule(p_rule_tbl->account_id, p_rule_tbl->target_mailbox_id, false, true, p_rule_tbl, NULL, NULL, &err)) { + EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed : [%d]", err); goto FINISH_OFF; } - if (!emstorage_delete_rule(filter_id, true, &err)) { + if (!emstorage_delete_rule(filter_id, true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_delete_rule failed [%d]", err); goto FINISH_OFF; } @@ -679,8 +750,10 @@ INTERNAL_FUNC int emdaemon_delete_filter(int filter_id, int* err_code) ret = true; FINISH_OFF: + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); return ret; } @@ -740,7 +813,7 @@ INTERNAL_FUNC int emdaemon_apply_filter(int filter_id, int *err_code) } if (!emcore_mail_filter_by_rule((email_rule_t *)filter_info, &err)) { - EM_DEBUG_EXCEPTION(" emstorage_delete_rule failed [%d]", err); + EM_DEBUG_EXCEPTION(" emstorage_mail_filter_by_rule failed [%d]", err); goto FINISH_OFF; } @@ -773,7 +846,10 @@ int emdaemon_initialize_account_reference() } } else { - EM_DEBUG_EXCEPTION("emcore_init_account_reference failed [%d]", err); + if (err == EMAIL_ERROR_ACCOUNT_NOT_FOUND) + EM_DEBUG_LOG ("no account found"); + else + EM_DEBUG_EXCEPTION ("emcore_init_account_reference failed [%d]", err); goto FINISH_OFF; } } @@ -808,4 +884,46 @@ INTERNAL_FUNC int emdaemon_update_accountinfo_to_contact(email_account_t* old_ac return ret; } +INTERNAL_FUNC int emdaemon_query_smtp_mail_size_limit(int account_id, int *handle, int* err_code) +{ + EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p], err_code[%p]", account_id, handle, err_code); + + int ret = false; + int err = EMAIL_ERROR_NONE; + email_event_t *event_data = NULL; + + if (account_id < 1) { + EM_DEBUG_EXCEPTION(" account_id[%d]", account_id); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_QUERY_SMTP_MAIL_SIZE_LIMIT; + event_data->event_param_data_1 = NULL; + event_data->event_param_data_3 = NULL; + event_data->account_id = account_id; + + if (!emcore_insert_event(event_data, (int*)handle, &err)) { + EM_DEBUG_EXCEPTION(" emcore_insert_event falied [%d]", err); + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + + if (err_code) + *err_code = err; + + EM_DEBUG_FUNC_END(); + + return ret; +} + /* EOF */ diff --git a/email-daemon/email-daemon-auto-poll.c b/email-daemon/email-daemon-auto-poll.c index 775b687..fa4f9a3 100755 --- a/email-daemon/email-daemon-auto-poll.c +++ b/email-daemon/email-daemon-auto-poll.c @@ -39,18 +39,19 @@ #include "email-core-alarm.h" #include "email-debug-log.h" #include "email-storage.h" +#include "email-network.h" #include "email-utilities.h" static int _emdaemon_get_polling_account_and_timeinterval(alarm_id_t alarm_id, int *account_id, int *timer_interval); -static int _emdaemon_create_alarm(int input_account_id, int input_alarm_interval); +static int _emdaemon_create_alarm_for_auto_polling(int input_account_id); -INTERNAL_FUNC int emdaemon_add_polling_alarm(int input_account_id, int input_alarm_interval_in_minutes) +INTERNAL_FUNC int emdaemon_add_polling_alarm(int input_account_id) { - EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_alarm_interval_in_minutes[%d]", input_account_id, input_alarm_interval_in_minutes); + EM_DEBUG_FUNC_BEGIN("input_account_id[%d]", input_account_id); int err = EMAIL_ERROR_NONE; - if(input_alarm_interval_in_minutes <= 0) { + if(input_account_id <= 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -61,8 +62,8 @@ INTERNAL_FUNC int emdaemon_add_polling_alarm(int input_account_id, int input_ala goto FINISH_OFF; } - if((err = _emdaemon_create_alarm(input_account_id, input_alarm_interval_in_minutes * 60)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("_emdaemon_create_alarm failed[%d]", err); + if((err = _emdaemon_create_alarm_for_auto_polling(input_account_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("_emdaemon_create_alarm_for_auto_polling failed[%d]", err); goto FINISH_OFF; } FINISH_OFF: @@ -78,7 +79,7 @@ INTERNAL_FUNC int emdaemon_remove_polling_alarm(int account_id) /* delete from list */ if((err = emcore_delete_alram_data_by_reference_id(EMAIL_ALARM_CLASS_AUTO_POLLING, account_id)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_delete_alram_data_by_reference_id failed[%d]", err); + EM_DEBUG_LOG ("emcore_delete_alram_data_by_reference_id return [%d]", err); } EM_DEBUG_FUNC_END("err[%d]", err); @@ -92,7 +93,7 @@ INTERNAL_FUNC int emdaemon_check_auto_polling_started(int account_id) email_alarm_data_t *alarm_data = NULL; if((err = emcore_get_alarm_data_by_reference_id(EMAIL_ALARM_CLASS_AUTO_POLLING, account_id, &alarm_data)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_get_alarm_data_by_reference_id failed [%d]", err); + EM_DEBUG_LOG ("emcore_get_alarm_data_by_reference_id error [%d]", err); goto FINISH_OFF; } @@ -108,9 +109,15 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_para int ret = false; int err = EMAIL_ERROR_NONE; + int handle = 0; int account_id = 0; int mailbox_id = 0; int timer_interval = 0; + int roaming_status = 0; + int wifi_status = 0; + email_account_t *ref_account = NULL; + + EM_DEBUG_ALARM_LOG("alarm_id [%d]", alarm_id); if(!_emdaemon_get_polling_account_and_timeinterval(alarm_id, &account_id, &timer_interval)) { EM_DEBUG_EXCEPTION("email_get_polling_account failed"); @@ -120,23 +127,51 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_para /* delete from list */ if ((err = emdaemon_remove_polling_alarm(account_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("email_get_polling_account failed [%d]", err); - return false; } EM_DEBUG_LOG("target account_id [%d]",account_id); /* create alarm, for polling */ - if ((err = _emdaemon_create_alarm(account_id, timer_interval * 60)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("_emdaemon_create_alarm failed [%d]", err); + if ((err = _emdaemon_create_alarm_for_auto_polling(account_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("_emdaemon_create_alarm_for_auto_polling failed [%d]", err); return false; } + ref_account = emcore_get_account_reference(account_id); + + if (ref_account == NULL) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed"); + err = EMAIL_ERROR_ACCOUNT_NOT_FOUND; + goto FINISH_OFF; + } + + if (ref_account->sync_disabled) { + err = EMAIL_ERROR_ACCOUNT_SYNC_IS_DISALBED; + EM_DEBUG_LOG("Sync disabled for this account. Do not sync."); + goto FINISH_OFF; + } + + if ((err = emnetwork_get_roaming_status(&roaming_status)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emnetwork_get_roaming_status failed [%d]", err); + goto FINISH_OFF; + } + + if ((err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emnetwork_get_roaming_status failed [%d]", err); + goto FINISH_OFF; + } + + if (wifi_status == 0 && roaming_status == 1 && ref_account->roaming_option == EMAIL_ROAMING_OPTION_RESTRICTED_BACKGROUND_TASK) { + EM_DEBUG_LOG("wifi_status[%d], roaming_status[%d], roaming_option[%d]", wifi_status, roaming_status, ref_account->roaming_option); + goto FINISH_OFF; + } + if (!emstorage_get_mailbox_id_by_mailbox_type(account_id,EMAIL_MAILBOX_TYPE_INBOX, &mailbox_id, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } - if (!emdaemon_sync_header(account_id, mailbox_id, NULL, &err)) { + if (!emdaemon_sync_header(account_id, mailbox_id, &handle, &err)) { EM_DEBUG_EXCEPTION("emdaemon_sync_header falied [%d]", err); goto FINISH_OFF; } @@ -144,6 +179,12 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_para ret = true; FINISH_OFF : + if(ref_account) { + emcore_free_account(ref_account); + EM_SAFE_FREE(ref_account); + } + + EM_DEBUG_FUNC_END("err[%d]", err); return ret; } @@ -184,14 +225,15 @@ FINISH_OFF: } -static int _emdaemon_create_alarm(int input_account_id, int input_alarm_interval_in_second) + +static int _emdaemon_create_alarm_for_auto_polling(int input_account_id) { - EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_alarm_interval_in_second[%d]", input_account_id, input_alarm_interval_in_second); + EM_DEBUG_FUNC_BEGIN("input_account_id [%d]", input_account_id); int err = EMAIL_ERROR_NONE; - time_t current_time; time_t trigger_at_time; + time_t current_time; - if(input_alarm_interval_in_second <= 0) { + if(input_account_id <= 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -199,9 +241,15 @@ static int _emdaemon_create_alarm(int input_account_id, int input_alarm_interval time(¤t_time); - trigger_at_time = current_time + input_alarm_interval_in_second; + if ((err = emcore_calc_next_time_to_sync(input_account_id, current_time, &trigger_at_time)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]",err); + goto FINISH_OFF; + } - if ((err = emcore_add_alarm(trigger_at_time, EMAIL_ALARM_CLASS_AUTO_POLLING, input_account_id, emdaemon_alarm_polling_cb, NULL)) != EMAIL_ERROR_NONE) { + if (trigger_at_time == 0) { + EM_DEBUG_LOG("trigger_at_time is 0. It means auto polling is disabled"); + } + else if ((err = emcore_add_alarm(trigger_at_time, EMAIL_ALARM_CLASS_AUTO_POLLING, input_account_id, emdaemon_alarm_polling_cb, NULL)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]",err); goto FINISH_OFF; } diff --git a/email-daemon/email-daemon-emn.c b/email-daemon/email-daemon-emn.c index a51bca1..d193b8f 100755 --- a/email-daemon/email-daemon-emn.c +++ b/email-daemon/email-daemon-emn.c @@ -50,7 +50,7 @@ static void _cb_parser_start_document(void* ctx, WB_LONG charset, const WBXMLLan { EM_DEBUG_FUNC_BEGIN(); EM_DEBUG_LOG("Root Element: %s", lang->publicID->xmlRootElt); - EM_DEBUG_LOG("Public ID: %s", lang->publicID->xmlPublicID); + EM_DEBUG_LOG_SEC("Public ID: %s", lang->publicID->xmlPublicID); EM_DEBUG_LOG("DTD: %s", lang->publicID->xmlDTD); EM_DEBUG_FUNC_END(); } @@ -89,12 +89,12 @@ static void _cb_parser_start_element(void* ctx, WBXMLTag* element, WBXMLAttribut return ; } - EM_DEBUG_LOG("<%s", (char *)wbxml_tag_get_xml_name(element)); + EM_DEBUG_LOG_SEC("<%s", (char *)wbxml_tag_get_xml_name(element)); sprintf((char *)p, "<%s", (char *)wbxml_tag_get_xml_name(element)); j = 0; while (atts[j] != NULL) { - EM_DEBUG_LOG(" %s=\"%s\"", (char *)wbxml_attribute_get_xml_name(atts[j]), (char *)wbxml_attribute_get_xml_value(atts[j])); + EM_DEBUG_LOG_SEC(" %s=\"%s\"", (char *)wbxml_attribute_get_xml_name(atts[j]), (char *)wbxml_attribute_get_xml_value(atts[j])); strcat((char *)p, " "); strcat((char *)p, (char *)wbxml_attribute_get_xml_name(atts[j])); strcat((char *)p, "="); @@ -105,11 +105,11 @@ static void _cb_parser_start_element(void* ctx, WBXMLTag* element, WBXMLAttribut } if (empty) { - EM_DEBUG_LOG("/>"); + EM_DEBUG_LOG_SEC("/>"); strcat((char *)p, "/>"); } else { - EM_DEBUG_LOG(">"); + EM_DEBUG_LOG_SEC(">"); strcat((char *)p, ">"); } @@ -351,6 +351,7 @@ static int _get_emn_account(unsigned char *input_wbxml, int input_wbxml_length, unsigned char* mbox_name = NULL; unsigned char* auth_type = NULL; unsigned char* time_stamp = NULL; + unsigned char email_address[MAX_EMAIL_ADDRESS_LENGTH] = { 0, }; int type = 0; int i = 0; int count = 0; @@ -416,12 +417,15 @@ static int _get_emn_account(unsigned char *input_wbxml, int input_wbxml_length, EM_SAFE_FREE(elm); EM_DEBUG_LOG("user_type = [%d]", type); - EM_DEBUG_LOG("incoming_server_user_name = [%s]", (char *)incoming_server_user_name ? (char*)incoming_server_user_name : "NIL"); + EM_DEBUG_LOG_SEC("incoming_server_user_name = [%s]", (char *)incoming_server_user_name ? (char*)incoming_server_user_name : "NIL"); EM_DEBUG_LOG("host_addr = [%s]", (char *)host_addr ? (char*)host_addr : "NIL"); - EM_DEBUG_LOG("mbox_name = [%s]", (char *)mbox_name ? (char*)mbox_name : "NIL"); + EM_DEBUG_LOG_SEC("mbox_name = [%s]", (char *)mbox_name ? (char*)mbox_name : "NIL"); EM_DEBUG_LOG("auth_type = [%s]", (char *)auth_type ? (char*)auth_type : "NIL"); EM_DEBUG_LOG("time_stamp= [%s]", (char *)time_stamp? (char*)time_stamp: "NIL"); + if(incoming_server_user_name && host_addr) + SNPRINTF((char*)email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", incoming_server_user_name, host_addr); + if (!emdaemon_get_account_list(&accounts, &count, &err)) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_DB_FAILURE"); err = EMAIL_ERROR_DB_FAILURE; @@ -440,15 +444,14 @@ static int _get_emn_account(unsigned char *input_wbxml, int input_wbxml_length, accounts[i].incoming_server_user_name = (char*)EM_SAFE_STRDUP((char *)temp_account_name); } EM_SAFE_FREE(temp_account_name); - if (incoming_server_user_name) { - if (strcmp(accounts[i].incoming_server_user_name, (char *)incoming_server_user_name) == 0 && - strstr(accounts[i].user_email_address, (char *)host_addr)) { + if (incoming_server_user_name && host_addr) { + if (strstr(accounts[i].user_email_address, (char*)email_address)) { EM_DEBUG_LOG(">>>> Account Match >>> "); if ((type == 1) || (type == 2 && accounts[i].incoming_server_type == EMAIL_SERVER_TYPE_POP3) || (type == 3 && accounts[i].incoming_server_type == EMAIL_SERVER_TYPE_IMAP4)) { /* accounts[i].flag2 = type; */ - EM_DEBUG_LOG("found target account id[%d] name[%s]", accounts[i].account_id, accounts[i].incoming_server_user_name); + EM_DEBUG_LOG_SEC("found target account id[%d] name[%s]", accounts[i].account_id, accounts[i].incoming_server_user_name); break; } } @@ -503,7 +506,8 @@ static int emdaemon_handle_emn_notification(unsigned char* wbxml_b64, int input_ { EM_DEBUG_FUNC_BEGIN("wbxml_b64[%p] input_body_lenth[%d]", wbxml_b64, input_body_lenth); - int err = EMAIL_ERROR_NONE;; + int err = EMAIL_ERROR_NONE; + int handle = 0; char* mailbox_name = NULL; email_account_t account = { 0 }; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; @@ -532,7 +536,7 @@ static int emdaemon_handle_emn_notification(unsigned char* wbxml_b64, int input_ } } - if (!emdaemon_sync_header(mailbox_tbl->account_id, mailbox_tbl->mailbox_id, NULL, &err)) { + if (!emdaemon_sync_header(mailbox_tbl->account_id, mailbox_tbl->mailbox_id, &handle, &err)) { EM_DEBUG_EXCEPTION("emdaemon_sync_header failed [%d]", err); goto FINISH_OFF; } @@ -552,9 +556,9 @@ void oma_emn_push_cb(msg_handle_t input_handle, const char *input_push_header, c EM_DEBUG_FUNC_BEGIN("input_handle[%d] input_push_header[%p] input_push_body[%p] input_push_body_lenth[%d] input_user_param[%p]", input_handle, input_push_header, input_push_body, input_push_body_lenth, input_user_param); int err = EMAIL_ERROR_NONE; - EM_DEBUG_EXCEPTION("input_push_header [%s]", input_push_header); - EM_DEBUG_EXCEPTION("input_push_body [%s]", input_push_body); - EM_DEBUG_EXCEPTION("input_push_body_lenth [%d]", input_push_body_lenth); + EM_DEBUG_LOG("input_push_header [%s]", input_push_header); + EM_DEBUG_LOG("input_push_body [%s]", input_push_body); + EM_DEBUG_LOG("input_push_body_lenth [%d]", input_push_body_lenth); if((err = emdaemon_handle_emn_notification((unsigned char*)input_push_body, input_push_body_lenth)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emdaemon_handle_emn_notification failed [%d]", err); @@ -595,7 +599,7 @@ static int emdaemon_register_wap_push_callback(msg_handle_t *input_msg_handle, c msg_add_push_event(*input_msg_handle, msg_struct); if ((msg_err = msg_reg_push_message_callback(*input_msg_handle, &oma_emn_push_cb, input_app_id, NULL)) != MSG_SUCCESS) { - EM_DEBUG_EXCEPTION("msg_reg_push_message_callback() for %s failed [%d]", msg_err, input_app_id); + EM_DEBUG_EXCEPTION_SEC("msg_reg_push_message_callback() for %s failed [%d]", msg_err, input_app_id); err = EMAIL_ERROR_INPROPER_RESPONSE_FROM_MSG_SERVICE; goto FINISH_OFF; } diff --git a/email-daemon/email-daemon-etc.c b/email-daemon/email-daemon-etc.c index c75d1ab..073c1bd 100755 --- a/email-daemon/email-daemon-etc.c +++ b/email-daemon/email-daemon-etc.c @@ -34,6 +34,13 @@ #include <stdlib.h> #include <string.h> #include <vconf.h> +#include <vconf-keys.h> +#include <glib.h> +#include <glib-object.h> +#include <sys/smack.h> +#include <notification.h> +#include <notification_type.h> + #include "email-daemon.h" #include "email-daemon-account.h" #include "email-debug-log.h" @@ -43,9 +50,13 @@ #include "email-core-utils.h" #include "email-core-alarm.h" #include "email-core-smtp.h" +#include "email-core-sound.h" #include "email-utilities.h" #include "email-storage.h" +#include "email-ipc.h" +extern pthread_mutex_t sound_mutex; +extern pthread_cond_t sound_condition; int emdaemon_register_event_callback(email_action_t action, email_event_callback callback, void* event_data) { @@ -312,6 +323,7 @@ INTERNAL_FUNC int emdaemon_search_mail_on_server(int input_account_id, int input int error = EMAIL_ERROR_NONE; int ret = false; char *criteria = NULL; + email_event_t *event_data = NULL; if (input_mailbox_id == 0 || input_account_id < 0) { EM_DEBUG_EXCEPTION("Invalid parameter"); @@ -319,22 +331,19 @@ INTERNAL_FUNC int emdaemon_search_mail_on_server(int input_account_id, int input return false; } - email_event_t event_data; - - memset(&event_data, 0x00, sizeof(email_event_t)); - criteria = _make_criteria_to_search_filter(input_search_filter, input_search_filter_count, &error); if (criteria == NULL) { EM_DEBUG_EXCEPTION("_make_criteria_to_search_filter failed"); goto FINISH_OFF; } - - event_data.type = EMAIL_EVENT_SEARCH_ON_SERVER; - event_data.account_id = input_account_id; - event_data.event_param_data_1 = EM_SAFE_STRDUP(criteria); - event_data.event_param_data_4 = input_mailbox_id; - if (!emcore_insert_event(&event_data, (int *)output_handle, &error)) { + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SEARCH_ON_SERVER; + event_data->account_id = input_account_id; + event_data->event_param_data_1 = EM_SAFE_STRDUP(criteria); + event_data->event_param_data_4 = input_mailbox_id; + + if (!emcore_insert_event(event_data, (int *)output_handle, &error)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", error); error = EMAIL_ERROR_NONE; goto FINISH_OFF; @@ -343,8 +352,10 @@ INTERNAL_FUNC int emdaemon_search_mail_on_server(int input_account_id, int input ret = true; FINISH_OFF: - if (!ret) { - EM_SAFE_FREE(event_data.event_param_data_1); + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); } EM_SAFE_FREE(criteria); @@ -361,9 +372,9 @@ INTERNAL_FUNC int emdaemon_reschedule_sending_mail() EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; char *conditional_clause_string = NULL; - email_list_filter_t filter_list[3]; + email_list_filter_t filter_list[7]; email_mail_list_item_t *result_mail_list = NULL; - int filter_rule_count = 3; + int filter_rule_count = 7; int result_mail_count = 0; int i = 0; @@ -377,10 +388,24 @@ INTERNAL_FUNC int emdaemon_reschedule_sending_mail() filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND; - filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; - filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS; - filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; - filter_list[2].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAIL_STATUS_SEND_SCHEDULED; + filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[2].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS; + + filter_list[3].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[3].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS; + filter_list[3].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[3].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAIL_STATUS_SEND_SCHEDULED; + + filter_list[4].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[4].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR; + + filter_list[5].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[5].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS; + filter_list[5].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[5].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAIL_STATUS_SEND_DELAYED; + + filter_list[6].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[6].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS; /* Get scheduled mail list */ if( (err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_rule_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) { @@ -442,5 +467,174 @@ INTERNAL_FUNC int emdaemon_clear_all_mail_data(int* err_code) EM_DEBUG_FUNC_END(); return ret; } - + +INTERNAL_FUNC int emdaemon_kill_daemon_if_no_account() +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + email_account_t *account_list = NULL; + int account_count = 0; + + if (!emcore_get_account_reference_list(&account_list, &account_count, &err)) { + EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err); + } + + EM_DEBUG_LOG("account_count [%d]", account_count); + + if (account_count == 0) { + EM_DEBUG_LOG("kill email-service daemon"); + exit(44); /* exit with exit code 44 to prevent restarting */ + } + + if(account_list) + emcore_free_account_list(&account_list, account_count, NULL); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +INTERNAL_FUNC int emdaemon_check_smack_rule(int app_sockfd, char *file_path) +{ + EM_DEBUG_FUNC_BEGIN_SEC("app_sockfd[%d], file_path[%s]", app_sockfd, file_path); + + if (app_sockfd <= 0 || !file_path) { + EM_DEBUG_LOG("Invalid parameter"); + return false; + } + + char *app_label = NULL; + char *file_label = NULL; + char *real_file_path = NULL; + int ret = 0; + int result = false; + + static int have_smack = -1; + + if (-1 == have_smack) { + if (NULL == smack_smackfs_path()) { + have_smack = 0; + } else { + have_smack = 1; + } + } + + if(!have_smack) { + EM_DEBUG_LOG("smack is disabled"); + result = true; + goto FINISH_OFF; + } + + /* Smack is enabled */ + + ret = smack_new_label_from_socket(app_sockfd, &app_label); + if (ret < 0) { + EM_DEBUG_LOG("smack_new_label_from_socket failed"); + result = false; + goto FINISH_OFF; + } + + real_file_path = realpath(file_path, NULL); + if (!real_file_path) { + EM_DEBUG_LOG("realpath failed"); + result = false; + goto FINISH_OFF; + } + + ret = smack_getlabel(real_file_path, &file_label, SMACK_LABEL_ACCESS); + if (ret < 0) { + EM_DEBUG_LOG("smack_getlabel failed"); + result = false; + goto FINISH_OFF; + } + + EM_DEBUG_LOG("APP_LABEL[%s], FILE_LABEL[%s]", app_label, file_label); + + ret = smack_have_access(app_label, file_label, "r"); + if (ret == 0) { + /* Access Denied */ + result = false; + goto FINISH_OFF; + } + + /* Access granted */ + result = true; + +FINISH_OFF: + + EM_SAFE_FREE(app_label); + EM_SAFE_FREE(file_label); + EM_SAFE_FREE(real_file_path); + + EM_DEBUG_FUNC_END(); + return result; +} + +INTERNAL_FUNC int emdaemon_set_smack_label(char *file_path, char *label) +{ + EM_DEBUG_FUNC_BEGIN(); + int ret = 0; + int result = true; + + if ((ret = smack_setlabel(file_path, label, SMACK_LABEL_ACCESS)) < 0) { + EM_DEBUG_LOG("smack_setlabel failed"); + result = false; + } + + EM_DEBUG_FUNC_END(); + return result; +} + +INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, int unread_mail_count, int *error) +{ + EM_DEBUG_FUNC_BEGIN("account_id [%d], total_mail_count [%d], unread_mail_count [%d], error [%p]", account_id, total_mail_count, unread_mail_count, error); + int err = EMAIL_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED; + int topmost = false; + + if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + + if (!emstorage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err)) + EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", err); + + /* Check the topmost of email app */ + if (vconf_get_int(VCONF_KEY_TOPMOST_WINDOW, &topmost) != 0) { + EM_DEBUG_EXCEPTION("vconf_get_int failed"); + } + + if (result_sync_status == SYNC_STATUS_SYNCING) { + if (topmost) { + EM_DEBUG_LOG("The email app is topmost"); + } else { + if ((err = emcore_add_notification(account_id, 0, total_mail_count, 0, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err); + } + } else if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) { + if (topmost) { + EM_DEBUG_LOG("The email app is topmost"); + } else { + + if ((err = emcore_add_notification(account_id, 0, total_mail_count, 1, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err); + +#ifdef __FEATURE_BLOCKING_MODE__ + emcore_set_blocking_mode_status(false); +#endif /* __FEATURE_BLOCKING_MODE__ */ + + if ((err = emcore_start_driving_mode(account_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err); + } + } + + if (!emcore_display_unread_in_badge()) + EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + + if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + } else { + EM_DEBUG_LOG("sync status : [%d]", result_sync_status); + } + + EM_DEBUG_FUNC_END(); + return ret; +} /* --------------------------------------------------------------------------------*/ diff --git a/email-daemon/email-daemon-init.c b/email-daemon/email-daemon-init.c index bb33235..c54aa02 100755 --- a/email-daemon/email-daemon-init.c +++ b/email-daemon/email-daemon-init.c @@ -38,27 +38,41 @@ #include <vconf.h> #include <vconf-internal-account-keys.h> #include <dbus/dbus.h> -#include <dlfcn.h> /* added for Disabling the Pthread flag log */ +#include <dlfcn.h> /* added for Disabling the Pthread flag log */ #include "email-daemon.h" #include "email-storage.h" #include "email-debug-log.h" +#include "email-daemon-init.h" #include "email-daemon-account.h" -#include "email-daemon-auto-poll.h" +#include "email-daemon-auto-poll.h" +#include "email-daemon-event.h" #include "email-core-utils.h" #include "email-core-mail.h" #include "email-core-event.h" -#include "email-core-account.h" -#include "email-core-mailbox.h" -#include "email-core-api.h" -#include "email-core-smtp.h" +#include "email-core-account.h" +#include "email-core-mailbox.h" +#include "email-core-smtp.h" #include "email-core-global.h" -#include "email-storage.h" +#include "email-storage.h" #include "email-core-sound.h" #include "email-core-task-manager.h" +#include "email-core-alarm.h" #include "email-daemon-emn.h" +#include "email-network.h" +#include "email-device.h" +#include "c-client.h" + +extern void * +pop3_parameters(long function, void *value); +extern void * +imap_parameters(long function, void *value); + +INTERNAL_FUNC int g_client_count = 0; +extern int blocking_mode_of_setting; +extern GList *alarm_data_list; -extern int g_client_count ; +static int default_alarm_callback(int input_timer_id, void *user_parameter); /* static functions */ static int _emdaemon_load_email_core() @@ -68,13 +82,13 @@ static int _emdaemon_load_email_core() int err = EMAIL_ERROR_NONE; /* initialize mail core */ - if (!emcore_init(&err)) + if (!emdaemon_core_init(&err)) goto FINISH_OFF; - if (emcore_start_event_loop(&err) < 0) + if (emdaemon_start_event_loop(&err) < 0) goto FINISH_OFF; - if (emcore_start_event_loop_for_sending_mails(&err) < 0) + if (emdaemon_start_event_loop_for_sending_mails(&err) < 0) goto FINISH_OFF; emcore_init_task_handler_array(); @@ -87,19 +101,16 @@ static int _emdaemon_load_email_core() */ #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ - if (emcore_start_thread_for_downloading_partial_body(&err) < 0) { + if (emdaemon_start_thread_for_downloading_partial_body(&err) < 0) { EM_DEBUG_EXCEPTION("emcore_start_thread_for_downloading_partial_body failed [%d]",err); goto FINISH_OFF; } #endif #ifdef __FEATURE_BLOCKING_MODE__ - emcore_init_blocking_mode_status(); + emdaemon_init_blocking_mode_status(); #endif /* __FEATURE_BLOCKING_MODE__ */ - if (emcore_start_thread_for_alerting_new_mails(&err) < 0) - goto FINISH_OFF; - FINISH_OFF: return err; @@ -148,7 +159,7 @@ static void callback_for_SYNC_ALL_STATUS_from_account_svc(keynode_t *input_node, EM_DEBUG_EXCEPTION("emdaemon_sync_header for [%d] failed [%d]", account_list[i].account_id, err); } - emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL); /* prevent 27459: remove unnecesary if clause */ + emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL); /* prevent 27459: remove unnecessary if clause */ mailbox_tbl_data = NULL; } else { @@ -314,6 +325,113 @@ static void callback_for_VCONFKEY_MSG_SERVER_READY(keynode_t *input_node, void * return; } +static void callback_for_VCONFKEY_GLOBAL_BADGE_STATUS(keynode_t *input_node, void *input_user_data) +{ + EM_DEBUG_FUNC_BEGIN(); + int noti_status = 0; + int err = EMAIL_ERROR_NONE; + int badge_ticker = 0; + + if (!input_node) { + EM_DEBUG_EXCEPTION("Invalid param"); + return; + } + + noti_status = vconf_keynode_get_bool(input_node); + + if (noti_status) { + if (!emcore_display_unread_in_badge()) + EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + } else { + if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_ticker) != 0) { + EM_DEBUG_EXCEPTION("vconf_get_bool failed"); + err = EMAIL_ERROR_GCONF_FAILURE; + goto FINISH_OFF; + } + /* if priority sender is on, show the priority sender unread */ + if (badge_ticker) { + if (!emcore_display_unread_in_badge()) + EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + goto FINISH_OFF; + } + + /* reset badge */ + if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); + } + +FINISH_OFF: + EM_DEBUG_FUNC_END(); +} + + +static void callback_for_VCONFKEY_PRIORITY_BADGE_STATUS(keynode_t *input_node, void *input_user_data) +{ + EM_DEBUG_FUNC_BEGIN(); + int noti_status = 0; + int err = EMAIL_ERROR_NONE; + int badge_ticker = 0; + + if (!input_node) { + EM_DEBUG_EXCEPTION("Invalid param"); + return; + } + + noti_status = vconf_keynode_get_bool(input_node); + + if (noti_status) { + if (!emcore_display_unread_in_badge()) + EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + } else { + + if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) { + EM_DEBUG_EXCEPTION("vconf_get_bool failed"); + err = EMAIL_ERROR_GCONF_FAILURE; + goto FINISH_OFF; + } + + /*if global badge is on, show the global unread*/ + if (badge_ticker) { + if (!emcore_display_unread_in_badge()) + EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + goto FINISH_OFF; + } + /* if all badges are off, reset badge count */ + if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); + } + +FINISH_OFF: + EM_DEBUG_FUNC_END(); +} + +static void callback_for_VCONFKEY_TELEPHONY_ZONE_TYPE(keynode_t *input_node, void *input_user_data) +{ + EM_DEBUG_FUNC_BEGIN(); + int telephony_zone = 0; + + if (!input_node) { + EM_DEBUG_EXCEPTION("Invalid param"); + return; + } + + telephony_zone = vconf_keynode_get_int(input_node); + + EM_DEBUG_LOG("telephony_zone [%d]", telephony_zone); + + /* + switch(telephony_zone) { + case VCONFKEY_TELEPHONY_ZONE_NONE : + case VCONFKEY_TELEPHONY_ZONE_HOME : + case VCONFKEY_TELEPHONY_ZONE_CITY : + default : + break; + } + */ + + EM_DEBUG_FUNC_END(); +} + INTERNAL_FUNC int emdaemon_initialize(int* err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -356,7 +474,7 @@ INTERNAL_FUNC int emdaemon_initialize(int* err_code) err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } - EM_DEBUG_LOG("emdaemon_initialize_account_reference over - g_client_count [%d]", g_client_count); + EM_DEBUG_LOG("emdaemon_initialize_account_reference over - g_client_count [%d]", g_client_count); if ((err = _emdaemon_load_email_core()) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_emdaemon_load_email_core failed [%d]", err); @@ -369,13 +487,27 @@ INTERNAL_FUNC int emdaemon_initialize(int* err_code) } #endif +#ifdef __FEATURE_AUTO_RETRY_SEND__ + if ((err = emcore_create_alarm_for_auto_resend (AUTO_RESEND_INTERVAL)) != EMAIL_ERROR_NONE) { + if (err == EMAIL_ERROR_MAIL_NOT_FOUND) + EM_DEBUG_LOG ("no mail found"); + else + EM_DEBUG_EXCEPTION("emcore_create_alarm_for_auto_resend failed [%d]", err); + } +#endif /* __FEATURE_AUTO_RETRY_SEND__ */ + /* Subscribe Events */ - vconf_notify_key_changed(VCONFKEY_ACCOUNT_SYNC_ALL_STATUS_INT, callback_for_SYNC_ALL_STATUS_from_account_svc, NULL); - vconf_notify_key_changed(VCONFKEY_ACCOUNT_AUTO_SYNC_STATUS_INT, callback_for_AUTO_SYNC_STATUS_from_account_svc, NULL); + vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS, callback_for_NETWORK_STATUS, NULL); #ifdef __FEATURE_BLOCKING_MODE__ - vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS, callback_for_BLOCKING_MODE_STATUS, NULL); + vconf_notify_key_changed(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, callback_for_BLOCKING_MODE_STATUS, NULL); #endif + vconf_notify_key_changed(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, callback_for_VCONFKEY_GLOBAL_BADGE_STATUS, NULL); + + vconf_notify_key_changed(VCONF_VIP_NOTI_BADGE_TICKER, callback_for_VCONFKEY_PRIORITY_BADGE_STATUS, NULL); + /* VCONFKEY_TELEPHONY_SVC_ROAM */ + /*vconf_notify_key_changed(VCONFKEY_TELEPHONY_ZONE_TYPE, callback_for_VCONFKEY_TELEPHONY_ZONE_TYPE, NULL);*/ + emcore_display_unread_in_badge(); ret = true; @@ -449,8 +581,8 @@ INTERNAL_FUNC int emdaemon_start_auto_polling(int* err_code) for (i = 0; i < count; i++) { /* start auto polling, if check_interval not zero */ - if(account_list[i].check_interval > 0) { - if(!emdaemon_add_polling_alarm( account_list[i].account_id,account_list[i].check_interval)) + if(account_list[i].check_interval > 0 || (account_list[i].peak_days && account_list[i].peak_interval > 0)) { + if(!emdaemon_add_polling_alarm( account_list[i].account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm failed"); } } @@ -463,7 +595,128 @@ FINISH_OFF: if (err_code != NULL) *err_code = err; + EM_DEBUG_FUNC_END("ret[%d]", ret); return ret; } #endif /* __FEATURE_AUTO_POLLING__ */ +/* initialize mail core */ +INTERNAL_FUNC int emdaemon_core_init(int *err_code) +{ + EM_DEBUG_FUNC_BEGIN(); + + if (err_code != NULL) { + *err_code = EMAIL_ERROR_NONE; + } + + mail_link(&imapdriver); /* link in the imap driver */ + mail_link(&pop3driver); /* link in the pop3 driver */ + + mail_link(&unixdriver); /* link in the unix driver */ + mail_link(&dummydriver); /* link in the dummy driver */ + + ssl_onceonlyinit(); + + auth_link(&auth_xoauth2); /* link in the xoauth2 authenticator */ + auth_link(&auth_md5); /* link in the md5 authenticator */ + auth_link(&auth_pla); /* link in the pla authenticator */ + auth_link(&auth_log); /* link in the log authenticator */ + + /* Disabled to authenticate with plain text */ + mail_parameters(NIL, SET_DISABLEPLAINTEXT, (void *) 2); + + /* Set max trials for login */ + imap_parameters(SET_MAXLOGINTRIALS, (void *)3); + pop3_parameters(SET_MAXLOGINTRIALS, (void *)3); + smtp_parameters(SET_MAXLOGINTRIALS, (void *)3); + + mail_parameters(NIL, SET_SSLCERTIFICATEQUERY, (void *)emnetwork_callback_ssl_cert_query); + mail_parameters(NIL, SET_SSLCAPATH, (void *)SSL_CERT_DIRECTORY); + + /* Set time out in second */ + mail_parameters(NIL, SET_OPENTIMEOUT , (void *)50); + mail_parameters(NIL, SET_READTIMEOUT , (void *)180); + mail_parameters(NIL, SET_WRITETIMEOUT , (void *)180); + mail_parameters(NIL, SET_CLOSETIMEOUT , (void *)30); + + emdaemon_init_alarm_data_list(); + + if (err_code) + *err_code = EMAIL_ERROR_NONE; + + return true; +} + +#ifdef __FEATURE_BLOCKING_MODE__ +INTERNAL_FUNC bool emdaemon_init_blocking_mode_status() +{ + EM_DEBUG_FUNC_BEGIN("blocking_mode_of_setting : [%d]", blocking_mode_of_setting); + + /*if (vconf_get_bool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &blocking_mode_of_setting) != 0) { + EM_DEBUG_EXCEPTION("vconf_get_bool failed"); + return false; + }*/ + + EM_DEBUG_FUNC_END(); + return false; +} +#endif + +INTERNAL_FUNC int emdaemon_init_alarm_data_list() +{ + EM_DEBUG_FUNC_BEGIN(); + int ret = ALARMMGR_RESULT_SUCCESS; + int err = EMAIL_ERROR_NONE; + alarm_data_list = NULL; + + if ((ret = alarmmgr_init(EMAIL_ALARM_DESTINATION)) != ALARMMGR_RESULT_SUCCESS) { + EM_DEBUG_EXCEPTION("alarmmgr_init failed [%d]",ret); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + if ((ret = alarmmgr_set_cb(default_alarm_callback, NULL)) != ALARMMGR_RESULT_SUCCESS) { + EM_DEBUG_EXCEPTION("alarmmgr_set_cb() failed [%d]", ret); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +static int default_alarm_callback(int input_timer_id, void *user_parameter) +{ + EM_DEBUG_FUNC_BEGIN("input_timer_id [%d] user_parameter [%p]", input_timer_id, user_parameter); + int err = EMAIL_ERROR_NONE; + email_alarm_data_t *alarm_data = NULL; + + EM_DEBUG_ALARM_LOG("default_alarm_callback input_timer_id[%d]", input_timer_id); + + emdevice_set_sleep_on_off(false, NULL); + + if ((err = emcore_get_alarm_data_by_alarm_id(input_timer_id, &alarm_data)) != EMAIL_ERROR_NONE || alarm_data == NULL) { + EM_DEBUG_EXCEPTION("emcore_get_alarm_data_by_alarm_id failed [%d]", err); + goto FINISH_OFF; + } + + if ((err = alarm_data->alarm_callback(input_timer_id, user_parameter)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("alarm_callback failed [%d]", err); + goto FINISH_OFF; + } + + emcore_delete_alram_data_from_alarm_data_list(alarm_data); + EM_SAFE_FREE(alarm_data); + +FINISH_OFF: + + if(err != EMAIL_ERROR_NONE) { + emdevice_set_sleep_on_off(true, NULL); + } + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + diff --git a/email-daemon/email-daemon-mail.c b/email-daemon/email-daemon-mail.c index 4ed1b6a..f422ac5 100755 --- a/email-daemon/email-daemon-mail.c +++ b/email-daemon/email-daemon-mail.c @@ -67,7 +67,7 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) int ret = false, err = EMAIL_ERROR_NONE, err_2 = EMAIL_ERROR_NONE; int result_handle = 0, account_id = 0; - email_event_t event_data = { 0, }; + email_event_t *event_data = NULL; emstorage_mail_tbl_t* mail_table_data = NULL; emstorage_mailbox_tbl_t* local_mailbox = NULL; email_account_t* ref_account = NULL; @@ -130,12 +130,13 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) goto FINISH_OFF; } - event_data.type = EMAIL_EVENT_SEND_MAIL; - event_data.account_id = account_id; - event_data.event_param_data_4 = mail_id; - event_data.event_param_data_5 = mail_table_data->mailbox_id; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SEND_MAIL; + event_data->account_id = account_id; + event_data->event_param_data_4 = mail_id; + event_data->event_param_data_5 = mail_table_data->mailbox_id; - if (!emcore_insert_event_for_sending_mails(&event_data, &result_handle, &err)) { + if (!emcore_insert_event_for_sending_mails(event_data, &result_handle, &err)) { EM_DEBUG_EXCEPTION(" emcore_insert_event failed [%d]", err); goto FINISH_OFF; } @@ -157,7 +158,10 @@ FINISH_OFF: if(!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", EMAIL_MAIL_STATUS_SAVED, true, &err)) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value [%d]",err); - EM_SAFE_FREE(event_data.event_param_data_3); + if (event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } } if (ref_account) { @@ -187,11 +191,11 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err int ret = false; int err = EMAIL_ERROR_NONE; - email_event_t event_data = { 0 , }; - email_account_t* ref_account = NULL; + email_event_t *event_data = NULL; + email_account_t *ref_account = NULL; char *mailbox_name = NULL; - if (account_id <= 0) { + if (account_id <= 0) { EM_DEBUG_EXCEPTION("account_id = %d", account_id); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -199,22 +203,23 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err ref_account = emcore_get_account_reference(account_id); - if (!ref_account) { + if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - if (!emstorage_get_mailbox_name_by_mailbox_type(account_id,EMAIL_MAILBOX_TYPE_OUTBOX,&mailbox_name, false, &err)) { + if (!emstorage_get_mailbox_name_by_mailbox_type(account_id,EMAIL_MAILBOX_TYPE_OUTBOX,&mailbox_name, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } - event_data.type = EMAIL_EVENT_SEND_MAIL_SAVED; - event_data.account_id = account_id; - event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox_name); + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SEND_MAIL_SAVED; + event_data->account_id = account_id; + event_data->event_param_data_3 = EM_SAFE_STRDUP(mailbox_name); - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } @@ -222,8 +227,10 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err ret = true; FINISH_OFF: - if (ret == false) { - EM_SAFE_FREE(event_data.event_param_data_3); + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); } if (ref_account) { @@ -244,10 +251,11 @@ INTERNAL_FUNC int emdaemon_add_mail(email_mail_data_t *input_mail_data, email_at { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_req [%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas); - int err = EMAIL_ERROR_NONE; - int handle = 0; - email_event_t event_data = { 0 }; - email_account_t* ref_account = NULL; + int ret = false; + int err = EMAIL_ERROR_NONE; + int handle = 0; + email_event_t *event_data = NULL; + email_account_t *ref_account = NULL; if (!input_mail_data || input_mail_data->account_id <= 0 || ( ((input_mail_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0) && !input_mail_data->full_address_to)) { @@ -263,32 +271,41 @@ INTERNAL_FUNC int emdaemon_add_mail(email_mail_data_t *input_mail_data, email_at goto FINISH_OFF; } - if ((err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) { + if ((err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas, false)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err); goto FINISH_OFF; } #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ if ( input_from_eas == 0 && ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { - event_data.type = EMAIL_EVENT_SAVE_MAIL; - event_data.account_id = input_mail_data->account_id; - event_data.event_param_data_4 = input_mail_data->mail_id; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SAVE_MAIL; + event_data->account_id = input_mail_data->account_id; + event_data->event_param_data_4 = input_mail_data->mail_id; - if (!emcore_insert_event(&event_data, &handle, &err)) { + if (!emcore_insert_event(event_data, &handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } } #endif + ret = true; + FINISH_OFF: + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); } EM_DEBUG_FUNC_END("err [%d]", err); + return err; } @@ -327,30 +344,27 @@ INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbos { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], verbose[%d], with_attachment[%d], handle[%p], err_code[%p]", account_id, mail_id, verbose, with_attachment, handle, err_code); - /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; -/* mpNewMail_StopAlertSound(); */ + email_event_t *event_data = NULL; - if (!_emdaemon_check_mail_id(mail_id, &err)) { + if (!_emdaemon_check_mail_id(mail_id, &err)) { EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err); goto FINISH_OFF; } - email_event_t event_data; - - memset(&event_data, 0x00, sizeof(email_event_t)); - - event_data.type = EMAIL_EVENT_DOWNLOAD_BODY; - event_data.event_param_data_4 = mail_id; - event_data.account_id = account_id; - event_data.event_param_data_3 = GINT_TO_POINTER(verbose << 1 | with_attachment); + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_DOWNLOAD_BODY; + event_data->account_id = account_id; + event_data->event_param_data_4 = mail_id; + event_data->event_param_data_5 = (verbose << 1 | with_attachment); - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } + #ifdef __FEATURE_LOCAL_ACTIVITY__ EM_DEBUG_LOG("Setting g_local_activity_run "); g_local_activity_run = 1; @@ -358,9 +372,17 @@ INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbos ret = true; FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -386,9 +408,12 @@ int emdaemon_get_attachment(int attachment_id, email_attachment_data_t** attachm ret = true; FINISH_OFF: + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -411,17 +436,20 @@ int emdaemon_add_attachment(int mail_id, email_attachment_data_t* attachment, in goto FINISH_OFF; } - if (!emcore_mail_add_attachment(mail_id, attachment, &err)) { - EM_DEBUG_EXCEPTION(" emcore_mail_add_attachment failed [%d]", err); + if (!emcore_add_attachment(mail_id, attachment, &err)) { + EM_DEBUG_EXCEPTION(" emcore_add_attachment failed [%d]", err); goto FINISH_OFF; } ret = true; FINISH_OFF: + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -447,9 +475,12 @@ int emdaemon_delete_mail_attachment(int attachment_id, int* err_code) ret = true; FINISH_OFF: + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -459,28 +490,26 @@ INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int int ret = false; int err = EMAIL_ERROR_NONE; + email_event_t *event_data = NULL; - if (!nth) { + if (!nth) { EM_DEBUG_EXCEPTION("nth[%p] is invalid", nth); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (!_emdaemon_check_mail_id(mail_id, &err)) { + if (!_emdaemon_check_mail_id(mail_id, &err)) { EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err); goto FINISH_OFF; } - email_event_t event_data; - - memset(&event_data, 0x00, sizeof(email_event_t)); + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_DOWNLOAD_ATTACHMENT; + event_data->account_id = account_id; + event_data->event_param_data_4 = mail_id; + event_data->event_param_data_5 = nth; - event_data.type = EMAIL_EVENT_DOWNLOAD_ATTACHMENT; - event_data.account_id = account_id; - event_data.event_param_data_4 = mail_id; - event_data.event_param_data_5 = nth; - - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } @@ -493,9 +522,17 @@ INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int ret = true; FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; } @@ -524,23 +561,29 @@ void* thread_func_to_delete_mail(void *thread_argument) if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_COMMAND, noti_param_2, &err)) { EM_DEBUG_EXCEPTION(" emcore_delete_mail failed [%d]", err); + emcore_free_event(event_data); /* prevent 17922 */ + EM_SAFE_FREE(event_data); goto FINISH_OFF; } if (from_server == EMAIL_DELETE_LOCAL_AND_SERVER || from_server == EMAIL_DELETE_FROM_SERVER) { if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); +/* if (from_server != EMAIL_DELETE_LOCAL_AND_SERVER && from_server != EMAIL_DELETE_FROM_SERVER) { + EM_SAFE_FREE(event_data->event_param_data_3); + } */ + emcore_free_event(event_data); /* prevent 17922 */ + EM_SAFE_FREE(event_data); goto FINISH_OFF; } } + else { + emcore_free_event(event_data); /* prevent 17922 */ + EM_SAFE_FREE(event_data); + } FINISH_OFF: - /* all of members will be freed after using in each event handler */ - - if (from_server != EMAIL_DELETE_LOCAL_AND_SERVER && from_server != EMAIL_DELETE_FROM_SERVER) { - EM_SAFE_FREE(event_data->event_param_data_3); - } - EM_SAFE_FREE(event_data); + /* Don't free event_data as if the data is destined to be passed to event handler through emcore_insert_event.*/ EM_DEBUG_FUNC_END(); return SUCCESS; @@ -632,10 +675,10 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o { EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_from_server[%d], handle[%p], err_code[%p]", input_mailbox_id, input_from_server, output_handle, output_err_code); - int ret = false; - int err = EMAIL_ERROR_NONE; + int ret = false; + int err = EMAIL_ERROR_NONE; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; - email_event_t event_data = { 0 }; + email_event_t *event_data = NULL; if (!input_mailbox_id) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -655,12 +698,13 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ if(input_from_server == EMAIL_DELETE_LOCAL_AND_SERVER || input_from_server == EMAIL_DELETE_FROM_SERVER) { - event_data.type = EMAIL_EVENT_DELETE_MAIL_ALL; - event_data.account_id = mailbox_tbl->account_id; - event_data.event_param_data_4 = input_mailbox_id; - event_data.event_param_data_5 = input_from_server; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_DELETE_MAIL_ALL; + event_data->account_id = mailbox_tbl->account_id; + event_data->event_param_data_4 = input_mailbox_id; + event_data->event_param_data_5 = input_from_server; - if (!emcore_insert_event(&event_data, (int*)output_handle, &err)) { + if (!emcore_insert_event(event_data, (int*)output_handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } @@ -724,6 +768,11 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o FINISH_OFF: + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (mailbox_tbl) emstorage_free_mailbox(&mailbox_tbl, 1, NULL); @@ -736,11 +785,19 @@ FINISH_OFF: void* thread_func_to_move_mail(void *thread_argument) { EM_DEBUG_FUNC_BEGIN(); + + int ret = false; int *mail_ids = NULL, mail_ids_count, noti_param_1, noti_param_2, err; int handle = 0; email_event_t *event_data = (email_event_t*)thread_argument; int dst_mailbox_id = 0; + if(!event_data) { /*prevent 53096*/ + EM_DEBUG_EXCEPTION("INVALID_PARMAETER"); + return NULL; + } + + /* dst_mailbox_name = (char*)event_data->event_param_data_1; */ /*prevent 33693*/ mail_ids = (int*)event_data->event_param_data_3; mail_ids_count = event_data->event_param_data_4; @@ -759,9 +816,14 @@ void* thread_func_to_move_mail(void *thread_argument) goto FINISH_OFF; } + ret = true; + FINISH_OFF: - /* emcore_free_event(event_data); */ /* all of members will be freed after using in each event handler */ - EM_SAFE_FREE(event_data); + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } EM_DEBUG_FUNC_END(); return SUCCESS; @@ -1033,10 +1095,13 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int onserver, int* err_code) { - EM_DEBUG_FUNC_BEGIN("mail_ids[%d], num[%d], field_type [%d], value[%d], err_code[%p]", mail_ids[0], num, field_type, value, err_code); + EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d], field_type [%d], value[%d], err_code[%p]", mail_ids, num, field_type, value, err_code); /*prevent 27460*/ int ret = false, err = EMAIL_ERROR_NONE; emstorage_account_tbl_t *account_tbl = NULL; + int *mail_id_array = NULL; + email_event_t *event_data = NULL; + int handle = 0; if(account_id <= 0 || !mail_ids || num <= 0) { err = EMAIL_ERROR_INVALID_PARAM; @@ -1054,30 +1119,27 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n goto FINISH_OFF; } - if( onserver && account_tbl->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 ) { - int *mail_id_array = NULL; - email_event_t event_data = {0}; - int handle = 0; - + if( onserver && account_tbl->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 ) { mail_id_array = em_malloc(sizeof(int) * num); if (mail_id_array == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; } memcpy(mail_id_array, mail_ids, sizeof(int) * num); - event_data.type = EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER; - event_data.account_id = account_id; - event_data.event_param_data_1 = NULL; - event_data.event_param_data_3 = (char*)mail_id_array; - event_data.event_param_data_4 = num; - event_data.event_param_data_5 = field_type; - event_data.event_param_data_6 = value; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER; + event_data->account_id = account_id; + event_data->event_param_data_1 = NULL; + event_data->event_param_data_3 = (char*)mail_id_array; + event_data->event_param_data_4 = num; + event_data->event_param_data_5 = field_type; + event_data->event_param_data_6 = value; - if (!emcore_insert_event(&event_data, (int*)&handle, &err)) { + if (!emcore_insert_event(event_data, (int*)&handle, &err)) { EM_DEBUG_LOG("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } @@ -1087,6 +1149,11 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n FINISH_OFF: + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (account_tbl) emstorage_free_account(&account_tbl, 1, NULL); @@ -1101,9 +1168,9 @@ INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_req [%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas); - int err = EMAIL_ERROR_NONE; - int handle = 0; - email_event_t event_data = { 0 }; + int ret = false; + int err = EMAIL_ERROR_NONE; + /*email_event_t *event_data = NULL;*/ email_account_t *ref_account = NULL; if (!input_mail_data || input_mail_data->account_id <= 0 || input_mail_data->mail_id == 0 || @@ -1126,25 +1193,35 @@ INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email } #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ - if ( input_from_eas == 0) { - event_data.type = EMAIL_EVENT_UPDATE_MAIL; - event_data.account_id = input_mail_data->account_id; - event_data.event_param_data_1 = (char*)input_mail_data; - event_data.event_param_data_2 = (char*)input_attachment_data_list; - event_data.event_param_data_3 = (char*)input_meeting_request; - event_data.event_param_data_4 = input_attachment_count; - event_data.event_param_data_5 = input_from_eas; - - if (!emcore_insert_event(&event_data, &handle, &err)) { +/* if ( input_from_eas == 0) { + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_UPDATE_MAIL; + event_data->account_id = input_mail_data->account_id; + event_data->event_param_data_1 = (char*)input_mail_data; // need to be duplicated, it is double freed + event_data->event_param_data_2 = (char*)input_attachment_data_list; // need to be duplicated, it is double freed + event_data->event_param_data_3 = (char*)input_meeting_request; // need to be duplicated, it is double freed + event_data->event_param_data_4 = input_attachment_count; + event_data->event_param_data_5 = input_from_eas; + + if (!emcore_insert_event(event_data, &handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event_for_sending_mails failed [%d]", err); err = EMAIL_ERROR_NONE; goto FINISH_OFF; } } +*/ #endif + ret = true; + FINISH_OFF: +/*prevent 64298*/ +/* if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } +*/ if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); @@ -1289,7 +1366,7 @@ INTERNAL_FUNC int emdaemon_move_mail_thread_to_mailbox(int thread_id, int target } for(i = 0; i < mailbox_count; i++) { - EM_DEBUG_LOG("%s %d", target_mailbox_list[i].mailbox_name, target_mailbox_id); + EM_DEBUG_LOG_SEC("%s %d", target_mailbox_list[i].mailbox_name, target_mailbox_id); if(target_mailbox_list[i].mailbox_id == target_mailbox_id) { target_mailbox = (target_mailbox_list + i); break; @@ -1301,10 +1378,12 @@ INTERNAL_FUNC int emdaemon_move_mail_thread_to_mailbox(int thread_id, int target goto FINISH_OFF; } +/* if (!emdaemon_move_mail(mail_id_list, result_count, target_mailbox->mailbox_id, EMAIL_MOVED_BY_MOVING_THREAD, move_always_flag, &err)) { EM_DEBUG_EXCEPTION("emdaemon_move_mail failed [%d]", err); goto FINISH_OFF; } +*/ SNPRINTF(mailbox_id_param_string, 10, "%d", target_mailbox->mailbox_id); if (!emcore_notify_storage_event(NOTI_THREAD_MOVE, account_id, thread_id, mailbox_id_param_string, move_always_flag)) @@ -1426,10 +1505,12 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle) { EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_on_server [%d], output_handle [%p]", input_mailbox_id, input_on_server, output_handle); - int err = EMAIL_ERROR_NONE; - int handle = 0; - email_event_t event_data = { 0 }; - email_account_t *ref_account = NULL; + int ret = false; + int err = EMAIL_ERROR_NONE; + int handle = 0; + int event_insert = false; + email_event_t *event_data = NULL; + email_account_t *ref_account = NULL; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; if (input_mailbox_id <= 0) { @@ -1452,14 +1533,16 @@ INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, i #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ if(input_on_server) { - event_data.type = EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED; - event_data.account_id = mailbox_tbl->account_id; - event_data.event_param_data_4 = input_mailbox_id; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED; + event_data->account_id = mailbox_tbl->account_id; + event_data->event_param_data_4 = input_mailbox_id; - if (!emcore_insert_event(&event_data, &handle, &err)) { + if (!emcore_insert_event(event_data, &handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } + event_insert = true; } else #endif @@ -1468,8 +1551,15 @@ INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, i goto FINISH_OFF; } + ret = true; + FINISH_OFF: + if (event_insert == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); diff --git a/email-daemon/email-daemon-mailbox.c b/email-daemon/email-daemon-mailbox.c index d71f8e5..86926f9 100755 --- a/email-daemon/email-daemon-mailbox.c +++ b/email-daemon/email-daemon-mailbox.c @@ -42,6 +42,8 @@ #include "email-core-account.h" #include "email-core-global.h" #include "email-core-utils.h" +#include "email-core-signal.h" +#include "email-utilities.h" #ifdef __FEATURE_LOCAL_ACTIVITY__ extern int g_local_activity_run; @@ -51,10 +53,10 @@ INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, { EM_DEBUG_FUNC_BEGIN("account_id[%d] mailbox[%p] err_code[%p]", account_id, mailbox, err_code); - /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - email_account_t* ref_account = NULL; + email_account_t *ref_account = NULL; + email_event_t *event_data = NULL; if (account_id <= 0 ||!mailbox) { EM_DEBUG_EXCEPTION("account_id[%d], mailbox[%p]", account_id, mailbox); @@ -64,20 +66,18 @@ INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, ref_account = emcore_get_account_reference(account_id); - if (!ref_account) { + if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - email_event_t event_data; - memset(&event_data, 0x00, sizeof(email_event_t)); - - event_data.type = EMAIL_EVENT_SYNC_IMAP_MAILBOX; - event_data.account_id = account_id; - event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox); + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SYNC_IMAP_MAILBOX; + event_data->account_id = account_id; + event_data->event_param_data_3 = EM_SAFE_STRDUP(mailbox); - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } @@ -86,6 +86,11 @@ INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, FINISH_OFF: + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); @@ -187,11 +192,13 @@ INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_serv { EM_DEBUG_FUNC_BEGIN("new_mailbox[%p], err_code[%p]", new_mailbox, err_code); - int ret = false;; + int ret = false; int err = EMAIL_ERROR_NONE; - email_account_t* ref_account = NULL; + email_account_t *ref_account = NULL; + email_event_t *event_data = NULL; + email_mailbox_t *mailbox = NULL; - if (!new_mailbox || new_mailbox->account_id <= 0 || !new_mailbox->mailbox_name) { + if (!new_mailbox || new_mailbox->account_id <= 0 || !new_mailbox->mailbox_name) { if (new_mailbox != NULL) EM_DEBUG_EXCEPTION("new_mailbox->account_id[%d], new_mailbox->mailbox_name[%p]", new_mailbox->account_id, new_mailbox->mailbox_name); err = EMAIL_ERROR_INVALID_PARAM; @@ -206,27 +213,45 @@ INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_serv goto FINISH_OFF; } - email_event_t event_data; - memset(&event_data, 0x00, sizeof(email_event_t)); - - /* on_server is allowed to be only 0 when server_type is EMAIL_SERVER_TYPE_ACTIVE_SYNC */ if ( ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) on_server = 0; - if ( on_server ) { /* async */ - event_data.type = EMAIL_EVENT_CREATE_MAILBOX; - event_data.account_id = new_mailbox->account_id; - event_data.event_param_data_1 = EM_SAFE_STRDUP(new_mailbox->mailbox_name); - event_data.event_param_data_2 = EM_SAFE_STRDUP(new_mailbox->alias); - event_data.event_param_data_4 = on_server; - event_data.event_param_data_3 = GINT_TO_POINTER(new_mailbox->mailbox_type); - if(!emcore_insert_event(&event_data, (int*)handle, &err)) { + if ( on_server ) { /* async */ + + mailbox = em_malloc(sizeof(email_mailbox_t)); + + if(mailbox == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + memcpy(mailbox, new_mailbox, sizeof(email_mailbox_t)); + mailbox->mailbox_name = EM_SAFE_STRDUP(new_mailbox->mailbox_name); + mailbox->alias = EM_SAFE_STRDUP(new_mailbox->alias); + + if(new_mailbox->eas_data_length > 0 && new_mailbox->eas_data) { + mailbox->eas_data = em_malloc(new_mailbox->eas_data_length); + if(mailbox->eas_data == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + memcpy(mailbox->eas_data, new_mailbox->eas_data, new_mailbox->eas_data_length); + } + + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_CREATE_MAILBOX; + event_data->account_id = new_mailbox->account_id; + event_data->event_param_data_1 = (char*)mailbox; + event_data->event_param_data_4 = on_server; + + if(!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } - } - else { /* sync */ + } else { /* sync */ if (!emcore_create_mailbox(new_mailbox, on_server, &err)) { EM_DEBUG_EXCEPTION("emcore_create failed [%d]", err); goto FINISH_OFF; @@ -237,6 +262,17 @@ INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_serv FINISH_OFF: + if (ret == false) { + if(event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if(mailbox) { + emcore_free_mailbox(mailbox); + EM_SAFE_FREE(mailbox); + } + } + if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); @@ -267,7 +303,7 @@ INTERNAL_FUNC int emdaemon_set_mailbox_type(int input_mailbox_id, email_mailbox_ goto FINISH_OFF; } - if (!emstorage_update_mailbox_type(mailbox_tbl->account_id, -1, mailbox_tbl->mailbox_name, input_mailbox_type, true, &err)) { + if (!emstorage_update_mailbox_type(mailbox_tbl->account_id, -1, input_mailbox_id, input_mailbox_type, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_mailbox failed [%d]", err); goto FINISH_OFF; } @@ -310,19 +346,19 @@ INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, i { EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], err_code[%p]", input_mailbox_id, err_code); - /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; int recursive = 1; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; - email_account_t* ref_account = NULL; + email_account_t *ref_account = NULL; + email_event_t *event_data = NULL; if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); goto FINISH_OFF; } - if (!input_mailbox_id || mailbox_tbl->account_id <= 0) { + if (!input_mailbox_id || mailbox_tbl->account_id <= 0) { if (input_mailbox_id != 0) EM_DEBUG_EXCEPTION("mailbox_tbl->account_id[%d]", mailbox_tbl->account_id); err = EMAIL_ERROR_INVALID_PARAM; @@ -331,33 +367,29 @@ INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, i ref_account = emcore_get_account_reference(mailbox_tbl->account_id); - if (!ref_account) { + if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", mailbox_tbl->account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - email_event_t event_data; - memset(&event_data, 0x00, sizeof(email_event_t)); - /* on_server is allowed to be only 0 when server_type is EMAIL_SERVER_TYPE_ACTIVE_SYNC */ if ( ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) { on_server = 0; - recursive = 0; } if ( on_server ) { /* async */ - event_data.type = EMAIL_EVENT_DELETE_MAILBOX; - event_data.account_id = mailbox_tbl->account_id; - event_data.event_param_data_4 = input_mailbox_id; - event_data.event_param_data_5 = on_server; - event_data.event_param_data_6 = recursive; - if(!emcore_insert_event(&event_data, (int*)handle, &err)) { + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_DELETE_MAILBOX; + event_data->account_id = mailbox_tbl->account_id; + event_data->event_param_data_4 = input_mailbox_id; + event_data->event_param_data_5 = on_server; + event_data->event_param_data_6 = recursive; + if(!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } - } - else { + } else { if (!emcore_delete_mailbox(input_mailbox_id, on_server, recursive)) { EM_DEBUG_EXCEPTION("emcore_delete failed [%d]", err); goto FINISH_OFF; @@ -368,6 +400,11 @@ INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, i FINISH_OFF: + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); @@ -432,49 +469,58 @@ INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_i { EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mailbox_id[%d], handle[%p], err_code[%p]", input_account_id, input_mailbox_id, handle, err_code); - /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; + email_event_t *event_data = NULL; - email_event_t event_data; - - memset(&event_data, 0x00, sizeof(email_event_t)); - - if (input_mailbox_id < 0) { + if (input_mailbox_id < 0 || handle == NULL) { EM_DEBUG_EXCEPTION("parameter is invalid"); - err = EMAIL_ERROR_INVALID_ACCOUNT; + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } + event_data = em_malloc(sizeof(email_event_t)); + if(input_account_id == ALL_ACCOUNT) { - EM_DEBUG_LOG(">>>> emdaemon_sync_header for all account event_data.event_param_data_4 [%d]", event_data.event_param_data_4); - event_data.type = EMAIL_EVENT_SYNC_HEADER; - event_data.account_id = input_account_id; - event_data.event_param_data_5 = input_mailbox_id; + EM_DEBUG_LOG(">>>> emdaemon_sync_header for all account event_data.event_param_data_4 [%d]", event_data->event_param_data_4); + event_data->type = EMAIL_EVENT_SYNC_HEADER; + event_data->account_id = input_account_id; + event_data->event_param_data_5 = input_mailbox_id; /* In case of Mailbox NULL, we need to set arg as EMAIL_SYNC_ALL_MAILBOX */ if (input_mailbox_id == 0) - event_data.event_param_data_4 = EMAIL_SYNC_ALL_MAILBOX; + event_data->event_param_data_4 = EMAIL_SYNC_ALL_MAILBOX; - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } } else { /* Modified the code to sync all mailbox in a Single Event */ - event_data.type = EMAIL_EVENT_SYNC_HEADER; - event_data.account_id = input_account_id; - event_data.event_param_data_5 = input_mailbox_id; + event_data->type = EMAIL_EVENT_SYNC_HEADER; + event_data->account_id = input_account_id; + event_data->event_param_data_5 = input_mailbox_id; /* In case of Mailbox NULL, we need to set arg as EMAIL_SYNC_ALL_MAILBOX */ if (input_mailbox_id == 0) - event_data.event_param_data_4 = EMAIL_SYNC_ALL_MAILBOX; - EM_DEBUG_LOG(">>>> EVENT ARG [ %d ] ", event_data.event_param_data_4); + event_data->event_param_data_4 = EMAIL_SYNC_ALL_MAILBOX; + EM_DEBUG_LOG(">>>> EVENT ARG [ %d ] ", event_data->event_param_data_4); - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } } + /* Due to fast response, event noti is moved here from worker_event_queue */ + char input_mailbox_id_str[10] = {0}; + snprintf(input_mailbox_id_str, 10, "%d ", input_mailbox_id); + if (!emcore_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, ((input_mailbox_id==0)? NULL:input_mailbox_id_str), *handle, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_START] Failed >>>> "); + +/* 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); +*/ + + #ifdef __FEATURE_LOCAL_ACTIVITY__ EM_DEBUG_LOG("Setting g_local_activity_run "); g_local_activity_run = 1; @@ -484,6 +530,11 @@ INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_i FINISH_OFF: + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); @@ -496,7 +547,7 @@ INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mai int ret = false; int err = EMAIL_ERROR_NONE; - email_event_t event_data; + email_event_t *event_data = NULL; if(handle == NULL) { EM_DEBUG_EXCEPTION("handle is required"); @@ -504,14 +555,13 @@ INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mai goto FINISH_OFF; } - memset(&event_data, 0x00, sizeof(email_event_t)); - - event_data.type = EMAIL_EVENT_SET_MAIL_SLOT_SIZE; - event_data.account_id = account_id; - event_data.event_param_data_4 = mailbox_id; - event_data.event_param_data_5 = new_slot_size; + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_SET_MAIL_SLOT_SIZE; + event_data->account_id = account_id; + event_data->event_param_data_4 = mailbox_id; + event_data->event_param_data_5 = new_slot_size; - if (!emcore_insert_event(&event_data, (int*)handle, &err)) { + if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } @@ -519,20 +569,27 @@ INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mai ret = true; FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); return ret; } -INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, int input_on_server, int *output_handle) +INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int *output_handle) { - EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_path [%p], input_mailbox_alias[%p], input_on_server [%d], output_handle[%p]", input_mailbox_id, input_mailbox_path, input_mailbox_alias, input_on_server, output_handle); + EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_mailbox_path[%p] input_mailbox_alias[%p] input_eas_data[%p] input_eas_data_length[%d] input_on_server[%d] output_handle[%p]", input_mailbox_id, input_mailbox_path, input_mailbox_alias, input_eas_data, input_eas_data_length, input_on_server, output_handle); + int ret = false; int err = EMAIL_ERROR_NONE; emstorage_account_tbl_t *account_data = NULL; emstorage_mailbox_tbl_t *old_mailbox_data = NULL; - email_event_t event_data; + email_event_t *event_data = NULL; if(input_mailbox_id <= 0 || output_handle == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -552,29 +609,35 @@ INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mail } if (account_data->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { - memset(&event_data, 0x00, sizeof(email_event_t)); - - event_data.type = EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER; - event_data.event_param_data_1 = EM_SAFE_STRDUP(old_mailbox_data->mailbox_name); - event_data.event_param_data_2 = EM_SAFE_STRDUP(input_mailbox_path); - event_data.event_param_data_3 = EM_SAFE_STRDUP(input_mailbox_alias); - event_data.event_param_data_4 = input_mailbox_id; - event_data.account_id = old_mailbox_data->account_id; - - if (!emcore_insert_event(&event_data, (int*)output_handle, &err)) { + event_data = em_malloc(sizeof(email_event_t)); + event_data->type = EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER; + event_data->event_param_data_1 = EM_SAFE_STRDUP(old_mailbox_data->mailbox_name); + event_data->event_param_data_2 = EM_SAFE_STRDUP(input_mailbox_path); + event_data->event_param_data_3 = EM_SAFE_STRDUP(input_mailbox_alias); + event_data->event_param_data_4 = input_mailbox_id; + event_data->account_id = old_mailbox_data->account_id; + + if (!emcore_insert_event(event_data, (int*)output_handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } } - } - else { - if ((err = emcore_rename_mailbox(input_mailbox_id, input_mailbox_path, input_mailbox_alias, false, true, 0)) != EMAIL_ERROR_NONE) { + } else { + if ((err = emcore_rename_mailbox(input_mailbox_id, input_mailbox_path, input_mailbox_alias, input_eas_data, input_eas_data_length, false, true, 0)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_rename_mailbox failed [%d]", err); goto FINISH_OFF; } } + ret = true; + FINISH_OFF: + + if (ret == false && event_data) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + } + if (old_mailbox_data) emstorage_free_mailbox(&old_mailbox_data, 1, NULL); diff --git a/email-daemon/include/email-daemon-auto-poll.h b/email-daemon/include/email-daemon-auto-poll.h index b165b18..b3fa69b 100755 --- a/email-daemon/include/email-daemon-auto-poll.h +++ b/email-daemon/include/email-daemon-auto-poll.h @@ -41,7 +41,7 @@ extern "C" #endif /* __cplusplus */ -INTERNAL_FUNC int emdaemon_add_polling_alarm(int account_id, int alarm_interval); +INTERNAL_FUNC int emdaemon_add_polling_alarm(int account_id); INTERNAL_FUNC int emdaemon_remove_polling_alarm(int account_id); INTERNAL_FUNC int emdaemon_check_auto_polling_started(int account_id); INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_param); diff --git a/email-daemon/include/email-daemon-init.h b/email-daemon/include/email-daemon-init.h index 74760fc..9524e37 100755 --- a/email-daemon/include/email-daemon-init.h +++ b/email-daemon/include/email-daemon-init.h @@ -39,6 +39,14 @@ extern "C" #include "email-storage.h" +INTERNAL_FUNC int emdaemon_core_init(int *err_code); + +#ifdef __FEATURE_BLOCKING_MODE__ +INTERNAL_FUNC bool emdaemon_init_blocking_mode_status(); +#endif + +INTERNAL_FUNC int emdaemon_init_alarm_data_list(); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-daemon/include/email-daemon.h b/email-daemon/include/email-daemon.h index 06a742c..e82347c 100755 --- a/email-daemon/include/email-daemon.h +++ b/email-daemon/include/email-daemon.h @@ -634,7 +634,7 @@ INTERNAL_FUNC int emdaemon_validate_account_and_create(email_account_t* new_acco INTERNAL_FUNC int emdaemon_set_mail_slot_size_of_mailbox(int account_id, int mailbox_id, int new_slot_size, int *handle, int *err_code); -INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, int input_on_server, int *output_handle); +INTERNAL_FUNC int emdaemon_rename_mailbox(int input_mailbox_id, char *input_mailbox_path, char *input_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int *output_handle); INTERNAL_FUNC int emdaemon_move_mail_thread_to_mailbox(int thread_id, int target_mailbox_id, int move_always_flag, int *err_code); @@ -644,6 +644,17 @@ INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_fl INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle); +INTERNAL_FUNC int emdaemon_kill_daemon_if_no_account(); + +INTERNAL_FUNC int emdaemon_check_smack_rule(int app_sockfd, char *file_path); + +INTERNAL_FUNC int emdaemon_set_smack_label(char *file_path, char *label); + +INTERNAL_FUNC void emdaemon_start_alert(void); + +INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, int unread_mail_count, int *error); + +INTERNAL_FUNC int emdaemon_query_smtp_mail_size_limit(int account_id, int *handle, int* err_code); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-daemon/main.c b/email-daemon/main.c index 6c2109b..5a01c29 100755 --- a/email-daemon/main.c +++ b/email-daemon/main.c @@ -34,6 +34,7 @@ #include "email-daemon.h" #include "email-ipc.h" +#include "email-ipc-api-info.h" #include "email-utilities.h" #include "email-debug-log.h" #include "email-daemon-auto-poll.h" @@ -53,6 +54,7 @@ #include "email-core-task-manager.h" #include "email-core-signal.h" #include "email-storage.h" +#include "email-dbus-activation.h" void stb_create_account(HIPC_API a_hAPI) { @@ -76,9 +78,8 @@ void stb_create_account(HIPC_API a_hAPI) /* Convert account stream to structure */ em_convert_byte_stream_to_account(local_account_stream, buffer_size, &account); - - EM_DEBUG_LOG("Account name - %s", account.account_name); - EM_DEBUG_LOG("Email Address - %s", account.user_email_address); + EM_DEBUG_LOG_SEC("Account name - %s", account.account_name); + EM_DEBUG_LOG_SEC("Email Address - %s", account.user_email_address); if(!emdaemon_create_account(&account, &err)) { EM_DEBUG_EXCEPTION("emdaemon_create_account fail "); @@ -88,8 +89,8 @@ void stb_create_account(HIPC_API a_hAPI) #ifdef __FEATURE_AUTO_POLLING__ /* start auto polling, if check_interval not zero */ - if(account.check_interval > 0) { - if(!emdaemon_add_polling_alarm( account.account_id,account.check_interval)) + if(account.check_interval > 0 || (account.peak_days && account.peak_interval > 0)) { + if(!emdaemon_add_polling_alarm(account.account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> "); } #endif @@ -112,6 +113,7 @@ void stb_create_account(HIPC_API a_hAPI) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); FINISH_OFF: + if ( local_result == 0 ) { if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result "); @@ -120,6 +122,8 @@ FINISH_OFF: if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); } + + emcore_free_account(&account); /* valgrind */ EM_DEBUG_FUNC_END(); } @@ -128,10 +132,17 @@ void stb_delete_account(HIPC_API a_hAPI) EM_DEBUG_FUNC_BEGIN(); int account_id = 0; int local_result = 0; + int *ret_nth_value = NULL; int err = EMAIL_ERROR_NONE; /* account_id */ - account_id = *((int*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0)); + if ((ret_nth_value = (int *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0))) + account_id = *ret_nth_value; + else { + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + goto FINISH_OFF; + } + if(!emdaemon_delete_account(account_id, &err)) { if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) EM_DEBUG_LOG("emipc_add_parameter failed "); @@ -167,14 +178,19 @@ void stb_update_account(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int account_id = 0, buffer_size = 0, local_result = 0, with_validation = 0; + int *ret_nth_value = NULL; char* local_account_stream = NULL; email_account_t new_account_info = {0}; email_account_t old_account_info = {0}; int err = EMAIL_ERROR_NONE; int handle = 0; - account_id = *((int*)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0)); - + if ((ret_nth_value = (int *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0))) + account_id = *ret_nth_value; + else { + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + goto FINISH_OFF; + } /* get account structure from stream */ buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 1); EM_DEBUG_LOG("size [%d]", buffer_size); @@ -182,8 +198,12 @@ void stb_update_account(HIPC_API a_hAPI) em_convert_byte_stream_to_account(local_account_stream, buffer_size, &new_account_info); /*get validation flag */ - with_validation = *((int*)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 2)); - + if ((ret_nth_value = (int *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 2))) { + with_validation = *ret_nth_value; + } else { + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + goto FINISH_OFF; + } if(!emdaemon_get_account(account_id, EMAIL_ACC_GET_OPT_FULL_DATA, &old_account_info, &err)) { EM_DEBUG_EXCEPTION("emdaemon_get_account failed "); @@ -193,7 +213,7 @@ void stb_update_account(HIPC_API a_hAPI) if( EM_SAFE_STRLEN (new_account_info.incoming_server_password) == 0 ) { EM_SAFE_FREE(new_account_info.incoming_server_password); /* be allocated but has zero length */ - EM_DEBUG_LOG("old_account_info->incoming_server_password [%s]", old_account_info.incoming_server_password); + EM_DEBUG_LOG_SEC("old_account_info->incoming_server_password [%s]", old_account_info.incoming_server_password); new_account_info.incoming_server_password = EM_SAFE_STRDUP(old_account_info.incoming_server_password); if(new_account_info.incoming_server_password == NULL) { EM_DEBUG_EXCEPTION("allocation for new_account_info->password failed"); @@ -313,7 +333,7 @@ void stb_get_account_list(HIPC_API a_hAPI) EM_DEBUG_EXCEPTION("emipc_add_parameter count failed "); for(i=0; i<count; i++) { - EM_DEBUG_LOG("Name - %s", account_list[i].account_name); + EM_DEBUG_LOG_SEC("Name - %s", account_list[i].account_name); local_stream = em_convert_account_to_byte_stream(account_list+i, &size); @@ -359,14 +379,12 @@ void stb_sync_header(HIPC_API a_hAPI) /* account_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); - EM_DEBUG_LOG("account_id [%d]", account_id); - /* maibox_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &maibox_id); - EM_DEBUG_LOG("maibox_id [%d]", maibox_id); + EM_DEBUG_LOG("account_id [%d] maibox_id [%d]", account_id, maibox_id); - if(emdaemon_sync_header(account_id, maibox_id, &handle, &err)) { - EM_DEBUG_LOG("emdaemon_sync_header success "); + if(!emdaemon_sync_header(account_id, maibox_id, &handle, &err)) { + EM_DEBUG_EXCEPTION ("emdaemon_sync_header failed [%d]", err); } if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) @@ -420,12 +438,13 @@ FINISH_OFF: void stb_create_mailbox(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); - int buffer_size = 0; - int err = EMAIL_ERROR_NONE; - char *local_stream = NULL; - int on_server = 0; - email_mailbox_t mailbox = {0}; - int handle = 0; /* Added for cancelling mailbox creating */ + int buffer_size = 0; + int err = EMAIL_ERROR_NONE; + int *ret_nth_value = NULL; + char *local_stream = NULL; + int on_server = 0; + email_mailbox_t mailbox = { 0 }; + int handle = 0; /* Added for cancelling mailbox creating */ buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0); EM_DEBUG_LOG("size [%d]", buffer_size); @@ -438,13 +457,19 @@ void stb_create_mailbox(HIPC_API a_hAPI) local_stream = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0); em_convert_byte_stream_to_mailbox(local_stream, buffer_size, &mailbox); - EM_DEBUG_LOG("Mailbox name - %s", mailbox.mailbox_name); + EM_DEBUG_LOG_SEC("Mailbox name - %s", mailbox.mailbox_name); - on_server = *((int*)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1)); + if ((ret_nth_value = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1))) + on_server = *ret_nth_value; + else + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; emdaemon_add_mailbox(&mailbox, on_server, &handle, &err); FINISH_OFF: + + emcore_free_mailbox(&mailbox); + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1"); if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) @@ -609,7 +634,7 @@ void stb_rename_mailbox(HIPC_API a_hAPI) emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &on_server); EM_DEBUG_LOG("on_server[%d]", on_server); - if ((err = emdaemon_rename_mailbox(mailbox_id, mailbox_path, mailbox_alias, on_server, &handle)) != EMAIL_ERROR_NONE) { + if ((err = emdaemon_rename_mailbox(mailbox_id, mailbox_path, mailbox_alias, NULL, 0, on_server, &handle)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emdaemon_rename_mailbox failed [%d]", err); } @@ -628,6 +653,68 @@ void stb_rename_mailbox(HIPC_API a_hAPI) EM_DEBUG_FUNC_END(); } +void stb_rename_mailbox_ex(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + int buffer_size = 0; + int err = EMAIL_ERROR_NONE; + int handle = 0; + int mailbox_id = 0; + int on_server = 0; + int eas_data_length = 0; + char *mailbox_path = NULL; + char *mailbox_alias = NULL; + void *eas_data = NULL; + + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id); + EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id); + + buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1); + EM_DEBUG_LOG("mailbox_path string size[%d]", buffer_size); + if(buffer_size > 0) { + mailbox_path = (char*)em_malloc(buffer_size); + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, mailbox_path); + EM_DEBUG_LOG("mailbox_path [%s]", mailbox_path); + } + + buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2); + EM_DEBUG_LOG("mailbox_alias string size[%d]", buffer_size); + if(buffer_size > 0) { + mailbox_alias = (char*)em_malloc(buffer_size); + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, mailbox_alias); + EM_DEBUG_LOG("mailbox_alias [%s]", mailbox_alias); + } + + eas_data_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 3); + EM_DEBUG_LOG("eas_data_length size[%d]", eas_data_length); + if(eas_data_length > 0) { + eas_data = (char*)em_malloc(eas_data_length); + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, eas_data_length, eas_data); + } + + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 4, sizeof(int), &on_server); + EM_DEBUG_LOG("on_server[%d]", on_server); + + if ((err = emdaemon_rename_mailbox(mailbox_id, mailbox_path, mailbox_alias, eas_data, eas_data_length, on_server, &handle)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emdaemon_rename_mailbox failed [%d]", err); + } + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1"); + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed 2"); + + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + + EM_SAFE_FREE(mailbox_alias); + EM_SAFE_FREE(mailbox_path); + EM_SAFE_FREE(eas_data); + + EM_DEBUG_FUNC_END(); +} + void stb_send_mail(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); @@ -661,6 +748,35 @@ void stb_send_mail(HIPC_API a_hAPI) EM_DEBUG_FUNC_END(); } +void stb_query_smtp_mail_size_limit(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + + int account_id; + int handle; + int err = EMAIL_ERROR_NONE; + + /* Mail_id */ + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); + EM_DEBUG_LOG("account_id [%d]", account_id); + + if(emdaemon_query_smtp_mail_size_limit(account_id, &handle, &err)) { + err = EMAIL_ERROR_NONE; + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter result failed "); + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter result failed "); + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + } else { + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + } + + EM_DEBUG_FUNC_END(); +} /* obsolete - there is no api calling this function */ void stb_get_mailbox_list(HIPC_API a_hAPI) @@ -688,7 +804,7 @@ void stb_get_mailbox_list(HIPC_API a_hAPI) EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); for(counter=0; counter<count; counter++) { - EM_DEBUG_LOG("Name - %s", mailbox_list[counter].mailbox_name); + EM_DEBUG_LOG_SEC("Name - %s", mailbox_list[counter].mailbox_name); local_stream = em_convert_mailbox_to_byte_stream(mailbox_list+counter, &size); @@ -848,15 +964,20 @@ void stb_get_rule(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; + int *ret_nth_value = NULL; int filter_id = 0; email_rule_t* rule = NULL; int size =0; char* local_rule_stream = NULL; - filter_id = *((int*)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0)); - - emdaemon_get_filter(filter_id, &rule, &err); + if ((ret_nth_value = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0))) { + filter_id = *ret_nth_value; + emdaemon_get_filter(filter_id, &rule, &err); + } else { + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + } + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); @@ -970,12 +1091,18 @@ void stb_update_rule(HIPC_API a_hAPI) int filter_id = 0; int buffer_size = 0; int err = EMAIL_ERROR_NONE; + int *ret_nth_value = NULL; char* rule_stream = NULL; email_rule_t rule = {0}; /* get filter_id */ - filter_id = *((int*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0)); + if ((ret_nth_value = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0))) { + filter_id = *ret_nth_value; + } else { + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + goto FINISH_OFF; + } /* get rule */ buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 1); @@ -1110,15 +1237,18 @@ FINISH_OFF: void stb_add_mail(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); - int buffer_size = 0; - int local_result = 0; - int result_attachment_data_count = 0; - int param_index = 0; - int sync_server = 0; - int err = EMAIL_ERROR_NONE; + int buffer_size = 0; + int local_result = 0; + int result_attachment_data_count = 0; + int param_index = 0; + int sync_server = 0; + int err = EMAIL_ERROR_NONE; + int mdm_err = EMAIL_ERROR_NONE; + int i = 0; email_mail_data_t result_mail_data = {0}; email_attachment_data_t *result_attachment_data = NULL; email_meeting_request_t result_meeting_request = {0}; + emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; /* email_mail_data_t */; @@ -1131,27 +1261,63 @@ void stb_add_mail(HIPC_API a_hAPI) em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data); } - /* attachment */ - if (result_mail_data.attachment_count > 0) { - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); + /* check smack rule for accessing file path */ + if (result_mail_data.file_path_html) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_html)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } - if(buffer_size > 0) { - char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); + if (result_mail_data.file_path_plain) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_plain)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + + if (result_mail_data.file_path_mime_entity) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_mime_entity)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + /* check smack rule - END */ - EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); + /* attachment */ + buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); - if(result_attachment_data_count && !result_attachment_data) { + if(buffer_size > 0) { + char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); + em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); + + EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); + if (!result_attachment_data_count) { + EM_DEBUG_LOG("Not include attachment data"); + } else { + if(!result_attachment_data) { EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); err = EMAIL_ERROR_ON_PARSING; goto FINISH_OFF; } + param_index++; } - - param_index++; } + /* check smack rule for accessing file path */ + for (i = 0; i < result_attachment_data_count ; i++) { + if (result_attachment_data[i].attachment_path) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_attachment_data[i].attachment_path)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + } /* meeting request */ EM_DEBUG_LOG("email_meeting_request_t"); @@ -1215,9 +1381,11 @@ void stb_update_mail(HIPC_API a_hAPI) int sync_server = 0; int *temp_buffer = NULL; int err = EMAIL_ERROR_NONE; + int i = 0; email_mail_data_t result_mail_data = {0}; email_attachment_data_t *result_attachment_data = NULL; email_meeting_request_t result_meeting_request = {0}; + emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; EM_DEBUG_LOG("email_mail_data_t"); buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); @@ -1227,27 +1395,61 @@ void stb_update_mail(HIPC_API a_hAPI) em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data); } - if (result_mail_data.attachment_count > 0) { - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); - - if(buffer_size > 0) { - char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); + /* check smack rule for accessing file path */ + if (result_mail_data.file_path_html) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_html)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } - EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); + if (result_mail_data.file_path_plain) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_plain)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } - if(result_attachment_data_count && !result_attachment_data) { + if (result_mail_data.file_path_mime_entity) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_mime_entity)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + /* check smack rule - END */ + buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + if(buffer_size > 0) { + char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); + em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); + + EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); + if (!result_attachment_data_count) { + EM_DEBUG_LOG("Not include attachment data"); + } else { + if(!result_attachment_data) { EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); err = EMAIL_ERROR_ON_PARSING; goto FINISH_OFF; } + param_index++; } - param_index++; } - EM_DEBUG_LOG("email_meeting_request_t"); + /* check smack rule for accessing file path */ + for (i = 0; i < result_attachment_data_count ; i++) { + if (result_attachment_data[i].attachment_path) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_attachment_data[i].attachment_path)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + } + EM_DEBUG_LOG("email_meeting_request_t"); if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { @@ -1522,8 +1724,10 @@ void stb_add_attachment(HIPC_API a_hAPI) int err = EMAIL_ERROR_NONE; int mail_id = -1; int attachment_count = 0; + int i = 0; char* attachment_stream = NULL; email_attachment_data_t* attachment = NULL; + emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; /* mail_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id); @@ -1543,11 +1747,25 @@ void stb_add_attachment(HIPC_API a_hAPI) if (!attachment) { EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed "); - return; + err = EMAIL_ERROR_ON_PARSING; + goto FINISH_OFF; + } + + /* check smack rule for accessing file path */ + for (i = 0; i < attachment_count ; i++) { + if (attachment[i].attachment_path) { + if (!emdaemon_check_smack_rule(api_info->response_id, attachment[i].attachment_path)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } } emdaemon_add_attachment(mail_id, attachment, &err); +FINISH_OFF: + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed "); if(EMAIL_ERROR_NONE == err) { @@ -1773,10 +1991,8 @@ void stb_cancel_job(HIPC_API a_hAPI) int err = EMAIL_ERROR_NONE; emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); - EM_DEBUG_LOG("account_id [%d]", account_id); - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &handle); - EM_DEBUG_LOG("handle [%d]", handle); + EM_DEBUG_LOG("account_id [%d] handle [%d]", account_id, handle); if(emdaemon_cancel_job(account_id, handle, &err)) err = EMAIL_ERROR_NONE; @@ -1968,7 +2184,7 @@ void stb_add_account_with_validation(HIPC_API a_hAPI) } ref_check_interval = ref_account->check_interval; - ref_account_id = ref_account->account_id; + ref_account_id = ref_account->account_id; if(!emdaemon_validate_account_and_create(ref_account, &handle, &err)) { EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_create fail [%d]", err); @@ -1976,8 +2192,8 @@ void stb_add_account_with_validation(HIPC_API a_hAPI) } #ifdef __FEATURE_AUTO_POLLING__ /* start auto polling, if check_interval not zero */ - if(ref_check_interval > 0) { - if(!emdaemon_add_polling_alarm(ref_account_id, ref_check_interval)) + if(ref_check_interval > 0 || (ref_account->peak_days && ref_account->peak_interval > 0)) { + if(!emdaemon_add_polling_alarm(ref_account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> "); } #endif /* __FEATURE_AUTO_POLLING__ */ @@ -2022,7 +2238,7 @@ void stb_backup_account(HIPC_API a_hAPI) EM_DEBUG_LOG("file_path_length [%d]", file_path_length); file_path = em_malloc(file_path_length); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path); - EM_DEBUG_LOG("file_path [%s]", file_path); + EM_DEBUG_LOG_SEC("file_path [%s]", file_path); local_result = emcore_backup_accounts((const char*)file_path, &err_code); } @@ -2056,7 +2272,7 @@ void stb_restore_account(HIPC_API a_hAPI) EM_DEBUG_LOG("file_path_length [%d]", file_path_length); file_path = em_malloc(file_path_length); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path); - EM_DEBUG_LOG("file_path [%s]", file_path); + EM_DEBUG_LOG_SEC("file_path [%s]", file_path); local_result = emcore_restore_accounts((const char*)file_path, &err_code); } @@ -2082,13 +2298,16 @@ void stb_get_password_length(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int account_id = 0; + int password_type = 0; int local_result = 0; int err_code = 0; int password_length = 0; /* account_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); - local_result = emstorage_get_password_length_of_account(account_id, &password_length,&err_code); + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &password_type); + + local_result = emstorage_get_password_length_of_account(account_id, password_type, &password_length,&err_code); EM_DEBUG_LOG("password_length [%d]", password_length); @@ -2147,6 +2366,7 @@ void stb_add_certificate(HIPC_API a_hAPI) int email_address_len = 0; char *cert_file_path = NULL; char *email_address = NULL; + emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0); if (cert_file_len > 0) { @@ -2154,6 +2374,15 @@ void stb_add_certificate(HIPC_API a_hAPI) emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path); } + /* check smack rule for accessing file path */ + if (cert_file_path) { + if (!emdaemon_check_smack_rule(api_info->response_id, cert_file_path)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1); if (email_address_len > 0) { email_address = em_malloc(email_address_len + 1); @@ -2164,6 +2393,8 @@ void stb_add_certificate(HIPC_API a_hAPI) EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed"); } +FINISH_OFF: + if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed "); @@ -2174,9 +2405,9 @@ void stb_add_certificate(HIPC_API a_hAPI) if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); - EM_SAFE_FREE(cert_file_path); - EM_SAFE_FREE(email_address); - EM_DEBUG_FUNC_END(); + EM_SAFE_FREE(cert_file_path); + EM_SAFE_FREE(email_address); + EM_DEBUG_FUNC_END(); } void stb_delete_certificate(HIPC_API a_hAPI) @@ -2191,7 +2422,7 @@ void stb_delete_certificate(HIPC_API a_hAPI) EM_DEBUG_LOG("email address string length [%d]", email_address_len); email_address = em_malloc(email_address_len + 1); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, email_address_len, email_address); - EM_DEBUG_LOG("email address [%s]", email_address); + EM_DEBUG_LOG_SEC("email address [%s]", email_address); } SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address); @@ -2317,11 +2548,13 @@ void stb_ping_service(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + EM_DEBUG_FUNC_END(); } @@ -2329,13 +2562,20 @@ void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE, account_id; + int total_mail_count = 0, unread_mail_count = 0; /* account_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); EM_DEBUG_LOG("account_id [%d]", account_id); - if(!emcore_finalize_sync(account_id, &err)) { - EM_DEBUG_EXCEPTION("emcore_finalize_sync failed [%d]", err); + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &total_mail_count); + EM_DEBUG_LOG("total_mail_count [%d]", total_mail_count); + + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &unread_mail_count); + EM_DEBUG_LOG("unread_mail_count [%d]", unread_mail_count); + + if(!emdaemon_finalize_sync(account_id, total_mail_count, unread_mail_count, &err)) { + EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err); } if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) @@ -2396,6 +2636,7 @@ void stb_write_mime_file(HIPC_API a_hAPI) email_attachment_data_t *result_attachment_data = NULL; emstorage_mail_tbl_t *input_mail_tbl_data = NULL; emstorage_attachment_tbl_t *input_attachment_tbl_data = NULL; + emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; /* email_mail_data_t */; buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); @@ -2407,32 +2648,68 @@ void stb_write_mime_file(HIPC_API a_hAPI) em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data); } - /* attachment */ - if (result_mail_data.attachment_count > 0) { - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); + /* check smack rule for accessing file path */ + if (result_mail_data.file_path_html) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_html)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } - if(buffer_size > 0) { - char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); + if (result_mail_data.file_path_plain) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_plain)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + + if (result_mail_data.file_path_mime_entity) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_mime_entity)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } + /* check smack rule - END */ - EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); + /* attachment */ + buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); + + if(buffer_size > 0) { + char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); + em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); - if(result_attachment_data_count && !result_attachment_data) { + EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); + if (!result_attachment_data_count) { + EM_DEBUG_LOG("Not include attachment data"); + } else { + if(!result_attachment_data) { EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); err = EMAIL_ERROR_ON_PARSING; goto FINISH_OFF; } + param_index++; } + } - param_index++; + /* check smack rule for accessing file path */ + for (i = 0; i < result_attachment_data_count ; i++) { + if (result_attachment_data[i].attachment_path && result_attachment_data[i].save_status) { + if (!emdaemon_check_smack_rule(api_info->response_id, result_attachment_data[i].attachment_path)) { + EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); + err = EMAIL_ERROR_NO_SMACK_RULE; + goto FINISH_OFF; + } + } } - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); if (buffer_size > 0) { output_file_path = (char *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("output_file_path : [%s]", output_file_path); + EM_DEBUG_LOG_SEC("output_file_path : [%s]", output_file_path); } /* Convert mail_data to mail_tbl */ @@ -2465,11 +2742,6 @@ void stb_write_mime_file(HIPC_API a_hAPI) input_attachment_tbl_data[i].attachment_mime_type = EM_SAFE_STRDUP(result_attachment_data[i].attachment_mime_type); } - if ((err = em_verify_email_address_of_mail_tbl(input_mail_tbl_data, false)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("em_verify_email_address_of_mail_tbl failed : [%d]", err); - goto FINISH_OFF; - } - if (!emcore_make_rfc822_file_from_mail(input_mail_tbl_data, input_attachment_tbl_data, result_attachment_data_count, NULL, &file_path, NULL, &err)) { EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed"); goto FINISH_OFF; @@ -2485,11 +2757,8 @@ void stb_write_mime_file(HIPC_API a_hAPI) output_file_path = EM_SAFE_STRDUP(file_path); } - - if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, (char *)output_file_path, EM_SAFE_STRLEN(output_file_path) + 1)) { - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - err = EMAIL_ERROR_NULL_VALUE; - goto FINISH_OFF; + if (!emdaemon_set_smack_label(output_file_path, "system::media")) { + EM_DEBUG_EXCEPTION("emdaemon_set_smack_label failed"); } local_result = 1; @@ -2498,6 +2767,15 @@ FINISH_OFF: if ( local_result == 0 ) { if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + } else { + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + + if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, (char *)output_file_path, EM_SAFE_STRLEN(output_file_path) + 1)) { + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + err = EMAIL_ERROR_NULL_VALUE; + goto FINISH_OFF; + } } if (!emipc_execute_stub_api(a_hAPI)) @@ -2568,6 +2846,7 @@ void stb_validate_account_ex(HIPC_API a_hAPI) goto FINISH_OFF; } + /* ref_account will be removed by worker_event_queue() */ if((err = emdaemon_validate_account_ex(ref_account, &handle)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emdaemon_validate_account_ex fail [%d]", err); goto FINISH_OFF; @@ -2591,9 +2870,6 @@ FINISH_OFF: EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); } -/* note: account is freed in thread_func_branch_command, which is run by other thread */ -/* emcore_free_account(account); */ - EM_DEBUG_FUNC_END(); } void stb_handle_task(int task_type, HIPC_API a_hAPI) @@ -2944,8 +3220,24 @@ FINISH_OFF: void stb_API_mapper(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; int nAPIID = emipc_get_api_id(a_hAPI); +#ifdef __FEATURE_ACCESS_CONTROL__ + int nAPPID = emipc_get_app_id(a_hAPI); + err = em_check_socket_privilege_by_pid(nAPPID); + if (err == EMAIL_ERROR_PERMISSION_DENIED) { + EM_DEBUG_LOG("permission denied"); + if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); + + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); + + return; + } +#endif + switch(nAPIID) { case _EMAIL_API_ADD_ACCOUNT: stb_create_account(a_hAPI); @@ -2975,10 +3267,18 @@ void stb_API_mapper(HIPC_API a_hAPI) stb_rename_mailbox(a_hAPI); break; + case _EMAIL_API_RENAME_MAILBOX_EX: + stb_rename_mailbox_ex(a_hAPI); + break; + case _EMAIL_API_SEND_MAIL: stb_send_mail(a_hAPI); break; + case _EMAIL_API_QUERY_SMTP_MAIL_SIZE_LIMIT: + stb_query_smtp_mail_size_limit(a_hAPI); + break; + case _EMAIL_API_GET_MAILBOX_LIST: stb_get_mailbox_list(a_hAPI); break; @@ -3219,6 +3519,43 @@ static void callback_for_sigterm(int signum) EM_DEBUG_FUNC_END(); } +gboolean callback_for_timeout(gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("user_data[%p]", user_data); + + if(emipc_get_launch_method() != EMAIL_LAUNCHED_BY_DBUS_ACTIVATION) { + emdaemon_kill_daemon_if_no_account(); + } + + EM_DEBUG_FUNC_END(); + return FALSE; +} + +gboolean callback_for_del_account (GIOChannel *ch, GIOCondition cond, gpointer data) +{ + static int file_del = 0; + static int db_del = 0; + int event = 0; + gsize len = 0; + g_io_channel_read_chars (ch, (gchar*) &event, sizeof (event), &len, NULL); + + if (event==EMAIL_SIGNAL_DB_DELETED) { + db_del = 1; + } + else if (event==EMAIL_SIGNAL_FILE_DELETED) { + file_del = 1; + } + EM_DEBUG_LOG ("callback_for_del_account called file_del[%d] db_del[%d]", file_del, db_del); + + /* if called twice, process termination begins. + two threads should complete the delete task */ + if (file_del && db_del) { + emdaemon_kill_daemon_if_no_account(); + file_del = db_del = 0; /* if there is an account, reset status */ + } + return TRUE; +} + INTERNAL_FUNC int main(int argc, char *argv[]) { /* Do the email-service Initialization @@ -3255,11 +3592,9 @@ INTERNAL_FUNC int main(int argc, char *argv[]) /* Clean up resources */ g_main_loop_unref(mainloop); - g_mainloop = NULL; emipc_finalize_stub(); - emdaemon_finalize(NULL); EM_DEBUG_FUNC_END(); |